Browse Source

A small patch to allow DSO-based PostgreSQL extensions to be more flexible by providing initialization and finishing hooks. This patch was contributed by Ralf S. Engelschall to the upstream vendor in August 2006 and taken over by the upstream vendor for inclusion into the next major PostgreSQL release. http://groups.google.com/group/pgsql.hackers/browse_frm/thread/ce7858f865a6fecd/19a3f052656f3a69?tvc=1&q=PG_init#19a3f052656f3a69 PS: This allows my OSSP uuid's PostgreSQL extension to finally do the Right Thing ;-)

Ralf S. Engelschall 19 years ago
parent
commit
b6f37fe8ed
2 changed files with 71 additions and 1 deletions
  1. 70 0
      postgresql/postgresql.patch
  2. 1 1
      postgresql/postgresql.spec

+ 70 - 0
postgresql/postgresql.patch

@@ -60,3 +60,73 @@ Index: src/template/linux
  # Force _GNU_SOURCE on; plperl is broken with Perl 5.8.0 otherwise
 -CPPFLAGS="-D_GNU_SOURCE"
 +CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
+
+-----------------------------------------------------------------------------
+
+A small patch to allow DSO-based PostgreSQL extensions to be more
+flexible by providing initialization and finishing hooks. This patch was
+contributed by Ralf S. Engelschall to the upstream vendor in August 2006
+and taken over by the upstream vendor for inclusion into the next major
+PostgreSQL release.
+
+http://groups.google.com/group/pgsql.hackers/browse_frm/thread/ce7858f865a6fecd/19a3f052656f3a69?tvc=1&q=PG_init#19a3f052656f3a69
+
+Index: src/backend/utils/fmgr/dfmgr.c
+--- src/backend/utils/fmgr/dfmgr.c.orig	2005-10-15 04:49:32 +0200
++++ src/backend/utils/fmgr/dfmgr.c	2006-10-07 11:53:58 +0200
+@@ -60,6 +60,10 @@
+ static char *expand_dynamic_library_name(const char *name);
+ static char *substitute_libpath_macro(const char *name);
+ 
++/* types for PostgreSQL-specific DSO init/fini functions */
++typedef void (*PG_init_t)(void);
++typedef void (*PG_fini_t)(void);
++
+ /*
+  * Load the specified dynamic-link library file, and look for a function
+  * named funcname in it.  (funcname can be NULL to just load the file.)
+@@ -77,6 +81,7 @@
+ load_external_function(char *filename, char *funcname,
+ 					   bool signalNotFound, void **filehandle)
+ {
++	PG_init_t *PG_init;
+ 	DynamicFileList *file_scanner;
+ 	PGFunction	retval;
+ 	char	   *load_error;
+@@ -146,6 +151,13 @@
+ 							fullname, load_error)));
+ 		}
+ 
++		/* optionally give the DSO a chance to initialize by calling a
++		   PostgreSQL-specific (and this way portable) "_PG_init" function
++		   similar to what dlopen(3) implicitly does with "_init" on some
++		   Unix platforms. */
++		if ((PG_init = (PG_init_t *)pg_dlsym(file_scanner->handle, "_PG_init")) != NULL)
++		        (*PG_init)();
++
+ 		/* OK to link it into list */
+ 		if (file_list == NULL)
+ 			file_list = file_scanner;
+@@ -187,6 +199,7 @@
+ void
+ load_file(char *filename)
+ {
++	PG_fini_t *PG_fini;
+ 	DynamicFileList *file_scanner,
+ 			   *prv,
+ 			   *nxt;
+@@ -223,6 +236,14 @@
+ 				prv->next = nxt;
+ 			else
+ 				file_list = nxt;
++
++			/* optionally give the DSO a chance to finish by calling
++			   a PostgreSQL-specific (and this way portable) "_PG_fini"
++			   function similar to what dlopen(3) implicitly does with
++			   "_fini" on some Unix platforms. */
++			if ((PG_fini = (PG_fini_t *)pg_dlsym(file_scanner->handle, "_PG_fini")) != NULL)
++				(*PG_fini)();
++
+ 			clear_external_function_hash(file_scanner->handle);
+ 			pg_dlclose(file_scanner->handle);
+ 			free((char *) file_scanner);

+ 1 - 1
postgresql/postgresql.spec

@@ -45,7 +45,7 @@ Class:        BASE
 Group:        Database
 License:      GPL
 Version:      %{V_postgresql}
-Release:      20060901
+Release:      20061007
 
 #   package options
 %option       with_server       yes