diff options
author | Magnus Hagander | 2007-10-29 12:35:41 +0000 |
---|---|---|
committer | Magnus Hagander | 2007-10-29 12:35:41 +0000 |
commit | 811be893fa743ef553950a5d31b7e68230d3cf11 (patch) | |
tree | e60f652655ced445bdc7df79896848c1de88ebd2 | |
parent | 6f14effbf9ce702614ee49cb36e1b31ead3fae45 (diff) |
Add compat file for dynamically loading the functions that MinGW is missing
the imports for. Add RegisterWaitForSingleObject() to the list of such
functions, which should take care of the current buildfarm breakage.
-rw-r--r-- | src/backend/port/win32/Makefile | 4 | ||||
-rw-r--r-- | src/backend/port/win32/mingwcompat.c | 77 |
2 files changed, 79 insertions, 2 deletions
diff --git a/src/backend/port/win32/Makefile b/src/backend/port/win32/Makefile index 620d921eddb..6aabc212395 100644 --- a/src/backend/port/win32/Makefile +++ b/src/backend/port/win32/Makefile @@ -4,7 +4,7 @@ # Makefile for backend/port/win32 # # IDENTIFICATION -# $PostgreSQL: pgsql/src/backend/port/win32/Makefile,v 1.10 2007/03/21 14:39:23 mha Exp $ +# $PostgreSQL: pgsql/src/backend/port/win32/Makefile,v 1.11 2007/10/29 12:35:41 mha Exp $ # #------------------------------------------------------------------------- @@ -12,7 +12,7 @@ subdir = src/backend/port/win32 top_builddir = ../../../.. include $(top_builddir)/src/Makefile.global -OBJS = timer.o socket.o signal.o security.o +OBJS = timer.o socket.o signal.o security.o mingwcompat.o all: SUBSYS.o diff --git a/src/backend/port/win32/mingwcompat.c b/src/backend/port/win32/mingwcompat.c new file mode 100644 index 00000000000..da45854ef9b --- /dev/null +++ b/src/backend/port/win32/mingwcompat.c @@ -0,0 +1,77 @@ +/*------------------------------------------------------------------------- + * + * mingwcompat.c + * MinGW compatibility functions + * + * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group + * + * IDENTIFICATION + * $PostgreSQL: pgsql/src/backend/port/win32/mingwcompat.c,v 1.1 2007/10/29 12:35:41 mha Exp $ + * + *------------------------------------------------------------------------- + */ + +#include "postgres.h" + +/* + * This file contains loaders for functions that are missing in the MinGW + * import libraries. It's only for actual Win32 API functions, so they are + * all present in proper Win32 compilers. + */ +#ifndef WIN32_ONLY_COMPILER + +static HMODULE kernel32 = NULL; + +/* + * Load DLL file just once regardless of how many functions + * we load/call in it. + */ +static void +LoadKernel32() +{ + if (kernel32 != NULL) + return; + + kernel32 = LoadLibraryEx("kernel32.dll", NULL, 0); + if (kernel32 == NULL) + ereport(FATAL, + (errmsg_internal("could not load kernel32.dll: %d", + (int)GetLastError()))); +} + + +/* + * Replacement for RegisterWaitForSingleObject(), which lives in + * kernel32.dll· + */ +typedef BOOL (WINAPI * __RegisterWaitForSingleObject) + (PHANDLE, HANDLE, WAITORTIMERCALLBACK, PVOID, ULONG, ULONG); +__RegisterWaitForSingleObject _RegisterWaitForSingleObject = NULL; + +BOOL WINAPI +RegisterWaitForSingleObject(PHANDLE phNewWaitObject, + HANDLE hObject, + WAITORTIMERCALLBACK Callback, + PVOID Context, + ULONG dwMilliseconds, + ULONG dwFlags) +{ + if (_RegisterWaitForSingleObject == NULL) + { + LoadKernel32(); + + _RegisterWaitForSingleObject = (__RegisterWaitForSingleObject) + GetProcAddress(kernel32, "RegisterWaitForSingleObject"); + + if (_RegisterWaitForSingleObject == NULL) + ereport(FATAL, + (errmsg_internal("could not locate RegisterWaitForSingleObject in kernel32.dll: %d", + (int)GetLastError()))); + } + + return (_RegisterWaitForSingleObject) + (phNewWaitObject, hObject, Callback, Context, dwMilliseconds, dwFlags); +} + +#endif + |