PL patches

Started by Brook Milliganover 27 years ago7 messages
#1Brook Milligan
brook@trillium.NMSU.Edu

I have had a few problems with the PL stuff recently committed. The
following patches fix the problems (i.e., all regression tests pass)
in what I hope to be a platform-independent fashion. The accomplish
the following:

1. Allow configure to check for the existence of the tclConfig.sh
script needed to configure the tcl component of PL. Configure
already checks other parts of the tcl installation, so it might
as well check for this script, too, so that paths need not be
hard-coded into mkMakefile.tcldefs.

A few extra files are created by configure from templates.

Configure is also cleaned up a bit at the end so the long list of
output files is easier to deal with.

NOTE: run autoconf.

2. A new script mkMakefile.tcldefs.sh is created from the template
mkMakefile.tcldefs.sh.in so that the substitution for tclConfig.sh
can be inserted. The script is simplified and renamed to reflect
the fact that it is a sh script.

NOTE: pl/tcl/mkMakefile.tcldefs should be removed from the tree.

3. The Makefile executes /bin/sh on the new script rather than
directly executing the script (hence the name change to make it
more explicit).

4. There are shared library problems with the plpgsql/src/Makefile.
The port-specific code was taken from the interfaces/tcl?/Makefile
so that shared libraries should work on all platforms. This means
that that Makefile must be a template for configure.

NOTE: pl/plpgsql/src/Makefile should be removed from the tree.

NOTE: should we be including libtool in our distribution to simplify
shared library (and other stuff) support?

Cheers,
Brook

===========================================================================
--- configure.in.orig	Wed Oct  7 01:00:23 1998
+++ configure.in	Thu Oct  8 08:22:40 1998
@@ -799,6 +799,30 @@
 	AC_SUBST(TCL_LIB)
 fi
+dnl Check for Tcl configuration script tclConfig.sh
+if test "$USE_TCL"; then
+	AC_MSG_CHECKING(for tclConfig.sh)
+	library_dirs="/usr/lib $LIBRARY_DIRS"
+	TCL_CONFIG_SH=
+	for dir in $library_dirs; do
+		for tcl_dir in $tcl_dirs; do
+			if test -z "$TCL_CONFIG_SH"; then
+				if test -d "$dir/$tcl_dir" -a -r "$dir/$tcl_dir/tclConfig.sh"; then
+					TCL_CONFIG_SH=$dir/$tcl_dir/tclConfig.sh
+				fi
+			fi
+		done
+	done
+	if test -z "$TCL_CONFIG_SH"; then
+		AC_MSG_RESULT(no)
+		AC_MSG_WARN(tcl support disabled; Tcl configuration script missing)
+		USE_TCL=
+	else
+		AC_MSG_RESULT($TCL_CONFIG_SH)
+		AC_SUBST(TCL_CONFIG_SH)
+	fi
+fi
+
 dnl Check for location of Tk support (only if Tcl used)
 dnl Disable Tcl support if Tk not found

@@ -883,4 +907,21 @@

AC_CONFIG_HEADER(interfaces/odbc/config.h)

-AC_OUTPUT(GNUmakefile Makefile.global backend/port/Makefile bin/pg_version/Makefile bin/psql/Makefile bin/pg_dump/Makefile backend/utils/Gen_fmgrtab.sh interfaces/libpq/Makefile interfaces/libpq++/Makefile interfaces/libpgtcl/Makefile interfaces/ecpg/lib/Makefile include/version.h interfaces/odbc/Makefile.global interfaces/odbc/GNUmakefile)
+AC_OUTPUT(
+  GNUmakefile
+  Makefile.global
+  backend/port/Makefile
+  backend/utils/Gen_fmgrtab.sh
+  bin/pg_dump/Makefile
+  bin/pg_version/Makefile
+  bin/psql/Makefile
+  include/version.h
+  interfaces/ecpg/lib/Makefile
+  interfaces/libpgtcl/Makefile
+  interfaces/libpq++/Makefile
+  interfaces/libpq/Makefile
+  interfaces/odbc/GNUmakefile
+  interfaces/odbc/Makefile.global
+  pl/plpgsql/src/Makefile
+  pl/tcl/mkMakefile.tcldefs.sh
+)
===========================================================================
--- pl/tcl/mkMakefile.tcldefs.sh.in.orig	Wed Oct  7 14:45:20 1998
+++ pl/tcl/mkMakefile.tcldefs.sh.in	Wed Oct  7 14:40:37 1998
@@ -0,0 +1,12 @@
+
+if [ -f @TCL_CONFIG_SH@ ]; then
+    . @TCL_CONFIG_SH@
+else
+    echo "@TCL_CONFIG_SH@ not found"
+    echo "I need this file! Please make a symbolic link to this file"
+    echo "and start make again."
+    exit 1
+fi
+
+set | grep '^TCL' > Makefile.tcldefs
+exit 0
===========================================================================
--- pl/tcl/Makefile.orig	Thu Apr  9 17:02:53 1998
+++ pl/tcl/Makefile	Wed Oct  7 15:52:48 1998
@@ -77,7 +77,7 @@
 all: $(INFILES)
 Makefile.tcldefs:
-	./mkMakefile.tcldefs
+	/bin/sh mkMakefile.tcldefs.sh
 #
 # Clean 
===========================================================================
--- pl/plpgsql/src/Makefile.in.orig	Thu Oct  8 08:18:46 1998
+++ pl/plpgsql/src/Makefile.in	Thu Oct  8 08:21:07 1998
@@ -0,0 +1,131 @@
+#-------------------------------------------------------------------------
+#
+# Makefile
+#    Makefile for the plpgsql shared object
+#
+# IDENTIFICATION
+#    $Header: /usr/local/cvsroot/pgsql/src/pl/plpgsql/src/Makefile,v 1.1 1998/09/25 15:50:02 momjian Exp $
+#
+#-------------------------------------------------------------------------
+
+#
+# Tell make where the postgresql sources live
+#
+SRCDIR= ../../..
+
+#
+# Include the global and port specific Makefiles
+#
+include $(SRCDIR)/Makefile.global
+
+PORTNAME=@PORTNAME@
+
+CFLAGS+= -I$(LIBPQDIR) -I$(SRCDIR)/include
+LFLAGS+= -i -l
+
+# For fmgr.h
+CFLAGS+= -I$(SRCDIR)/backend
+
+LDADD+= -L$(LIBPQDIR) -lpq
+
+ifeq ($(PORTNAME), linux)
+  CFLAGS		+= $(CFLAGS_SL)
+  LDFLAGS_SL		= -shared
+endif
+
+ifeq ($(PORTNAME), bsd)
+  ifdef BSD_SHLIB
+    LDFLAGS_SL		= -x -Bshareable -Bforcearchive
+    CFLAGS		+= $(CFLAGS_SL)
+  endif
+endif
+
+ifeq ($(PORTNAME), bsdi)
+  ifdef BSD_SHLIB
+    ifeq ($(LDSUFFIX), .so)
+      LD		:= shlicc
+      LDFLAGS_SL	+= -O -shared
+      CFLAGS		+= $(CFLAGS_SL)
+    endif
+    ifeq ($(LDSUFFIX), .o)
+      LD		:= shlicc
+      LDFLAGS_SL	+= -O -r
+      CFLAGS		+= $(CFLAGS_SL)
+    endif
+  endif
+endif
+
+ifeq ($(PORTNAME), solaris)
+  LDFLAGS_SL		:= -G -z text
+  CFLAGS		+= $(CFLAGS_SL)
+endif
+
+ifeq ($(PORTNAME), unixware)
+  LDFLAGS_SL		:= -G -z text
+  CFLAGS		+= $(CFLAGS_SL)
+endif
+
+ifeq ($(PORTNAME), univel)
+  LDFLAGS_SL		:= -G -z text
+  CFLAGS		+= $(CFLAGS_SL)
+endif
+
+ifeq ($(PORTNAME), hpux)
+  LDFLAGS_SL		:= -b
+  CFLAGS		+= $(CFLAGS_SL)
+endif
+
+#
+# DLOBJ is the dynamically-loaded object file.
+#
+DLOBJ= plpgsql$(DLSUFFIX)
+
+OBJS=	pl_parse.o pl_handler.o pl_comp.o pl_exec.o pl_funcs.o
+
+ALL=	$(DLOBJ)
+
+#
+# Build the shared object
+#
+all: $(ALL)
+
+$(DLOBJ):	$(OBJS)
+
+#
+# Clean 
+#
+clean:
+	rm -f $(ALL)
+	rm -f *.o y.tab.h pl.tab.h pl_gram.c gram.c pl_scan.c scan.c
+
+install: all
+	$(INSTALL) $(INSTL_LIB_OPTS) $(DLOBJ) $(DESTDIR)$(LIBDIR)/$(DLOBJ)
+
+$(DLOBJ):	$(OBJS)
+	$(LD) $(LDFLAGS_SL) -o $@ $(OBJS)
+
+
+
+pl_handler.o:	pl_handler.c plpgsql.h pl.tab.h
+
+pl_comp.o:	pl_comp.c plpgsql.h pl.tab.h
+
+pl_exec.o:	pl_exec.c plpgsql.h pl.tab.h
+
+pl_funcs.o:	pl_funcs.c plpgsql.h pl.tab.h
+
+pl_parse.o:	pl_gram.c pl_scan.c plpgsql.h
+	$(CC) $(CFLAGS) -c -o $@ pl_gram.c
+
+pl_gram.c:	gram.c
+	sed -e 's/yy/plpgsql_yy/g' -e 's/YY/PLPGSQL_YY/g' <gram.c >pl_gram.c
+	sed -e 's/yy/plpgsql_yy/g' -e 's/YY/PLPGSQL_YY/g' <y.tab.h >pl.tab.h
+
+pl_scan.c:	scan.c
+	sed -e 's/yy/plpgsql_yy/g' -e 's/YY/PLPGSQL_YY/g' <scan.c >pl_scan.c
+
+gram.c:		gram.y
+
+scan.c:		scan.l
+
+pl.tab.h:	pl_gram.c
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Brook Milligan (#1)
Re: [HACKERS] PL patches

Brook Milligan <brook@trillium.NMSU.Edu> writes:

NOTE: should we be including libtool in our distribution to simplify
shared library (and other stuff) support?

This is probably a reasonable thing to think about for the next release
(I think it's too late to risk it for 6.4). It'd be a nice way of
getting rid of that platform-specific Makefile cruft I was complaining
about the other day.

But ... libtool isn't completely ready for prime time. I've been
distributing the latest release of libjpeg with libtool-based shared
lib support, but I was not brave enough to make that the default
configuration, let alone depend on its working correctly to be able
to build at all. And I've gotten enough trouble reports to convince
me this was a wise choice. If we do use libtool, we had better make
sure that there is a a way to fall back to a simple no-shared-libraries
build process.

regards, tom lane

#3Bruce Momjian
maillist@candle.pha.pa.us
In reply to: Brook Milligan (#1)
Re: [PATCHES] PL patches

Applied, and Makefile.in added.

I have had a few problems with the PL stuff recently committed. The
following patches fix the problems (i.e., all regression tests pass)
in what I hope to be a platform-independent fashion. The accomplish
the following:

1. Allow configure to check for the existence of the tclConfig.sh
script needed to configure the tcl component of PL. Configure
already checks other parts of the tcl installation, so it might
as well check for this script, too, so that paths need not be
hard-coded into mkMakefile.tcldefs.

A few extra files are created by configure from templates.

Configure is also cleaned up a bit at the end so the long list of
output files is easier to deal with.

NOTE: run autoconf.

2. A new script mkMakefile.tcldefs.sh is created from the template
mkMakefile.tcldefs.sh.in so that the substitution for tclConfig.sh
can be inserted. The script is simplified and renamed to reflect
the fact that it is a sh script.

NOTE: pl/tcl/mkMakefile.tcldefs should be removed from the tree.

3. The Makefile executes /bin/sh on the new script rather than
directly executing the script (hence the name change to make it
more explicit).

4. There are shared library problems with the plpgsql/src/Makefile.
The port-specific code was taken from the interfaces/tcl?/Makefile
so that shared libraries should work on all platforms. This means
that that Makefile must be a template for configure.

NOTE: pl/plpgsql/src/Makefile should be removed from the tree.

NOTE: should we be including libtool in our distribution to simplify
shared library (and other stuff) support?

Cheers,
Brook

-- 
  Bruce Momjian                        |  http://www.op.net/~candle
  maillist@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#4Noname
jwieck@debis.com
In reply to: Brook Milligan (#1)
PL patches (one more)

Bruce, please apply this too.

I have had a few problems with the PL stuff recently committed. The
following patches fix the problems (i.e., all regression tests pass)
in what I hope to be a platform-independent fashion. The accomplish
the following:

Thanks for assisting in that area, Brook. It all really needs
to become platform independent.

There where a few more problems fixed by the patch below.

o configure.in

The tclConfig.sh file here doesn't reside in the tcl
subdirectory. It is sitting in /usr/lib directly. I
added another check for that.

NOTE: run autoconf

o pl/tcl/mkMakefile.tcldefs.sh.in

At least one bash I'm using on one of my systems single
quotes the values in the output of the set command. But
make interprets CC=gcc -O2 different from CC='gcc -O2'.

o pl/tcl/pltcl.c

Return values where allocated in SPI memory context and
got freed on SPI_finish().

o pl/pgsql/Makefile.in

David Hartwig had some bad problems compiling PL/pgSQL on
AIX. I found that the AIX specific mkldexport.sh doesn't
support multiple object files. I added another linking
step where all the objects are combined first into
plpgsql.o and only this one is then linked into a shared
object.

David (or someone else with access to AIX), could you
please check if this works now?

Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#======================================== jwieck@debis.com (Jan Wieck) #

diff -cr src.orig/configure.in src/configure.in
*** src.orig/configure.in	Fri Oct  9 09:13:14 1998
--- src/configure.in	Fri Oct  9 09:54:18 1998
***************
*** 812,817 ****
--- 812,822 ----
  				fi
  			fi
  		done
+ 		if test -z "$TCL_CONFIG_SH"; then
+ 			if test -d "$dir" -a -r "$dir/tclConfig.sh"; then
+ 				TCL_CONFIG_SH=$dir/tclConfig.sh
+ 			fi
+ 		fi
  	done
  	if test -z "$TCL_CONFIG_SH"; then
  		AC_MSG_RESULT(no)
diff -cr src.orig/pl/plpgsql/src/Makefile.in src/pl/plpgsql/src/Makefile.in
*** src.orig/pl/plpgsql/src/Makefile.in	Fri Oct  9 09:13:42 1998
--- src/pl/plpgsql/src/Makefile.in	Fri Oct  9 09:26:59 1998
***************
*** 79,85 ****
  #
  DLOBJ= plpgsql$(DLSUFFIX)

! OBJS= pl_parse.o pl_handler.o pl_comp.o pl_exec.o pl_funcs.o

ALL= $(DLOBJ)

--- 79,87 ----
  #
  DLOBJ= plpgsql$(DLSUFFIX)

! OBJS= plpgsql.o
!
! PLOBJS= pl_parse.o pl_handler.o pl_comp.o pl_exec.o pl_funcs.o

ALL= $(DLOBJ)

***************
*** 87,92 ****
--- 89,97 ----
  # Build the shared object
  #
  all: $(ALL)
+ 
+ $(OBJS):	$(PLOBJS)
+ 	$(LD) -r -o $(OBJS) $(PLOBJS)

$(DLOBJ): $(OBJS)

diff -cr src.orig/pl/tcl/mkMakefile.tcldefs.sh.in src/pl/tcl/mkMakefile.tcldefs.sh.in
*** src.orig/pl/tcl/mkMakefile.tcldefs.sh.in	Fri Oct  9 09:13:41 1998
--- src/pl/tcl/mkMakefile.tcldefs.sh.in	Fri Oct  9 09:15:44 1998
***************
*** 8,12 ****
      exit 1
  fi
! set | grep '^TCL' > Makefile.tcldefs
  exit 0
--- 8,15 ----
      exit 1
  fi
! for v in `set | grep '^TCL' | sed -e 's/=.*//'` ; do
!     echo $v = `eval "echo \\$$v"`
! done >Makefile.tcldefs
! 
  exit 0
diff -cr src.orig/pl/tcl/pltcl.c src/pl/tcl/pltcl.c
*** src.orig/pl/tcl/pltcl.c	Fri Oct  9 09:13:41 1998
--- src/pl/tcl/pltcl.c	Fri Oct  9 10:40:08 1998
***************
*** 417,428 ****

pltcl_call_level--;

- /************************************************************
- * Disconnect from SPI manager
- ************************************************************/
- if (SPI_finish() != SPI_OK_FINISH)
- elog(ERROR, "pltcl: SPI_finish() failed");
-
return retval;
}

--- 417,422 ----
***************
*** 731,736 ****
--- 725,739 ----
  		siglongjmp(Warn_restart, 1);
  	}
+ 	/************************************************************
+ 	 * Disconnect from SPI manager and then create the return
+ 	 * values datum (if the input function does a palloc for it
+ 	 * this must not be allocated in the SPI memory context
+ 	 * because SPI_finish would free it).
+ 	 ************************************************************/
+ 	if (SPI_finish() != SPI_OK_FINISH)
+ 		elog(ERROR, "pltcl: SPI_finish() failed");
+ 
  	retval = (Datum) (*fmgr_faddr(&prodesc->result_in_func))
  		(pltcl_safe_interp->result,
  		 prodesc->result_in_elem,
***************
*** 1051,1058 ****
  	 * The return value from the procedure might be one of
  	 * the magic strings OK or SKIP or a list from array get
  	 ************************************************************/
! 	if (strcmp(pltcl_safe_interp->result, "OK") == 0)
  		return rettup;
  	if (strcmp(pltcl_safe_interp->result, "SKIP") == 0)
  	{
  		return (HeapTuple) NULL;;
--- 1054,1065 ----
  	 * The return value from the procedure might be one of
  	 * the magic strings OK or SKIP or a list from array get
  	 ************************************************************/
! 	if (SPI_finish() != SPI_OK_FINISH)
! 		elog(ERROR, "pltcl: SPI_finish() failed");
! 
! 	if (strcmp(pltcl_safe_interp->result, "OK") == 0) {
  		return rettup;
+ 	}
  	if (strcmp(pltcl_safe_interp->result, "SKIP") == 0)
  	{
  		return (HeapTuple) NULL;;
***************
*** 1309,1315 ****
  	int			loop_rc;
  	int			ntuples;
  	HeapTuple  *tuples;
! 	TupleDesc	tupdesc;
  	sigjmp_buf	save_restart;
  	char	   *usage = "syntax error - 'SPI_exec "
--- 1316,1322 ----
  	int			loop_rc;
  	int			ntuples;
  	HeapTuple  *tuples;
! 	TupleDesc	tupdesc = NULL;
  	sigjmp_buf	save_restart;

char *usage = "syntax error - 'SPI_exec "

#5Thomas G. Lockhart
lockhart@alumni.caltech.edu
In reply to: Noname (#4)
Re: [HACKERS] PL patches (one more)

o pl/tcl/mkMakefile.tcldefs.sh.in

At least one bash I'm using on one of my systems single
quotes the values in the output of the set command. But
make interprets CC=gcc -O2 different from CC='gcc -O2'.

istm that perhaps

make CC=gcc CFLAGS+=-O2

would be the best choice for achieving this. (And it works :).

- Tom

#6Noname
jwieck@debis.com
In reply to: Thomas G. Lockhart (#5)
Re: [HACKERS] PL patches (one more)

o pl/tcl/mkMakefile.tcldefs.sh.in

At least one bash I'm using on one of my systems single
quotes the values in the output of the set command. But
make interprets CC=gcc -O2 different from CC='gcc -O2'.

istm that perhaps

make CC=gcc CFLAGS+=-O2

would be the best choice for achieving this. (And it works :).

- Tom

Right - but that's not the point.

If (as it is on one of my systems) the shells set command
outputs

TCL_LIBS='-ldl -lieee -lm'

instead of

TCL_LIBS=-ldl -lieee -lm

and we put this exactly into the Makefile.tcldefs, then gmake
will put the whole string into one single argv element in the
linker call. But then the linker will not find the library
"libdl -lieee -lm.a" or it's shared version.

Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#======================================== jwieck@debis.com (Jan Wieck) #

#7Bruce Momjian
maillist@candle.pha.pa.us
In reply to: Noname (#4)
Re: [PATCHES] PL patches (one more)

Applied.

Bruce, please apply this too.

I have had a few problems with the PL stuff recently committed. The
following patches fix the problems (i.e., all regression tests pass)
in what I hope to be a platform-independent fashion. The accomplish
the following:

Thanks for assisting in that area, Brook. It all really needs
to become platform independent.

There where a few more problems fixed by the patch below.

o configure.in

The tclConfig.sh file here doesn't reside in the tcl
subdirectory. It is sitting in /usr/lib directly. I
added another check for that.

NOTE: run autoconf

o pl/tcl/mkMakefile.tcldefs.sh.in

At least one bash I'm using on one of my systems single
quotes the values in the output of the set command. But
make interprets CC=gcc -O2 different from CC='gcc -O2'.

o pl/tcl/pltcl.c

Return values where allocated in SPI memory context and
got freed on SPI_finish().

o pl/pgsql/Makefile.in

David Hartwig had some bad problems compiling PL/pgSQL on
AIX. I found that the AIX specific mkldexport.sh doesn't
support multiple object files. I added another linking
step where all the objects are combined first into
plpgsql.o and only this one is then linked into a shared
object.

David (or someone else with access to AIX), could you
please check if this works now?

-- 
  Bruce Momjian                        |  http://www.op.net/~candle
  maillist@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026