Skip to content

Commit 4ddf151

Browse files
committed
Fix quite-bogus handling of arrays in plpython datum-to-PyObject
conversion. Per bug #5497 from David Gardner.
1 parent 932de89 commit 4ddf151

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/pl/plpython/plpython.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**********************************************************************
22
* plpython.c - python as a procedural language for PostgreSQL
33
*
4-
* $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.143 2010/05/01 17:04:38 tgl Exp $
4+
* $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.144 2010/06/10 04:05:01 tgl Exp $
55
*
66
*********************************************************************
77
*/
@@ -1838,6 +1838,7 @@ PLy_input_datum_func2(PLyDatumToOb *arg, Oid typeOid, HeapTuple typeTup)
18381838
arg->typioparam = getTypeIOParam(typeTup);
18391839
arg->typbyval = typeStruct->typbyval;
18401840
arg->typlen = typeStruct->typlen;
1841+
arg->typalign = typeStruct->typalign;
18411842

18421843
/* Determine which kind of Python object we will convert to */
18431844
switch (getBaseType(element_type ? element_type : typeOid))
@@ -1873,10 +1874,17 @@ PLy_input_datum_func2(PLyDatumToOb *arg, Oid typeOid, HeapTuple typeTup)
18731874

18741875
if (element_type)
18751876
{
1877+
char dummy_delim;
1878+
Oid funcid;
1879+
18761880
arg->elm = PLy_malloc0(sizeof(*arg->elm));
18771881
arg->elm->func = arg->func;
18781882
arg->func = PLyList_FromArray;
1879-
get_typlenbyvalalign(element_type, &arg->elm->typlen, &arg->elm->typbyval, &arg->elm->typalign);
1883+
arg->elm->typoid = element_type;
1884+
get_type_io_data(element_type, IOFunc_output,
1885+
&arg->elm->typlen, &arg->elm->typbyval, &arg->elm->typalign, &dummy_delim,
1886+
&arg->elm->typioparam, &funcid);
1887+
perm_fmgr_info(funcid, &arg->elm->typfunc);
18801888
}
18811889
}
18821890

@@ -1986,6 +1994,7 @@ static PyObject *
19861994
PLyList_FromArray(PLyDatumToOb *arg, Datum d)
19871995
{
19881996
ArrayType *array = DatumGetArrayTypeP(d);
1997+
PLyDatumToOb *elm = arg->elm;
19891998
PyObject *list;
19901999
int length;
19912000
int lbound;
@@ -2011,11 +2020,13 @@ PLyList_FromArray(PLyDatumToOb *arg, Datum d)
20112020
int offset;
20122021

20132022
offset = lbound + i;
2014-
elem = array_ref(array, 1, &offset, arg->typlen, arg->elm->typlen, arg->elm->typbyval, arg->elm->typalign, &isnull);
2023+
elem = array_ref(array, 1, &offset, arg->typlen,
2024+
elm->typlen, elm->typbyval, elm->typalign,
2025+
&isnull);
20152026
if (isnull)
20162027
PyList_SET_ITEM(list, i, Py_None);
20172028
else
2018-
PyList_SET_ITEM(list, i, arg->elm->func(arg, elem));
2029+
PyList_SET_ITEM(list, i, elm->func(elm, elem));
20192030
}
20202031

20212032
return list;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy