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

Commit29bf501

Browse files
committed
Add a direct function call mechanism using the caller's context.
The current DirectFunctionCall functions use NULL as the flinfo ininitializing the FunctionCallInfoData for the call. That means thecalled function has no fn_mcxt or fn_extra to work with, and attemptingto do so will result in an access violation. These functions instead usethe provided flinfo, which will usually be the caller's own flinfo. Thecaller needs to ensure that it doesn't use the fn_extra in way that isincompatible with the way the called function will use it. The calledfunction should not rely on anything else in the provided context, as itwill be relevant to the caller, not the callee.Original code from Tom Lane.Discussion:https://postgr.es/m/db2b70a4-78d7-294a-a315-8e7f506c5978@2ndQuadrant.com
1 parent0105055 commit29bf501

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

‎src/backend/utils/fmgr/fmgr.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,6 +1276,56 @@ DirectFunctionCall9Coll(PGFunction func, Oid collation, Datum arg1, Datum arg2,
12761276
returnresult;
12771277
}
12781278

1279+
/*
1280+
* These functions work like the DirectFunctionCall functions except that
1281+
* they use the flinfo parameter to initialise the fcinfo for the call.
1282+
* It's recommended that the callee only use the fn_extra and fn_mcxt
1283+
* fields, as other fields will typically describe the calling function
1284+
* not the callee. Conversely, the calling function should not have
1285+
* used fn_extra, unless its use is known to be compatible with the callee's.
1286+
*/
1287+
1288+
Datum
1289+
CallerFInfoFunctionCall1(PGFunctionfunc,FmgrInfo*flinfo,Oidcollation,Datumarg1)
1290+
{
1291+
FunctionCallInfoDatafcinfo;
1292+
Datumresult;
1293+
1294+
InitFunctionCallInfoData(fcinfo,flinfo,1,collation,NULL,NULL);
1295+
1296+
fcinfo.arg[0]=arg1;
1297+
fcinfo.argnull[0]= false;
1298+
1299+
result= (*func) (&fcinfo);
1300+
1301+
/* Check for null result, since caller is clearly not expecting one */
1302+
if (fcinfo.isnull)
1303+
elog(ERROR,"function %p returned NULL", (void*)func);
1304+
1305+
returnresult;
1306+
}
1307+
1308+
Datum
1309+
CallerFInfoFunctionCall2(PGFunctionfunc,FmgrInfo*flinfo,Oidcollation,Datumarg1,Datumarg2)
1310+
{
1311+
FunctionCallInfoDatafcinfo;
1312+
Datumresult;
1313+
1314+
InitFunctionCallInfoData(fcinfo,flinfo,2,collation,NULL,NULL);
1315+
1316+
fcinfo.arg[0]=arg1;
1317+
fcinfo.arg[1]=arg2;
1318+
fcinfo.argnull[0]= false;
1319+
fcinfo.argnull[1]= false;
1320+
1321+
result= (*func) (&fcinfo);
1322+
1323+
/* Check for null result, since caller is clearly not expecting one */
1324+
if (fcinfo.isnull)
1325+
elog(ERROR,"function %p returned NULL", (void*)func);
1326+
1327+
returnresult;
1328+
}
12791329

12801330
/*
12811331
* These are for invocation of a previously-looked-up function with a

‎src/include/fmgr.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,19 @@ extern Datum DirectFunctionCall9Coll(PGFunction func, Oid collation,
483483
Datumarg6,Datumarg7,Datumarg8,
484484
Datumarg9);
485485

486+
/*
487+
* These functions work like the DirectFunctionCall functions except that
488+
* they use the flinfo parameter to initialise the fcinfo for the call.
489+
* It's recommended that the callee only use the fn_extra and fn_mcxt
490+
* fields, as other fields will typically describe the calling function
491+
* not the callee. Conversely, the calling function should not have
492+
* used fn_extra, unless its use is known to be compatible with the callee's.
493+
*/
494+
externDatumCallerFInfoFunctionCall1(PGFunctionfunc,FmgrInfo*flinfo,
495+
Oidcollation,Datumarg1);
496+
externDatumCallerFInfoFunctionCall2(PGFunctionfunc,FmgrInfo*flinfo,
497+
Oidcollation,Datumarg1,Datumarg2);
498+
486499
/* These are for invocation of a previously-looked-up function with a
487500
* directly-computed parameter list. Note that neither arguments nor result
488501
* are allowed to be NULL.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp