test/testnative.h
author Sam Lantinga <slouken@libsdl.org>
Fri, 28 Nov 2014 04:51:33 -0800
changeset 9246 a761913e5e91
parent 8149 681eb46b8ac4
child 9619 b94b6d0bff0f
permissions -rw-r--r--
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).
slouken@5535
     1
/*
slouken@8149
     2
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
slouken@5535
     3
slouken@5535
     4
  This software is provided 'as-is', without any express or implied
slouken@5535
     5
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     6
  arising from the use of this software.
slouken@5535
     7
slouken@5535
     8
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
     9
  including commercial applications, and to alter it and redistribute it
slouken@5535
    10
  freely.
slouken@5535
    11
*/
slouken@3059
    12
slouken@3059
    13
/* Definitions for platform dependent windowing functions to test SDL
slouken@3059
    14
   integration with native windows
slouken@3059
    15
*/
slouken@3059
    16
slouken@3059
    17
#include "SDL.h"
slouken@3059
    18
slouken@3059
    19
/* This header includes all the necessary system headers for native windows */
slouken@3059
    20
#include "SDL_syswm.h"
slouken@3059
    21
slouken@3059
    22
typedef struct
slouken@3059
    23
{
slouken@3059
    24
    const char *tag;
slouken@3061
    25
    void *(*CreateNativeWindow) (int w, int h);
slouken@3061
    26
    void (*DestroyNativeWindow) (void *window);
slouken@3059
    27
} NativeWindowFactory;
slouken@3059
    28
slouken@5062
    29
#ifdef SDL_VIDEO_DRIVER_WINDOWS
slouken@5062
    30
#define TEST_NATIVE_WINDOWS
slouken@5062
    31
extern NativeWindowFactory WindowsWindowFactory;
slouken@3059
    32
#endif
slouken@3059
    33
slouken@3059
    34
#ifdef SDL_VIDEO_DRIVER_X11
slouken@3059
    35
#define TEST_NATIVE_X11
slouken@3059
    36
extern NativeWindowFactory X11WindowFactory;
slouken@3059
    37
#endif
slouken@3059
    38
slouken@3059
    39
#ifdef SDL_VIDEO_DRIVER_COCOA
slouken@3059
    40
/* Actually, we don't really do this, since it involves adding Objective C
slouken@3059
    41
   support to the build system, which is a little tricky.  You can uncomment
slouken@3059
    42
   it manually though and link testnativecocoa.m into the test application.
slouken@3059
    43
*/
slouken@3059
    44
#define TEST_NATIVE_COCOA
slouken@3059
    45
extern NativeWindowFactory CocoaWindowFactory;
slouken@3059
    46
#endif