mirror of
https://github.com/postgres/postgres.git
synced 2026-10-29 15:58:33 +03:00
Our maintenance of typedefs.list has been a little haphazard (and apparently we can't alphabetize worth a darn). Replace the file with the authoritative list from our buildfarm, and run pgindent using that. I also updated the additions/exclusions lists in pgindent where necessary to keep pgindent from messing things up significantly. Notably, now that regex_t and some related names are macros not real typedefs, we have to whitelist them explicitly. The exclusions list has also drifted noticeably, presumably due to changes of system headers on the buildfarm animals that contribute to the list. Unlike in prior years, I've not manually added typedef names that are missing from the buildfarm's list because they are not used to declare any variables or fields. So there are a few places where the typedef declaration itself is formatted worse than before, e.g. typedef enum IoMethod. I could preserve the names that were manually added to the list previously, but I'd really prefer to find a less manual way of dealing with these cases. A quick grep finds about 75 such symbols, most of which have never gotten any special treatment. Per discussion among pgsql-release, doing this now seems appropriate even though we're still a week or two away from making the v18 branch.
152 lines
2.8 KiB
C
152 lines
2.8 KiB
C
/*
|
|
* the PLyPlan class
|
|
*
|
|
* src/pl/plpython/plpy_planobject.c
|
|
*/
|
|
|
|
#include "postgres.h"
|
|
|
|
#include "plpy_cursorobject.h"
|
|
#include "plpy_planobject.h"
|
|
#include "plpy_spi.h"
|
|
#include "plpy_util.h"
|
|
#include "utils/memutils.h"
|
|
|
|
static void PLy_plan_dealloc(PLyPlanObject *self);
|
|
static PyObject *PLy_plan_cursor(PyObject *self, PyObject *args);
|
|
static PyObject *PLy_plan_execute(PyObject *self, PyObject *args);
|
|
static PyObject *PLy_plan_status(PyObject *self, PyObject *args);
|
|
|
|
static char PLy_plan_doc[] = "Store a PostgreSQL plan";
|
|
|
|
static PyMethodDef PLy_plan_methods[] = {
|
|
{"cursor", PLy_plan_cursor, METH_VARARGS, NULL},
|
|
{"execute", PLy_plan_execute, METH_VARARGS, NULL},
|
|
{"status", PLy_plan_status, METH_VARARGS, NULL},
|
|
{NULL, NULL, 0, NULL}
|
|
};
|
|
|
|
static PyType_Slot PLyPlan_slots[] =
|
|
{
|
|
{
|
|
Py_tp_dealloc, PLy_plan_dealloc
|
|
},
|
|
{
|
|
Py_tp_doc, (char *) PLy_plan_doc
|
|
},
|
|
{
|
|
Py_tp_methods, PLy_plan_methods
|
|
},
|
|
{
|
|
0, NULL
|
|
}
|
|
};
|
|
|
|
static PyType_Spec PLyPlan_spec =
|
|
{
|
|
.name = "PLyPlan",
|
|
.basicsize = sizeof(PLyPlanObject),
|
|
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
|
|
.slots = PLyPlan_slots,
|
|
};
|
|
|
|
static PyTypeObject *PLy_PlanType;
|
|
|
|
void
|
|
PLy_plan_init_type(void)
|
|
{
|
|
PLy_PlanType = (PyTypeObject *) PyType_FromSpec(&PLyPlan_spec);
|
|
if (!PLy_PlanType)
|
|
elog(ERROR, "could not initialize PLy_PlanType");
|
|
}
|
|
|
|
PyObject *
|
|
PLy_plan_new(void)
|
|
{
|
|
PLyPlanObject *ob;
|
|
|
|
if ((ob = PyObject_New(PLyPlanObject, PLy_PlanType)) == NULL)
|
|
return NULL;
|
|
#if PY_VERSION_HEX < 0x03080000
|
|
/* Workaround for Python issue 35810; no longer necessary in Python 3.8 */
|
|
Py_INCREF(PLy_PlanType);
|
|
#endif
|
|
|
|
ob->plan = NULL;
|
|
ob->nargs = 0;
|
|
ob->types = NULL;
|
|
ob->args = NULL;
|
|
ob->mcxt = NULL;
|
|
|
|
return (PyObject *) ob;
|
|
}
|
|
|
|
bool
|
|
is_PLyPlanObject(PyObject *ob)
|
|
{
|
|
return ob->ob_type == PLy_PlanType;
|
|
}
|
|
|
|
static void
|
|
PLy_plan_dealloc(PLyPlanObject *self)
|
|
{
|
|
#if PY_VERSION_HEX >= 0x03080000
|
|
PyTypeObject *tp = Py_TYPE(self);
|
|
#endif
|
|
|
|
if (self->plan)
|
|
{
|
|
SPI_freeplan(self->plan);
|
|
self->plan = NULL;
|
|
}
|
|
if (self->mcxt)
|
|
{
|
|
MemoryContextDelete(self->mcxt);
|
|
self->mcxt = NULL;
|
|
}
|
|
|
|
PyObject_Free(self);
|
|
#if PY_VERSION_HEX >= 0x03080000
|
|
/* This was not needed before Python 3.8 (Python issue 35810) */
|
|
Py_DECREF(tp);
|
|
#endif
|
|
}
|
|
|
|
|
|
static PyObject *
|
|
PLy_plan_cursor(PyObject *self, PyObject *args)
|
|
{
|
|
PyObject *planargs = NULL;
|
|
|
|
if (!PyArg_ParseTuple(args, "|O", &planargs))
|
|
return NULL;
|
|
|
|
return PLy_cursor_plan(self, planargs);
|
|
}
|
|
|
|
|
|
static PyObject *
|
|
PLy_plan_execute(PyObject *self, PyObject *args)
|
|
{
|
|
PyObject *list = NULL;
|
|
long limit = 0;
|
|
|
|
if (!PyArg_ParseTuple(args, "|Ol", &list, &limit))
|
|
return NULL;
|
|
|
|
return PLy_spi_execute_plan(self, list, limit);
|
|
}
|
|
|
|
|
|
static PyObject *
|
|
PLy_plan_status(PyObject *self, PyObject *args)
|
|
{
|
|
if (PyArg_ParseTuple(args, ":status"))
|
|
{
|
|
Py_INCREF(Py_True);
|
|
return Py_True;
|
|
/* return PyLong_FromLong(self->status); */
|
|
}
|
|
return NULL;
|
|
}
|