aboutsummaryrefslogtreecommitdiff
path: root/src/pl/plpython/plpy_subxactobject.c
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2025-02-26 16:14:16 +0100
committerPeter Eisentraut <peter@eisentraut.org>2025-02-26 16:14:39 +0100
commitc47e8df815c1c45f4e4fc90d5817d67ab088279f (patch)
tree3302d85398d391115c202da0155cbc9c34983f29 /src/pl/plpython/plpy_subxactobject.c
parent0e42d31b0b2273c376ce9de946b59d155fac589c (diff)
downloadpostgresql-c47e8df815c1c45f4e4fc90d5817d67ab088279f.tar.gz
postgresql-c47e8df815c1c45f4e4fc90d5817d67ab088279f.zip
Prepare for Python "Limited API" in PL/Python
Using the Python Limited API would allow building PL/Python against any Python 3.x version and using another Python 3.x version at run time. This commit does not activate that, but it prepares the code to only use APIs supported by the Limited API. Implementation details: - Convert static types to heap types (https://docs.python.org/3/howto/isolating-extensions.html#heap-types). - Replace PyRun_String() with component functions. - Replace PyList_SET_ITEM() with PyList_SetItem(). Reviewed-by: Jakob Egger <jakob@eggerapps.at> Discussion: https://www.postgresql.org/message-id/flat/ee410de1-1e0b-4770-b125-eeefd4726a24@eisentraut.org
Diffstat (limited to 'src/pl/plpython/plpy_subxactobject.c')
-rw-r--r--src/pl/plpython/plpy_subxactobject.c41
1 files changed, 24 insertions, 17 deletions
diff --git a/src/pl/plpython/plpy_subxactobject.c b/src/pl/plpython/plpy_subxactobject.c
index 5c92a0e089a..cc7ff3f9df7 100644
--- a/src/pl/plpython/plpy_subxactobject.c
+++ b/src/pl/plpython/plpy_subxactobject.c
@@ -15,7 +15,6 @@
List *explicit_subtransactions = NIL;
-static void PLy_subtransaction_dealloc(PyObject *subxact);
static PyObject *PLy_subtransaction_enter(PyObject *self, PyObject *unused);
static PyObject *PLy_subtransaction_exit(PyObject *self, PyObject *args);
@@ -31,21 +30,35 @@ static PyMethodDef PLy_subtransaction_methods[] = {
{NULL, NULL, 0, NULL}
};
-static PyTypeObject PLy_SubtransactionType = {
- PyVarObject_HEAD_INIT(NULL, 0)
- .tp_name = "PLySubtransaction",
- .tp_basicsize = sizeof(PLySubtransactionObject),
- .tp_dealloc = PLy_subtransaction_dealloc,
- .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- .tp_doc = PLy_subtransaction_doc,
- .tp_methods = PLy_subtransaction_methods,
+static PyType_Slot PLySubtransaction_slots[] =
+{
+ {
+ Py_tp_doc, (char *) PLy_subtransaction_doc
+ },
+ {
+ Py_tp_methods, PLy_subtransaction_methods
+ },
+ {
+ 0, NULL
+ }
+};
+
+static PyType_Spec PLySubtransaction_spec =
+{
+ .name = "PLySubtransaction",
+ .basicsize = sizeof(PLySubtransactionObject),
+ .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+ .slots = PLySubtransaction_slots,
};
+static PyTypeObject *PLy_SubtransactionType;
+
void
PLy_subtransaction_init_type(void)
{
- if (PyType_Ready(&PLy_SubtransactionType) < 0)
+ PLy_SubtransactionType = (PyTypeObject *) PyType_FromSpec(&PLySubtransaction_spec);
+ if (!PLy_SubtransactionType)
elog(ERROR, "could not initialize PLy_SubtransactionType");
}
@@ -55,7 +68,7 @@ PLy_subtransaction_new(PyObject *self, PyObject *unused)
{
PLySubtransactionObject *ob;
- ob = PyObject_New(PLySubtransactionObject, &PLy_SubtransactionType);
+ ob = PyObject_New(PLySubtransactionObject, PLy_SubtransactionType);
if (ob == NULL)
return NULL;
@@ -66,12 +79,6 @@ PLy_subtransaction_new(PyObject *self, PyObject *unused)
return (PyObject *) ob;
}
-/* Python requires a dealloc function to be defined */
-static void
-PLy_subtransaction_dealloc(PyObject *subxact)
-{
-}
-
/*
* subxact.__enter__() or subxact.enter()
*