dynamic loading on NT works!
Hi all,
I have played with dynamic loading of modules to the backend and it works.
It needs only to add "DLLIMPORT" to all data structures, that should be
exported.
The main thing is done in the src/include/c.h - it defines DLLIMPORT to
nothing on platforms other then Cygwin and __declspec(...) on Cygwin, and in
src/makefiles/Makefile.win - it defines the symbol BUILDING_DLL only when
the make process is in the src/backend subtree.
I have tested it with trigger regression test - it works, and with some
plpgsql stuff - it doesn't work and it probably needs some other data to be
exported from the backend.
I think the changes are minimal so they can by applied to the development
source tree for 6.5.
Dan
----------------------------------------------
Daniel Horak
network and system administrator
e-mail: horak@mmp.plzen-city.cz
privat e-mail: dan.horak@email.cz
----------------------------------------------
Attachments:
dll.patchapplication/octet-stream; name=dll.patchDownload
Index: src/makefiles/Makefile.win
===================================================================
RCS file: /usr/local/cvsroot/pgsql/src/makefiles/Makefile.win,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Makefile.win 1999/01/08 19:29:18 1.3
+++ Makefile.win 1999/03/05 18:42:11 1.4
@@ -13,3 +13,8 @@
$(DLLTOOL) --export-all --output-def $*.def $<
$(DLLWRAP) -o $@ --def $*.def $< $(SRCDIR)/utils/dllinit.o $(DLLLIBS)
rm -f $*.def
+
+curdir:=$(shell pwd)
+ifeq ($(findstring backend,$(curdir)), backend)
+CFLAGS+= -DBUILDING_DLL=1
+endif
Index: src/include/c.h
===================================================================
RCS file: /usr/local/cvsroot/pgsql/src/include/c.h,v
retrieving revision 1.1.1.1
retrieving revision 1.3
diff -u -r1.1.1.1 -r1.3
--- c.h 1999/01/02 14:52:04 1.1.1.1
+++ c.h 1999/03/05 18:39:46 1.3
@@ -49,6 +49,10 @@
*/
#include <stdlib.h>
+#ifdef __CYGWIN32__
+#include <errno.h>
+#endif
+
/* ----------------------------------------------------------------
* Section 1: bool, true, false, TRUE, FALSE
* ----------------------------------------------------------------
@@ -819,6 +823,20 @@
#define NULL_DEV "/dev/null"
#define COPY_CMD "cp"
#define SEP_CHAR '/'
+
+/* defines for dynamic linking on Win32 platform */
+#ifdef __CYGWIN32__
+#if __GNUC__ && ! defined (__declspec)
+#error You need egcs 1.1 or newer for compiling!
+#endif
+#ifdef BUILDING_DLL
+#define DLLIMPORT __declspec (dllexport)
+#else /* not BUILDING_DLL */
+#define DLLIMPORT __declspec (dllimport)
+#endif
+#else /* not CYGWIN */
+#define DLLIMPORT
+#endif
/* ----------------
* end of c.h
Index: src/backend/executor/spi.c
===================================================================
RCS file: /usr/local/cvsroot/pgsql/src/backend/executor/spi.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- spi.c 1999/01/02 14:51:36 1.1.1.1
+++ spi.c 1999/03/05 18:37:59 1.2
@@ -26,9 +26,9 @@
static int _SPI_connected = -1;
static int _SPI_curid = -1;
-uint32 SPI_processed = 0;
-SPITupleTable *SPI_tuptable;
-int SPI_result;
+DLLIMPORT uint32 SPI_processed = 0;
+DLLIMPORT SPITupleTable *SPI_tuptable;
+DLLIMPORT int SPI_result;
void spi_printtup(HeapTuple tuple, TupleDesc tupdesc);
Index: src/include/executor/spi.h
===================================================================
RCS file: /usr/local/cvsroot/pgsql/src/include/executor/spi.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- spi.h 1999/01/02 14:52:11 1.1
+++ spi.h 1999/03/05 18:41:21 1.2
@@ -66,9 +66,9 @@
#define SPI_OK_UPDATE 9
#define SPI_OK_CURSOR 10
-extern uint32 SPI_processed;
-extern SPITupleTable *SPI_tuptable;
-extern int SPI_result;
+extern DLLIMPORT uint32 SPI_processed;
+extern DLLIMPORT SPITupleTable *SPI_tuptable;
+extern DLLIMPORT int SPI_result;
extern int SPI_connect(void);
extern int SPI_finish(void);
Index: src/backend/commands/trigger.c
===================================================================
RCS file: /usr/local/cvsroot/pgsql/src/backend/commands/trigger.c,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -u -r1.1.1.2 -r1.2
--- trigger.c 1999/02/26 18:39:19 1.1.1.2
+++ trigger.c 1999/03/05 18:36:53 1.2
@@ -34,7 +34,7 @@
#include "utils/acl.h"
#endif
-TriggerData *CurrentTriggerData = NULL;
+DLLIMPORT TriggerData *CurrentTriggerData = NULL;
void RelationBuildTriggers(Relation relation);
void FreeTriggerDesc(Relation relation);
Index: src/include/commands/trigger.h
===================================================================
RCS file: /usr/local/cvsroot/pgsql/src/include/commands/trigger.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- trigger.h 1999/01/02 14:52:09 1.1
+++ trigger.h 1999/03/05 18:41:15 1.2
@@ -25,7 +25,7 @@
Trigger *tg_trigger;
} TriggerData;
-extern TriggerData *CurrentTriggerData;
+extern DLLIMPORT TriggerData *CurrentTriggerData;
#define TRIGGER_EVENT_INSERT 0x00000000
#define TRIGGER_EVENT_DELETE 0x00000001
Applied...
On Tue, 9 Mar 1999, Horak Daniel wrote:
Hi all,
I have played with dynamic loading of modules to the backend and it works.
It needs only to add "DLLIMPORT" to all data structures, that should be
exported.The main thing is done in the src/include/c.h - it defines DLLIMPORT to
nothing on platforms other then Cygwin and __declspec(...) on Cygwin, and in
src/makefiles/Makefile.win - it defines the symbol BUILDING_DLL only when
the make process is in the src/backend subtree.I have tested it with trigger regression test - it works, and with some
plpgsql stuff - it doesn't work and it probably needs some other data to be
exported from the backend.I think the changes are minimal so they can by applied to the development
source tree for 6.5.Dan
----------------------------------------------
Daniel Horak
network and system administrator
e-mail: horak@mmp.plzen-city.cz
privat e-mail: dan.horak@email.cz
----------------------------------------------
Marc G. Fournier
Systems Administrator @ hub.org
primary: scrappy@hub.org secondary: scrappy@{freebsd|postgresql}.org