Skip to content

Commit 99b9538

Browse files
author
Victor Stinner
committed
Issue python#9642: Uniformize the tests on the availability of the mbcs codec
Add a new HAVE_MBCS define.
1 parent 9122fdd commit 99b9538

6 files changed

Lines changed: 22 additions & 15 deletions

File tree

Include/unicodeobject.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ Copyright (c) Corporation for National Research Initiatives.
109109
# endif
110110
#endif
111111

112+
#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
113+
# define HAVE_MBCS
114+
#endif
115+
112116
#ifdef HAVE_WCHAR_H
113117
/* Work around a cosmetic bug in BSDI 4.x wchar.h; thanks to Thomas Wouters */
114118
# ifdef _HAVE_BSDI
@@ -1162,7 +1166,7 @@ PyAPI_FUNC(PyObject *) PyUnicode_TranslateCharmap(
11621166
);
11631167
#endif
11641168

1165-
#ifdef MS_WIN32
1169+
#ifdef HAVE_MBCS
11661170

11671171
/* --- MBCS codecs for Windows -------------------------------------------- */
11681172

@@ -1191,7 +1195,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_EncodeMBCS(
11911195
);
11921196
#endif
11931197

1194-
#endif /* MS_WIN32 */
1198+
#endif /* HAVE_MBCS */
11951199

11961200
/* --- Decimal Encoder ---------------------------------------------------- */
11971201

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.3 Alpha 1?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #9642: Uniformize the tests on the availability of the mbcs codec, add
14+
a new HAVE_MBCS define.
15+
1316
- Issue #9642: Fix filesystem encoding initialization: use the ANSI code page
1417
on Windows if the mbcs codec is not available, and fail with a fatal error if
1518
we cannot get the locale encoding (if nl_langinfo(CODESET) is not available)

Modules/_codecsmodule.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ charmap_decode(PyObject *self,
588588
return codec_tuple(unicode, pbuf.len);
589589
}
590590

591-
#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
591+
#ifdef HAVE_MBCS
592592

593593
static PyObject *
594594
mbcs_decode(PyObject *self,
@@ -613,7 +613,7 @@ mbcs_decode(PyObject *self,
613613
return codec_tuple(decoded, consumed);
614614
}
615615

616-
#endif /* MS_WINDOWS */
616+
#endif /* HAVE_MBCS */
617617

618618
/* --- Encoder ------------------------------------------------------------ */
619619

@@ -989,7 +989,7 @@ charmap_build(PyObject *self, PyObject *args)
989989
return PyUnicode_BuildEncodingMap(map);
990990
}
991991

992-
#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
992+
#ifdef HAVE_MBCS
993993

994994
static PyObject *
995995
mbcs_encode(PyObject *self,
@@ -1014,7 +1014,7 @@ mbcs_encode(PyObject *self,
10141014
return v;
10151015
}
10161016

1017-
#endif /* MS_WINDOWS */
1017+
#endif /* HAVE_MBCS */
10181018

10191019
/* --- Error handler registry --------------------------------------------- */
10201020

@@ -1101,7 +1101,7 @@ static PyMethodDef _codecs_functions[] = {
11011101
{"charmap_decode", charmap_decode, METH_VARARGS},
11021102
{"charmap_build", charmap_build, METH_VARARGS},
11031103
{"readbuffer_encode", readbuffer_encode, METH_VARARGS},
1104-
#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
1104+
#ifdef HAVE_MBCS
11051105
{"mbcs_encode", mbcs_encode, METH_VARARGS},
11061106
{"mbcs_decode", mbcs_decode, METH_VARARGS},
11071107
#endif

Modules/timemodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static long main_thread;
4343
#endif /* MS_WINDOWS */
4444
#endif /* !__WATCOMC__ || __QNX__ */
4545

46-
#if defined(MS_WINDOWS)
46+
#if defined(HAVE_MBCS)
4747
# define TZNAME_ENCODING "mbcs"
4848
#else
4949
# define TZNAME_ENCODING "utf-8"

Objects/unicodeobject.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,7 +1506,7 @@ PyUnicode_Decode(const char *s,
15061506
(strcmp(lower, "latin1") == 0) ||
15071507
(strcmp(lower, "iso-8859-1") == 0))
15081508
return PyUnicode_DecodeLatin1(s, size, errors);
1509-
#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
1509+
#ifdef HAVE_MBCS
15101510
else if (strcmp(lower, "mbcs") == 0)
15111511
return PyUnicode_DecodeMBCS(s, size, errors);
15121512
#endif
@@ -1644,7 +1644,7 @@ PyUnicode_AsEncodedObject(PyObject *unicode,
16441644
PyObject *
16451645
PyUnicode_EncodeFSDefault(PyObject *unicode)
16461646
{
1647-
#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
1647+
#ifdef HAVE_MBCS
16481648
return PyUnicode_EncodeMBCS(PyUnicode_AS_UNICODE(unicode),
16491649
PyUnicode_GET_SIZE(unicode),
16501650
NULL);
@@ -1746,7 +1746,7 @@ PyUnicode_AsEncodedString(PyObject *unicode,
17461746
return PyUnicode_EncodeLatin1(PyUnicode_AS_UNICODE(unicode),
17471747
PyUnicode_GET_SIZE(unicode),
17481748
errors);
1749-
#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
1749+
#ifdef HAVE_MBCS
17501750
else if (strcmp(lower, "mbcs") == 0)
17511751
return PyUnicode_EncodeMBCS(PyUnicode_AS_UNICODE(unicode),
17521752
PyUnicode_GET_SIZE(unicode),
@@ -1848,7 +1848,7 @@ PyUnicode_DecodeFSDefault(const char *s) {
18481848
PyObject*
18491849
PyUnicode_DecodeFSDefaultAndSize(const char *s, Py_ssize_t size)
18501850
{
1851-
#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
1851+
#ifdef HAVE_MBCS
18521852
return PyUnicode_DecodeMBCS(s, size, NULL);
18531853
#elif defined(__APPLE__)
18541854
return PyUnicode_DecodeUTF8(s, size, "surrogateescape");
@@ -4942,7 +4942,7 @@ PyUnicode_AsASCIIString(PyObject *unicode)
49424942
NULL);
49434943
}
49444944

4945-
#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
4945+
#ifdef HAVE_MBCS
49464946

49474947
/* --- MBCS codecs for Windows -------------------------------------------- */
49484948

@@ -5229,7 +5229,7 @@ PyUnicode_AsMBCSString(PyObject *unicode)
52295229

52305230
#undef NEED_RETRY
52315231

5232-
#endif /* MS_WINDOWS */
5232+
#endif /* HAVE_MBCS */
52335233

52345234
/* --- Character Mapping Codec -------------------------------------------- */
52355235

Python/bltinmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
Don't forget to modify PyUnicode_DecodeFSDefault() if you touch any of the
1919
values for Py_FileSystemDefaultEncoding!
2020
*/
21-
#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
21+
#ifdef HAVE_MBCS
2222
const char *Py_FileSystemDefaultEncoding = "mbcs";
2323
int Py_HasFileSystemDefaultEncoding = 1;
2424
#elif defined(__APPLE__)

0 commit comments

Comments
 (0)