From 2fa86c13816417d1d62616d1bb8114a5a9831c33 Mon Sep 17 00:00:00 2001 From: Gurusamy Sarathy Date: Wed, 1 Mar 2000 03:38:03 +0000 Subject: [PATCH] Windows miscellany p4raw-id: //depot/perl@5388 --- pod/perlguts.pod | 4 ++-- win32/perllib.c | 4 ++++ win32/win32.c | 43 +++++++++++++++++++++++++------------------ win32/win32.h | 6 ------ 4 files changed, 31 insertions(+), 26 deletions(-) diff --git a/pod/perlguts.pod b/pod/perlguts.pod index 2686c39..58bcea3 100644 --- a/pod/perlguts.pod +++ b/pod/perlguts.pod @@ -1672,14 +1672,14 @@ Thus, something like: in your extesion will translate to this when PERL_IMPLICIT_CONTEXT is in effect: - Perl_sv_setsv(GetPerlInterpreter(), asv, bsv); + Perl_sv_setsv(Perl_get_context(), asv, bsv); or to this otherwise: Perl_sv_setsv(asv, bsv); You have to do nothing new in your extension to get this; since -the Perl library provides GetPerlInterpreter(), it will all just +the Perl library provides Perl_get_context(), it will all just work. The second, more efficient way is to use the following template for diff --git a/win32/perllib.c b/win32/perllib.c index 3aed241..2a0cb85 100644 --- a/win32/perllib.c +++ b/win32/perllib.c @@ -334,6 +334,9 @@ RunPerl(int argc, char **argv, char **env) return (exitstatus); } +EXTERN_C void +set_w32_module_name(void); + BOOL APIENTRY DllMain(HANDLE hModule, /* DLL module handle */ DWORD fdwReason, /* reason called */ @@ -353,6 +356,7 @@ DllMain(HANDLE hModule, /* DLL module handle */ #endif DisableThreadLibraryCalls((HMODULE)hModule); w32_perldll_handle = hModule; + set_w32_module_name(); break; /* The DLL is detaching from a process due to diff --git a/win32/win32.c b/win32/win32.c index 54f0455..5fb1f46 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -124,6 +124,30 @@ IsWinNT(void) return (win32_os_id() == VER_PLATFORM_WIN32_NT); } +EXTERN_C void +set_w32_module_name(void) +{ + char* ptr; + GetModuleFileName((HMODULE)((w32_perldll_handle == INVALID_HANDLE_VALUE) + ? GetModuleHandle(NULL) + : w32_perldll_handle), + w32_module_name, sizeof(w32_module_name)); + + /* try to get full path to binary (which may be mangled when perl is + * run from a 16-bit app) */ + /*PerlIO_printf(Perl_debug_log, "Before %s\n", w32_module_name);*/ + (void)win32_longpath(w32_module_name); + /*PerlIO_printf(Perl_debug_log, "After %s\n", w32_module_name);*/ + + /* normalize to forward slashes */ + ptr = w32_module_name; + while (*ptr) { + if (*ptr == '\\') + *ptr = '/'; + ++ptr; + } +} + /* *svp (if non-NULL) is expected to be POK (valid allocated SvPVX(*svp)) */ static char* get_regstr_from(HKEY hkey, const char *valuename, SV **svp) @@ -186,24 +210,7 @@ get_emd_part(SV **prev_pathp, char *trailing_path, ...) baselen = strlen(base); if (!*w32_module_name) { - GetModuleFileName((HMODULE)((w32_perldll_handle == INVALID_HANDLE_VALUE) - ? GetModuleHandle(NULL) - : w32_perldll_handle), - w32_module_name, sizeof(w32_module_name)); - - /* try to get full path to binary (which may be mangled when perl is - * run from a 16-bit app) */ - /*PerlIO_printf(Perl_debug_log, "Before %s\n", w32_module_name);*/ - (void)win32_longpath(w32_module_name); - /*PerlIO_printf(Perl_debug_log, "After %s\n", w32_module_name);*/ - - /* normalize to forward slashes */ - ptr = w32_module_name; - while (*ptr) { - if (*ptr == '\\') - *ptr = '/'; - ++ptr; - } + set_w32_module_name(); } strcpy(mod_name, w32_module_name); ptr = strrchr(mod_name, '/'); diff --git a/win32/win32.h b/win32/win32.h index bbf88bb..b0ccd14 100644 --- a/win32/win32.h +++ b/win32/win32.h @@ -27,12 +27,6 @@ # define win32_get_sitelib PerlEnv_sitelib_path #endif -#if defined(PERL_IMPLICIT_CONTEXT) -/* compat */ -# define GetPerlInterpreter Perl_get_context -# define SetPerlInterpreter Perl_set_context -#endif - #ifdef __GNUC__ # ifndef __int64 /* some versions seem to #define it already */ # define __int64 long long -- 2.7.4