making prosrc instead of proname be the link to the actual internal function.
*
*
* 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
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 = "-";
}
#
#
# 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
*
* 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
* ******************************
*
*
* 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
*
*/
#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
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)
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
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
#include "utils/syscache.h"
#include "nodes/params.h"
+#include "utils/builtins.h"
#include "utils/elog.h"
#include "nodes/parsenodes.h"
HeapTuple languageTuple;
Form_pg_language languageStruct;
Oid language;
+ char *prosrc;
finfo->fn_addr = NULL;
finfo->fn_plhandler = NULL;
{
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));
*
* 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 $
*
*-------------------------------------------------------------------------
*/
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 */