Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 549928d

Browse files
committed
Fix for breakage of C-coded SRFs, from Joe Conway.
1 parent e2d156f commit 549928d

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

src/backend/utils/fmgr/funcapi.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Copyright (c) 2002, PostgreSQL Global Development Group
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/fmgr/funcapi.c,v 1.4 2002/08/29 17:14:33 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/fmgr/funcapi.c,v 1.5 2002/08/30 19:56:49 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -83,8 +83,16 @@ per_MultiFuncCall(PG_FUNCTION_ARGS)
8383
{
8484
FuncCallContext *retval = (FuncCallContext *) fcinfo->flinfo->fn_extra;
8585

86-
/* make sure we start with a fresh slot */
87-
if(retval->slot != NULL)
86+
/*
87+
* Clear the TupleTableSlot, if present. This is for safety's sake:
88+
* the Slot will be in a long-lived context (it better be, if the
89+
* FuncCallContext is pointing to it), but in most usage patterns the
90+
* tuples stored in it will be in the function's per-tuple context.
91+
* So at the beginning of each call, the Slot will hold a dangling
92+
* pointer to an already-recycled tuple. We clear it out here. (See
93+
* also the definition of TupleGetDatum() in funcapi.h!)
94+
*/
95+
if (retval->slot != NULL)
8896
ExecClearTuple(retval->slot);
8997

9098
return retval;

src/include/funcapi.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
* Copyright (c) 2002, PostgreSQL Global Development Group
1111
*
12-
* $Id: funcapi.h,v 1.6 2002/08/29 17:14:33 tgl Exp $
12+
* $Id: funcapi.h,v 1.7 2002/08/30 19:56:49 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -147,8 +147,12 @@ extern TupleTableSlot *TupleDescGetSlot(TupleDesc tupdesc);
147147
extern AttInMetadata *TupleDescGetAttInMetadata(TupleDesc tupdesc);
148148
extern HeapTuple BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values);
149149

150+
/*
151+
* Note we pass shouldFree = false; this is needed because the tuple will
152+
* typically be in a shorter-lived memory context than the TupleTableSlot.
153+
*/
150154
#define TupleGetDatum(_slot, _tuple) \
151-
PointerGetDatum(ExecStoreTuple(_tuple, _slot, InvalidBuffer, true))
155+
PointerGetDatum(ExecStoreTuple(_tuple, _slot, InvalidBuffer, false))
152156

153157

154158
/*----------

src/test/regress/expected/rangefuncs.out

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
SELECT * FROM pg_settings WHERE name LIKE 'enable%';
2+
name | setting
3+
------------------+---------
4+
enable_hashjoin | on
5+
enable_indexscan | on
6+
enable_mergejoin | on
7+
enable_nestloop | on
8+
enable_seqscan | on
9+
enable_sort | on
10+
enable_tidscan | on
11+
(7 rows)
12+
113
CREATE TABLE foo2(fooid int, f2 int);
214
INSERT INTO foo2 VALUES(1, 11);
315
INSERT INTO foo2 VALUES(2, 22);

src/test/regress/sql/rangefuncs.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
SELECT * FROM pg_settings WHERE name LIKE 'enable%';
2+
13
CREATE TABLE foo2(fooid int, f2 int);
24
INSERT INTO foo2 VALUES(1, 11);
35
INSERT INTO foo2 VALUES(2, 22);

0 commit comments

Comments
 (0)