Skip to content

Commit 1a3e574

Browse files
arp242brammool
authored andcommitted
patch 8.2.3208: dynamic library load error does not mention why it failed
Problem: Dynamic library load error does not mention why it failed. Solution: Add the error message. (Martin Tournoij, closes #8621)
1 parent 5a234eb commit 1a3e574

14 files changed

Lines changed: 45 additions & 30 deletions

src/globals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1632,7 +1632,7 @@ EXTERN char e_fsync[] INIT(= N_("E667: Fsync failed"));
16321632
|| defined(DYNAMIC_MZSCHEME) \
16331633
|| defined(DYNAMIC_LUA) \
16341634
|| defined(FEAT_TERMINAL)
1635-
EXTERN char e_loadlib[] INIT(= N_("E370: Could not load library %s"));
1635+
EXTERN char e_loadlib[] INIT(= N_("E370: Could not load library %s: %s"));
16361636
EXTERN char e_loadfunc[] INIT(= N_("E448: Could not load library function %s"));
16371637
#endif
16381638
EXTERN char e_nobang[] INIT(= N_("E477: No ! allowed"));

src/if_cscope.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,24 +1329,6 @@ clear_csinfo(int i)
13291329
#endif
13301330
}
13311331

1332-
#ifndef UNIX
1333-
static char *
1334-
GetWin32Error(void)
1335-
{
1336-
char *msg = NULL;
1337-
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
1338-
NULL, GetLastError(), 0, (LPSTR)&msg, 0, NULL);
1339-
if (msg != NULL)
1340-
{
1341-
// remove trailing \r\n
1342-
char *pcrlf = strstr(msg, "\r\n");
1343-
if (pcrlf != NULL)
1344-
*pcrlf = '\0';
1345-
}
1346-
return msg;
1347-
}
1348-
#endif
1349-
13501332
/*
13511333
* Insert a new cscope database filename into the filelist.
13521334
*/

src/if_lua.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,12 @@ static void luaV_call_lua_func_free(void *state);
105105
# define load_dll(n) dlopen((n), RTLD_LAZY|RTLD_GLOBAL)
106106
# define symbol_from_dll dlsym
107107
# define close_dll dlclose
108+
# define load_dll_error dlerror
108109
#else
109110
# define load_dll vimLoadLib
110111
# define symbol_from_dll GetProcAddress
111112
# define close_dll FreeLibrary
113+
# define load_dll_error GetWin32Error
112114
#endif
113115

114116
// lauxlib
@@ -446,7 +448,7 @@ lua_link_init(char *libname, int verbose)
446448
if (!hinstLua)
447449
{
448450
if (verbose)
449-
semsg(_(e_loadlib), libname);
451+
semsg(_(e_loadlib), libname, load_dll_error());
450452
return FAIL;
451453
}
452454
for (reg = luaV_dll; reg->func; reg++)

src/if_mzsch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,14 +668,14 @@ mzscheme_runtime_link_init(char *sch_dll, char *gc_dll, int verbose)
668668
if (!hMzGC)
669669
{
670670
if (verbose)
671-
semsg(_(e_loadlib), gc_dll);
671+
semsg(_(e_loadlib), gc_dll, GetWin32Error());
672672
return FAIL;
673673
}
674674

675675
if (!hMzSch)
676676
{
677677
if (verbose)
678-
semsg(_(e_loadlib), sch_dll);
678+
semsg(_(e_loadlib), sch_dll, GetWin32Error());
679679
return FAIL;
680680
}
681681

src/if_perl.xs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,13 @@ typedef int perl_key;
175175
# define load_dll(n) dlopen((n), RTLD_LAZY|RTLD_GLOBAL)
176176
# define symbol_from_dll dlsym
177177
# define close_dll dlclose
178+
# define load_dll_error dlerror
178179
# else
179180
# define PERL_PROC FARPROC
180181
# define load_dll vimLoadLib
181182
# define symbol_from_dll GetProcAddress
182183
# define close_dll FreeLibrary
184+
# define load_dll_error GetWin32Error
183185
# endif
184186
/*
185187
* Wrapper defines

src/if_python.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,12 @@ struct PyMethodDef { Py_ssize_t a; };
141141
# endif
142142
# define close_dll dlclose
143143
# define symbol_from_dll dlsym
144+
# define load_dll_error dlerror
144145
# else
145146
# define load_dll vimLoadLib
146147
# define close_dll FreeLibrary
147148
# define symbol_from_dll GetProcAddress
149+
# define load_dll_error GetWin32Error
148150
# endif
149151

150152
// This makes if_python.c compile without warnings against Python 2.5
@@ -688,7 +690,7 @@ python_runtime_link_init(char *libname, int verbose)
688690
if (!hinstPython)
689691
{
690692
if (verbose)
691-
semsg(_(e_loadlib), libname);
693+
semsg(_(e_loadlib), libname, load_dll_error());
692694
return FAIL;
693695
}
694696

src/if_python3.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,12 @@ typedef PySliceObject PySliceObject_T;
125125
# endif
126126
# define close_dll dlclose
127127
# define symbol_from_dll dlsym
128+
# define load_dll_error dlerror
128129
# else
129130
# define load_dll vimLoadLib
130131
# define close_dll FreeLibrary
131132
# define symbol_from_dll GetProcAddress
133+
# define load_dll_error GetWin32Error
132134
# endif
133135
/*
134136
* Wrapper defines
@@ -795,7 +797,7 @@ py3_runtime_link_init(char *libname, int verbose)
795797
if (!hinstPy3)
796798
{
797799
if (verbose)
798-
semsg(_(e_loadlib), libname);
800+
semsg(_(e_loadlib), libname, load_dll_error());
799801
return FAIL;
800802
}
801803

src/if_ruby.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,13 @@
184184
# define load_dll(n) dlopen((n), RTLD_LAZY|RTLD_GLOBAL)
185185
# define symbol_from_dll dlsym
186186
# define close_dll dlclose
187+
# define load_dll_error dlerror
187188
# else
188189
# define RUBY_PROC FARPROC
189190
# define load_dll vimLoadLib
190191
# define symbol_from_dll GetProcAddress
191192
# define close_dll FreeLibrary
193+
# define load_dll_error GetWin32Error
192194
# endif
193195
#endif
194196

@@ -806,7 +808,7 @@ ruby_runtime_link_init(char *libname, int verbose)
806808
if (!hinstRuby)
807809
{
808810
if (verbose)
809-
semsg(_(e_loadlib), libname);
811+
semsg(_(e_loadlib), libname, load_dll_error());
810812
return FAIL;
811813
}
812814

src/if_tcl.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,13 @@ typedef int HANDLE;
167167
# define load_dll(n) dlopen((n), RTLD_LAZY|RTLD_GLOBAL)
168168
# define symbol_from_dll dlsym
169169
# define close_dll dlclose
170+
# define load_dll_error dlerror
170171
# else
171172
# define TCL_PROC FARPROC
172173
# define load_dll vimLoadLib
173174
# define symbol_from_dll GetProcAddress
174175
# define close_dll FreeLibrary
176+
# define load_dll_error GetWin32Error
175177
# endif
176178

177179
/*
@@ -213,7 +215,7 @@ tcl_runtime_link_init(char *libname, int verbose)
213215
if (!(hTclLib = load_dll(libname)))
214216
{
215217
if (verbose)
216-
semsg(_(e_loadlib), libname);
218+
semsg(_(e_loadlib), libname, load_dll_error());
217219
return FAIL;
218220
}
219221
for (i = 0; tcl_funcname_table[i].ptr; ++i)

src/mbyte.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4902,7 +4902,8 @@ iconv_enabled(int verbose)
49024902
{
49034903
verbose_enter();
49044904
semsg(_(e_loadlib),
4905-
hIconvDLL == 0 ? DYNAMIC_ICONV_DLL : DYNAMIC_MSVCRT_DLL);
4905+
hIconvDLL == 0 ? DYNAMIC_ICONV_DLL : DYNAMIC_MSVCRT_DLL,
4906+
GetWin32Error());
49064907
verbose_leave();
49074908
}
49084909
iconv_end();

0 commit comments

Comments
 (0)