summaryrefslogtreecommitdiff
path: root/src/pl/plpython/plpy_planobject.c
diff options
context:
space:
mode:
authorPeter Eisentraut2011-12-18 19:14:16 +0000
committerPeter Eisentraut2011-12-18 19:24:00 +0000
commit147c2482542868d1f9dcf7d2ecfeac58d845335c (patch)
tree11617370d58bfc7ff6cca2b5b78212dd804a1147 /src/pl/plpython/plpy_planobject.c
parent59e242a4969d2efa6ce68dc7aab3cbd8cf975b08 (diff)
Split plpython.c into smaller pieces
This moves the code around from one huge file into hopefully logical and more manageable modules. For the most part, the code itself was not touched, except: PLy_function_handler and PLy_trigger_handler were renamed to PLy_exec_function and PLy_exec_trigger, because they were not actually handlers in the PL handler sense, and it makes the naming more similar to the way PL/pgSQL is organized. The initialization of the procedure caches was separated into a new function init_procedure_caches to keep the hash tables private to plpy_procedures.c. Jan UrbaƄski and Peter Eisentraut
Diffstat (limited to 'src/pl/plpython/plpy_planobject.c')
-rw-r--r--src/pl/plpython/plpy_planobject.c128
1 files changed, 128 insertions, 0 deletions
diff --git a/src/pl/plpython/plpy_planobject.c b/src/pl/plpython/plpy_planobject.c
new file mode 100644
index 00000000000..01b40d1d817
--- /dev/null
+++ b/src/pl/plpython/plpy_planobject.c
@@ -0,0 +1,128 @@
+/*
+ * the PLyPlan class
+ *
+ * src/pl/plpython/plpy_planobject.c
+ */
+
+#include "postgres.h"
+
+#include "plpython.h"
+
+#include "plpy_planobject.h"
+
+#include "plpy_elog.h"
+
+
+static void PLy_plan_dealloc(PyObject *);
+static PyObject *PLy_plan_status(PyObject *, PyObject *);
+
+static char PLy_plan_doc[] = {
+ "Store a PostgreSQL plan"
+};
+
+static PyMethodDef PLy_plan_methods[] = {
+ {"status", PLy_plan_status, METH_VARARGS, NULL},
+ {NULL, NULL, 0, NULL}
+};
+
+static PyTypeObject PLy_PlanType = {
+ PyVarObject_HEAD_INIT(NULL, 0)
+ "PLyPlan", /* tp_name */
+ sizeof(PLyPlanObject), /* tp_size */
+ 0, /* tp_itemsize */
+
+ /*
+ * methods
+ */
+ PLy_plan_dealloc, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
+ PLy_plan_doc, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ PLy_plan_methods, /* tp_tpmethods */
+};
+
+void
+PLy_plan_init_type(void)
+{
+ if (PyType_Ready(&PLy_PlanType) < 0)
+ elog(ERROR, "could not initialize PLy_PlanType");
+}
+
+PyObject *
+PLy_plan_new(void)
+{
+ PLyPlanObject *ob;
+
+ if ((ob = PyObject_New(PLyPlanObject, &PLy_PlanType)) == NULL)
+ return NULL;
+
+ ob->plan = NULL;
+ ob->nargs = 0;
+ ob->types = NULL;
+ ob->values = NULL;
+ ob->args = NULL;
+
+ return (PyObject *) ob;
+}
+
+bool
+is_PLyPlanObject(PyObject *ob)
+{
+ return ob->ob_type == &PLy_PlanType;
+}
+
+static void
+PLy_plan_dealloc(PyObject *arg)
+{
+ PLyPlanObject *ob = (PLyPlanObject *) arg;
+
+ if (ob->plan)
+ SPI_freeplan(ob->plan);
+ if (ob->types)
+ PLy_free(ob->types);
+ if (ob->values)
+ PLy_free(ob->values);
+ if (ob->args)
+ {
+ int i;
+
+ for (i = 0; i < ob->nargs; i++)
+ PLy_typeinfo_dealloc(&ob->args[i]);
+ PLy_free(ob->args);
+ }
+
+ arg->ob_type->tp_free(arg);
+}
+
+
+static PyObject *
+PLy_plan_status(PyObject *self, PyObject *args)
+{
+ if (PyArg_ParseTuple(args, ""))
+ {
+ Py_INCREF(Py_True);
+ return Py_True;
+ /* return PyInt_FromLong(self->status); */
+ }
+ PLy_exception_set(PLy_exc_error, "plan.status takes no arguments");
+ return NULL;
+}