premake/patches/709.patch
author Sam Lantinga <slouken@libsdl.org>
Fri, 28 Nov 2014 04:51:33 -0800
changeset 9246 a761913e5e91
parent 7925 f090a47eb7f7
permissions -rwxr-xr-x
Fixed bug 2786 - "UCS-2-INTERNAL" iconv encoding is not supported everywhere, use UTF-16LE instead

Jonas Kulla

src/main/windows/SDL_windows_main.c:137:
cmdline = SDL_iconv_string("UTF-8", "UCS-2-INTERNAL", (char *)(text), (SDL_wcslen(text)+1)*sizeof(WCHAR));

I'm trying to compile an SDL2 application for windows using the mingw-w64 32bit toolchain provided by my distro (Fedora 19). However, even the simplest test program that does nothing at all fails to startup with a "Fatal error - out of memory" message because the mingw iconv library provided by my distro does not support the "UCS-2-INTERNAL" encoding and the conversion returns null.

From my little bit of research, it turns out that even though this encoding is supported by the external GNU libiconv library, some glibc versions (?) don't support it with their internal iconv routines, and will instead provide the native endian encoding when "UCS-2" is specified.

Nonetheless, I wonder why the native endianness is considered in the first place when Windows doesn't even run on any big endian archs (to my knowledge). And true enough, 'WIN_StringToUTF8' from core/windows/SDL_windows.h is used everywhere else in the windows backend, which is just a macro to iconv with "UTF-16LE" as source. Therefore it would IMO make sense to use this macro here as well, which would solve my problem (patch attached).
     1 # HG changeset patch
     2 # User Ben Henning
     3 # Date 1375901577 25200
     4 #      Wed Aug 07 11:52:57 2013 -0700
     5 # Node ID 1d820b5754a9bc79b5c4c6a26d1acc170ebf4784
     6 # Parent  0af3bf0e3755477eafb247935db77b2765df2d19
     7 Updated the GCC make option to handle its linker cmomand generation a bit
     8 differently. Rather than putting the sibling libraries before the linker
     9 flags, they are put after. This allows for some extra flexibility in putting
    10 custom linker libraries before the list of sibling libraries, in case one of
    11 them depends on it.
    12 
    13 diff --git a/src/actions/make/make_cpp.lua b/src/actions/make/make_cpp.lua
    14 --- a/src/actions/make/make_cpp.lua
    15 +++ b/src/actions/make/make_cpp.lua
    16 @@ -267,11 +267,12 @@
    17  				_p('  LINKCMD    = $(AR) -rcs $(TARGET) $(OBJECTS)')
    18  			end
    19  		else
    20 +			-- Ben: changed order of ALL_LDFLAGS and LIBS (switched them)
    21  			-- this was $(TARGET) $(LDFLAGS) $(OBJECTS)
    22  			--  but had trouble linking to certain static libs so $(OBJECTS) moved up
    23  			-- then $(LDFLAGS) moved to end
    24  			--   https://sourceforge.net/tracker/?func=detail&aid=3430158&group_id=71616&atid=531880
    25 -			_p('  LINKCMD    = $(%s) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(LIBS) $(ALL_LDFLAGS)', iif(cfg.language == "C", "CC", "CXX"))
    26 +			_p('  LINKCMD    = $(%s) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(ALL_LDFLAGS) $(LIBS)', iif(cfg.language == "C", "CC", "CXX"))
    27  		end
    28  	end
    29