Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 811be89

Browse files
committed
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.
1 parent 6f14eff commit 811be89

File tree

2 files changed

+79
-2
lines changed

2 files changed

+79
-2
lines changed

src/backend/port/win32/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
# Makefile for backend/port/win32
55
#
66
# IDENTIFICATION
7-
# $PostgreSQL: pgsql/src/backend/port/win32/Makefile,v 1.10 2007/03/21 14:39:23 mha Exp $
7+
# $PostgreSQL: pgsql/src/backend/port/win32/Makefile,v 1.11 2007/10/29 12:35:41 mha Exp $
88
#
99
#-------------------------------------------------------------------------
1010

1111
subdir = src/backend/port/win32
1212
top_builddir = ../../../..
1313
include $(top_builddir)/src/Makefile.global
1414

15-
OBJS = timer.o socket.o signal.o security.o
15+
OBJS = timer.o socket.o signal.o security.o mingwcompat.o
1616

1717
all: SUBSYS.o
1818

src/backend/port/win32/mingwcompat.c

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* mingwcompat.c
4+
* MinGW compatibility functions
5+
*
6+
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
7+
*
8+
* IDENTIFICATION
9+
* $PostgreSQL: pgsql/src/backend/port/win32/mingwcompat.c,v 1.1 2007/10/29 12:35:41 mha Exp $
10+
*
11+
*-------------------------------------------------------------------------
12+
*/
13+
14+
#include "postgres.h"
15+
16+
/*
17+
* This file contains loaders for functions that are missing in the MinGW
18+
* import libraries. It's only for actual Win32 API functions, so they are
19+
* all present in proper Win32 compilers.
20+
*/
21+
#ifndef WIN32_ONLY_COMPILER
22+
23+
static HMODULE kernel32 = NULL;
24+
25+
/*
26+
* Load DLL file just once regardless of how many functions
27+
* we load/call in it.
28+
*/
29+
static void
30+
LoadKernel32()
31+
{
32+
if (kernel32 != NULL)
33+
return;
34+
35+
kernel32 = LoadLibraryEx("kernel32.dll", NULL, 0);
36+
if (kernel32 == NULL)
37+
ereport(FATAL,
38+
(errmsg_internal("could not load kernel32.dll: %d",
39+
(int)GetLastError())));
40+
}
41+
42+
43+
/*
44+
* Replacement for RegisterWaitForSingleObject(), which lives in
45+
* kernel32.dll·
46+
*/
47+
typedef BOOL (WINAPI * __RegisterWaitForSingleObject)
48+
(PHANDLE, HANDLE, WAITORTIMERCALLBACK, PVOID, ULONG, ULONG);
49+
__RegisterWaitForSingleObject _RegisterWaitForSingleObject = NULL;
50+
51+
BOOL WINAPI
52+
RegisterWaitForSingleObject(PHANDLE phNewWaitObject,
53+
HANDLE hObject,
54+
WAITORTIMERCALLBACK Callback,
55+
PVOID Context,
56+
ULONG dwMilliseconds,
57+
ULONG dwFlags)
58+
{
59+
if (_RegisterWaitForSingleObject == NULL)
60+
{
61+
LoadKernel32();
62+
63+
_RegisterWaitForSingleObject = (__RegisterWaitForSingleObject)
64+
GetProcAddress(kernel32, "RegisterWaitForSingleObject");
65+
66+
if (_RegisterWaitForSingleObject == NULL)
67+
ereport(FATAL,
68+
(errmsg_internal("could not locate RegisterWaitForSingleObject in kernel32.dll: %d",
69+
(int)GetLastError())));
70+
}
71+
72+
return (_RegisterWaitForSingleObject)
73+
(phNewWaitObject, hObject, Callback, Context, dwMilliseconds, dwFlags);
74+
}
75+
76+
#endif
77+

0 commit comments

Comments
 (0)