20
20
#include "utils/memutils.h"
21
21
22
22
static PyObject * PLy_cursor_query (const char * query );
23
- static void PLy_cursor_dealloc (PyObject * arg );
23
+ static void PLy_cursor_dealloc (PLyCursorObject * self );
24
24
static PyObject * PLy_cursor_iternext (PyObject * self );
25
25
static PyObject * PLy_cursor_fetch (PyObject * self , PyObject * args );
26
26
static PyObject * PLy_cursor_close (PyObject * self , PyObject * unused );
@@ -33,22 +33,43 @@ static PyMethodDef PLy_cursor_methods[] = {
33
33
{NULL , NULL , 0 , NULL }
34
34
};
35
35
36
- static PyTypeObject PLy_CursorType = {
37
- PyVarObject_HEAD_INIT (NULL , 0 )
38
- .tp_name = "PLyCursor" ,
39
- .tp_basicsize = sizeof (PLyCursorObject ),
40
- .tp_dealloc = PLy_cursor_dealloc ,
41
- .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE ,
42
- .tp_doc = PLy_cursor_doc ,
43
- .tp_iter = PyObject_SelfIter ,
44
- .tp_iternext = PLy_cursor_iternext ,
45
- .tp_methods = PLy_cursor_methods ,
36
+ static PyType_Slot PLyCursor_slots [] =
37
+ {
38
+ {
39
+ Py_tp_dealloc , PLy_cursor_dealloc
40
+ },
41
+ {
42
+ Py_tp_doc , (char * ) PLy_cursor_doc
43
+ },
44
+ {
45
+ Py_tp_iter , PyObject_SelfIter
46
+ },
47
+ {
48
+ Py_tp_iternext , PLy_cursor_iternext
49
+ },
50
+ {
51
+ Py_tp_methods , PLy_cursor_methods
52
+ },
53
+ {
54
+ 0 , NULL
55
+ }
46
56
};
47
57
58
+ static PyType_Spec PLyCursor_spec =
59
+ {
60
+ .name = "PLyCursor" ,
61
+ .basicsize = sizeof (PLyCursorObject ),
62
+ .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE ,
63
+ .slots = PLyCursor_slots ,
64
+ };
65
+
66
+ static PyTypeObject * PLy_CursorType ;
67
+
48
68
void
49
69
PLy_cursor_init_type (void )
50
70
{
51
- if (PyType_Ready (& PLy_CursorType ) < 0 )
71
+ PLy_CursorType = (PyTypeObject * ) PyType_FromSpec (& PLyCursor_spec );
72
+ if (!PLy_CursorType )
52
73
elog (ERROR , "could not initialize PLy_CursorType" );
53
74
}
54
75
@@ -80,7 +101,7 @@ PLy_cursor_query(const char *query)
80
101
volatile MemoryContext oldcontext ;
81
102
volatile ResourceOwner oldowner ;
82
103
83
- if ((cursor = PyObject_New (PLyCursorObject , & PLy_CursorType )) == NULL )
104
+ if ((cursor = PyObject_New (PLyCursorObject , PLy_CursorType )) == NULL )
84
105
return NULL ;
85
106
cursor -> portalname = NULL ;
86
107
cursor -> closed = false;
@@ -177,7 +198,7 @@ PLy_cursor_plan(PyObject *ob, PyObject *args)
177
198
return NULL ;
178
199
}
179
200
180
- if ((cursor = PyObject_New (PLyCursorObject , & PLy_CursorType )) == NULL )
201
+ if ((cursor = PyObject_New (PLyCursorObject , PLy_CursorType )) == NULL )
181
202
return NULL ;
182
203
cursor -> portalname = NULL ;
183
204
cursor -> closed = false;
@@ -272,30 +293,30 @@ PLy_cursor_plan(PyObject *ob, PyObject *args)
272
293
}
273
294
274
295
static void
275
- PLy_cursor_dealloc (PyObject * arg )
296
+ PLy_cursor_dealloc (PLyCursorObject * self )
276
297
{
277
- PLyCursorObject * cursor ;
298
+ PyTypeObject * tp = Py_TYPE ( self ) ;
278
299
Portal portal ;
279
300
280
- cursor = (PLyCursorObject * ) arg ;
281
-
282
- if (!cursor -> closed )
301
+ if (!self -> closed )
283
302
{
284
- portal = GetPortalByName (cursor -> portalname );
303
+ portal = GetPortalByName (self -> portalname );
285
304
286
305
if (PortalIsValid (portal ))
287
306
{
288
307
UnpinPortal (portal );
289
308
SPI_cursor_close (portal );
290
309
}
291
- cursor -> closed = true;
310
+ self -> closed = true;
292
311
}
293
- if (cursor -> mcxt )
312
+ if (self -> mcxt )
294
313
{
295
- MemoryContextDelete (cursor -> mcxt );
296
- cursor -> mcxt = NULL ;
314
+ MemoryContextDelete (self -> mcxt );
315
+ self -> mcxt = NULL ;
297
316
}
298
- arg -> ob_type -> tp_free (arg );
317
+
318
+ PyObject_Free (self );
319
+ Py_DECREF (tp );
299
320
}
300
321
301
322
static PyObject *
0 commit comments