Prepare for Python "Limited API" in PL/Python
authorPeter Eisentraut
Wed, 12 Mar 2025 07:49:37 +0000 (08:49 +0100)
committerPeter Eisentraut
Wed, 12 Mar 2025 07:53:54 +0000 (08:53 +0100)
commit72a3d0462b9a7f6265267950668af0c0246e7c01
tree8360cb6fc037f984a888458f8f978471ee81b98e
parentc872516d8fe5ba3ce27e7020fad887d90d308e29
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().

This was previously committed as c47e8df815c and then reverted because
it wasn't working under Python older than 3.8.  That has been fixed in
this version.  There was a Python API change/bugfix between 3.7 and
3.8 that directly affects this patch.  The relevant commit is
364f0b0f19c>.  The
workarounds described there have been applied in this patch, and it
has been confirmed to work with Python 3.6 and 3.7.

Reviewed-by: Jakob Egger
Discussion: https://www.postgresql.org/message-id/flat/ee410de1-1e0b-4770-b125-eeefd4726a24@eisentraut.org
src/pl/plpython/plpy_cursorobject.c
src/pl/plpython/plpy_planobject.c
src/pl/plpython/plpy_procedure.c
src/pl/plpython/plpy_resultobject.c
src/pl/plpython/plpy_subxactobject.c
src/pl/plpython/plpy_typeio.c