pl/python refactoring

From: Jan Urbański <wulczer(at)wulczer(dot)org>
To: Postgres - Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: pl/python refactoring
Date: 2010-12-23 13:41:04
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Here's the base refactoring patch mentioned in

Git branch for this patch:

It does some architectural changes to PL/Python that make it easier to
implement other features, like for instance a validator function. The
full list of changes in the patch is:

* Use HTABs keyed with OIDs for procedure and trigger caches. Using
Python dictionaries for these caches seemes like using the wrong tool,
and then you get better error reporting and memory management with PG HTABs.

* Get rid of global error state. It was wrong, 'nuff said.

* Fix an error when the iterator was left half-open after an error.

* Factor out PLy_procedure_{input,output}_conversion functions.

* Use palloc in TopMemoryContext instead of malloc. As discussed in

* Use PyObject_New instead of PyObject_NEW (which is undocumented).

* Reset exception state after catching an error from SPI calls. Doing
SPI calls in subtransactions will remove the need to do that altogether,
so this little wart will go away soon.

* Correctly put the exceptions in the plpy module. Previous coding
failed for Python 3 (the exceptions were not available on Python 3 from
the plpy module, see the new test in plpython_test.sql and also

* Define all fields of the PyModuleDef structure for Python 3 (see Not sure why
this worked at all, I guess by some lucky coincidence the undefined
fields were falling in an accessible memory region filled with zeroes...

* Raise normal exceptions from plpy.error() instead of relying on the
global error state.

* Do not prefix error messages with "PL/Python: ". It's redundant given
the error context.

All other PL/Python patches rely on these refactorings.


Attachment Content-Type Size
plpython-refactor.diff text/x-patch 61.3 KB


Browse pgsql-hackers by date

  From Date Subject
Next Message Jan Urbański 2010-12-23 13:41:21 pl/python validator function
Previous Message Pavel Golub 2010-12-23 12:11:59 Cannot compile Pg 9.0.2 with MinGW under Windows