diff --git a/src/backend/commands/define.c b/src/backend/commands/define.c index 11e17283a1ec9b5aebca8f3a0d69329e7babb3c3..04bd1e89638f45a7f6f81da1fc8445b818c1c8dd 100644 --- a/src/backend/commands/define.c +++ b/src/backend/commands/define.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/define.c,v 1.27 1999/02/13 23:15:06 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/define.c,v 1.28 1999/04/09 22:35:41 tgl Exp $ * * DESCRIPTION * The "DefineFoo" routines take the parse tree and pick out the @@ -186,14 +186,15 @@ interpret_AS_clause(const char *languageName, const char *as, char **prosrc_str_p, char **probin_str_p) { - if (strcmp(languageName, "C") == 0 || - strcmp(languageName, "internal") == 0) + if (strcmp(languageName, "C") == 0) { + /* For "C" language, store the given string in probin */ *prosrc_str_p = "-"; *probin_str_p = (char *) as; } else { + /* Everything else wants the given string in prosrc */ *prosrc_str_p = (char *) as; *probin_str_p = "-"; } diff --git a/src/backend/utils/Gen_fmgrtab.sh.in b/src/backend/utils/Gen_fmgrtab.sh.in index 24bd9fdde14685e739fe50a486fc3920a073f1b7..4537f91d48f0b44070e7343f999702781425979d 100644 --- a/src/backend/utils/Gen_fmgrtab.sh.in +++ b/src/backend/utils/Gen_fmgrtab.sh.in @@ -8,7 +8,7 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/backend/utils/Attic/Gen_fmgrtab.sh.in,v 1.14 1999/03/29 01:30:35 tgl Exp $ +# $Header: /cvsroot/pgsql/src/backend/utils/Attic/Gen_fmgrtab.sh.in,v 1.15 1999/04/09 22:35:41 tgl Exp $ # # NOTES # Passes any -D options on to cpp prior to generating the list @@ -83,7 +83,7 @@ cat > $HFILE <<FuNkYfMgRsTuFf * * Copyright (c) 1994, Regents of the University of California * - * $Id: Gen_fmgrtab.sh.in,v 1.14 1999/03/29 01:30:35 tgl Exp $ + * $Id: Gen_fmgrtab.sh.in,v 1.15 1999/04/09 22:35:41 tgl Exp $ * * NOTES * ****************************** @@ -206,7 +206,7 @@ cat > $TABCFILE <<FuNkYfMgRtAbStUfF * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/Attic/Gen_fmgrtab.sh.in,v 1.14 1999/03/29 01:30:35 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/Attic/Gen_fmgrtab.sh.in,v 1.15 1999/04/09 22:35:41 tgl Exp $ * * NOTES * @@ -225,22 +225,7 @@ cat > $TABCFILE <<FuNkYfMgRtAbStUfF */ #include <string.h> - #include <postgres.h> - -#ifdef WIN32 -# include <limits.h> -#else -# ifdef HAVE_LIMITS_H -# include <limits.h> -# ifndef MAXINT -# define MAXINT INT_MAX -# endif -# else -# include <values.h> -# endif -#endif - #include "utils/fmgrtab.h" FuNkYfMgRtAbStUfF @@ -252,20 +237,14 @@ cat >> $TABCFILE <<FuNkYfMgRtAbStUfF static FmgrCall fmgr_builtins[] = { FuNkYfMgRtAbStUfF -awk '{ printf (" {%d, %d, %s },\n"), $1, $8, $(NF-1) }' $RAWFILE >> $TABCFILE +awk '{ printf (" {%d, %d, %s, \"%s\" },\n"), $1, $8, $(NF-1), $(NF-1) }' $RAWFILE >> $TABCFILE cat >> $TABCFILE <<FuNkYfMgRtAbStUfF - /* guardian value */ -#ifndef WIN32 - { MAXINT, 0, (func_ptr) NULL } -#else - { INT_MAX, 0, (func_ptr) NULL } -#endif /* WIN32 */ + /* dummy entry is easier than getting rid of comma after last real one */ + { 0, 0, (func_ptr) NULL, NULL } }; -/* Note FMGR_NBUILTINS excludes the guardian entry, which is probably - * not really needed at all ... - */ +/* Note FMGR_NBUILTINS excludes the dummy entry */ #define FMGR_NBUILTINS ((sizeof(fmgr_builtins) / sizeof(FmgrCall)) - 1) FmgrCall *fmgr_isbuiltin(Oid id) @@ -289,6 +268,20 @@ FmgrCall *fmgr_isbuiltin(Oid id) return (FmgrCall *) NULL; } +func_ptr fmgr_lookupByName(char *name) +{ + /* Lookup a builtin by name. Note there can be more than one entry in + * the array matching this name, but they should all point to the same + * routine. + */ + int i; + for (i=0; i<FMGR_NBUILTINS; i++) { + if (strcmp(name, fmgr_builtins[i].funcName) == 0) + return fmgr_builtins[i].func; + } + return (func_ptr) NULL; +} + FuNkYfMgRtAbStUfF rm -f $RAWFILE diff --git a/src/backend/utils/fmgr/fmgr.c b/src/backend/utils/fmgr/fmgr.c index 7fa6171c72e7f3a18b427c704f96be887f3e9932..c88d4994b282e0f0204b185a85c9470a5414ea58 100644 --- a/src/backend/utils/fmgr/fmgr.c +++ b/src/backend/utils/fmgr/fmgr.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/fmgr/fmgr.c,v 1.24 1999/04/03 22:57:29 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/fmgr/fmgr.c,v 1.25 1999/04/09 22:35:42 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -27,6 +27,7 @@ #include "utils/syscache.h" #include "nodes/params.h" +#include "utils/builtins.h" #include "utils/elog.h" #include "nodes/parsenodes.h" @@ -206,6 +207,7 @@ fmgr_info(Oid procedureId, FmgrInfo *finfo) HeapTuple languageTuple; Form_pg_language languageStruct; Oid language; + char *prosrc; finfo->fn_addr = NULL; finfo->fn_plhandler = NULL; @@ -239,11 +241,21 @@ fmgr_info(Oid procedureId, FmgrInfo *finfo) { case INTERNALlanguageId: /* - * Since we already tried to look up the OID as a builtin - * function, we should never get here... + * For an ordinary builtin function, we should never get here + * because the isbuiltin() search above will have succeeded. + * However, if the user has done a CREATE FUNCTION to create + * an alias for a builtin function, we end up here. In that + * case we have to look up the function by name. The name + * of the internal function is stored in prosrc (it doesn't + * have to be the same as the name of the alias!) */ - elog(ERROR, "fmgr_info: function %d: not in internal table", - procedureId); + prosrc = textout(&(procedureStruct->prosrc)); + finfo->fn_addr = fmgr_lookupByName(prosrc); + if (!finfo->fn_addr) + elog(ERROR, "fmgr_info: function %s not in internal table", + prosrc); + finfo->fn_nargs = procedureStruct->pronargs; + pfree(prosrc); break; case ClanguageId: finfo->fn_addr = fmgr_dynamic(procedureId, &(finfo->fn_nargs)); diff --git a/src/include/utils/fmgrtab.h b/src/include/utils/fmgrtab.h index edee95aa8ebcd053cfbd91b72e5be09077e56fb9..96f8e1293a28e6833e5f01a86d6a25750dd18f25 100644 --- a/src/include/utils/fmgrtab.h +++ b/src/include/utils/fmgrtab.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: fmgrtab.h,v 1.10 1999/03/29 01:30:41 tgl Exp $ + * $Id: fmgrtab.h,v 1.11 1999/04/09 22:35:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -19,11 +19,11 @@ typedef struct Oid proid; int nargs; func_ptr func; - int dummy; /* pad struct to 4 words for fast indexing */ + char *funcName; } FmgrCall; extern FmgrCall *fmgr_isbuiltin(Oid id); - +extern func_ptr fmgr_lookupByName(char *name); extern void load_file(char *filename); #endif /* FMGRTAB_H */