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

Commit 7d781c6

Browse files
committed
[ backpatched to 8.0.X.]
> >> 3) I restarted the postmaster both times. I got this error > both times. > >> :25: ERROR: could not load library "C:/Program > >> Files/PostgreSQL/8.0/lib/testtrigfuncs.dll": dynamic load error > > > Yes. We really need to look at fixing that error message. I had > > forgotten it completely :-( > > > Bruce, you think we can sneak that in after feature freeze? I would > > call it a bugfix :-) > > Me too. That's been on the radar for awhile --- please do > send in a patch. Here we go, that wasn't too hard :-) Apart from adding the error handling, it does one more thing: it changes the errormode when loading the DLLs. Previously if a DLL was broken, or referenced other DLLs that couldn't be found, a popup dialog box would appear on the screen. Which had to be clicked before the backend could continue. This patch also disables the popup error message for DLL loads. I think this is something we should consider doing for the entire backend - disable those popups, and say we deal with it ourselves. What do you other win32 hackers thinnk about this? In the meantime, this patch fixes the error msgs. Please apply for 8.1 and please consider a backpatch to 8.0. Magnus Hagander
1 parent 479a8fd commit 7d781c6

File tree

1 file changed

+57
-5
lines changed

1 file changed

+57
-5
lines changed

src/backend/port/dynloader/win32.c

+57-5
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,84 @@
1-
/* $PostgreSQL: pgsql/src/backend/port/dynloader/win32.c,v 1.5 2004/12/02 19:38:50 momjian Exp $ */
1+
/* $PostgreSQL: pgsql/src/backend/port/dynloader/win32.c,v 1.6 2005/08/12 21:23:10 momjian Exp $ */
22

33
#include <windows.h>
4+
#include <stdio.h>
45

56
char *dlerror(void);
67
int dlclose(void *handle);
78
void *dlsym(void *handle, const char *symbol);
89
void *dlopen(const char *path, int mode);
910

11+
static char last_dyn_error[512];
12+
13+
static void set_dl_error(void)
14+
{
15+
DWORD err = GetLastError();
16+
17+
if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS |
18+
FORMAT_MESSAGE_FROM_SYSTEM,
19+
NULL,
20+
err,
21+
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
22+
last_dyn_error,
23+
sizeof(last_dyn_error)-1,
24+
NULL) == 0)
25+
{
26+
snprintf(last_dyn_error, sizeof(last_dyn_error)-1,
27+
"unknown error %lu", err);
28+
}
29+
}
30+
1031
char *
1132
dlerror(void)
1233
{
13-
return "dynamic load error";
34+
if (last_dyn_error[0])
35+
return last_dyn_error;
36+
else
37+
return NULL;
1438
}
1539

1640
int
1741
dlclose(void *handle)
1842
{
19-
return FreeLibrary((HMODULE) handle) ? 0 : 1;
43+
if (!FreeLibrary((HMODULE) handle))
44+
{
45+
set_dl_error();
46+
return 1;
47+
}
48+
last_dyn_error[0] = 0;
49+
return 0;
2050
}
2151

2252
void *
2353
dlsym(void *handle, const char *symbol)
2454
{
25-
return (void *) GetProcAddress((HMODULE) handle, symbol);
55+
void *ptr;
56+
ptr = GetProcAddress((HMODULE) handle, symbol);
57+
if (!ptr)
58+
{
59+
set_dl_error();
60+
return NULL;
61+
}
62+
last_dyn_error[0] = 0;
63+
return ptr;
2664
}
2765

2866
void *
2967
dlopen(const char *path, int mode)
3068
{
31-
return (void *) LoadLibrary(path);
69+
HMODULE h;
70+
int prevmode;
71+
72+
/* Disable popup error messages when loading DLLs */
73+
prevmode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
74+
h = LoadLibrary(path);
75+
SetErrorMode(prevmode);
76+
77+
if (!h)
78+
{
79+
set_dl_error();
80+
return NULL;
81+
}
82+
last_dyn_error[0] = 0;
83+
return (void *) h;
3284
}

0 commit comments

Comments
 (0)