[Python-checkins] cpython: Issue #9642: Uniformize the tests on the availability of the mbcs codec

victor.stinner python-checkins at python.org
Mon Jul 4 14:25:56 CEST 2011


http://hg.python.org/cpython/rev/13e6d3cb2ecd
changeset:   71193:13e6d3cb2ecd
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Mon Jul 04 14:23:54 2011 +0200
summary:
  Issue #9642: Uniformize the tests on the availability of the mbcs codec

Add a new HAVE_MBCS define.

files:
  Include/unicodeobject.h |   8 ++++++--
  Misc/NEWS               |   3 +++
  Modules/_codecsmodule.c |  10 +++++-----
  Modules/timemodule.c    |   2 +-
  Objects/unicodeobject.c |  12 ++++++------
  Python/bltinmodule.c    |   2 +-
  6 files changed, 22 insertions(+), 15 deletions(-)


diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h
--- a/Include/unicodeobject.h
+++ b/Include/unicodeobject.h
@@ -109,6 +109,10 @@
 # endif
 #endif
 
+#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
+#  define HAVE_MBCS
+#endif
+
 #ifdef HAVE_WCHAR_H
 /* Work around a cosmetic bug in BSDI 4.x wchar.h; thanks to Thomas Wouters */
 # ifdef _HAVE_BSDI
@@ -1162,7 +1166,7 @@
     );
 #endif
 
-#ifdef MS_WIN32
+#ifdef HAVE_MBCS
 
 /* --- MBCS codecs for Windows -------------------------------------------- */
 
@@ -1191,7 +1195,7 @@
     );
 #endif
 
-#endif /* MS_WIN32 */
+#endif /* HAVE_MBCS */
 
 /* --- Decimal Encoder ---------------------------------------------------- */
 
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@
 Core and Builtins
 -----------------
 
+- Issue #9642: Uniformize the tests on the availability of the mbcs codec, add
+  a new HAVE_MBCS define.
+
 - Issue #9642: Fix filesystem encoding initialization: use the ANSI code page
   on Windows if the mbcs codec is not available, and fail with a fatal error if
   we cannot get the locale encoding (if nl_langinfo(CODESET) is not available)
diff --git a/Modules/_codecsmodule.c b/Modules/_codecsmodule.c
--- a/Modules/_codecsmodule.c
+++ b/Modules/_codecsmodule.c
@@ -588,7 +588,7 @@
     return codec_tuple(unicode, pbuf.len);
 }
 
-#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
+#ifdef HAVE_MBCS
 
 static PyObject *
 mbcs_decode(PyObject *self,
@@ -613,7 +613,7 @@
     return codec_tuple(decoded, consumed);
 }
 
-#endif /* MS_WINDOWS */
+#endif /* HAVE_MBCS */
 
 /* --- Encoder ------------------------------------------------------------ */
 
@@ -989,7 +989,7 @@
     return PyUnicode_BuildEncodingMap(map);
 }
 
-#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
+#ifdef HAVE_MBCS
 
 static PyObject *
 mbcs_encode(PyObject *self,
@@ -1014,7 +1014,7 @@
     return v;
 }
 
-#endif /* MS_WINDOWS */
+#endif /* HAVE_MBCS */
 
 /* --- Error handler registry --------------------------------------------- */
 
@@ -1101,7 +1101,7 @@
     {"charmap_decode",          charmap_decode,                 METH_VARARGS},
     {"charmap_build",           charmap_build,                  METH_VARARGS},
     {"readbuffer_encode",       readbuffer_encode,              METH_VARARGS},
-#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
+#ifdef HAVE_MBCS
     {"mbcs_encode",             mbcs_encode,                    METH_VARARGS},
     {"mbcs_decode",             mbcs_decode,                    METH_VARARGS},
 #endif
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -43,7 +43,7 @@
 #endif /* MS_WINDOWS */
 #endif /* !__WATCOMC__ || __QNX__ */
 
-#if defined(MS_WINDOWS)
+#if defined(HAVE_MBCS)
 #  define TZNAME_ENCODING "mbcs"
 #else
 #  define TZNAME_ENCODING "utf-8"
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -1506,7 +1506,7 @@
                  (strcmp(lower, "latin1") == 0) ||
                  (strcmp(lower, "iso-8859-1") == 0))
             return PyUnicode_DecodeLatin1(s, size, errors);
-#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
+#ifdef HAVE_MBCS
         else if (strcmp(lower, "mbcs") == 0)
             return PyUnicode_DecodeMBCS(s, size, errors);
 #endif
@@ -1644,7 +1644,7 @@
 PyObject *
 PyUnicode_EncodeFSDefault(PyObject *unicode)
 {
-#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
+#ifdef HAVE_MBCS
     return PyUnicode_EncodeMBCS(PyUnicode_AS_UNICODE(unicode),
                                 PyUnicode_GET_SIZE(unicode),
                                 NULL);
@@ -1746,7 +1746,7 @@
             return PyUnicode_EncodeLatin1(PyUnicode_AS_UNICODE(unicode),
                                           PyUnicode_GET_SIZE(unicode),
                                           errors);
-#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
+#ifdef HAVE_MBCS
         else if (strcmp(lower, "mbcs") == 0)
             return PyUnicode_EncodeMBCS(PyUnicode_AS_UNICODE(unicode),
                                         PyUnicode_GET_SIZE(unicode),
@@ -1848,7 +1848,7 @@
 PyObject*
 PyUnicode_DecodeFSDefaultAndSize(const char *s, Py_ssize_t size)
 {
-#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
+#ifdef HAVE_MBCS
     return PyUnicode_DecodeMBCS(s, size, NULL);
 #elif defined(__APPLE__)
     return PyUnicode_DecodeUTF8(s, size, "surrogateescape");
@@ -4942,7 +4942,7 @@
                                  NULL);
 }
 
-#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
+#ifdef HAVE_MBCS
 
 /* --- MBCS codecs for Windows -------------------------------------------- */
 
@@ -5229,7 +5229,7 @@
 
 #undef NEED_RETRY
 
-#endif /* MS_WINDOWS */
+#endif /* HAVE_MBCS */
 
 /* --- Character Mapping Codec -------------------------------------------- */
 
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -18,7 +18,7 @@
    Don't forget to modify PyUnicode_DecodeFSDefault() if you touch any of the
    values for Py_FileSystemDefaultEncoding!
 */
-#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
+#ifdef HAVE_MBCS
 const char *Py_FileSystemDefaultEncoding = "mbcs";
 int Py_HasFileSystemDefaultEncoding = 1;
 #elif defined(__APPLE__)

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list