[cfe-commits] [libcxx] r140728 - in /libcxx/trunk: include/__config include/cwchar include/locale include/support/win32/locale.h include/support/win32/support.h lib/buildit src/support/win32/support.cpp

Howard Hinnant hhinnant at apple.com
Wed Sep 28 14:39:20 PDT 2011


Author: hhinnant
Date: Wed Sep 28 16:39:20 2011
New Revision: 140728

URL: http://llvm.org/viewvc/llvm-project?rev=140728&view=rev
Log:
Work on Windows port by Ruben Van Boxem

Modified:
    libcxx/trunk/include/__config
    libcxx/trunk/include/cwchar
    libcxx/trunk/include/locale
    libcxx/trunk/include/support/win32/locale.h
    libcxx/trunk/include/support/win32/support.h
    libcxx/trunk/lib/buildit
    libcxx/trunk/src/support/win32/support.cpp

Modified: libcxx/trunk/include/__config
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=140728&r1=140727&r2=140728&view=diff
==============================================================================
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Wed Sep 28 16:39:20 2011
@@ -305,11 +305,11 @@
 #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
 

Modified: libcxx/trunk/include/cwchar
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/cwchar?rev=140728&r1=140727&r2=140728&view=diff
==============================================================================
--- libcxx/trunk/include/cwchar (original)
+++ libcxx/trunk/include/cwchar Wed Sep 28 16:39:20 2011
@@ -106,6 +106,9 @@
 #include <__config>
 #include <cwctype>
 #include <wchar.h>
+#if _WIN32
+#include <support/win32/support.h> // pull in *swprintf defines
+#endif // _WIN32
 
 #pragma GCC system_header
 

Modified: libcxx/trunk/include/locale
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/locale?rev=140728&r1=140727&r2=140728&view=diff
==============================================================================
--- libcxx/trunk/include/locale (original)
+++ libcxx/trunk/include/locale Wed Sep 28 16:39:20 2011
@@ -187,7 +187,8 @@
 #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

Modified: libcxx/trunk/include/support/win32/locale.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/support/win32/locale.h?rev=140728&r1=140727&r2=140728&view=diff
==============================================================================
--- libcxx/trunk/include/support/win32/locale.h (original)
+++ libcxx/trunk/include/support/win32/locale.h Wed Sep 28 16:39:20 2011
@@ -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 @@
 {
     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

Modified: libcxx/trunk/include/support/win32/support.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/support/win32/support.h?rev=140728&r1=140727&r2=140728&view=diff
==============================================================================
--- libcxx/trunk/include/support/win32/support.h (original)
+++ libcxx/trunk/include/support/win32/support.h Wed Sep 28 16:39:20 2011
@@ -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

Modified: libcxx/trunk/lib/buildit
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/lib/buildit?rev=140728&r1=140727&r2=140728&view=diff
==============================================================================
--- libcxx/trunk/lib/buildit (original)
+++ libcxx/trunk/lib/buildit Wed Sep 28 16:39:20 2011
@@ -78,6 +78,13 @@
 			-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 @@
 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

Modified: libcxx/trunk/src/support/win32/support.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/support/win32/support.cpp?rev=140728&r1=140727&r2=140728&view=diff
==============================================================================
--- libcxx/trunk/src/support/win32/support.cpp (original)
+++ libcxx/trunk/src/support/win32/support.cpp Wed Sep 28 16:39:20 2011
@@ -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;





More information about the cfe-commits mailing list