premake/patches/712.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 1376509869 25200
     4 #      Wed Aug 14 12:51:09 2013 -0700
     5 # Node ID e8558df4fbdb173a2b9ed0d354d6c3e76b376698
     6 # Parent  a5f8b4f709722222e02fa481873d76ad25255e09
     7 Fixed a bug in Xcode project generation wherein pre/prelink/post-build commands
     8 would not be properly executed if the premake script only had the commands
     9 in configuration blocks, rather than in the project block. According to the
    10 website, these commands can exist in both blocks and the Xcode script does
    11 properly generate the commands, it just doesn't add a single line which allows
    12 Xcode to execute the commands at the correct stage. This patch fixes those
    13 issues.
    14 
    15 diff --git a/src/actions/xcode/xcode_common.lua b/src/actions/xcode/xcode_common.lua
    16 --- a/src/actions/xcode/xcode_common.lua
    17 +++ b/src/actions/xcode/xcode_common.lua
    18 @@ -432,20 +432,37 @@
    19  		for _, node in ipairs(tr.products.children) do
    20  			local name = tr.project.name
    21  			
    22 +			-- This function checks whether there are build commands of a specific
    23 +			-- type to be executed; they will be generated correctly, but the project
    24 +			-- commands will not contain any per-configuration commands, so the logic
    25 +			-- has to be extended a bit to account for that.
    26 +			local function hasBuildCommands(which)
    27 +				-- standard check...this is what existed before
    28 +				if #tr.project[which] > 0 then
    29 +					return true
    30 +				end
    31 +				-- what if there are no project-level commands? check configs...
    32 +				for _, cfg in ipairs(tr.configs) do
    33 +					if #cfg[which] > 0 then
    34 +						return true
    35 +					end
    36 +				end
    37 +			end
    38 +			
    39  			_p(2,'%s /* %s */ = {', node.targetid, name)
    40  			_p(3,'isa = PBXNativeTarget;')
    41  			_p(3,'buildConfigurationList = %s /* Build configuration list for PBXNativeTarget "%s" */;', node.cfgsection, name)
    42  			_p(3,'buildPhases = (')
    43 -			if #tr.project.prebuildcommands > 0 then
    44 +			if hasBuildCommands('prebuildcommands') then
    45  				_p(4,'9607AE1010C857E500CD1376 /* Prebuild */,')
    46  			end
    47  			_p(4,'%s /* Resources */,', node.resstageid)
    48  			_p(4,'%s /* Sources */,', node.sourcesid)
    49 -			if #tr.project.prelinkcommands > 0 then
    50 +			if hasBuildCommands('prelinkcommands') then
    51  				_p(4,'9607AE3510C85E7E00CD1376 /* Prelink */,')
    52  			end
    53  			_p(4,'%s /* Frameworks */,', node.fxstageid)
    54 -			if #tr.project.postbuildcommands > 0 then
    55 +			if hasBuildCommands('postbuildcommands') then
    56  				_p(4,'9607AE3710C85E8F00CD1376 /* Postbuild */,')
    57  			end
    58  			_p(3,');')