Re: [xslt] Patch for xsl:sort lang support



Roumen Petrov wrote:
Nick Wellnhofer wrote:
Roumen Petrov wrote:
Please find patch that is first attempt to avoid build problem after recent commits related to xsltlocale.

I'm not convinced that xsltlocale.c is correct for msvcrt:
The manuals show that rfc3066 language tags are supported but the current code ignore all of them.

I took the language codes from here:
http://msdn.microsoft.com/en-us/library/39cwe7zf(VS.80).aspx

10x. I see that the _create_locale is related to setlocale.

Yes, _create_locale accepts the same parameters as setocale.

On this page http://msdn.microsoft.com/en-us/library/ms776260(VS.85).aspx
is listed another information but for other functions.
May be win32 locale has to be based on this.

No, the CRT functions don't seem to accept those language codes.

Also I think that _create_locale is missing before msvcrt80. The proposed patch don't resolve this in makefile based win32 build.

You're right, it seems it was introduced with VC8. Maybe it would be best to have a configure switch to disable locale support in case you want a build that runs without msvcr80.dll?

In the proposed patch configure will try detect presence of _create_locale if don't exist header xlocale.h , but not in makefile based build ( win32/Makefile.msvc ). May a new makefile win32/Makefile.msvcXX can ersolve problem.

Your patch looks good. See the attached version (also against current trunk) that additionally moves the defines to libxslt/xsltconfig.h and adds a switch to win32/configure.js.

I only wonder which setup uses GNU make and MSVCRT.


I wonder why the implementation assume that if exist xlocale.h the charmap is ascii.

Which charmap do you mean?

EBCDIC

I didn't think about that. Maybe one should add an appropriate #ifdef somewhere...

Nick


--
aevum gmbh
rumfordstr. 4
80469 münchen
germany

tel: +49 89 3838 0653
http://aevum.de/
Index: libxslt/xsltconfig.h.in
===================================================================
--- libxslt/xsltconfig.h.in	(revision 1477)
+++ libxslt/xsltconfig.h.in	(working copy)
@@ -124,6 +124,19 @@
 #endif
 
 /**
+ * Locale support
+ */
+#if @XSLT_LOCALE_XLOCALE@
+#ifndef XSLT_LOCALE_XLOCALE
+#define XSLT_LOCALE_XLOCALE
+#endif
+#elif @XSLT_LOCALE_MSVCRT@
+#ifndef XSLT_LOCALE_MSVCRT
+#define XSLT_LOCALE_MSVCRT
+#endif
+#endif
+
+/**
  * ATTRIBUTE_UNUSED:
  *
  * This macro is used to flag unused function parameters to GCC
Index: libxslt/xsltlocale.h
===================================================================
--- libxslt/xsltlocale.h	(revision 1477)
+++ libxslt/xsltlocale.h	(working copy)
@@ -13,10 +13,8 @@
 
 #include <libxml/xmlstring.h>
 
-#ifdef HAVE_XLOCALE_H
+#ifdef XSLT_LOCALE_XLOCALE
 
-#define XSLT_LOCALE_XLOCALE
-
 #include <locale.h>
 #include <xlocale.h>
 
@@ -27,11 +25,8 @@
 #endif
 typedef xmlChar xsltLocaleChar;
 
-#else
-#if defined(_MSC_VER) || defined (__MINGW32__) && defined(__MSVCRT__)
+#elif defined(XSLT_LOCALE_MSVCRT)
 
-#define XSLT_LOCALE_MSVCRT
-
 #include <locale.h>
 
 typedef _locale_t xsltLocale;
@@ -39,13 +34,14 @@
 
 #else
 
+#ifndef XSLT_LOCALE_NONE
 #define XSLT_LOCALE_NONE
+#endif
 
 typedef void *xsltLocale;
 typedef xmlChar xsltLocaleChar;
 
 #endif
-#endif
 
 xsltLocale xsltNewLocale(const xmlChar *langName);
 void xsltFreeLocale(xsltLocale locale);
Index: configure.in
===================================================================
--- configure.in	(revision 1477)
+++ configure.in	(working copy)
@@ -106,9 +106,18 @@
 AC_STDC_HEADERS
 AM_PROG_LIBTOOL
 
-AC_MSG_CHECKING([for working xlocale.h])
-AC_TRY_RUN(
-[
+
+dnl
+dnl Detect supported locale
+dnl
+
+XSLT_LOCALE_XLOCALE=0
+XSLT_LOCALE_MSVCRT=0
+
+AC_CHECK_HEADERS([xlocale.h])
+if test $ac_cv_header_xlocale_h = yes; then
+AC_MSG_CHECKING([for working xlocale])
+AC_RUN_IFELSE(AC_LANG_PROGRAM([[
 #include <locale.h>
 #include <xlocale.h>
 #include <string.h>
@@ -121,33 +130,41 @@
 #define strxfrm_l __strxfrm_l
 #define LC_COLLATE_MASK (1 << LC_COLLATE)
 #endif
-
-int main()
-{
+]],[[
     locale_t locale;
-    const char *src[2] = { "\xc3\x84rger", "Zeppelin" };
-    char *dst[2];
+    const char *src[[2]] = { "\xc3\x84rger", "Zeppelin" };
+    char *dst[[2]];
     size_t len, r;
     int i;
-    
+
     locale = newlocale(LC_COLLATE_MASK, "en_US.utf8", NULL);
     if (locale == NULL) exit(1);
     for (i=0; i<2; ++i) {
-        len = strxfrm_l(NULL, src[i], 0, locale) + 1;
-        dst[i] = malloc(len);
-        if(dst[i] == NULL) exit(1);
-        r = strxfrm_l(dst[i], src[i], len, locale);
+        len = strxfrm_l(NULL, src[[i]], 0, locale) + 1;
+        dst[[i]] = malloc(len);
+        if(dst[[i]] == NULL) exit(1);
+        r = strxfrm_l(dst[[i]], src[[i]], len, locale);
         if(r >= len) exit(1);
     }
-    if (strcmp(dst[0], dst[1]) >= 0) exit(1);
-    
+    if (strcmp(dst[[0]], dst[[1]]) >= 0) exit(1);
+
     exit(0);
-}
-],
-  [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_XLOCALE_H, 1, [Have working xlocale.h])],
-  [AC_MSG_RESULT(no)]
+    return(0);
+]]),
+  [AC_MSG_RESULT(yes); XSLT_LOCALE_XLOCALE=1],
+  [AC_MSG_RESULT(no)],
+  [AC_MSG_WARN([cross compiling: assuming no])]
 )
+else
+  dnl defined in msvcrt
+  AC_CHECK_FUNC(_create_locale,
+    [XSLT_LOCALE_MSVCRT=1]
+  )
+fi
 
+AC_SUBST(XSLT_LOCALE_XLOCALE)
+AC_SUBST(XSLT_LOCALE_MSVCRT)
+
 dnl
 dnl Math detection
 dnl
Index: config.h.in
===================================================================
--- config.h.in	(revision 1477)
+++ config.h.in	(working copy)
@@ -123,7 +123,7 @@
 /* Define to 1 if you have the `vsprintf' function. */
 #undef HAVE_VSPRINTF
 
-/* Have working xlocale.h */
+/* Define to 1 if you have the <xlocale.h> header file. */
 #undef HAVE_XLOCALE_H
 
 /* Define to 1 if you have the `_stat' function. */
Index: win32/configure.js
===================================================================
--- win32/configure.js	(revision 1477)
+++ win32/configure.js	(working copy)
@@ -47,6 +47,7 @@
 var withZlib = false;
 var withCrypto = true;
 var withModules = false;
+var withLocale = true;
 /* Win32 build options. */
 var dirSep = "\\";
 var compiler = "msvc";
@@ -106,6 +107,7 @@
 	txt += "  zlib:       Use zlib library (" + (withZlib? "yes" : "no") + ")\n";
 	txt += "  crypto:     Enable Crypto support (" + (withCrypto? "yes" : "no") + ")\n";
 	txt += "  modules:    Enable Module support (" + (withModules? "yes" : "no") + ")\n";
+	txt += "  locale:     Enable Locale support, requires msvcr80.dll (" + (withLocale? "yes" : "no") + ")\n";
 	txt += "\nWin32 build options, default value given in parentheses:\n\n";
 	txt += "  compiler:   Compiler to be used [msvc|mingw] (" + compiler + ")\n";
 	txt += "  cruntime:   C-runtime compiler option (only msvc) (" + cruntime + ")\n";
@@ -240,6 +242,10 @@
 			of.WriteLine(s.replace(/\ WITH_DEBUGGER\@/, withDebugger? "1" : "0"));
 		} else if (s.search(/\ WITH_MODULES\@/) != -1) {
 			of.WriteLine(s.replace(/\ WITH_MODULES\@/, withModules? "1" : "0"));
+		} else if (s.search(/\ XSLT_LOCALE_XLOCALE\@/) != -1) {
+			of.WriteLine(s.replace(/\ XSLT_LOCALE_XLOCALE\@/, "0"));
+		} else if (s.search(/\ XSLT_LOCALE_MSVCRT\@/) != -1) {
+			of.WriteLine(s.replace(/\ XSLT_LOCALE_MSVCRT\@/, withLocale? "1" : "0"));
 		} else if (s.search(/\ LIBXSLT_DEFAULT_PLUGINS_PATH\@/) != -1) {
 			of.WriteLine(s.replace(/\ LIBXSLT_DEFAULT_PLUGINS_PATH\@/, "NULL"));
 		} else
@@ -343,6 +349,8 @@
 			withCrypto = strToBool(arg.substring(opt.length + 1, arg.length));
 		else if (opt == "modules")
 			withModules = strToBool(arg.substring(opt.length + 1, arg.length));
+		else if (opt == "locale")
+			withLocale = strToBool(arg.substring(opt.length + 1, arg.length));
 		else if (opt == "compiler")
 			compiler = arg.substring(opt.length + 1, arg.length);
  		else if (opt == "cruntime")
@@ -477,6 +485,7 @@
 txtOut += "         With zlib: " + boolToStr(withZlib) + "\n";
 txtOut += "            Crypto: " + boolToStr(withCrypto) + "\n";
 txtOut += "           Modules: " + boolToStr(withModules) + "\n";
+txtOut += "            Locale: " + boolToStr(withLocale) + "\n";
 txtOut += "\n";
 txtOut += "Win32 build configuration\n";
 txtOut += "-------------------------\n";


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]