@@ -118,24 +118,15 @@ Datum
118118to_regproc (PG_FUNCTION_ARGS )
119119{
120120 char * pro_name = text_to_cstring (PG_GETARG_TEXT_PP (0 ));
121- List * names ;
122- FuncCandidateList clist ;
121+ Datum result ;
123122 ErrorSaveContext escontext = {T_ErrorSaveContext };
124123
125- /*
126- * Parse the name into components and see if it matches any pg_proc
127- * entries in the current search path.
128- */
129- names = stringToQualifiedNameList (pro_name , (Node * ) & escontext );
130- if (names == NIL )
131- PG_RETURN_NULL ();
132-
133- clist = FuncnameGetCandidates (names , -1 , NIL , false, false, false, true);
134-
135- if (clist == NULL || clist -> next != NULL )
124+ if (!DirectInputFunctionCallSafe (regprocin , pro_name ,
125+ InvalidOid , -1 ,
126+ (Node * ) & escontext ,
127+ & result ))
136128 PG_RETURN_NULL ();
137-
138- PG_RETURN_OID (clist -> oid );
129+ PG_RETURN_DATUM (result );
139130}
140131
141132/*
@@ -287,31 +278,15 @@ Datum
287278to_regprocedure (PG_FUNCTION_ARGS )
288279{
289280 char * pro_name = text_to_cstring (PG_GETARG_TEXT_PP (0 ));
290- List * names ;
291- int nargs ;
292- Oid argtypes [FUNC_MAX_ARGS ];
293- FuncCandidateList clist ;
281+ Datum result ;
294282 ErrorSaveContext escontext = {T_ErrorSaveContext };
295283
296- /*
297- * Parse the name and arguments, look up potential matches in the current
298- * namespace search list, and scan to see which one exactly matches the
299- * given argument types. (There will not be more than one match.)
300- */
301- if (!parseNameAndArgTypes (pro_name , false,
302- & names , & nargs , argtypes ,
303- (Node * ) & escontext ))
284+ if (!DirectInputFunctionCallSafe (regprocedurein , pro_name ,
285+ InvalidOid , -1 ,
286+ (Node * ) & escontext ,
287+ & result ))
304288 PG_RETURN_NULL ();
305-
306- clist = FuncnameGetCandidates (names , nargs , NIL , false, false, false, true);
307-
308- for (; clist ; clist = clist -> next )
309- {
310- if (memcmp (clist -> args , argtypes , nargs * sizeof (Oid )) == 0 )
311- PG_RETURN_OID (clist -> oid );
312- }
313-
314- PG_RETURN_NULL ();
289+ PG_RETURN_DATUM (result );
315290}
316291
317292/*
@@ -552,24 +527,15 @@ Datum
552527to_regoper (PG_FUNCTION_ARGS )
553528{
554529 char * opr_name = text_to_cstring (PG_GETARG_TEXT_PP (0 ));
555- List * names ;
556- FuncCandidateList clist ;
530+ Datum result ;
557531 ErrorSaveContext escontext = {T_ErrorSaveContext };
558532
559- /*
560- * Parse the name into components and see if it matches any pg_operator
561- * entries in the current search path.
562- */
563- names = stringToQualifiedNameList (opr_name , (Node * ) & escontext );
564- if (names == NIL )
533+ if (!DirectInputFunctionCallSafe (regoperin , opr_name ,
534+ InvalidOid , -1 ,
535+ (Node * ) & escontext ,
536+ & result ))
565537 PG_RETURN_NULL ();
566-
567- clist = OpernameGetCandidates (names , '\0' , true);
568-
569- if (clist == NULL || clist -> next != NULL )
570- PG_RETURN_NULL ();
571-
572- PG_RETURN_OID (clist -> oid );
538+ PG_RETURN_DATUM (result );
573539}
574540
575541/*
@@ -728,31 +694,15 @@ Datum
728694to_regoperator (PG_FUNCTION_ARGS )
729695{
730696 char * opr_name_or_oid = text_to_cstring (PG_GETARG_TEXT_PP (0 ));
731- Oid result ;
732- List * names ;
733- int nargs ;
734- Oid argtypes [FUNC_MAX_ARGS ];
697+ Datum result ;
735698 ErrorSaveContext escontext = {T_ErrorSaveContext };
736699
737- /*
738- * Parse the name and arguments, look up potential matches in the current
739- * namespace search list, and scan to see which one exactly matches the
740- * given argument types. (There will not be more than one match.)
741- */
742- if (!parseNameAndArgTypes (opr_name_or_oid , true,
743- & names , & nargs , argtypes ,
744- (Node * ) & escontext ))
745- PG_RETURN_NULL ();
746-
747- if (nargs != 2 )
700+ if (!DirectInputFunctionCallSafe (regoperatorin , opr_name_or_oid ,
701+ InvalidOid , -1 ,
702+ (Node * ) & escontext ,
703+ & result ))
748704 PG_RETURN_NULL ();
749-
750- result = OpernameGetOprid (names , argtypes [0 ], argtypes [1 ]);
751-
752- if (!OidIsValid (result ))
753- PG_RETURN_NULL ();
754-
755- PG_RETURN_OID (result );
705+ PG_RETURN_DATUM (result );
756706}
757707
758708/*
@@ -975,25 +925,15 @@ Datum
975925to_regclass (PG_FUNCTION_ARGS )
976926{
977927 char * class_name = text_to_cstring (PG_GETARG_TEXT_PP (0 ));
978- Oid result ;
979- List * names ;
928+ Datum result ;
980929 ErrorSaveContext escontext = {T_ErrorSaveContext };
981930
982- /*
983- * Parse the name into components and see if it matches any pg_class
984- * entries in the current search path.
985- */
986- names = stringToQualifiedNameList (class_name , (Node * ) & escontext );
987- if (names == NIL )
988- PG_RETURN_NULL ();
989-
990- /* We might not even have permissions on this relation; don't lock it. */
991- result = RangeVarGetRelid (makeRangeVarFromNameList (names ), NoLock , true);
992-
993- if (OidIsValid (result ))
994- PG_RETURN_OID (result );
995- else
931+ if (!DirectInputFunctionCallSafe (regclassin , class_name ,
932+ InvalidOid , -1 ,
933+ (Node * ) & escontext ,
934+ & result ))
996935 PG_RETURN_NULL ();
936+ PG_RETURN_DATUM (result );
997937}
998938
999939/*
@@ -1128,24 +1068,15 @@ Datum
11281068to_regcollation (PG_FUNCTION_ARGS )
11291069{
11301070 char * collation_name = text_to_cstring (PG_GETARG_TEXT_PP (0 ));
1131- Oid result ;
1132- List * names ;
1071+ Datum result ;
11331072 ErrorSaveContext escontext = {T_ErrorSaveContext };
11341073
1135- /*
1136- * Parse the name into components and see if it matches any pg_collation
1137- * entries in the current search path.
1138- */
1139- names = stringToQualifiedNameList (collation_name , (Node * ) & escontext );
1140- if (names == NIL )
1141- PG_RETURN_NULL ();
1142-
1143- result = get_collation_oid (names , true);
1144-
1145- if (OidIsValid (result ))
1146- PG_RETURN_OID (result );
1147- else
1074+ if (!DirectInputFunctionCallSafe (regcollationin , collation_name ,
1075+ InvalidOid , -1 ,
1076+ (Node * ) & escontext ,
1077+ & result ))
11481078 PG_RETURN_NULL ();
1079+ PG_RETURN_DATUM (result );
11491080}
11501081
11511082/*
@@ -1278,17 +1209,15 @@ Datum
12781209to_regtype (PG_FUNCTION_ARGS )
12791210{
12801211 char * typ_name = text_to_cstring (PG_GETARG_TEXT_PP (0 ));
1281- Oid result ;
1282- int32 typmod ;
1212+ Datum result ;
12831213 ErrorSaveContext escontext = {T_ErrorSaveContext };
12841214
1285- /*
1286- * Invoke the full parser to deal with special cases such as array syntax.
1287- */
1288- if (parseTypeString (typ_name , & result , & typmod , (Node * ) & escontext ))
1289- PG_RETURN_OID (result );
1290- else
1215+ if (!DirectInputFunctionCallSafe (regtypein , typ_name ,
1216+ InvalidOid , -1 ,
1217+ (Node * ) & escontext ,
1218+ & result ))
12911219 PG_RETURN_NULL ();
1220+ PG_RETURN_DATUM (result );
12921221}
12931222
12941223/*
@@ -1634,23 +1563,15 @@ Datum
16341563to_regrole (PG_FUNCTION_ARGS )
16351564{
16361565 char * role_name = text_to_cstring (PG_GETARG_TEXT_PP (0 ));
1637- Oid result ;
1638- List * names ;
1566+ Datum result ;
16391567 ErrorSaveContext escontext = {T_ErrorSaveContext };
16401568
1641- names = stringToQualifiedNameList (role_name , (Node * ) & escontext );
1642- if (names == NIL )
1643- PG_RETURN_NULL ();
1644-
1645- if (list_length (names ) != 1 )
1646- PG_RETURN_NULL ();
1647-
1648- result = get_role_oid (strVal (linitial (names )), true);
1649-
1650- if (OidIsValid (result ))
1651- PG_RETURN_OID (result );
1652- else
1569+ if (!DirectInputFunctionCallSafe (regrolein , role_name ,
1570+ InvalidOid , -1 ,
1571+ (Node * ) & escontext ,
1572+ & result ))
16531573 PG_RETURN_NULL ();
1574+ PG_RETURN_DATUM (result );
16541575}
16551576
16561577/*
@@ -1759,23 +1680,15 @@ Datum
17591680to_regnamespace (PG_FUNCTION_ARGS )
17601681{
17611682 char * nsp_name = text_to_cstring (PG_GETARG_TEXT_PP (0 ));
1762- Oid result ;
1763- List * names ;
1683+ Datum result ;
17641684 ErrorSaveContext escontext = {T_ErrorSaveContext };
17651685
1766- names = stringToQualifiedNameList (nsp_name , (Node * ) & escontext );
1767- if (names == NIL )
1768- PG_RETURN_NULL ();
1769-
1770- if (list_length (names ) != 1 )
1771- PG_RETURN_NULL ();
1772-
1773- result = get_namespace_oid (strVal (linitial (names )), true);
1774-
1775- if (OidIsValid (result ))
1776- PG_RETURN_OID (result );
1777- else
1686+ if (!DirectInputFunctionCallSafe (regnamespacein , nsp_name ,
1687+ InvalidOid , -1 ,
1688+ (Node * ) & escontext ,
1689+ & result ))
17781690 PG_RETURN_NULL ();
1691+ PG_RETURN_DATUM (result );
17791692}
17801693
17811694/*
0 commit comments