diff options
author | Howard Hinnant <hhinnant@apple.com> | 2011-09-28 21:39:20 +0000 |
---|---|---|
committer | Howard Hinnant <hhinnant@apple.com> | 2011-09-28 21:39:20 +0000 |
commit | 3438889dec44b623921f19943ca18b3decb95d92 (patch) | |
tree | 724cc0728516d9546651d600e16bbd8ddd754c7f /libcxx | |
parent | 7f168777e5313bf40d0b65a630a55c8b537571db (diff) | |
download | bcm5719-llvm-3438889dec44b623921f19943ca18b3decb95d92.tar.gz bcm5719-llvm-3438889dec44b623921f19943ca18b3decb95d92.zip |
Work on Windows port by Ruben Van Boxem
llvm-svn: 140728
Diffstat (limited to 'libcxx')
-rw-r--r-- | libcxx/include/__config | 4 | ||||
-rw-r--r-- | libcxx/include/cwchar | 3 | ||||
-rw-r--r-- | libcxx/include/locale | 3 | ||||
-rw-r--r-- | libcxx/include/support/win32/locale.h | 91 | ||||
-rw-r--r-- | libcxx/include/support/win32/support.h | 18 | ||||
-rwxr-xr-x | libcxx/lib/buildit | 16 | ||||
-rw-r--r-- | libcxx/src/support/win32/support.cpp | 13 |
7 files changed, 107 insertions, 41 deletions
diff --git a/libcxx/include/__config b/libcxx/include/__config index 6f983223a58..315cec9dff8 100644 --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -305,11 +305,11 @@ template <unsigned> struct __static_assert_check {}; #define __has_feature(__x) 0 #endif -#if __APPLE__ || __FreeBSD__ +#if __APPLE__ || __FreeBSD__ || _WIN32 #define _LIBCPP_LOCALE__L_EXTENSIONS 1 #endif -#ifdef __APPLE__ +#if __APPLE__ || _WIN32 #define _LIBCPP_STABLE_APPLE_ABI #endif diff --git a/libcxx/include/cwchar b/libcxx/include/cwchar index ce71782c86b..0a67fe8bba9 100644 --- a/libcxx/include/cwchar +++ b/libcxx/include/cwchar @@ -106,6 +106,9 @@ size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len, #include <__config> #include <cwctype> #include <wchar.h> +#if _WIN32 +#include <support/win32/support.h> // pull in *swprintf defines +#endif // _WIN32 #pragma GCC system_header diff --git a/libcxx/include/locale b/libcxx/include/locale index 81c48918747..c0724a50333 100644 --- a/libcxx/include/locale +++ b/libcxx/include/locale @@ -187,7 +187,8 @@ template <class charT> class messages_byname; #include <cstdlib> #include <ctime> #if _WIN32 -#include <support/win32/support.h> // vasprintf +#include <support/win32/support.h> +#include <support/win32/locale.h> #else // _WIN32 #include <nl_types.h> #endif // !_WIN32 diff --git a/libcxx/include/support/win32/locale.h b/libcxx/include/support/win32/locale.h index 6be80acecb6..dd56a049020 100644 --- a/libcxx/include/support/win32/locale.h +++ b/libcxx/include/support/win32/locale.h @@ -1,5 +1,5 @@ // -*- C++ -*- -//===--------------------------- support/win32/locale.h --------------------------===// +//===------------------------ support/win32/locale.h ----------------------===// // // The LLVM Compiler Infrastructure // @@ -8,10 +8,56 @@ // //===----------------------------------------------------------------------===// -// Locale stuff -// FIXME: the *_l functions are fairly new, only available on Vista?/7+ -#include <xlocinfo.h> // +#ifndef _LIBCPP_SUPPORT_WIN32_LOCALE_H +#define _LIBCPP_SUPPORT_WIN32_LOCALE_H + +#include "support/win32/support.h" +#include <memory> +#include <xlocinfo.h> // _locale_t #define locale_t _locale_t +#define LC_COLLATE_MASK _M_COLLATE +#define LC_CTYPE_MASK _M_CTYPE +#define LC_MONETARY_MASK _M_MONETARY +#define LC_NUMERIC_MASK _M_NUMERIC +#define LC_TIME_MASK _M_TIME +#define LC_MESSAGES_MASK _M_MESSAGES +#define LC_ALL_MASK ( LC_COLLATE_MASK \ + | LC_CTYPE_MASK \ + | LC_MESSAGES_MASK \ + | LC_MONETARY_MASK \ + | LC_NUMERIC_MASK \ + | LC_TIME_MASK ) +#define freelocale _free_locale +// FIXME: base currently unused. Needs manual work to construct the new locale +locale_t newlocale( int mask, const char * locale, locale_t base ); +locale_t uselocale( locale_t newloc ); +lconv *localeconv_l( locale_t loc ); +size_t mbrlen_l( const char *__restrict__ s, size_t n, + mbstate_t *__restrict__ ps, locale_t loc); +size_t mbsrtowcs_l( wchar_t *__restrict__ dst, const char **__restrict__ src, + size_t len, mbstate_t *__restrict__ ps, locale_t loc ); +size_t wcrtomb_l( char *__restrict__ s, wchar_t wc, mbstate_t *__restrict__ ps, + locale_t loc); +size_t mbrtowc_l( wchar_t *__restrict__ pwc, const char *__restrict__ s, + size_t n, mbstate_t *__restrict__ ps, locale_t loc); +size_t mbsnrtowcs_l( wchar_t *__restrict__ dst, const char **__restrict__ src, + size_t nms, size_t len, mbstate_t *__restrict__ ps, locale_t loc); +size_t wcsnrtombs_l( char *__restrict__ dst, const wchar_t **__restrict__ src, + size_t nwc, size_t len, mbstate_t *__restrict__ ps, locale_t loc); +wint_t btowc_l( int c, locale_t loc ); +int wctob_l( wint_t c, locale_t loc ); +typedef _VSTD::remove_pointer<locale_t>::type __locale_struct; +typedef _VSTD::unique_ptr<__locale_struct, decltype(&uselocale)> __locale_raii; +_LIBCPP_ALWAYS_INLINE inline +decltype(MB_CUR_MAX) MB_CUR_MAX_L( locale_t __l ) +{ + __locale_raii __current( uselocale(__l), uselocale ); + return MB_CUR_MAX; +} + +// the *_l functions are prefixed on Windows, only available for msvcr80+, VS2005+ +#include <stdio.h> +#define mbtowc_l _mbtowc_l #define strtoll_l _strtoi64_l #define strtoull_l _strtoui64_l // FIXME: current msvcrt does not know about long double @@ -36,6 +82,17 @@ #define towupper_l _towupper_l #define towlower_l _towlower_l #define strftime_l _strftime_l +#define sscanf_l( __s, __l, __f, ...) _sscanf_l( __s, __f, __l, __VA_ARGS__ ) +#define vsscanf_l( __s, __l, __f, ...) _sscanf_l( __s, __f, __l, __VA_ARGS__ ) +#define sprintf_l( __s, __l, __f, ... ) _sprintf_l( __s, __f, __l, __VA_ARGS__ ) +#define snprintf_l( __s, __n, __l, __f, ... ) _snprintf_l( __s, __n, __f, __l, __VA_ARGS__ ) +#define vsprintf_l( __s, __l, __f, ... ) _vsprintf_l( __s, __f, __l, __VA_ARGS__ ) +#define vsnprintf_l( __s, __n, __l, __f, ... ) _vsnprintf_l( __s, __n, __f, __l, __VA_ARGS__ ) +int asprintf_l( char **ret, locale_t loc, const char *format, ... ); +int vasprintf_l( char **ret, locale_t loc, const char *format, va_list ap ); + + +// not-so-pressing FIXME: use locale to determine blank characters inline int isblank_l( int c, locale_t /*loc*/ ) { return ( c == ' ' || c == '\t' ); @@ -44,29 +101,5 @@ inline int iswblank_l( wint_t c, locale_t /*loc*/ ) { return ( c == L' ' || c == L'\t' ); } -#define freelocale _free_locale -// ignore base; it is always 0 in libc++ code -inline locale_t newlocale( int mask, const char * locale, locale_t /*base*/ ) -{ - return _create_locale( mask, locale ); -} -// FIXME: first call _configthreadlocale(_ENABLE_PER_THREAD_LOCALE) somewhere -// FIXME: return types are different, need to make locale_t from char* -inline locale_t uselocale(locale_t newloc) -{ - return _create_locale( LC_ALL, setlocale(LC_ALL, newloc->locinfo->lc_category[LC_ALL].locale) ); -} - -#define LC_COLLATE_MASK _M_COLLATE -#define LC_CTYPE_MASK _M_CTYPE -#define LC_MONETARY_MASK _M_MONETARY -#define LC_NUMERIC_MASK _M_NUMERIC -#define LC_TIME_MASK _M_TIME -#define LC_MESSAGES_MASK _M_MESSAGES -#define LC_ALL_MASK ( LC_COLLATE_MASK \ - | LC_CTYPE_MASK \ - | LC_MESSAGES_MASK \ - | LC_MONETARY_MASK \ - | LC_NUMERIC_MASK \ - | LC_TIME_MASK ) +#endif // _LIBCPP_SUPPORT_WIN32_LOCALE_H
\ No newline at end of file diff --git a/libcxx/include/support/win32/support.h b/libcxx/include/support/win32/support.h index 48225690d7a..8ce947a16a3 100644 --- a/libcxx/include/support/win32/support.h +++ b/libcxx/include/support/win32/support.h @@ -1,5 +1,5 @@ // -*- C++ -*- -//===--------------------------- support/win32/support.h --------------------------===// +//===----------------------- support/win32/support.h ----------------------===// // // The LLVM Compiler Infrastructure // @@ -8,16 +8,24 @@ // //===----------------------------------------------------------------------===// +#ifndef _LIBCPP_SUPPORT_WIN32_SUPPORT_H +#define _LIBCPP_SUPPORT_WIN32_SUPPORT_H + /* Functions and constants used in libc++ that are missing from the Windows C library. */ -#if __MINGW32__ -#include <stdio.h> -#define swprintf snwprintf -#endif // __MINGW32__ +#include <wchar.h> // mbstate_t +#include <stdio.h> // _snwprintf +#define swprintf _snwprintf +#define vswprintf _vsnwprintf + int vasprintf( char **sptr, const char *__restrict__ fmt , va_list ap ); +int asprintf(char **sptr, const char *__restrict__ fmt, ...); + size_t mbsnrtowcs( wchar_t *__restrict__ dst, const char **__restrict__ src, size_t nmc, size_t len, mbstate_t *__restrict__ ps ); size_t wcsnrtombs( char *__restrict__ dst, const wchar_t **__restrict__ src, size_t nwc, size_t len, mbstate_t *__restrict__ ps ); + +#endif // _LIBCPP_SUPPORT_WIN32_SUPPORT_H
\ No newline at end of file diff --git a/libcxx/lib/buildit b/libcxx/lib/buildit index 16df7c51d4b..13d6f8e07ab 100755 --- a/libcxx/lib/buildit +++ b/libcxx/lib/buildit @@ -78,6 +78,13 @@ case $TRIPLE in -Wl,-force_symbols_not_weak_list,notweak.exp " fi ;; + *-*-mingw*) + # FIXME: removing libgcc and libsupc++ dependencies means porting libcxxrt and LLVM/compiler-rt + SOEXT=dll + LDSHARED_FLAGS="-o libc++.dll \ + -shared -nodefaultlibs -Wl,--export-all-symbols -Wl,--allow-multiple-definition -Wl,--out-implib,libc++.dll.a \ + -lsupc++ -lpthread -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcr100 -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt" + ;; *) RC_CFLAGS="-fPIC" SOEXT=so @@ -97,8 +104,13 @@ set -x for FILE in ../src/*.cpp; do $CXX -c -g -Os $RC_CFLAGS $EXTRA_FLAGS -nostdinc++ -I../include $FILE done - - +case $TRIPLE in + *-*-mingw*) + for FILE in ../src/support/win32/*.cpp; do + $CXX -c -g -Os $RC_CFLAGS $EXTRA_FLAGS -nostdinc++ -I../include $FILE + done + ;; +esac $CC *.o $RC_CFLAGS $LDSHARED_FLAGS $EXTRA_FLAGS #libtool -static -o libc++.a *.o diff --git a/libcxx/src/support/win32/support.cpp b/libcxx/src/support/win32/support.cpp index db80063c690..8ed2921d241 100644 --- a/libcxx/src/support/win32/support.cpp +++ b/libcxx/src/support/win32/support.cpp @@ -1,5 +1,5 @@ // -*- C++ -*- -//===--------------------------- support/win32/support.h --------------------------===// +//===----------------------- support/win32/support.h ----------------------===// // // The LLVM Compiler Infrastructure // @@ -8,12 +8,21 @@ // //===----------------------------------------------------------------------===// +#include <support/win32/support.h> +#include <stdarg.h> // va_start, va_end #include <stddef.h> // size_t #include <stdlib.h> // malloc #include <stdio.h> // vsprintf, vsnprintf #include <string.h> // strcpy, wcsncpy -#include <wchar.h> // mbstate_t +int asprintf(char **sptr, const char *__restrict__ fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + int result = vasprintf(sptr, fmt, ap); + va_end(ap); + return result; +} int vasprintf( char **sptr, const char *__restrict__ fmt, va_list ap ) { *sptr = NULL; |