aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/Gen_fmgrtab.sh.in
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/utils/Gen_fmgrtab.sh.in')
-rw-r--r--src/backend/utils/Gen_fmgrtab.sh.in196
1 files changed, 51 insertions, 145 deletions
diff --git a/src/backend/utils/Gen_fmgrtab.sh.in b/src/backend/utils/Gen_fmgrtab.sh.in
index 975e2a0f9a2..f075ac28376 100644
--- a/src/backend/utils/Gen_fmgrtab.sh.in
+++ b/src/backend/utils/Gen_fmgrtab.sh.in
@@ -1,14 +1,15 @@
#!/bin/sh
#-------------------------------------------------------------------------
#
-# Gen_fmgrtab.sh--
-# shell script to generate fmgr.h and fmgrtab.c from pg_proc.h
+# Gen_fmgrtab.sh
+# shell script to generate fmgroids.h and fmgrtab.c from pg_proc.h
#
-# Copyright (c) 1994, Regents of the University of California
+# Portions Copyright (c) 1996-2000, PostgreSQL, Inc
+# Portions Copyright (c) 1994, Regents of the University of California
#
#
# IDENTIFICATION
-# $Header: /cvsroot/pgsql/src/backend/utils/Attic/Gen_fmgrtab.sh.in,v 1.21 2000/05/22 02:34:21 momjian Exp $
+# $Header: /cvsroot/pgsql/src/backend/utils/Attic/Gen_fmgrtab.sh.in,v 1.22 2000/05/28 17:56:05 tgl Exp $
#
# NOTES
# Passes any -D options on to cpp prior to generating the list
@@ -16,12 +17,6 @@
#
#-------------------------------------------------------------------------
-if [ $? != 0 ]
-then
- echo `basename $0`: Bad option
- exit 1
-fi
-
BKIOPTS=''
#
@@ -32,7 +27,7 @@ for opt in $*
do
case $opt in
-D) BKIOPTS="$BKIOPTS -D$2"; shift; shift;;
- -D*) BKIOPTS="$BKIOPTS $1";shift;;
+ -D*) BKIOPTS="$BKIOPTS $1"; shift;;
--) shift; break;;
-*) shift;;
esac
@@ -41,8 +36,8 @@ done
INFILE=$1
RAWFILE=fmgr.raw
CPPTMPFILE=fmgrtmp.c
-HFILE=fmgr.h
-TABCFILE=fmgrtab.c
+OIDSFILE=fmgroids.h
+TABLEFILE=fmgrtab.c
#
# Generate the file containing raw pg_proc tuple data
@@ -63,7 +58,8 @@ sed -e 's/^.*OID[^=]*=[^0-9]*//' \
-e 's/[ ]*).*$//' | \
awk '
/^#/ { print; next; }
-$4 == "11" { print; next; }' > $CPPTMPFILE
+$4 == "11" { print; next; }
+$4 == "12" { print; next; }' > $CPPTMPFILE
@CPP@ $BKIOPTS $CPPTMPFILE | \
egrep '^[0-9]' | \
@@ -72,18 +68,21 @@ sort -n > $RAWFILE
rm -f $CPPTMPFILE
#
-# Generate fmgr.h
+# Generate fmgroids.h
#
-cat > $HFILE <<FuNkYfMgRsTuFf
+cat > $OIDSFILE <<FuNkYfMgRsTuFf
/*-------------------------------------------------------------------------
*
- * $HFILE--
- * Definitions for using internal procedures.
+ * $OIDSFILE
+ * Macros that define the OIDs of built-in functions.
*
+ * These macros can be used to avoid a catalog lookup when a specific
+ * fmgr-callable function needs to be referenced.
*
- * Copyright (c) 1994, Regents of the University of California
+ * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
+ * Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: Gen_fmgrtab.sh.in,v 1.21 2000/05/22 02:34:21 momjian Exp $
+ * $Id: Gen_fmgrtab.sh.in,v 1.22 2000/05/28 17:56:05 tgl Exp $
*
* NOTES
* ******************************
@@ -91,77 +90,12 @@ cat > $HFILE <<FuNkYfMgRsTuFf
* ******************************
*
* It has been GENERATED by $0
- * from $1
+ * from $INFILE
*
*-------------------------------------------------------------------------
*/
-#ifndef FMGR_H
-#define FMGR_H
-
-#include "postgres.h"
-
-typedef struct {
- char *data[FUNC_MAX_ARGS];
-} FmgrValues;
-
-typedef struct {
- func_ptr fn_addr;
- func_ptr fn_plhandler;
- Oid fn_oid;
- int fn_nargs;
-} FmgrInfo;
-
-/*
- * defined in fmgr.c
- */
-extern char *fmgr_c(FmgrInfo *finfo, FmgrValues *values, bool *isNull);
-extern void fmgr_info(Oid procedureId, FmgrInfo *finfo);
-extern char *fmgr(Oid procedureId, ... );
-extern char *fmgr_ptr(FmgrInfo *finfo, ... );
-extern char *fmgr_array_args(Oid procedureId, int nargs,
- char *args[], bool *isNull);
-
-/*
- * defined in dfmgr.c
- */
-extern func_ptr fmgr_dynamic(Oid procedureId, int *pronargs);
-extern void load_file(char *filename);
-
-/*
- * For performance reasons, we often want to simply jump through a
- * a function pointer (if it's valid, that is). These calls have
- * been macroized so we can run them through a routine that does
- * sanity-checking (and so we can track them down more easily when
- * we must).
- */
-
-/* We don't make this static so fmgr_faddr() macros can access it */
-extern FmgrInfo *fmgr_pl_finfo;
-
-#define fmgr_faddr(finfo) \
-( \
- fmgr_pl_finfo = (finfo), \
- (func_ptr)(finfo)->fn_addr \
-)
-
-#ifdef TRACE_FMGR_PTR
-#define FMGR_PTR2(FINFO, ARG1, ARG2) \
- fmgr_ptr(FINFO, 2, ARG1, ARG2)
-#else
-#define FMGR_PTR2(FINFO, ARG1, ARG2) \
-( \
- ((FINFO)->fn_addr) ? \
- (*(fmgr_faddr(FINFO)))(ARG1, ARG2) \
- : \
- fmgr((FINFO)->fn_oid, ARG1, ARG2) \
-)
-#endif
-
-/*
- * Flags for the builtin oprrest selectivity routines.
- */
-#define SEL_CONSTANT 1 /* constant does not vary (not a parameter) */
-#define SEL_RIGHT 2 /* constant appears to right of operator */
+#ifndef FMGROIDS_H
+#define FMGROIDS_H
/*
* Constant macros for the OIDs of entries in pg_proc.
@@ -174,30 +108,33 @@ FuNkYfMgRsTuFf
tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' < $RAWFILE | \
awk '
BEGIN { OFS = ""; }
- { if (seenit[$2]++ == 0) print "#define F_", $2, " ", $1; }' >> $HFILE
+ { if (seenit[$2]++ == 0) print "#define F_", $2, " ", $1; }' >> $OIDSFILE
-cat >> $HFILE <<FuNkYfMgRsTuFf
+cat >> $OIDSFILE <<FuNkYfMgRsTuFf
-#endif /* FMGR_H */
+#endif /* FMGROIDS_H */
FuNkYfMgRsTuFf
#
-# Generate fmgr function table file.
+# Generate fmgr's built-in-function table.
#
-# Print out the bogus function declarations, then the table that
-# refers to them.
+# Print out the function declarations, then the table that refers to them.
+# NB: the function declarations are bogus in the case of old-style functions,
+# although they should be correct for new-style. Therefore we need to compile
+# this table definition as a separate C file that won't need to include any
+# "real" declarations for those functions!
#
-cat > $TABCFILE <<FuNkYfMgRtAbStUfF
+cat > $TABLEFILE <<FuNkYfMgRtAbStUfF
/*-------------------------------------------------------------------------
*
- * $TABCFILE--
+ * $TABLEFILE
* The function manager's table of internal functions.
*
- * Copyright (c) 1994, Regents of the University of California
- *
+ * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
+ * Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/Attic/Gen_fmgrtab.sh.in,v 1.21 2000/05/22 02:34:21 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/Attic/Gen_fmgrtab.sh.in,v 1.22 2000/05/28 17:56:05 tgl Exp $
*
* NOTES
*
@@ -206,72 +143,41 @@ cat > $TABCFILE <<FuNkYfMgRtAbStUfF
* ******************************
*
* It has been GENERATED by $0
- * from $1
+ * from $INFILE
*
- * We lie here to cc about the return type and arguments of the
+ * We lie here to cc about the return type and arguments of old-style
* builtin functions; all ld cares about is the fact that it
* will need to resolve an external function reference.
*
*-------------------------------------------------------------------------
*/
-#include <string.h>
#include "postgres.h"
+
#include "utils/fmgrtab.h"
FuNkYfMgRtAbStUfF
-awk '{ print "extern char *", $(NF-1), "();"; }' $RAWFILE >> $TABCFILE
+awk '{ print "extern Datum", $(NF-1), "(PG_FUNCTION_ARGS);"; }' $RAWFILE >> $TABLEFILE
-cat >> $TABCFILE <<FuNkYfMgRtAbStUfF
+cat >> $TABLEFILE <<FuNkYfMgRtAbStUfF
-static FmgrCall fmgr_builtins[] = {
+const FmgrBuiltin fmgr_builtins[] = {
FuNkYfMgRtAbStUfF
-awk '{ printf (" {%d, %d, %s, \"%s\" },\n"), $1, $8, $(NF-1), $(NF-1) }' $RAWFILE >> $TABCFILE
+awk '{ printf (" { %d, \"%s\", %d, %s, %s, %s },\n"), \
+ $1, $(NF-1), $9, \
+ ($8 == "t") ? "true" : "false", \
+ ($4 == "11") ? "true" : "false", \
+ $(NF-1) }' $RAWFILE >> $TABLEFILE
-cat >> $TABCFILE <<FuNkYfMgRtAbStUfF
+cat >> $TABLEFILE <<FuNkYfMgRtAbStUfF
/* dummy entry is easier than getting rid of comma after last real one */
- { 0, 0, (func_ptr) NULL, NULL }
+ { 0, NULL, 0, false, false, (PGFunction) NULL }
};
-/* Note FMGR_NBUILTINS excludes the dummy entry */
-#define FMGR_NBUILTINS ((sizeof(fmgr_builtins) / sizeof(FmgrCall)) - 1)
-
-FmgrCall *fmgr_isbuiltin(Oid id)
-{
- int low = 0;
- int high = FMGR_NBUILTINS - 1;
-
- /* Loop invariant: low is the first index that could contain target
- * entry, and high is the last index that could contain it.
- */
- while (low <= high) {
- int i = (high + low) / 2;
- FmgrCall * ptr = &fmgr_builtins[i];
- if (id == ptr->proid)
- return ptr;
- else if (id > ptr->proid)
- low = i + 1;
- else
- high = i - 1;
- }
- 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;
-}
+/* Note fmgr_nbuiltins excludes the dummy entry */
+const int fmgr_nbuiltins = (sizeof(fmgr_builtins) / sizeof(FmgrBuiltin)) - 1;
FuNkYfMgRtAbStUfF