1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-11 20:28:21 +03:00

Consistently catch errors from Python _New() functions

Python Py*_New() functions can fail and return NULL in out-of-memory
conditions.  The previous code handled that inconsistently or not at
all.  This change organizes that better.  If we are in a function that
is called from Python, we just check for failure and return NULL
ourselves, which will cause any exception information to be passed up.
If we are called from PostgreSQL, we consistently create an "out of
memory" error.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
This commit is contained in:
Peter Eisentraut
2017-10-31 10:49:36 -04:00
parent 976a1a48fc
commit d0aa965c0a
10 changed files with 70 additions and 23 deletions

View File

@ -46,6 +46,10 @@ ltree_to_plpython(PG_FUNCTION_ARGS)
ltree_level *curlevel;
list = PyList_New(in->numlevel);
if (!list)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
curlevel = LTREE_FIRST(in);
for (i = 0; i < in->numlevel; i++)