[Mono-dev] Fix shadow copy and define UNICODE on windows
Here is a patch that fixes shadow copy on windows, and also sets UNICODE and _UNICODE in configure.in on windows. I was getting warning in VS that some Win32 functions we were calling was using the ANSI version (meaning UNICODE was not getting defined in some places) even though we were passing Unicode strings. Also, I changed a macro in mono-dl.c to a function so I could convert the utf8 string to utf16. One question about shadow copy, do I/we need to worry about UNC paths, i.e. \\location\blah. My code assumes a drive letter based path, C:\ etc. I never messed with configure.in before, so please make sure I put the defines in the right and correctly. Also, I'll fix the vcproj's after this patch (the need to be set to use Unicode). Thanks, Jonathan Index: configure.in === --- configure.in (revision 73955) +++ configure.in (working copy) @@ -70,7 +70,7 @@ export CC fi HOST_CC=gcc - CPPFLAGS=$CPPFLAGS -DWIN32_THREADS -DFD_SETSIZE=1024 + CPPFLAGS=$CPPFLAGS -DWIN32_THREADS -DFD_SETSIZE=1024 -DUNICODE -D_UNICODE libmono_cflags=-mno-cygwin libmono_ldflags=-mno-cygwin libdl= Index: mono/metadata/appdomain.c === --- mono/metadata/appdomain.c (revision 73955) +++ mono/metadata/appdomain.c (working copy) @@ -37,6 +37,9 @@ #include mono/utils/mono-logger.h #include mono/utils/mono-path.h #include mono/utils/mono-stdlib.h +#ifdef PLATFORM_WIN32 +#include direct.h +#endif #define MONO_CORLIB_VERSION 54 @@ -851,8 +854,8 @@ hash = get_cstring_hash (bname); hash2 = get_cstring_hash (g_path_get_dirname (filename)); - snprintf (name_hash, sizeof (name_hash), %08x, hash); - snprintf (path_hash, sizeof (path_hash), %08x_%08x, hash ^ hash2, hash2); + g_snprintf (name_hash, sizeof (name_hash), %08x, hash); + g_snprintf (path_hash, sizeof (path_hash), %08x_%08x, hash ^ hash2, hash2); return g_build_filename (mono_string_to_utf8 (domain-setup-dynamic_base), assembly, shadow, @@ -865,6 +868,56 @@ static gboolean ensure_directory_exists (const char *filename) { +#ifdef PLATFORM_WIN32 + gchar *dir_utf8 = g_path_get_dirname (filename); + gunichar2 *p; + gunichar2 *dir_utf16 = NULL; + int retval; + + if (!dir_utf8 || !dir_utf8 [0]) + return FALSE; + + dir_utf16 = g_utf8_to_utf16 (dir_utf8, strlen (dir_utf8), NULL, NULL, NULL); + g_free (dir_utf8); + + if (!dir_utf16) + return FALSE; + + p = dir_utf16; + + /* make life easy and only use one directory seperator */ + while (*p != '\0') + { + if (*p == '/') + *p = '\\'; + p++; + } + + p = dir_utf16; + + /* get past C:\ )*/ + while (*p++ != '\\') + { + } + + while (1) { + BOOL bRet = FALSE; + p = wcschr (p, '\\'); + if (p) + *p = '\0'; + retval = _wmkdir (dir_utf16); + if (retval != 0 errno != EEXIST) { + g_free (dir_utf16); + return FALSE; + } + if (!p) + break; + *p++ = '\\'; + } + + g_free (dir_utf16); + return TRUE; +#else char *p; gchar *dir = g_path_get_dirname (filename); int retval; @@ -880,11 +933,7 @@ p = strchr (p, '/'); if (p) *p = '\0'; -#ifdef PLATFORM_WIN32 - retval = mkdir (dir); -#else retval = mkdir (dir, 0777); -#endif if (retval != 0 errno != EEXIST) { g_free (dir); return FALSE; @@ -896,6 +945,7 @@ g_free (dir); return TRUE; +#endif } static char * Index: mono/metadata/ChangeLog === --- mono/metadata/ChangeLog (revision 73955) +++ mono/metadata/ChangeLog (working copy) @@ -1,3 +1,7 @@ +2007-03-08 Jonathan Chambers [EMAIL PROTECTED] + + * appdomain.c: Fix shadow copy on Windows. + 2007-03-06 Zoltan Varga [EMAIL PROTECTED] * metadata.c (mono_type_to_unmanaged): Only convert object to Index: mono/io-layer/ChangeLog === --- mono/io-layer/ChangeLog (revision 73955) +++ mono/io-layer/ChangeLog (working copy) @@ -1,4 +1,8 @@ +2007-03-08 Jonathan Chambers [EMAIL PROTECTED] + * io-layer.h: Remove UNICODE and _UNICODE defines as +these are done by configure.in now. + Thu Mar 8 19:42:17 CET 2007 Paolo Molaro [EMAIL PROTECTED] * shared.c: partial support for MONO_DISABLE_SHM env var. Index: mono/io-layer/io-layer.h === --- mono/io-layer/io-layer.h (revision 73955) +++ mono/io-layer/io-layer.h (working copy) @@ -13,8 +13,6 @@ #if defined(__WIN32__) /* Native win32 */ -#define UNICODE -#define _UNICODE #define __USE_W32_SOCKETS #include winsock2.h #include windows.h Index: mono/utils/mono-dl.c === --- mono/utils/mono-dl.c (revision 73955) +++ mono/utils/mono-dl.c (working copy) @@ -32,7 +32,7 @@ #include psapi.h #define SO_HANDLE_TYPE HMODULE -#define LL_SO_OPEN(file,flags) (file)? LoadLibrary ((file)): GetModuleHandle
Re: [Mono-dev] Fix shadow copy and define UNICODE on windows
Hello, Why did you need to change snprintf to g_snprintf? There is no rationale documented in the ChangeLog. Miguel. ___ Mono-devel-list mailing list Mono-devel-list@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-devel-list
Re: [Mono-dev] Fix shadow copy and define UNICODE on windows
Sorry, reattached ChangeLog with reason (snprintf doesn't exist on Win32 (VS build); also for uniformity as we use g_snprintf everywhere else) and added signoff. If you would rather me do something else than use g_snprintf please let me know. Code is contributed under MIT/X11 license. Thanks, Jonathan On 3/8/07, Miguel de Icaza [EMAIL PROTECTED] wrote: Hello, Why did you need to change snprintf to g_snprintf? There is no rationale documented in the ChangeLog. Miguel. Index: configure.in === --- configure.in (revision 73955) +++ configure.in (working copy) @@ -70,7 +70,7 @@ export CC fi HOST_CC=gcc - CPPFLAGS=$CPPFLAGS -DWIN32_THREADS -DFD_SETSIZE=1024 + CPPFLAGS=$CPPFLAGS -DWIN32_THREADS -DFD_SETSIZE=1024 -DUNICODE -D_UNICODE libmono_cflags=-mno-cygwin libmono_ldflags=-mno-cygwin libdl= Index: mono/metadata/appdomain.c === --- mono/metadata/appdomain.c (revision 73955) +++ mono/metadata/appdomain.c (working copy) @@ -37,6 +37,9 @@ #include mono/utils/mono-logger.h #include mono/utils/mono-path.h #include mono/utils/mono-stdlib.h +#ifdef PLATFORM_WIN32 +#include direct.h +#endif #define MONO_CORLIB_VERSION 54 @@ -851,8 +854,8 @@ hash = get_cstring_hash (bname); hash2 = get_cstring_hash (g_path_get_dirname (filename)); - snprintf (name_hash, sizeof (name_hash), %08x, hash); - snprintf (path_hash, sizeof (path_hash), %08x_%08x, hash ^ hash2, hash2); + g_snprintf (name_hash, sizeof (name_hash), %08x, hash); + g_snprintf (path_hash, sizeof (path_hash), %08x_%08x, hash ^ hash2, hash2); return g_build_filename (mono_string_to_utf8 (domain-setup-dynamic_base), assembly, shadow, @@ -865,6 +868,56 @@ static gboolean ensure_directory_exists (const char *filename) { +#ifdef PLATFORM_WIN32 + gchar *dir_utf8 = g_path_get_dirname (filename); + gunichar2 *p; + gunichar2 *dir_utf16 = NULL; + int retval; + + if (!dir_utf8 || !dir_utf8 [0]) + return FALSE; + + dir_utf16 = g_utf8_to_utf16 (dir_utf8, strlen (dir_utf8), NULL, NULL, NULL); + g_free (dir_utf8); + + if (!dir_utf16) + return FALSE; + + p = dir_utf16; + + /* make life easy and only use one directory seperator */ + while (*p != '\0') + { + if (*p == '/') + *p = '\\'; + p++; + } + + p = dir_utf16; + + /* get past C:\ )*/ + while (*p++ != '\\') + { + } + + while (1) { + BOOL bRet = FALSE; + p = wcschr (p, '\\'); + if (p) + *p = '\0'; + retval = _wmkdir (dir_utf16); + if (retval != 0 errno != EEXIST) { + g_free (dir_utf16); + return FALSE; + } + if (!p) + break; + *p++ = '\\'; + } + + g_free (dir_utf16); + return TRUE; +#else char *p; gchar *dir = g_path_get_dirname (filename); int retval; @@ -880,11 +933,7 @@ p = strchr (p, '/'); if (p) *p = '\0'; -#ifdef PLATFORM_WIN32 - retval = mkdir (dir); -#else retval = mkdir (dir, 0777); -#endif if (retval != 0 errno != EEXIST) { g_free (dir); return FALSE; @@ -896,6 +945,7 @@ g_free (dir); return TRUE; +#endif } static char * Index: mono/metadata/ChangeLog === --- mono/metadata/ChangeLog (revision 73955) +++ mono/metadata/ChangeLog (working copy) @@ -1,3 +1,10 @@ +2007-03-08 Jonathan Chambers [EMAIL PROTECTED] + + * appdomain.c: Fix shadow copy on Windows. Use g_snprintf instead + of snprintf as it doesn't exist on Win32 (VS build); also for uniformity. + + Code is contributed under MIT/X11 license. + 2007-03-06 Zoltan Varga [EMAIL PROTECTED] * metadata.c (mono_type_to_unmanaged): Only convert object to Index: mono/io-layer/ChangeLog === --- mono/io-layer/ChangeLog (revision 73955) +++ mono/io-layer/ChangeLog (working copy) @@ -1,4 +1,10 @@ +2007-03-08 Jonathan Chambers [EMAIL PROTECTED] + * io-layer.h: Remove UNICODE and _UNICODE defines as +these are done by configure.in now. + + Code is contributed under MIT/X11 license. + Thu Mar 8 19:42:17 CET 2007 Paolo Molaro [EMAIL PROTECTED] * shared.c: partial support for MONO_DISABLE_SHM env var. Index: mono/io-layer/io-layer.h === --- mono/io-layer/io-layer.h (revision 73955) +++ mono/io-layer/io-layer.h (working copy) @@ -13,8 +13,6 @@ #if defined(__WIN32__) /* Native win32 */ -#define UNICODE -#define _UNICODE #define __USE_W32_SOCKETS #include winsock2.h #include windows.h Index: mono/utils/mono-dl.c === --- mono/utils/mono-dl.c (revision 73955) +++ mono/utils/mono-dl.c (working copy) @@ -32,7 +32,7 @@ #include psapi.h #define SO_HANDLE_TYPE HMODULE -#define LL_SO_OPEN(file,flags) (file)? LoadLibrary ((file)): GetModuleHandle (NULL) +#define LL_SO_OPEN(file,flags) w32_load_module ((file), (flags))
Re: [Mono-dev] Fix shadow copy and define UNICODE on windows
Sorry, reattached ChangeLog with reason (snprintf doesn't exist on Win32 (VS build); also for uniformity as we use g_snprintf everywhere else) and added signoff. If you would rather me do something else than use g_snprintf please let me know. There is _snprintf on VS. What we do in our codebase is just a #define for those, and use snprintf. -- Aras Pranckevicius Graphics programmer at unity3d.com ___ Mono-devel-list mailing list Mono-devel-list@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-devel-list
Re: [Mono-dev] Fix shadow copy and define UNICODE on windows
Hello, The patch looks fine. Sorry, reattached ChangeLog with reason (snprintf doesn't exist on Win32 (VS build); also for uniformity as we use g_snprintf everywhere else) and added signoff. If you would rather me do something else than use g_snprintf please let me know. Code is contributed under MIT/X11 license. Thanks, Jonathan On 3/8/07, Miguel de Icaza [EMAIL PROTECTED] wrote: Hello, Why did you need to change snprintf to g_snprintf? There is no rationale documented in the ChangeLog. Miguel. ___ Mono-devel-list mailing list Mono-devel-list@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-devel-list ___ Mono-devel-list mailing list Mono-devel-list@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-devel-list