diff --git a/src/configure.in b/src/configure.in
index 81208640fd613470f4fcc22ab3db9f7a5910a6a1..71525c35b3d3efd51d9a6f706762b3c1512215b2 100644
--- a/src/configure.in
+++ b/src/configure.in
@@ -817,6 +817,11 @@ if test "$USE_TCL"; then
 				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 --git a/src/pl/plpgsql/src/Makefile.in b/src/pl/plpgsql/src/Makefile.in
index cd8bb815d7bf31a4aad6623bc23ca9f879214199..aad3dcb0b441d6ce4df887d2fe3ef9d2188bbfe5 100644
--- a/src/pl/plpgsql/src/Makefile.in
+++ b/src/pl/plpgsql/src/Makefile.in
@@ -4,7 +4,7 @@
 #    Makefile for the plpgsql shared object
 #
 # IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/pl/plpgsql/src/Attic/Makefile.in,v 1.4 1998/10/09 04:50:12 momjian Exp $
+#    $Header: /cvsroot/pgsql/src/pl/plpgsql/src/Attic/Makefile.in,v 1.5 1998/10/09 16:57:07 momjian Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -79,7 +79,9 @@ endif
 #
 DLOBJ= plpgsql$(DLSUFFIX)
 
-OBJS=	pl_parse.o pl_handler.o pl_comp.o pl_exec.o pl_funcs.o
+OBJS=	plpgsql.o
+
+PLOBJS=	pl_parse.o pl_handler.o pl_comp.o pl_exec.o pl_funcs.o
 
 ALL=	$(DLOBJ)
 
@@ -88,6 +90,9 @@ ALL=	$(DLOBJ)
 #
 all: $(ALL)
 
+$(OBJS):	$(PLOBJS)
+	$(LD) -r -o $(OBJS) $(PLOBJS)
+
 $(DLOBJ):	$(OBJS)
 
 #
diff --git a/src/pl/tcl/mkMakefile.tcldefs.sh.in b/src/pl/tcl/mkMakefile.tcldefs.sh.in
index 95491d7279d4999da8de79dd4d005aef53cec545..c3981dd3102b246bfe39843e494e79ee56f73f27 100644
--- a/src/pl/tcl/mkMakefile.tcldefs.sh.in
+++ b/src/pl/tcl/mkMakefile.tcldefs.sh.in
@@ -8,5 +8,8 @@ else
     exit 1
 fi
 
-set | grep '^TCL' > Makefile.tcldefs
+for v in `set | grep '^TCL' | sed -e 's/=.*//'` ; do
+    echo $v = `eval "echo \\$$v"`
+done >Makefile.tcldefs
+
 exit 0
diff --git a/src/pl/tcl/pltcl.c b/src/pl/tcl/pltcl.c
index c6f418d331520a141a801d1b349ff9d38df92196..3ce921b0378e00f55121767ed58080d4ea05bcc7 100644
--- a/src/pl/tcl/pltcl.c
+++ b/src/pl/tcl/pltcl.c
@@ -3,7 +3,7 @@
  *			  procedural language (PL)
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/pl/tcl/pltcl.c,v 1.6 1998/09/01 04:40:28 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/pl/tcl/pltcl.c,v 1.7 1998/10/09 16:57:10 momjian Exp $
  *
  *	  This software is copyrighted by Jan Wieck - Hamburg.
  *
@@ -417,12 +417,6 @@ pltcl_call_handler(FmgrInfo *proinfo,
 
 	pltcl_call_level--;
 
-	/************************************************************
-	 * Disconnect from SPI manager
-	 ************************************************************/
-	if (SPI_finish() != SPI_OK_FINISH)
-		elog(ERROR, "pltcl: SPI_finish() failed");
-
 	return retval;
 }
 
@@ -731,6 +725,15 @@ pltcl_func_handler(FmgrInfo *proinfo,
 		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,8 +1054,12 @@ pltcl_trigger_handler(FmgrInfo *proinfo)
 	 * 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)
+	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,7 +1316,7 @@ pltcl_SPI_exec(ClientData cdata, Tcl_Interp * interp,
 	int			loop_rc;
 	int			ntuples;
 	HeapTuple  *tuples;
-	TupleDesc	tupdesc;
+	TupleDesc	tupdesc = NULL;
 	sigjmp_buf	save_restart;
 
 	char	   *usage = "syntax error - 'SPI_exec "