Here is a patch that will enable a module to change the stack_base_ptr
temporarilly during a call. A background discussion can be found here:
http://www.mail-archive.com/pgsql-hackers@postgresql.org/msg64586.html
Regards,
Thomas Hallgren
Index: src/backend/tcop/postgres.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/tcop/postgres.c,v
retrieving revision 1.463
diff -u -r1.463 postgres.c
--- src/backend/tcop/postgres.c 26 Sep 2005 15:51:12 -0000 1.463
+++ src/backend/tcop/postgres.c 2 Oct 2005 07:16:14 -0000
@@ -2285,6 +2285,27 @@
}
}
+/*
+ * set_stack_base_ptr: Assign a new stack base pointer
+ *
+ * Modules that call on the backend code from a thread different then the
+ * main thread can use this function to temporarilly swap the stack base
+ * pointer during the call.
+ *
+ * NOTE! This does in no way mean that the backend code is thread-safe. It
+ * cannot run multiple threads simultaniously. The caller must ensure that
+ * only one thread at a time is calling, that the call is encapsulated in
+ * a PG_TRY/PG_CATCH, and that signal handlers are installed to cater for
+ * signals in other threads then main.
+ */
+char*
+set_stack_base_ptr(char* new_base_ptr)
+{
+ char* old_base_ptr = stack_base_ptr;
+ stack_base_ptr = new_base_ptr;
+ return old_base_ptr;
+}
+
/* GUC assign hook to update max_stack_depth_bytes from max_stack_depth */
bool
assign_max_stack_depth(int newval, bool doit, GucSource source)
Index: src/include/miscadmin.h
===================================================================
RCS file: /projects/cvsroot/pgsql/src/include/miscadmin.h,v
retrieving revision 1.179
diff -u -r1.179 miscadmin.h
--- src/include/miscadmin.h 17 Aug 2005 22:14:34 -0000 1.179
+++ src/include/miscadmin.h 2 Oct 2005 07:16:15 -0000
@@ -216,6 +216,7 @@
/* in tcop/postgres.c */
extern void check_stack_depth(void);
+extern char* set_stack_base_ptr(char* new_base_ptr);
/*****************************************************************************