Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f734c9f

Browse files
committed
Revert "Prepare for Python "Limited API" in PL/Python"
This reverts commit c47e8df. That commit makes the plpython tests crash with Python 3.6.* and 3.7.*. It will need further investigation and testing, so revert for now.
1 parent 945a9e3 commit f734c9f

File tree

6 files changed

+105
-177
lines changed

6 files changed

+105
-177
lines changed

src/pl/plpython/plpy_cursorobject.c

Lines changed: 25 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "utils/memutils.h"
2121

2222
static PyObject *PLy_cursor_query(const char *query);
23-
static void PLy_cursor_dealloc(PLyCursorObject *self);
23+
static void PLy_cursor_dealloc(PyObject *arg);
2424
static PyObject *PLy_cursor_iternext(PyObject *self);
2525
static PyObject *PLy_cursor_fetch(PyObject *self, PyObject *args);
2626
static PyObject *PLy_cursor_close(PyObject *self, PyObject *unused);
@@ -33,43 +33,22 @@ static PyMethodDef PLy_cursor_methods[] = {
3333
{NULL, NULL, 0, NULL}
3434
};
3535

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-
}
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,
5646
};
5747

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-
6848
void
6949
PLy_cursor_init_type(void)
7050
{
71-
PLy_CursorType = (PyTypeObject *) PyType_FromSpec(&PLyCursor_spec);
72-
if (!PLy_CursorType)
51+
if (PyType_Ready(&PLy_CursorType) < 0)
7352
elog(ERROR, "could not initialize PLy_CursorType");
7453
}
7554

@@ -101,7 +80,7 @@ PLy_cursor_query(const char *query)
10180
volatile MemoryContext oldcontext;
10281
volatile ResourceOwner oldowner;
10382

104-
if ((cursor = PyObject_New(PLyCursorObject, PLy_CursorType)) == NULL)
83+
if ((cursor = PyObject_New(PLyCursorObject, &PLy_CursorType)) == NULL)
10584
return NULL;
10685
cursor->portalname = NULL;
10786
cursor->closed = false;
@@ -198,7 +177,7 @@ PLy_cursor_plan(PyObject *ob, PyObject *args)
198177
return NULL;
199178
}
200179

201-
if ((cursor = PyObject_New(PLyCursorObject, PLy_CursorType)) == NULL)
180+
if ((cursor = PyObject_New(PLyCursorObject, &PLy_CursorType)) == NULL)
202181
return NULL;
203182
cursor->portalname = NULL;
204183
cursor->closed = false;
@@ -293,30 +272,30 @@ PLy_cursor_plan(PyObject *ob, PyObject *args)
293272
}
294273

295274
static void
296-
PLy_cursor_dealloc(PLyCursorObject *self)
275+
PLy_cursor_dealloc(PyObject *arg)
297276
{
298-
PyTypeObject *tp = Py_TYPE(self);
277+
PLyCursorObject *cursor;
299278
Portal portal;
300279

301-
if (!self->closed)
280+
cursor = (PLyCursorObject *) arg;
281+
282+
if (!cursor->closed)
302283
{
303-
portal = GetPortalByName(self->portalname);
284+
portal = GetPortalByName(cursor->portalname);
304285

305286
if (PortalIsValid(portal))
306287
{
307288
UnpinPortal(portal);
308289
SPI_cursor_close(portal);
309290
}
310-
self->closed = true;
291+
cursor->closed = true;
311292
}
312-
if (self->mcxt)
293+
if (cursor->mcxt)
313294
{
314-
MemoryContextDelete(self->mcxt);
315-
self->mcxt = NULL;
295+
MemoryContextDelete(cursor->mcxt);
296+
cursor->mcxt = NULL;
316297
}
317-
318-
PyObject_Free(self);
319-
Py_DECREF(tp);
298+
arg->ob_type->tp_free(arg);
320299
}
321300

322301
static PyObject *

src/pl/plpython/plpy_planobject.c

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "plpython.h"
1313
#include "utils/memutils.h"
1414

15-
static void PLy_plan_dealloc(PLyPlanObject *self);
15+
static void PLy_plan_dealloc(PyObject *arg);
1616
static PyObject *PLy_plan_cursor(PyObject *self, PyObject *args);
1717
static PyObject *PLy_plan_execute(PyObject *self, PyObject *args);
1818
static PyObject *PLy_plan_status(PyObject *self, PyObject *args);
@@ -26,37 +26,20 @@ static PyMethodDef PLy_plan_methods[] = {
2626
{NULL, NULL, 0, NULL}
2727
};
2828

29-
static PyType_Slot PLyPlan_slots[] =
30-
{
31-
{
32-
Py_tp_dealloc, PLy_plan_dealloc
33-
},
34-
{
35-
Py_tp_doc, (char *) PLy_plan_doc
36-
},
37-
{
38-
Py_tp_methods, PLy_plan_methods
39-
},
40-
{
41-
0, NULL
42-
}
29+
static PyTypeObject PLy_PlanType = {
30+
PyVarObject_HEAD_INIT(NULL, 0)
31+
.tp_name = "PLyPlan",
32+
.tp_basicsize = sizeof(PLyPlanObject),
33+
.tp_dealloc = PLy_plan_dealloc,
34+
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
35+
.tp_doc = PLy_plan_doc,
36+
.tp_methods = PLy_plan_methods,
4337
};
4438

45-
static PyType_Spec PLyPlan_spec =
46-
{
47-
.name = "PLyPlan",
48-
.basicsize = sizeof(PLyPlanObject),
49-
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
50-
.slots = PLyPlan_slots,
51-
};
52-
53-
static PyTypeObject *PLy_PlanType;
54-
5539
void
5640
PLy_plan_init_type(void)
5741
{
58-
PLy_PlanType = (PyTypeObject *) PyType_FromSpec(&PLyPlan_spec);
59-
if (!PLy_PlanType)
42+
if (PyType_Ready(&PLy_PlanType) < 0)
6043
elog(ERROR, "could not initialize PLy_PlanType");
6144
}
6245

@@ -65,7 +48,7 @@ PLy_plan_new(void)
6548
{
6649
PLyPlanObject *ob;
6750

68-
if ((ob = PyObject_New(PLyPlanObject, PLy_PlanType)) == NULL)
51+
if ((ob = PyObject_New(PLyPlanObject, &PLy_PlanType)) == NULL)
6952
return NULL;
7053

7154
ob->plan = NULL;
@@ -80,27 +63,25 @@ PLy_plan_new(void)
8063
bool
8164
is_PLyPlanObject(PyObject *ob)
8265
{
83-
return ob->ob_type == PLy_PlanType;
66+
return ob->ob_type == &PLy_PlanType;
8467
}
8568

8669
static void
87-
PLy_plan_dealloc(PLyPlanObject *self)
70+
PLy_plan_dealloc(PyObject *arg)
8871
{
89-
PyTypeObject *tp = Py_TYPE(self);
72+
PLyPlanObject *ob = (PLyPlanObject *) arg;
9073

91-
if (self->plan)
74+
if (ob->plan)
9275
{
93-
SPI_freeplan(self->plan);
94-
self->plan = NULL;
76+
SPI_freeplan(ob->plan);
77+
ob->plan = NULL;
9578
}
96-
if (self->mcxt)
79+
if (ob->mcxt)
9780
{
98-
MemoryContextDelete(self->mcxt);
99-
self->mcxt = NULL;
81+
MemoryContextDelete(ob->mcxt);
82+
ob->mcxt = NULL;
10083
}
101-
102-
PyObject_Free(self);
103-
Py_DECREF(tp);
84+
arg->ob_type->tp_free(arg);
10485
}
10586

10687

src/pl/plpython/plpy_procedure.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,6 @@ PLy_procedure_compile(PLyProcedure *proc, const char *src)
350350
{
351351
PyObject *crv = NULL;
352352
char *msrc;
353-
PyObject *code0;
354353

355354
proc->globals = PyDict_Copy(PLy_interp_globals);
356355

@@ -369,9 +368,7 @@ PLy_procedure_compile(PLyProcedure *proc, const char *src)
369368
msrc = PLy_procedure_munge_source(proc->pyname, src);
370369
/* Save the mangled source for later inclusion in tracebacks */
371370
proc->src = MemoryContextStrdup(proc->mcxt, msrc);
372-
code0 = Py_CompileString(msrc, "<string>", Py_file_input);
373-
if (code0)
374-
crv = PyEval_EvalCode(code0, proc->globals, NULL);
371+
crv = PyRun_String(msrc, Py_file_input, proc->globals, NULL);
375372
pfree(msrc);
376373

377374
if (crv != NULL)

0 commit comments

Comments
 (0)