diff options
Diffstat (limited to 'src/pl/plpython/plpy_cursorobject.c')
-rw-r--r-- | src/pl/plpython/plpy_cursorobject.c | 71 |
1 files changed, 25 insertions, 46 deletions
diff --git a/src/pl/plpython/plpy_cursorobject.c b/src/pl/plpython/plpy_cursorobject.c index 2a370157f90..bb3fa8a3909 100644 --- a/src/pl/plpython/plpy_cursorobject.c +++ b/src/pl/plpython/plpy_cursorobject.c @@ -20,7 +20,7 @@ #include "utils/memutils.h" static PyObject *PLy_cursor_query(const char *query); -static void PLy_cursor_dealloc(PLyCursorObject *self); +static void PLy_cursor_dealloc(PyObject *arg); static PyObject *PLy_cursor_iternext(PyObject *self); static PyObject *PLy_cursor_fetch(PyObject *self, PyObject *args); static PyObject *PLy_cursor_close(PyObject *self, PyObject *unused); @@ -33,43 +33,22 @@ static PyMethodDef PLy_cursor_methods[] = { {NULL, NULL, 0, NULL} }; -static PyType_Slot PLyCursor_slots[] = -{ - { - Py_tp_dealloc, PLy_cursor_dealloc - }, - { - Py_tp_doc, (char *) PLy_cursor_doc - }, - { - Py_tp_iter, PyObject_SelfIter - }, - { - Py_tp_iternext, PLy_cursor_iternext - }, - { - Py_tp_methods, PLy_cursor_methods - }, - { - 0, NULL - } +static PyTypeObject PLy_CursorType = { + PyVarObject_HEAD_INIT(NULL, 0) + .tp_name = "PLyCursor", + .tp_basicsize = sizeof(PLyCursorObject), + .tp_dealloc = PLy_cursor_dealloc, + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + .tp_doc = PLy_cursor_doc, + .tp_iter = PyObject_SelfIter, + .tp_iternext = PLy_cursor_iternext, + .tp_methods = PLy_cursor_methods, }; -static PyType_Spec PLyCursor_spec = -{ - .name = "PLyCursor", - .basicsize = sizeof(PLyCursorObject), - .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - .slots = PLyCursor_slots, -}; - -static PyTypeObject *PLy_CursorType; - void PLy_cursor_init_type(void) { - PLy_CursorType = (PyTypeObject *) PyType_FromSpec(&PLyCursor_spec); - if (!PLy_CursorType) + if (PyType_Ready(&PLy_CursorType) < 0) elog(ERROR, "could not initialize PLy_CursorType"); } @@ -101,7 +80,7 @@ PLy_cursor_query(const char *query) volatile MemoryContext oldcontext; volatile ResourceOwner oldowner; - if ((cursor = PyObject_New(PLyCursorObject, PLy_CursorType)) == NULL) + if ((cursor = PyObject_New(PLyCursorObject, &PLy_CursorType)) == NULL) return NULL; cursor->portalname = NULL; cursor->closed = false; @@ -198,7 +177,7 @@ PLy_cursor_plan(PyObject *ob, PyObject *args) return NULL; } - if ((cursor = PyObject_New(PLyCursorObject, PLy_CursorType)) == NULL) + if ((cursor = PyObject_New(PLyCursorObject, &PLy_CursorType)) == NULL) return NULL; cursor->portalname = NULL; cursor->closed = false; @@ -293,30 +272,30 @@ PLy_cursor_plan(PyObject *ob, PyObject *args) } static void -PLy_cursor_dealloc(PLyCursorObject *self) +PLy_cursor_dealloc(PyObject *arg) { - PyTypeObject *tp = Py_TYPE(self); + PLyCursorObject *cursor; Portal portal; - if (!self->closed) + cursor = (PLyCursorObject *) arg; + + if (!cursor->closed) { - portal = GetPortalByName(self->portalname); + portal = GetPortalByName(cursor->portalname); if (PortalIsValid(portal)) { UnpinPortal(portal); SPI_cursor_close(portal); } - self->closed = true; + cursor->closed = true; } - if (self->mcxt) + if (cursor->mcxt) { - MemoryContextDelete(self->mcxt); - self->mcxt = NULL; + MemoryContextDelete(cursor->mcxt); + cursor->mcxt = NULL; } - - PyObject_Free(self); - Py_DECREF(tp); + arg->ob_type->tp_free(arg); } static PyObject * |