Commit 098e0438 authored by Tom Lane's avatar Tom Lane

Fix CREATE OPERATOR ... LANGUAGE 'internal', which I broke while

making prosrc instead of proname be the link to the actual internal function.
parent 7eb16b78
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * 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 * DESCRIPTION
* The "DefineFoo" routines take the parse tree and pick out the * The "DefineFoo" routines take the parse tree and pick out the
...@@ -186,14 +186,15 @@ interpret_AS_clause(const char *languageName, const char *as, ...@@ -186,14 +186,15 @@ interpret_AS_clause(const char *languageName, const char *as,
char **prosrc_str_p, char **probin_str_p) char **prosrc_str_p, char **probin_str_p)
{ {
if (strcmp(languageName, "C") == 0 || if (strcmp(languageName, "C") == 0)
strcmp(languageName, "internal") == 0)
{ {
/* For "C" language, store the given string in probin */
*prosrc_str_p = "-"; *prosrc_str_p = "-";
*probin_str_p = (char *) as; *probin_str_p = (char *) as;
} }
else else
{ {
/* Everything else wants the given string in prosrc */
*prosrc_str_p = (char *) as; *prosrc_str_p = (char *) as;
*probin_str_p = "-"; *probin_str_p = "-";
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
# #
# #
# IDENTIFICATION # 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 # NOTES
# Passes any -D options on to cpp prior to generating the list # Passes any -D options on to cpp prior to generating the list
...@@ -83,7 +83,7 @@ cat > $HFILE <<FuNkYfMgRsTuFf ...@@ -83,7 +83,7 @@ cat > $HFILE <<FuNkYfMgRsTuFf
* *
* Copyright (c) 1994, Regents of the University of California * 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 * NOTES
* ****************************** * ******************************
...@@ -206,7 +206,7 @@ cat > $TABCFILE <<FuNkYfMgRtAbStUfF ...@@ -206,7 +206,7 @@ cat > $TABCFILE <<FuNkYfMgRtAbStUfF
* *
* *
* IDENTIFICATION * 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 * NOTES
* *
...@@ -225,22 +225,7 @@ cat > $TABCFILE <<FuNkYfMgRtAbStUfF ...@@ -225,22 +225,7 @@ cat > $TABCFILE <<FuNkYfMgRtAbStUfF
*/ */
#include <string.h> #include <string.h>
#include <postgres.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" #include "utils/fmgrtab.h"
FuNkYfMgRtAbStUfF FuNkYfMgRtAbStUfF
...@@ -252,20 +237,14 @@ cat >> $TABCFILE <<FuNkYfMgRtAbStUfF ...@@ -252,20 +237,14 @@ cat >> $TABCFILE <<FuNkYfMgRtAbStUfF
static FmgrCall fmgr_builtins[] = { static FmgrCall fmgr_builtins[] = {
FuNkYfMgRtAbStUfF 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 cat >> $TABCFILE <<FuNkYfMgRtAbStUfF
/* guardian value */ /* dummy entry is easier than getting rid of comma after last real one */
#ifndef WIN32 { 0, 0, (func_ptr) NULL, NULL }
{ MAXINT, 0, (func_ptr) NULL }
#else
{ INT_MAX, 0, (func_ptr) NULL }
#endif /* WIN32 */
}; };
/* Note FMGR_NBUILTINS excludes the guardian entry, which is probably /* Note FMGR_NBUILTINS excludes the dummy entry */
* not really needed at all ...
*/
#define FMGR_NBUILTINS ((sizeof(fmgr_builtins) / sizeof(FmgrCall)) - 1) #define FMGR_NBUILTINS ((sizeof(fmgr_builtins) / sizeof(FmgrCall)) - 1)
FmgrCall *fmgr_isbuiltin(Oid id) FmgrCall *fmgr_isbuiltin(Oid id)
...@@ -289,6 +268,20 @@ FmgrCall *fmgr_isbuiltin(Oid id) ...@@ -289,6 +268,20 @@ FmgrCall *fmgr_isbuiltin(Oid id)
return (FmgrCall *) NULL; 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 FuNkYfMgRtAbStUfF
rm -f $RAWFILE rm -f $RAWFILE
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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 @@ ...@@ -27,6 +27,7 @@
#include "utils/syscache.h" #include "utils/syscache.h"
#include "nodes/params.h" #include "nodes/params.h"
#include "utils/builtins.h"
#include "utils/elog.h" #include "utils/elog.h"
#include "nodes/parsenodes.h" #include "nodes/parsenodes.h"
...@@ -206,6 +207,7 @@ fmgr_info(Oid procedureId, FmgrInfo *finfo) ...@@ -206,6 +207,7 @@ fmgr_info(Oid procedureId, FmgrInfo *finfo)
HeapTuple languageTuple; HeapTuple languageTuple;
Form_pg_language languageStruct; Form_pg_language languageStruct;
Oid language; Oid language;
char *prosrc;
finfo->fn_addr = NULL; finfo->fn_addr = NULL;
finfo->fn_plhandler = NULL; finfo->fn_plhandler = NULL;
...@@ -239,11 +241,21 @@ fmgr_info(Oid procedureId, FmgrInfo *finfo) ...@@ -239,11 +241,21 @@ fmgr_info(Oid procedureId, FmgrInfo *finfo)
{ {
case INTERNALlanguageId: case INTERNALlanguageId:
/* /*
* Since we already tried to look up the OID as a builtin * For an ordinary builtin function, we should never get here
* 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", prosrc = textout(&(procedureStruct->prosrc));
procedureId); 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; break;
case ClanguageId: case ClanguageId:
finfo->fn_addr = fmgr_dynamic(procedureId, &(finfo->fn_nargs)); finfo->fn_addr = fmgr_dynamic(procedureId, &(finfo->fn_nargs));
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * 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 ...@@ -19,11 +19,11 @@ typedef struct
Oid proid; Oid proid;
int nargs; int nargs;
func_ptr func; func_ptr func;
int dummy; /* pad struct to 4 words for fast indexing */ char *funcName;
} FmgrCall; } FmgrCall;
extern FmgrCall *fmgr_isbuiltin(Oid id); extern FmgrCall *fmgr_isbuiltin(Oid id);
extern func_ptr fmgr_lookupByName(char *name);
extern void load_file(char *filename); extern void load_file(char *filename);
#endif /* FMGRTAB_H */ #endif /* FMGRTAB_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment