diff -r 588fe0fc7160 Include/unicodeobject.h --- a/Include/unicodeobject.h Fri Jul 01 02:57:33 2011 +0200 +++ b/Include/unicodeobject.h Mon Jul 04 13:36:18 2011 +0200 @@ -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 -r 588fe0fc7160 Modules/_codecsmodule.c --- a/Modules/_codecsmodule.c Fri Jul 01 02:57:33 2011 +0200 +++ b/Modules/_codecsmodule.c Mon Jul 04 13:36:18 2011 +0200 @@ -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 -r 588fe0fc7160 Modules/timemodule.c --- a/Modules/timemodule.c Fri Jul 01 02:57:33 2011 +0200 +++ b/Modules/timemodule.c Mon Jul 04 13:36:18 2011 +0200 @@ -3,8 +3,6 @@ #include "Python.h" #include "_time.h" -#define TZNAME_ENCODING "utf-8" - #include #ifdef HAVE_SYS_TYPES_H @@ -45,12 +43,11 @@ #endif /* MS_WINDOWS */ #endif /* !__WATCOMC__ || __QNX__ */ -#if defined(MS_WINDOWS) && !defined(__BORLANDC__) -/* Win32 has better clock replacement; we have our own version below. */ -#undef HAVE_CLOCK -#undef TZNAME_ENCODING -#define TZNAME_ENCODING "mbcs" -#endif /* MS_WINDOWS && !defined(__BORLANDC__) */ +#if defined(HAVE_MBCS) +# define TZNAME_ENCODING "mbcs" +#else +# define TZNAME_ENCODING "utf-8" +#endif #if defined(PYOS_OS2) #define INCL_DOS @@ -84,24 +81,8 @@ Return the current time in seconds since the Epoch.\n\ Fractions of a second may be present if the system clock provides them."); -#ifdef HAVE_CLOCK - -#ifndef CLOCKS_PER_SEC -#ifdef CLK_TCK -#define CLOCKS_PER_SEC CLK_TCK -#else -#define CLOCKS_PER_SEC 1000000 -#endif -#endif - -static PyObject * -time_clock(PyObject *self, PyObject *unused) -{ - return PyFloat_FromDouble(((double)clock()) / CLOCKS_PER_SEC); -} -#endif /* HAVE_CLOCK */ - #if defined(MS_WINDOWS) && !defined(__BORLANDC__) +/* Win32 has better clock replacement; we have our own version below. */ /* Due to Mark Hammond and Tim Peters */ static PyObject * time_clock(PyObject *self, PyObject *unused) @@ -127,8 +108,22 @@ return PyFloat_FromDouble(diff / divisor); } -#define HAVE_CLOCK /* So it gets included in the methods */ -#endif /* MS_WINDOWS && !defined(__BORLANDC__) */ +#elif defined(HAVE_CLOCK) + +#ifndef CLOCKS_PER_SEC +#ifdef CLK_TCK +#define CLOCKS_PER_SEC CLK_TCK +#else +#define CLOCKS_PER_SEC 1000000 +#endif +#endif + +static PyObject * +time_clock(PyObject *self, PyObject *unused) +{ + return PyFloat_FromDouble(((double)clock()) / CLOCKS_PER_SEC); +} +#endif /* HAVE_CLOCK */ #ifdef HAVE_CLOCK PyDoc_STRVAR(clock_doc, @@ -784,7 +779,7 @@ static PyMethodDef time_methods[] = { {"time", time_time, METH_NOARGS, time_doc}, -#ifdef HAVE_CLOCK +#if (defined(MS_WINDOWS) && !defined(__BORLANDC__)) || defined(HAVE_CLOCK) {"clock", time_clock, METH_NOARGS, clock_doc}, #endif {"sleep", time_sleep, METH_VARARGS, sleep_doc}, diff -r 588fe0fc7160 Objects/unicodeobject.c --- a/Objects/unicodeobject.c Fri Jul 01 02:57:33 2011 +0200 +++ b/Objects/unicodeobject.c Mon Jul 04 13:36:18 2011 +0200 @@ -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 -r 588fe0fc7160 Python/bltinmodule.c --- a/Python/bltinmodule.c Fri Jul 01 02:57:33 2011 +0200 +++ b/Python/bltinmodule.c Mon Jul 04 13:36:18 2011 +0200 @@ -18,18 +18,15 @@ 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__) const char *Py_FileSystemDefaultEncoding = "utf-8"; int Py_HasFileSystemDefaultEncoding = 1; -#elif defined(HAVE_LANGINFO_H) && defined(CODESET) +#else const char *Py_FileSystemDefaultEncoding = NULL; /* set by initfsencoding() */ int Py_HasFileSystemDefaultEncoding = 0; -#else -const char *Py_FileSystemDefaultEncoding = "utf-8"; -int Py_HasFileSystemDefaultEncoding = 1; #endif static PyObject * diff -r 588fe0fc7160 Python/pythonrun.c --- a/Python/pythonrun.c Fri Jul 01 02:57:33 2011 +0200 +++ b/Python/pythonrun.c Mon Jul 04 13:36:18 2011 +0200 @@ -168,18 +168,25 @@ return NULL; } -#if defined(HAVE_LANGINFO_H) && defined(CODESET) static char* -get_codeset(void) +get_locale_encoding(void) { +#ifdef MS_WINDOWS + char codepage[100]; + PyOS_snprintf(codepage, sizeof(codepage), "cp%d", GetACP()); + return get_codec_name(codepage); +#elif defined(HAVE_LANGINFO_H) && defined(CODESET) char* codeset = nl_langinfo(CODESET); if (!codeset || codeset[0] == '\0') { PyErr_SetString(PyExc_ValueError, "CODESET is not set or empty"); return NULL; } return get_codec_name(codeset); +#else + PyErr_SetNone(PyExc_NotImplementedError); + return NULL; +#endif } -#endif void Py_InitializeEx(int install_sigs) @@ -746,7 +753,6 @@ initfsencoding(PyInterpreterState *interp) { PyObject *codec; -#if defined(HAVE_LANGINFO_H) && defined(CODESET) char *codeset = NULL; if (Py_FileSystemDefaultEncoding == NULL) { @@ -754,7 +760,7 @@ user's preference, if the CODESET names a well-known Python codec, and Py_FileSystemDefaultEncoding isn't initialized by other means. */ - codeset = get_codeset(); + codeset = get_locale_encoding(); if (codeset == NULL) Py_FatalError("Py_Initialize: Unable to get the locale encoding"); @@ -763,7 +769,6 @@ interp->fscodec_initialized = 1; return 0; } -#endif /* the encoding is mbcs, utf-8 or ascii */ codec = _PyCodec_Lookup(Py_FileSystemDefaultEncoding);