7
7
*
8
8
*
9
9
* IDENTIFICATION
10
- * $Header: /cvsroot/pgsql/src/backend/utils/fmgr/fmgr.c,v 1.23 1999/03/29 01:30:36 tgl Exp $
10
+ * $Header: /cvsroot/pgsql/src/backend/utils/fmgr/fmgr.c,v 1.24 1999/04/03 22:57:29 tgl Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
33
33
#include "commands/trigger.h"
34
34
35
35
36
+ /*
37
+ * Interface for PL functions
38
+ *
39
+ * XXX: use of global fmgr_pl_finfo variable is really ugly. FIXME
40
+ */
41
+
36
42
static char *
37
43
fmgr_pl (char * arg0 ,...)
38
44
{
39
45
va_list pvar ;
40
46
FmgrValues values ;
47
+ int n_arguments = fmgr_pl_finfo -> fn_nargs ;
41
48
bool isNull = false;
42
49
int i ;
43
50
44
51
memset (& values , 0 , sizeof (values ));
45
52
46
- if (fmgr_pl_finfo -> fn_nargs > 0 )
53
+ if (n_arguments > 0 )
47
54
{
48
55
values .data [0 ] = arg0 ;
49
- if (fmgr_pl_finfo -> fn_nargs > 1 )
56
+ if (n_arguments > 1 )
50
57
{
58
+ if (n_arguments > MAXFMGRARGS )
59
+ elog (ERROR , "fmgr_pl: function %d: too many arguments (%d > %d)" ,
60
+ fmgr_pl_finfo -> fn_oid , n_arguments , MAXFMGRARGS );
51
61
va_start (pvar , arg0 );
52
- for (i = 1 ; i < fmgr_pl_finfo -> fn_nargs ; i ++ )
62
+ for (i = 1 ; i < n_arguments ; i ++ )
53
63
values .data [i ] = va_arg (pvar , char * );
54
64
va_end (pvar );
55
65
}
@@ -63,6 +73,43 @@ fmgr_pl(char *arg0,...)
63
73
}
64
74
65
75
76
+ /*
77
+ * Interface for untrusted functions
78
+ */
79
+
80
+ static char *
81
+ fmgr_untrusted (char * arg0 ,...)
82
+ {
83
+ /* Currently these are unsupported. Someday we might do something like
84
+ * forking a subprocess to execute 'em.
85
+ */
86
+ elog (ERROR , "Untrusted functions not supported." );
87
+ return NULL ; /* keep compiler happy */
88
+ }
89
+
90
+
91
+ /*
92
+ * Interface for SQL-language functions
93
+ */
94
+
95
+ static char *
96
+ fmgr_sql (char * arg0 ,...)
97
+ {
98
+ /*
99
+ * XXX It'd be really nice to support SQL functions anywhere that builtins
100
+ * are supported. What would we have to do? What pitfalls are there?
101
+ */
102
+ elog (ERROR , "SQL-language function not supported in this context." );
103
+ return NULL ; /* keep compiler happy */
104
+ }
105
+
106
+
107
+ /*
108
+ * fmgr_c is not really for C functions only; it can be called for functions
109
+ * in any language. Many parts of the system use this entry point if they
110
+ * want to pass the arguments in an array rather than as explicit arguments.
111
+ */
112
+
66
113
char *
67
114
fmgr_c (FmgrInfo * finfo ,
68
115
FmgrValues * values ,
@@ -72,25 +119,16 @@ fmgr_c(FmgrInfo *finfo,
72
119
int n_arguments = finfo -> fn_nargs ;
73
120
func_ptr user_fn = fmgr_faddr (finfo );
74
121
75
-
76
- if (user_fn == (func_ptr ) NULL )
77
- {
78
-
79
- /*
80
- * a NULL func_ptr denotet untrusted function (in postgres 4.2).
81
- * Untrusted functions have very limited use and is clumsy. We
82
- * just get rid of it.
83
- */
84
- elog (ERROR , "internal error: untrusted function not supported." );
85
- }
86
-
87
122
/*
88
123
* If finfo contains a PL handler for this function, call that
89
124
* instead.
90
125
*/
91
126
if (finfo -> fn_plhandler != NULL )
92
127
return (* (finfo -> fn_plhandler )) (finfo , values , isNull );
93
128
129
+ if (user_fn == (func_ptr ) NULL )
130
+ elog (ERROR , "Internal error: fmgr_c received NULL function pointer." );
131
+
94
132
switch (n_arguments )
95
133
{
96
134
case 0 :
@@ -155,6 +193,10 @@ fmgr_c(FmgrInfo *finfo,
155
193
return returnValue ;
156
194
}
157
195
196
+ /*
197
+ * Expand a regproc OID into an FmgrInfo cache struct.
198
+ */
199
+
158
200
void
159
201
fmgr_info (Oid procedureId , FmgrInfo * finfo )
160
202
{
@@ -188,7 +230,7 @@ fmgr_info(Oid procedureId, FmgrInfo *finfo)
188
230
procedureStruct = (FormData_pg_proc * ) GETSTRUCT (procedureTuple );
189
231
if (!procedureStruct -> proistrusted )
190
232
{
191
- finfo -> fn_addr = (func_ptr ) NULL ;
233
+ finfo -> fn_addr = (func_ptr ) fmgr_untrusted ;
192
234
finfo -> fn_nargs = procedureStruct -> pronargs ;
193
235
return ;
194
236
}
@@ -207,7 +249,7 @@ fmgr_info(Oid procedureId, FmgrInfo *finfo)
207
249
finfo -> fn_addr = fmgr_dynamic (procedureId , & (finfo -> fn_nargs ));
208
250
break ;
209
251
case SQLlanguageId :
210
- finfo -> fn_addr = (func_ptr ) NULL ;
252
+ finfo -> fn_addr = (func_ptr ) fmgr_sql ;
211
253
finfo -> fn_nargs = procedureStruct -> pronargs ;
212
254
break ;
213
255
default :
@@ -227,13 +269,12 @@ fmgr_info(Oid procedureId, FmgrInfo *finfo)
227
269
"Cache lookup for language %d failed" ,
228
270
ObjectIdGetDatum (procedureStruct -> prolang ));
229
271
}
230
- languageStruct = (Form_pg_language )
231
- GETSTRUCT (languageTuple );
272
+ languageStruct = (Form_pg_language ) GETSTRUCT (languageTuple );
232
273
if (languageStruct -> lanispl )
233
274
{
234
275
FmgrInfo plfinfo ;
235
276
236
- fmgr_info ((( Form_pg_language ) GETSTRUCT ( languageTuple )) -> lanplcallfoid , & plfinfo );
277
+ fmgr_info (languageStruct -> lanplcallfoid , & plfinfo );
237
278
finfo -> fn_addr = (func_ptr ) fmgr_pl ;
238
279
finfo -> fn_plhandler = plfinfo .fn_addr ;
239
280
finfo -> fn_nargs = procedureStruct -> pronargs ;
@@ -269,16 +310,14 @@ fmgr(Oid procedureId,...)
269
310
FmgrInfo finfo ;
270
311
bool isNull = false;
271
312
272
- va_start (pvar , procedureId );
273
-
274
313
fmgr_info (procedureId , & finfo );
275
314
pronargs = finfo .fn_nargs ;
276
315
277
316
if (pronargs > MAXFMGRARGS )
278
- {
279
317
elog (ERROR , "fmgr: function %d: too many arguments (%d > %d)" ,
280
318
procedureId , pronargs , MAXFMGRARGS );
281
- }
319
+
320
+ va_start (pvar , procedureId );
282
321
for (i = 0 ; i < pronargs ; ++ i )
283
322
values .data [i ] = va_arg (pvar , char * );
284
323
va_end (pvar );
@@ -296,7 +335,8 @@ fmgr(Oid procedureId,...)
296
335
*
297
336
* funcinfo, n_arguments, args...
298
337
*/
299
- #ifdef NOT_USED
338
+ #ifdef TRACE_FMGR_PTR
339
+
300
340
char *
301
341
fmgr_ptr (FmgrInfo * finfo ,...)
302
342
{
@@ -343,7 +383,7 @@ fmgr_array_args(Oid procedureId, int nargs, char *args[], bool *isNull)
343
383
finfo .fn_nargs = nargs ;
344
384
345
385
/* XXX see WAY_COOL_ORTHOGONAL_FUNCTIONS */
346
- return ( fmgr_c (& finfo ,
347
- (FmgrValues * ) args ,
348
- isNull ) );
386
+ return fmgr_c (& finfo ,
387
+ (FmgrValues * ) args ,
388
+ isNull );
349
389
}
0 commit comments