From 098e0438496e558902e3b4407090032d6b2d9221 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 9 Apr 1999 22:35:43 +0000 Subject: [PATCH] Fix CREATE OPERATOR ... LANGUAGE 'internal', which I broke while making prosrc instead of proname be the link to the actual internal function. --- src/backend/commands/define.c | 7 +++-- src/backend/utils/Gen_fmgrtab.sh.in | 49 +++++++++++++---------------- src/backend/utils/fmgr/fmgr.c | 22 ++++++++++--- src/include/utils/fmgrtab.h | 6 ++-- 4 files changed, 45 insertions(+), 39 deletions(-) diff --git a/src/backend/commands/define.c b/src/backend/commands/define.c index 11e17283a1..04bd1e8963 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 24bd9fdde1..4537f91d48 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 < $TABCFILE < $TABCFILE < - #include - -#ifdef WIN32 -# include -#else -# ifdef HAVE_LIMITS_H -# include -# ifndef MAXINT -# define MAXINT INT_MAX -# endif -# else -# include -# endif -#endif - #include "utils/fmgrtab.h" FuNkYfMgRtAbStUfF @@ -252,20 +237,14 @@ cat >> $TABCFILE <> $TABCFILE +awk '{ printf (" {%d, %d, %s, \"%s\" },\n"), $1, $8, $(NF-1), $(NF-1) }' $RAWFILE >> $TABCFILE cat >> $TABCFILE <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 edee95aa8e..96f8e1293a 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 */