Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7748e9e

Browse files
committed
pltcl, plperl, and plpython all suffer the same bug previously fixed
in plpgsql: they fail for datatypes that have old-style I/O functionsdue to caching FmgrInfo structs with wrong fn_mcxt lifetime.Although the plpython fix seems straightforward, I can't check it heresince I don't have Python installed --- would someone check it?
1 parent7c0c9b3 commit7748e9e

File tree

3 files changed

+85
-19
lines changed

3 files changed

+85
-19
lines changed

‎src/pl/plperl/plperl.c

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* ENHANCEMENTS, OR MODIFICATIONS.
3434
*
3535
* IDENTIFICATION
36-
* $Header: /cvsroot/pgsql/src/pl/plperl/plperl.c,v 1.19 2001/03/22 04:01:40 momjian Exp $
36+
* $Header: /cvsroot/pgsql/src/pl/plperl/plperl.c,v 1.20 2001/06/01 18:17:44 tgl Exp $
3737
*
3838
**********************************************************************/
3939

@@ -163,6 +163,27 @@ static void plperl_set_tuple_values(Tcl_Interp *interp, char *arrayname,
163163
#endif
164164

165165

166+
/*
167+
* This routine is a crock, and so is everyplace that calls it. The problem
168+
* is that the cached form of plperl functions/queries is allocated permanently
169+
* (mostly via malloc()) and never released until backend exit. Subsidiary
170+
* data structures such as fmgr info records therefore must live forever
171+
* as well. A better implementation would store all this stuff in a per-
172+
* function memory context that could be reclaimed at need. In the meantime,
173+
* fmgr_info must be called in TopMemoryContext so that whatever it might
174+
* allocate, and whatever the eventual function might allocate using fn_mcxt,
175+
* will live forever too.
176+
*/
177+
staticvoid
178+
perm_fmgr_info(OidfunctionId,FmgrInfo*finfo)
179+
{
180+
MemoryContextoldcontext;
181+
182+
oldcontext=MemoryContextSwitchTo(TopMemoryContext);
183+
fmgr_info(functionId,finfo);
184+
MemoryContextSwitchTo(oldcontext);
185+
}
186+
166187
/**********************************************************************
167188
* plperl_init_all()- Initialize all
168189
**********************************************************************/
@@ -562,7 +583,7 @@ plperl_func_handler(PG_FUNCTION_ARGS)
562583
elog(ERROR,"plperl: return types of tuples not supported yet");
563584
}
564585

565-
fmgr_info(typeStruct->typinput,&(prodesc->result_in_func));
586+
perm_fmgr_info(typeStruct->typinput,&(prodesc->result_in_func));
566587
prodesc->result_in_elem= (Oid) (typeStruct->typelem);
567588
prodesc->result_in_len=typeStruct->typlen;
568589

@@ -595,7 +616,7 @@ plperl_func_handler(PG_FUNCTION_ARGS)
595616
else
596617
prodesc->arg_is_rel[i]=0;
597618

598-
fmgr_info(typeStruct->typoutput,&(prodesc->arg_out_func[i]));
619+
perm_fmgr_info(typeStruct->typoutput,&(prodesc->arg_out_func[i]));
599620
prodesc->arg_out_elem[i]= (Oid) (typeStruct->typelem);
600621
prodesc->arg_out_len[i]=typeStruct->typlen;
601622
ReleaseSysCache(typeTup);
@@ -1560,8 +1581,8 @@ plperl_SPI_prepare(ClientData cdata, Tcl_Interp *interp,
15601581
if (!HeapTupleIsValid(typeTup))
15611582
elog(ERROR,"plperl: Cache lookup of type %s failed",args[i]);
15621583
qdesc->argtypes[i]=typeTup->t_data->t_oid;
1563-
fmgr_info(((Form_pg_type)GETSTRUCT(typeTup))->typinput,
1564-
&(qdesc->arginfuncs[i]));
1584+
perm_fmgr_info(((Form_pg_type)GETSTRUCT(typeTup))->typinput,
1585+
&(qdesc->arginfuncs[i]));
15651586
qdesc->argtypelems[i]= ((Form_pg_type)GETSTRUCT(typeTup))->typelem;
15661587
qdesc->argvalues[i]= (Datum)NULL;
15671588
qdesc->arglen[i]= (int) (((Form_pg_type)GETSTRUCT(typeTup))->typlen);

‎src/pl/plpython/plpython.c

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
/* $Header: /cvsroot/pgsql/src/pl/plpython/plpython.c,v 1.3 2001/05/25 15:48:33 momjian Exp $ */
2-
3-
/*
1+
/**********************************************************************
42
* plpython.c - python as a procedural language for PostgreSQL
53
*
6-
* IDENTIFICATION
7-
*
84
* This software is copyright by Andrew Bosma
95
* but is really shameless cribbed from pltcl.c by Jan Weick, and
106
* plperl.c by Mark Hollomon.
@@ -32,7 +28,11 @@
3228
* AND THE AUTHOR AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
3329
* MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
3430
*
35-
**********************************************************************/
31+
* IDENTIFICATION
32+
*$Header: /cvsroot/pgsql/src/pl/plpython/plpython.c,v 1.4 2001/06/01 18:17:44 tgl Exp $
33+
*
34+
*********************************************************************
35+
*/
3636

3737
#include"postgres.h"
3838

@@ -296,8 +296,32 @@ volatile int func_enter_calls = 0;
296296
volatileintfunc_leave_calls=0;
297297
#endif
298298

299-
/* the function definitions
299+
/*
300+
* the function definitions
300301
*/
302+
303+
/*
304+
* This routine is a crock, and so is everyplace that calls it. The problem
305+
* is that the cached form of plpython functions/queries is allocated permanently
306+
* (mostly via malloc()) and never released until backend exit. Subsidiary
307+
* data structures such as fmgr info records therefore must live forever
308+
* as well. A better implementation would store all this stuff in a per-
309+
* function memory context that could be reclaimed at need. In the meantime,
310+
* fmgr_info must be called in TopMemoryContext so that whatever it might
311+
* allocate, and whatever the eventual function might allocate using fn_mcxt,
312+
* will live forever too.
313+
*/
314+
staticvoid
315+
perm_fmgr_info(OidfunctionId,FmgrInfo*finfo)
316+
{
317+
MemoryContextoldcontext;
318+
319+
oldcontext=MemoryContextSwitchTo(TopMemoryContext);
320+
fmgr_info(functionId,finfo);
321+
MemoryContextSwitchTo(oldcontext);
322+
}
323+
324+
301325
Datum
302326
plpython_call_handler(PG_FUNCTION_ARGS)
303327
{
@@ -1282,7 +1306,7 @@ PLy_output_datum_func2(PLyObToDatum *arg, Form_pg_type typeStruct)
12821306
{
12831307
enter();
12841308

1285-
fmgr_info(typeStruct->typinput,&arg->typfunc);
1309+
perm_fmgr_info(typeStruct->typinput,&arg->typfunc);
12861310
arg->typelem= (Oid)typeStruct->typelem;
12871311
arg->typlen=typeStruct->typlen;
12881312
}
@@ -1304,7 +1328,7 @@ PLy_input_datum_func2(PLyDatumToOb *arg, Form_pg_type typeStruct)
13041328
char*type;
13051329

13061330
arg->typoutput=typeStruct->typoutput;
1307-
fmgr_info(typeStruct->typoutput,&arg->typfunc);
1331+
perm_fmgr_info(typeStruct->typoutput,&arg->typfunc);
13081332
arg->typlen=typeStruct->typlen;
13091333
arg->typelem=typeStruct->typelem;
13101334

‎src/pl/tcl/pltcl.c

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* ENHANCEMENTS, OR MODIFICATIONS.
3232
*
3333
* IDENTIFICATION
34-
* $Header: /cvsroot/pgsql/src/pl/tcl/pltcl.c,v 1.35 2001/05/11 23:38:06 petere Exp $
34+
* $Header: /cvsroot/pgsql/src/pl/tcl/pltcl.c,v 1.36 2001/06/01 18:17:44 tgl Exp $
3535
*
3636
**********************************************************************/
3737

@@ -145,6 +145,27 @@ static void pltcl_set_tuple_values(Tcl_Interp *interp, char *arrayname,
145145
staticvoidpltcl_build_tuple_argument(HeapTupletuple,TupleDesctupdesc,
146146
Tcl_DString*retval);
147147

148+
/*
149+
* This routine is a crock, and so is everyplace that calls it. The problem
150+
* is that the cached form of pltcl functions/queries is allocated permanently
151+
* (mostly via malloc()) and never released until backend exit. Subsidiary
152+
* data structures such as fmgr info records therefore must live forever
153+
* as well. A better implementation would store all this stuff in a per-
154+
* function memory context that could be reclaimed at need. In the meantime,
155+
* fmgr_info must be called in TopMemoryContext so that whatever it might
156+
* allocate, and whatever the eventual function might allocate using fn_mcxt,
157+
* will live forever too.
158+
*/
159+
staticvoid
160+
perm_fmgr_info(OidfunctionId,FmgrInfo*finfo)
161+
{
162+
MemoryContextoldcontext;
163+
164+
oldcontext=MemoryContextSwitchTo(TopMemoryContext);
165+
fmgr_info(functionId,finfo);
166+
MemoryContextSwitchTo(oldcontext);
167+
}
168+
148169
/**********************************************************************
149170
* pltcl_init_all()- Initialize all
150171
**********************************************************************/
@@ -508,7 +529,7 @@ pltcl_func_handler(PG_FUNCTION_ARGS)
508529
elog(ERROR,"pltcl: return types of tuples not supported yet");
509530
}
510531

511-
fmgr_info(typeStruct->typinput,&(prodesc->result_in_func));
532+
perm_fmgr_info(typeStruct->typinput,&(prodesc->result_in_func));
512533
prodesc->result_in_elem=typeStruct->typelem;
513534

514535
ReleaseSysCache(typeTup);
@@ -549,7 +570,7 @@ pltcl_func_handler(PG_FUNCTION_ARGS)
549570
else
550571
prodesc->arg_is_rel[i]=0;
551572

552-
fmgr_info(typeStruct->typoutput,&(prodesc->arg_out_func[i]));
573+
perm_fmgr_info(typeStruct->typoutput,&(prodesc->arg_out_func[i]));
553574
prodesc->arg_out_elem[i]= (Oid) (typeStruct->typelem);
554575
prodesc->arg_out_len[i]=typeStruct->typlen;
555576

@@ -1760,8 +1781,8 @@ pltcl_SPI_prepare(ClientData cdata, Tcl_Interp *interp,
17601781
if (!HeapTupleIsValid(typeTup))
17611782
elog(ERROR,"pltcl: Cache lookup of type %s failed",args[i]);
17621783
qdesc->argtypes[i]=typeTup->t_data->t_oid;
1763-
fmgr_info(((Form_pg_type)GETSTRUCT(typeTup))->typinput,
1764-
&(qdesc->arginfuncs[i]));
1784+
perm_fmgr_info(((Form_pg_type)GETSTRUCT(typeTup))->typinput,
1785+
&(qdesc->arginfuncs[i]));
17651786
qdesc->argtypelems[i]= ((Form_pg_type)GETSTRUCT(typeTup))->typelem;
17661787
qdesc->argvalues[i]= (Datum)NULL;
17671788
qdesc->arglen[i]= (int) (((Form_pg_type)GETSTRUCT(typeTup))->typlen);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp