0
0
mirror of https://github.com/vim/vim.git synced 2025-07-25 10:54:51 -04:00

updated for version 7.3.034

Problem:    Win32: may be loading .dll from the wrong directory.
Solution:   Go to the Vim executable directory when opening a library.
This commit is contained in:
Bram Moolenaar 2010-10-23 14:02:54 +02:00
parent b8e86705ca
commit ebbcb824ba
12 changed files with 69 additions and 51 deletions

View File

@ -1260,7 +1260,7 @@ gui_mch_prepare(int *argc, char **argv)
/* try and load the user32.dll library and get the entry points for /* try and load the user32.dll library and get the entry points for
* multi-monitor-support. */ * multi-monitor-support. */
if ((user32_lib = LoadLibrary("User32.dll")) != NULL) if ((user32_lib = vimLoadLib("User32.dll")) != NULL)
{ {
pMonitorFromWindow = (TMonitorFromWindow)GetProcAddress(user32_lib, pMonitorFromWindow = (TMonitorFromWindow)GetProcAddress(user32_lib,
"MonitorFromWindow"); "MonitorFromWindow");
@ -4188,7 +4188,7 @@ gui_mch_set_foreground(void)
static void static void
dyn_imm_load(void) dyn_imm_load(void)
{ {
hLibImm = LoadLibrary("imm32.dll"); hLibImm = vimLoadLib("imm32.dll");
if (hLibImm == NULL) if (hLibImm == NULL)
return; return;

View File

@ -49,7 +49,7 @@ static const char LUAVIM_FREE[] = "luaV_free";
# define symbol_from_dll dlsym # define symbol_from_dll dlsym
# define close_dll dlclose # define close_dll dlclose
#else #else
# define load_dll LoadLibrary # define load_dll vimLoadLib
# define symbol_from_dll GetProcAddress # define symbol_from_dll GetProcAddress
# define close_dll FreeLibrary # define close_dll FreeLibrary
#endif #endif

View File

@ -556,8 +556,8 @@ mzscheme_runtime_link_init(char *sch_dll, char *gc_dll, int verbose)
if (hMzGC && hMzSch) if (hMzGC && hMzSch)
return OK; return OK;
hMzSch = LoadLibrary(sch_dll); hMzSch = vimLoadLib(sch_dll);
hMzGC = LoadLibrary(gc_dll); hMzGC = vimLoadLib(gc_dll);
if (!hMzSch) if (!hMzSch)
{ {

View File

@ -106,7 +106,7 @@ typedef int perl_key;
#define close_dll dlclose #define close_dll dlclose
#else #else
#define PERL_PROC FARPROC #define PERL_PROC FARPROC
#define load_dll LoadLibrary #define load_dll vimLoadLib
#define symbol_from_dll GetProcAddress #define symbol_from_dll GetProcAddress
#define close_dll FreeLibrary #define close_dll FreeLibrary
#endif #endif

View File

@ -110,7 +110,7 @@ struct PyMethodDef { Py_ssize_t a; };
# define close_dll dlclose # define close_dll dlclose
# define symbol_from_dll dlsym # define symbol_from_dll dlsym
# else # else
# define load_dll LoadLibrary # define load_dll vimLoadLib
# define close_dll FreeLibrary # define close_dll FreeLibrary
# define symbol_from_dll GetProcAddress # define symbol_from_dll GetProcAddress
# endif # endif

View File

@ -88,7 +88,7 @@ static void init_structs(void);
# define close_dll dlclose # define close_dll dlclose
# define symbol_from_dll dlsym # define symbol_from_dll dlsym
# else # else
# define load_dll LoadLibrary # define load_dll vimLoadLib
# define close_dll FreeLibrary # define close_dll FreeLibrary
# define symbol_from_dll GetProcAddress # define symbol_from_dll GetProcAddress
# endif # endif

View File

@ -55,7 +55,7 @@
# define symbol_from_dll dlsym # define symbol_from_dll dlsym
# define close_dll dlclose # define close_dll dlclose
#else #else
# define load_dll LoadLibrary # define load_dll vimLoadLib
# define symbol_from_dll GetProcAddress # define symbol_from_dll GetProcAddress
# define close_dll FreeLibrary # define close_dll FreeLibrary
#endif #endif

View File

@ -4159,11 +4159,11 @@ iconv_enabled(verbose)
{ {
if (hIconvDLL != 0 && hMsvcrtDLL != 0) if (hIconvDLL != 0 && hMsvcrtDLL != 0)
return TRUE; return TRUE;
hIconvDLL = LoadLibrary(DYNAMIC_ICONV_DLL); hIconvDLL = vimLoadLib(DYNAMIC_ICONV_DLL);
if (hIconvDLL == 0) /* sometimes it's called libiconv.dll */ if (hIconvDLL == 0) /* sometimes it's called libiconv.dll */
hIconvDLL = LoadLibrary(DYNAMIC_ICONV_DLL_ALT); hIconvDLL = vimLoadLib(DYNAMIC_ICONV_DLL_ALT);
if (hIconvDLL != 0) if (hIconvDLL != 0)
hMsvcrtDLL = LoadLibrary(DYNAMIC_MSVCRT_DLL); hMsvcrtDLL = vimLoadLib(DYNAMIC_MSVCRT_DLL);
if (hIconvDLL == 0 || hMsvcrtDLL == 0) if (hIconvDLL == 0 || hMsvcrtDLL == 0)
{ {
/* Only give the message when 'verbose' is set, otherwise it might be /* Only give the message when 'verbose' is set, otherwise it might be

View File

@ -817,7 +817,11 @@ mch_libcall(
BOOL fRunTimeLinkSuccess = FALSE; BOOL fRunTimeLinkSuccess = FALSE;
// Get a handle to the DLL module. // Get a handle to the DLL module.
# ifdef WIN16
hinstLib = LoadLibrary(libname); hinstLib = LoadLibrary(libname);
# else
hinstLib = vimLoadLib(libname);
# endif
// If the handle is valid, try to get the function address. // If the handle is valid, try to get the function address.
if (hinstLib != NULL) if (hinstLib != NULL)

View File

@ -206,44 +206,65 @@ static char *vimrun_path = "vimrun ";
static int suppress_winsize = 1; /* don't fiddle with console */ static int suppress_winsize = 1; /* don't fiddle with console */
#endif #endif
static char_u *exe_path = NULL;
static void static void
get_exe_name(void) get_exe_name(void)
{ {
char temp[256]; char temp[MAXPATHL];
static int did_set_PATH = FALSE; char_u *p;
if (exe_name == NULL) if (exe_name == NULL)
{ {
/* store the name of the executable, may be used for $VIM */ /* store the name of the executable, may be used for $VIM */
GetModuleFileName(NULL, temp, 255); GetModuleFileName(NULL, temp, MAXPATHL - 1);
if (*temp != NUL) if (*temp != NUL)
exe_name = FullName_save((char_u *)temp, FALSE); exe_name = FullName_save((char_u *)temp, FALSE);
} }
if (!did_set_PATH && exe_name != NULL) if (exe_path == NULL && exe_name != NULL)
{ {
char_u *p; exe_path = vim_strnsave(exe_name, gettail_sep(exe_name) - exe_name);
char_u *newpath; if (exe_path != NULL)
/* Append our starting directory to $PATH, so that when doing "!xxd"
* it's found in our starting directory. Needed because SearchPath()
* also looks there. */
p = mch_getenv("PATH");
newpath = alloc((unsigned)(STRLEN(p) + STRLEN(exe_name) + 2));
if (newpath != NULL)
{ {
STRCPY(newpath, p); /* Append our starting directory to $PATH, so that when doing
STRCAT(newpath, ";"); * "!xxd" it's found in our starting directory. Needed because
vim_strncpy(newpath + STRLEN(newpath), exe_name, * SearchPath() also looks there. */
gettail_sep(exe_name) - exe_name); p = mch_getenv("PATH");
vim_setenv((char_u *)"PATH", newpath); if (STRLEN(p) + STRLEN(exe_path) + 2 < MAXPATHL);
vim_free(newpath); {
STRCPY(temp, p);
STRCAT(temp, ";");
STRCAT(temp, exe_path);
vim_setenv((char_u *)"PATH", temp);
}
} }
did_set_PATH = TRUE;
} }
} }
/*
* Load library "name".
*/
HINSTANCE
vimLoadLib(char *name)
{
HINSTANCE dll = NULL;
char old_dir[MAXPATHL];
if (exe_path == NULL)
get_exe_name();
if (exe_path != NULL && mch_dirname(old_dir, MAXPATHL) == OK)
{
/* Change directory to where the executable is, both to make sure we
* find a .dll there and to avoid looking for a .dll in the current
* directory. */
mch_chdir(exe_path);
dll = LoadLibrary(name);
mch_chdir(old_dir);
}
return dll;
}
#if defined(DYNAMIC_GETTEXT) || defined(PROTO) #if defined(DYNAMIC_GETTEXT) || defined(PROTO)
# ifndef GETTEXT_DLL # ifndef GETTEXT_DLL
# define GETTEXT_DLL "libintl.dll" # define GETTEXT_DLL "libintl.dll"
@ -254,7 +275,7 @@ static char *null_libintl_textdomain(const char *);
static char *null_libintl_bindtextdomain(const char *, const char *); static char *null_libintl_bindtextdomain(const char *, const char *);
static char *null_libintl_bind_textdomain_codeset(const char *, const char *); static char *null_libintl_bind_textdomain_codeset(const char *, const char *);
static HINSTANCE hLibintlDLL = 0; static HINSTANCE hLibintlDLL = NULL;
char *(*dyn_libintl_gettext)(const char *) = null_libintl_gettext; char *(*dyn_libintl_gettext)(const char *) = null_libintl_gettext;
char *(*dyn_libintl_textdomain)(const char *) = null_libintl_textdomain; char *(*dyn_libintl_textdomain)(const char *) = null_libintl_textdomain;
char *(*dyn_libintl_bindtextdomain)(const char *, const char *) char *(*dyn_libintl_bindtextdomain)(const char *, const char *)
@ -282,26 +303,16 @@ dyn_libintl_init(char *libname)
if (hLibintlDLL) if (hLibintlDLL)
return 1; return 1;
/* Load gettext library (libintl.dll) */ /* Load gettext library (libintl.dll) */
hLibintlDLL = LoadLibrary(libname != NULL ? libname : GETTEXT_DLL); hLibintlDLL = vimLoadLib(libname != NULL ? libname : GETTEXT_DLL);
if (!hLibintlDLL) if (!hLibintlDLL)
{ {
char_u dirname[_MAX_PATH]; if (p_verbose > 0)
/* Try using the path from gvim.exe to find the .dll there. */
get_exe_name();
STRCPY(dirname, exe_name);
STRCPY(gettail(dirname), GETTEXT_DLL);
hLibintlDLL = LoadLibrary((char *)dirname);
if (!hLibintlDLL)
{ {
if (p_verbose > 0) verbose_enter();
{ EMSG2(_(e_loadlib), GETTEXT_DLL);
verbose_enter(); verbose_leave();
EMSG2(_(e_loadlib), GETTEXT_DLL);
verbose_leave();
}
return 0;
} }
return 0;
} }
for (i = 0; libintl_entry[i].name != NULL for (i = 0; libintl_entry[i].name != NULL
&& libintl_entry[i].ptr != NULL; ++i) && libintl_entry[i].ptr != NULL; ++i)
@ -430,7 +441,7 @@ PlatformId(void)
* Seems like a lot of overhead to load/unload ADVAPI32.DLL each * Seems like a lot of overhead to load/unload ADVAPI32.DLL each
* time we verify security... * time we verify security...
*/ */
advapi_lib = LoadLibrary("ADVAPI32.DLL"); advapi_lib = vimLoadLib("ADVAPI32.DLL");
if (advapi_lib != NULL) if (advapi_lib != NULL)
{ {
pSetNamedSecurityInfo = (PSNSECINFO)GetProcAddress(advapi_lib, pSetNamedSecurityInfo = (PSNSECINFO)GetProcAddress(advapi_lib,

View File

@ -1,4 +1,5 @@
/* os_win32.c */ /* os_win32.c */
HINSTANCE vimLoadLib __ARGS((char *name));
int dyn_libintl_init __ARGS((char *libname)); int dyn_libintl_init __ARGS((char *libname));
void dyn_libintl_end __ARGS((void)); void dyn_libintl_end __ARGS((void));
void PlatformId __ARGS((void)); void PlatformId __ARGS((void));

View File

@ -714,6 +714,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
34,
/**/ /**/
33, 33,
/**/ /**/