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

Commitb5d0051

Browse files
committed
Fix multiple causes of breakage in plperl's error handling.
1 parentb40bc9e commitb5d0051

File tree

1 file changed

+34
-61
lines changed

1 file changed

+34
-61
lines changed

‎src/pl/plperl/plperl.c

Lines changed: 34 additions & 61 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.35 2002/09/21 18:39:26 tgl Exp $
36+
* $Header: /cvsroot/pgsql/src/pl/plperl/plperl.c,v 1.36 2003/04/20 21:15:34 tgl Exp $
3737
*
3838
**********************************************************************/
3939

@@ -92,8 +92,6 @@ typedef struct plperl_proc_desc
9292
* Global data
9393
**********************************************************************/
9494
staticintplperl_firstcall=1;
95-
staticintplperl_call_level=0;
96-
staticintplperl_restart_in_progress=0;
9795
staticPerlInterpreter*plperl_interp=NULL;
9896
staticHV*plperl_proc_hash=NULL;
9997

@@ -143,6 +141,15 @@ plperl_init_all(void)
143141
if (!plperl_firstcall)
144142
return;
145143

144+
/************************************************************
145+
* Free the proc hash table
146+
************************************************************/
147+
if (plperl_proc_hash!=NULL)
148+
{
149+
hv_undef(plperl_proc_hash);
150+
SvREFCNT_dec((SV*)plperl_proc_hash);
151+
plperl_proc_hash=NULL;
152+
}
146153

147154
/************************************************************
148155
* Destroy the existing Perl interpreter
@@ -154,16 +161,6 @@ plperl_init_all(void)
154161
plperl_interp=NULL;
155162
}
156163

157-
/************************************************************
158-
* Free the proc hash table
159-
************************************************************/
160-
if (plperl_proc_hash!=NULL)
161-
{
162-
hv_undef(plperl_proc_hash);
163-
SvREFCNT_dec((SV*)plperl_proc_hash);
164-
plperl_proc_hash=NULL;
165-
}
166-
167164
/************************************************************
168165
* Now recreate a new Perl interpreter
169166
************************************************************/
@@ -202,8 +199,6 @@ plperl_init_interp(void)
202199
perl_parse(plperl_interp,plperl_init_shared_libs,3,embedding,NULL);
203200
perl_run(plperl_interp);
204201

205-
206-
207202
/************************************************************
208203
* Initialize the proc and query hash tables
209204
************************************************************/
@@ -212,7 +207,6 @@ plperl_init_interp(void)
212207
}
213208

214209

215-
216210
/**********************************************************************
217211
* plperl_call_handler- This is the only visible function
218212
* of the PL interpreter. The PostgreSQL
@@ -229,7 +223,7 @@ plperl_call_handler(PG_FUNCTION_ARGS)
229223
Datumretval;
230224

231225
/************************************************************
232-
* Initializeinterpreters on first call
226+
* Initializeinterpreter on first call
233227
************************************************************/
234228
if (plperl_firstcall)
235229
plperl_init_all();
@@ -239,10 +233,6 @@ plperl_call_handler(PG_FUNCTION_ARGS)
239233
************************************************************/
240234
if (SPI_connect()!=SPI_OK_CONNECT)
241235
elog(ERROR,"plperl: cannot connect to SPI manager");
242-
/************************************************************
243-
* Keep track about the nesting of Perl-SPI-Perl-... calls
244-
************************************************************/
245-
plperl_call_level++;
246236

247237
/************************************************************
248238
* Determine if called as function or trigger and
@@ -261,8 +251,6 @@ plperl_call_handler(PG_FUNCTION_ARGS)
261251
else
262252
retval=plperl_func_handler(fcinfo);
263253

264-
plperl_call_level--;
265-
266254
returnretval;
267255
}
268256

@@ -272,24 +260,35 @@ plperl_call_handler(PG_FUNCTION_ARGS)
272260
*create the anonymous subroutine whose text is in the SV.
273261
*Returns the SV containing the RV to the closure.
274262
**********************************************************************/
275-
static
276-
SV*
263+
staticSV*
277264
plperl_create_sub(char*s,booltrusted)
278265
{
279266
dSP;
280-
281-
SV*subref=NULL;
267+
SV*subref;
282268
intcount;
283269

284270
ENTER;
285271
SAVETMPS;
286272
PUSHMARK(SP);
287273
XPUSHs(sv_2mortal(newSVpv(s,0)));
288274
PUTBACK;
275+
/*
276+
* G_KEEPERR seems to be needed here, else we don't recognize compile
277+
* errors properly. Perhaps it's because there's another level of eval
278+
* inside mksafefunc?
279+
*/
289280
count=perl_call_pv((trusted ?"mksafefunc" :"mkunsafefunc"),
290281
G_SCALAR |G_EVAL |G_KEEPERR);
291282
SPAGAIN;
292283

284+
if (count!=1)
285+
{
286+
PUTBACK;
287+
FREETMPS;
288+
LEAVE;
289+
elog(ERROR,"plperl: didn't get a return item from mksafefunc");
290+
}
291+
293292
if (SvTRUE(ERRSV))
294293
{
295294
POPs;
@@ -299,9 +298,6 @@ plperl_create_sub(char *s, bool trusted)
299298
elog(ERROR,"creation of function failed: %s",SvPV(ERRSV,PL_na));
300299
}
301300

302-
if (count!=1)
303-
elog(ERROR,"creation of function failed - no return from mksafefunc");
304-
305301
/*
306302
* need to make a deep copy of the return. it comes off the stack as a
307303
* temporary.
@@ -324,6 +320,7 @@ plperl_create_sub(char *s, bool trusted)
324320
PUTBACK;
325321
FREETMPS;
326322
LEAVE;
323+
327324
returnsubref;
328325
}
329326

@@ -352,21 +349,18 @@ plperl_init_shared_libs(pTHX)
352349
* plperl_call_perl_func()- calls a perl function through the RV
353350
*stored in the prodesc structure. massages the input parms properly
354351
**********************************************************************/
355-
static
356-
SV*
352+
staticSV*
357353
plperl_call_perl_func(plperl_proc_desc*desc,FunctionCallInfofcinfo)
358354
{
359355
dSP;
360-
361356
SV*retval;
362357
inti;
363358
intcount;
364359

365-
366360
ENTER;
367361
SAVETMPS;
368362

369-
PUSHMARK(sp);
363+
PUSHMARK(SP);
370364
for (i=0;i<desc->nargs;i++)
371365
{
372366
if (desc->arg_is_rel[i])
@@ -401,7 +395,9 @@ plperl_call_perl_func(plperl_proc_desc * desc, FunctionCallInfo fcinfo)
401395
}
402396
}
403397
PUTBACK;
404-
count=perl_call_sv(desc->reference,G_SCALAR |G_EVAL |G_KEEPERR);
398+
399+
/* Do NOT use G_KEEPERR here */
400+
count=perl_call_sv(desc->reference,G_SCALAR |G_EVAL);
405401

406402
SPAGAIN;
407403

@@ -424,16 +420,14 @@ plperl_call_perl_func(plperl_proc_desc * desc, FunctionCallInfo fcinfo)
424420

425421
retval=newSVsv(POPs);
426422

427-
428423
PUTBACK;
429424
FREETMPS;
430425
LEAVE;
431426

432427
returnretval;
433-
434-
435428
}
436429

430+
437431
/**********************************************************************
438432
* plperl_func_handler()- Handler for regular function calls
439433
**********************************************************************/
@@ -443,23 +437,10 @@ plperl_func_handler(PG_FUNCTION_ARGS)
443437
plperl_proc_desc*prodesc;
444438
SV*perlret;
445439
Datumretval;
446-
sigjmp_bufsave_restart;
447440

448441
/* Find or compile the function */
449442
prodesc=compile_plperl_function(fcinfo->flinfo->fn_oid, false);
450443

451-
/* Set up error handling */
452-
memcpy(&save_restart,&Warn_restart,sizeof(save_restart));
453-
454-
if (sigsetjmp(Warn_restart,1)!=0)
455-
{
456-
memcpy(&Warn_restart,&save_restart,sizeof(Warn_restart));
457-
plperl_restart_in_progress=1;
458-
if (--plperl_call_level==0)
459-
plperl_restart_in_progress=0;
460-
siglongjmp(Warn_restart,1);
461-
}
462-
463444
/************************************************************
464445
* Call the Perl function
465446
************************************************************/
@@ -490,14 +471,6 @@ plperl_func_handler(PG_FUNCTION_ARGS)
490471

491472
SvREFCNT_dec(perlret);
492473

493-
memcpy(&Warn_restart,&save_restart,sizeof(Warn_restart));
494-
if (plperl_restart_in_progress)
495-
{
496-
if (--plperl_call_level==0)
497-
plperl_restart_in_progress=0;
498-
siglongjmp(Warn_restart,1);
499-
}
500-
501474
returnretval;
502475
}
503476

@@ -734,7 +707,7 @@ compile_plperl_function(Oid fn_oid, bool is_trigger)
734707
* plperl_build_tuple_argument() - Build a string for a ref to a hash
735708
* from all attributes of a given tuple
736709
**********************************************************************/
737-
staticSV*
710+
staticSV*
738711
plperl_build_tuple_argument(HeapTupletuple,TupleDesctupdesc)
739712
{
740713
inti;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp