Boszormenyi Zoltan wrote: > Hi, > > I am using this code on 8.4/8.5, which works on 64-bit, > but segfaults on 32-bit Linux: > I'm not sure but perhaps this patch could help you. It may be a bit outdated. -- Alvaro Herrera http://www.CommandPrompt.com/ PostgreSQL Replication, Consulting, Custom Development, 24x7 support
Index: doc/src/sgml/spi.sgml =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/doc/src/sgml/spi.sgml,v retrieving revision 1.65 diff -c -p -r1.65 spi.sgml *** doc/src/sgml/spi.sgml 5 Aug 2009 19:31:50 -0000 1.65 --- doc/src/sgml/spi.sgml 9 Oct 2009 20:16:58 -0000 *************** char * SPI_getnspname(Relation <paramete *** 2969,2974 **** --- 2969,2975 ---- allocations made by <function>palloc</function>, <function>repalloc</function>, or SPI utility functions (except for <function>SPI_copytuple</function>, + <function>SPI_copydatum</function>, <function>SPI_returntuple</function>, <function>SPI_modifytuple</function>, and <function>SPI_palloc</function>) are made in this context. When a *************** HeapTuple SPI_copytuple(HeapTuple <param *** 3221,3226 **** --- 3222,3301 ---- <!-- *********************************************** --> + <refentry id="spi-spi-copydatum"> + <refmeta> + <refentrytitle>SPI_copydatum</refentrytitle> + <manvolnum>3</manvolnum> + </refmeta> + + <refnamediv> + <refname>SPI_copydatum</refname> + <refpurpose>make a copy of a datum in the upper executor context</refpurpose> + </refnamediv> + + <indexterm><primary>SPI_copydatum</primary></indexterm> + + <refsynopsisdiv> + <synopsis> + Datum SPI_copydatum(Datum <parameter>value</parameter>, bool <parameter>typByVal</parameter>, int <parameter>typLen</parameter>) + </synopsis> + </refsynopsisdiv> + + <refsect1> + <title>Description</title> + + <para> + <function>SPI_copydatum</function> makes a copy of a datum in the + upper executor context. + </para> + </refsect1> + + <refsect1> + <title>Arguments</title> + + <variablelist> + <varlistentry> + <term><literal>Datum <parameter>value</parameter></literal></term> + <listitem> + <para> + datum to be copied + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term><literal>bool <parameter>typByVal</parameter></literal></term> + <listitem> + <para> + whether the type of the datum is passed by value + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term><literal>int <parameter>typLen</parameter></literal></term> + <listitem> + <para> + length of the type + </para> + </listitem> + </varlistentry> + + </variablelist> + </refsect1> + + <refsect1> + <title>Return Value</title> + + <para> + the copied datum; <symbol>NULL</symbol> only if + <parameter>value</parameter> is <symbol>NULL</symbol> + </para> + </refsect1> + </refentry> + + <!-- *********************************************** --> + <refentry id="spi-spi-returntuple"> <refmeta> <refentrytitle>SPI_returntuple</refentrytitle> Index: src/backend/executor/spi.c =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/src/backend/executor/spi.c,v retrieving revision 1.209 diff -c -p -r1.209 spi.c *** src/backend/executor/spi.c 2 Oct 2009 17:57:30 -0000 1.209 --- src/backend/executor/spi.c 9 Oct 2009 20:35:03 -0000 *************** SPI_copytuple(HeapTuple tuple) *** 615,620 **** --- 615,635 ---- return ctuple; } + Datum + SPI_copydatum(Datum value, bool typByVal, int typLen) + { + Size len; + void *tmp; + Datum retval; + + len = datumGetSize(value, typByVal, typLen); + tmp = SPI_palloc(len); + memcpy(tmp, DatumGetPointer(value), len); + retval = PointerGetDatum(tmp); + + return retval; + } + HeapTupleHeader SPI_returntuple(HeapTuple tuple, TupleDesc tupdesc) { Index: src/include/executor/spi.h =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/src/include/executor/spi.h,v retrieving revision 1.72 diff -c -p -r1.72 spi.h *** src/include/executor/spi.h 11 Jun 2009 14:49:11 -0000 1.72 --- src/include/executor/spi.h 9 Oct 2009 20:00:19 -0000 *************** extern bool SPI_plan_is_valid(SPIPlanPtr *** 98,103 **** --- 98,104 ---- extern const char *SPI_result_code_string(int code); extern HeapTuple SPI_copytuple(HeapTuple tuple); + extern Datum SPI_copydatum(Datum value, bool typByVal, int typLen); extern HeapTupleHeader SPI_returntuple(HeapTuple tuple, TupleDesc tupdesc); extern HeapTuple SPI_modifytuple(Relation rel, HeapTuple tuple, int natts, int *attnum, Datum *Values, const char *Nulls); Index: src/pl/plpgsql/src/pl_exec.c =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/src/pl/plpgsql/src/pl_exec.c,v retrieving revision 1.248 diff -c -p -r1.248 pl_exec.c *** src/pl/plpgsql/src/pl_exec.c 6 Aug 2009 20:44:31 -0000 1.248 --- src/pl/plpgsql/src/pl_exec.c 9 Oct 2009 20:36:01 -0000 *************** plpgsql_exec_function(PLpgSQL_function * *** 438,452 **** * into upper executor memory context. */ if (!fcinfo->isnull && !func->fn_retbyval) ! { ! Size len; ! void *tmp; ! ! len = datumGetSize(estate.retval, false, func->fn_rettyplen); ! tmp = SPI_palloc(len); ! memcpy(tmp, DatumGetPointer(estate.retval), len); ! estate.retval = PointerGetDatum(tmp); ! } } } --- 438,445 ---- * into upper executor memory context. */ if (!fcinfo->isnull && !func->fn_retbyval) ! estate.retval = SPI_copydatum(estate.retval, false, ! func->fn_rettyplen); } }
-- Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general