diff options
author | Christian Heimes <christian@cheimes.de> | 2012-10-17 21:52:17 (GMT) |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2012-10-17 21:52:17 (GMT) |
commit | 743e0cd6b5d59767aae2524700857f188ca1e80e (patch) | |
tree | 89897c0424a3b361e04d451e2b3a64e5c7c17756 /Modules/_io/textio.c | |
parent | 1e9af84e2ef41115dd07d00b57e5a2a7041bfeed (diff) | |
download | cpython-743e0cd6b5d59767aae2524700857f188ca1e80e.zip cpython-743e0cd6b5d59767aae2524700857f188ca1e80e.tar.gz cpython-743e0cd6b5d59767aae2524700857f188ca1e80e.tar.bz2 |
Issue #16166: Add PY_LITTLE_ENDIAN and PY_BIG_ENDIAN macros and unified
endianess detection and handling.
Diffstat (limited to 'Modules/_io/textio.c')
-rw-r--r-- | Modules/_io/textio.c | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index 96434a8..8344d43 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -747,7 +747,7 @@ utf16_encode(textio *self, PyObject *text) { if (!self->encoding_start_of_stream) { /* Skip the BOM and use native byte ordering */ -#if defined(WORDS_BIGENDIAN) +#if PY_BIG_ENDIAN return utf16be_encode(self, text); #else return utf16le_encode(self, text); @@ -776,7 +776,7 @@ utf32_encode(textio *self, PyObject *text) { if (!self->encoding_start_of_stream) { /* Skip the BOM and use native byte ordering */ -#if defined(WORDS_BIGENDIAN) +#if PY_BIG_ENDIAN return utf32be_encode(self, text); #else return utf32le_encode(self, text); @@ -1913,10 +1913,7 @@ typedef struct { #define COOKIE_BUF_LEN (sizeof(Py_off_t) + 3 * sizeof(int) + sizeof(char)) -#if defined(WORDS_BIGENDIAN) - -# define IS_LITTLE_ENDIAN 0 - +#if PY_BIG_ENDIAN /* We want the least significant byte of start_pos to also be the least significant byte of the cookie, which means that in big-endian mode we must copy the fields in reverse order. */ @@ -1928,9 +1925,6 @@ typedef struct { # define OFF_NEED_EOF 0 #else - -# define IS_LITTLE_ENDIAN 1 - /* Little-endian mode: the least significant byte of start_pos will naturally end up the least significant byte of the cookie. */ @@ -1951,7 +1945,7 @@ textiowrapper_parse_cookie(cookie_type *cookie, PyObject *cookieObj) return -1; if (_PyLong_AsByteArray(cookieLong, buffer, sizeof(buffer), - IS_LITTLE_ENDIAN, 0) < 0) { + PY_LITTLE_ENDIAN, 0) < 0) { Py_DECREF(cookieLong); return -1; } @@ -1977,9 +1971,9 @@ textiowrapper_build_cookie(cookie_type *cookie) memcpy(buffer + OFF_CHARS_TO_SKIP, &cookie->chars_to_skip, sizeof(cookie->chars_to_skip)); memcpy(buffer + OFF_NEED_EOF, &cookie->need_eof, sizeof(cookie->need_eof)); - return _PyLong_FromByteArray(buffer, sizeof(buffer), IS_LITTLE_ENDIAN, 0); + return _PyLong_FromByteArray(buffer, sizeof(buffer), + PY_LITTLE_ENDIAN, 0); } -#undef IS_LITTLE_ENDIAN static int _textiowrapper_decoder_setstate(textio *self, cookie_type *cookie) |