From fb5f5f24207ff18bab339561b4017b59ee3b3bc8 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 28 Sep 2011 21:39:49 +0200 Subject: Mark PyUnicode_CONVERT_BYTES as private --- Include/unicodeobject.h | 15 --------------- Objects/unicodeobject.c | 35 +++++++++++++++++++++++++---------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h index dbd4fd8..b23f8a7 100644 --- a/Include/unicodeobject.h +++ b/Include/unicodeobject.h @@ -468,21 +468,6 @@ PyAPI_DATA(PyTypeObject) PyUnicodeIter_Type; (PyUnicode_IS_READY(op) ? \ 0 : _PyUnicode_Ready((PyUnicodeObject *)(op)))) -/* Generic helper macro to convert characters of different types. - from_type and to_type have to be valid type names, begin and end - are pointers to the source characters which should be of type - "from_type *". to is a pointer of type "to_type *" and points to the - buffer where the result characters are written to. */ -#define PyUnicode_CONVERT_BYTES(from_type, to_type, begin, end, to) \ - do { \ - const from_type *iter_; to_type *to_; \ - for (iter_ = (begin), to_ = (to_type *)(to); \ - iter_ < (end); \ - ++iter_, ++to_) { \ - *to_ = (to_type)*iter_; \ - } \ - } while (0) - /* Return a maximum character value which is suitable for creating another string based on op. This is always an approximation but more efficient than interating over the string. */ diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 7232653..ea88e21 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -90,6 +90,21 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. extern "C" { #endif +/* Generic helper macro to convert characters of different types. + from_type and to_type have to be valid type names, begin and end + are pointers to the source characters which should be of type + "from_type *". to is a pointer of type "to_type *" and points to the + buffer where the result characters are written to. */ +#define _PyUnicode_CONVERT_BYTES(from_type, to_type, begin, end, to) \ + do { \ + const from_type *iter_; to_type *to_; \ + for (iter_ = (begin), to_ = (to_type *)(to); \ + iter_ < (end); \ + ++iter_, ++to_) { \ + *to_ = (to_type)*iter_; \ + } \ + } while (0) + #define _PyUnicode_WSTR(op) (((PyASCIIObject*)(op))->wstr) #define _PyUnicode_WSTR_LENGTH(op) (((PyCompactUnicodeObject*)(op))->wstr_length) #define _PyUnicode_LENGTH(op) (((PyASCIIObject *)(op))->length) @@ -622,7 +637,7 @@ PyUnicode_CopyCharacters(PyObject *to, Py_ssize_t to_start, case PyUnicode_1BYTE_KIND: switch (to_kind) { case PyUnicode_2BYTE_KIND: - PyUnicode_CONVERT_BYTES( + _PyUnicode_CONVERT_BYTES( unsigned char, Py_UCS2, PyUnicode_1BYTE_DATA(from) + from_start, PyUnicode_1BYTE_DATA(from) + from_start + how_many, @@ -630,7 +645,7 @@ PyUnicode_CopyCharacters(PyObject *to, Py_ssize_t to_start, ); break; case PyUnicode_4BYTE_KIND: - PyUnicode_CONVERT_BYTES( + _PyUnicode_CONVERT_BYTES( unsigned char, Py_UCS4, PyUnicode_1BYTE_DATA(from) + from_start, PyUnicode_1BYTE_DATA(from) + from_start + how_many, @@ -644,7 +659,7 @@ PyUnicode_CopyCharacters(PyObject *to, Py_ssize_t to_start, case PyUnicode_2BYTE_KIND: switch (to_kind) { case PyUnicode_1BYTE_KIND: - PyUnicode_CONVERT_BYTES( + _PyUnicode_CONVERT_BYTES( Py_UCS2, unsigned char, PyUnicode_2BYTE_DATA(from) + from_start, PyUnicode_2BYTE_DATA(from) + from_start + how_many, @@ -652,7 +667,7 @@ PyUnicode_CopyCharacters(PyObject *to, Py_ssize_t to_start, ); break; case PyUnicode_4BYTE_KIND: - PyUnicode_CONVERT_BYTES( + _PyUnicode_CONVERT_BYTES( Py_UCS2, Py_UCS4, PyUnicode_2BYTE_DATA(from) + from_start, PyUnicode_2BYTE_DATA(from) + from_start + how_many, @@ -666,7 +681,7 @@ PyUnicode_CopyCharacters(PyObject *to, Py_ssize_t to_start, case PyUnicode_4BYTE_KIND: switch (to_kind) { case PyUnicode_1BYTE_KIND: - PyUnicode_CONVERT_BYTES( + _PyUnicode_CONVERT_BYTES( Py_UCS4, unsigned char, PyUnicode_4BYTE_DATA(from) + from_start, PyUnicode_4BYTE_DATA(from) + from_start + how_many, @@ -674,7 +689,7 @@ PyUnicode_CopyCharacters(PyObject *to, Py_ssize_t to_start, ); break; case PyUnicode_2BYTE_KIND: - PyUnicode_CONVERT_BYTES( + _PyUnicode_CONVERT_BYTES( Py_UCS4, Py_UCS2, PyUnicode_4BYTE_DATA(from) + from_start, PyUnicode_4BYTE_DATA(from) + from_start + how_many, @@ -792,7 +807,7 @@ _PyUnicode_Ready(PyUnicodeObject *unicode) PyErr_NoMemory(); return -1; } - PyUnicode_CONVERT_BYTES(wchar_t, unsigned char, + _PyUnicode_CONVERT_BYTES(wchar_t, unsigned char, _PyUnicode_WSTR(unicode), end, PyUnicode_1BYTE_DATA(unicode)); PyUnicode_1BYTE_DATA(unicode)[_PyUnicode_WSTR_LENGTH(unicode)] = '\0'; @@ -834,7 +849,7 @@ _PyUnicode_Ready(PyUnicodeObject *unicode) PyErr_NoMemory(); return -1; } - PyUnicode_CONVERT_BYTES(wchar_t, Py_UCS2, + _PyUnicode_CONVERT_BYTES(wchar_t, Py_UCS2, _PyUnicode_WSTR(unicode), end, PyUnicode_2BYTE_DATA(unicode)); PyUnicode_2BYTE_DATA(unicode)[_PyUnicode_WSTR_LENGTH(unicode)] = '\0'; @@ -1023,14 +1038,14 @@ PyUnicode_FromUnicode(const Py_UNICODE *u, Py_ssize_t size) switch (PyUnicode_KIND(unicode)) { case PyUnicode_1BYTE_KIND: - PyUnicode_CONVERT_BYTES(Py_UNICODE, unsigned char, + _PyUnicode_CONVERT_BYTES(Py_UNICODE, unsigned char, u, u + size, PyUnicode_1BYTE_DATA(unicode)); break; case PyUnicode_2BYTE_KIND: #if Py_UNICODE_SIZE == 2 Py_MEMCPY(PyUnicode_2BYTE_DATA(unicode), u, size * 2); #else - PyUnicode_CONVERT_BYTES(Py_UNICODE, Py_UCS2, + _PyUnicode_CONVERT_BYTES(Py_UNICODE, Py_UCS2, u, u + size, PyUnicode_2BYTE_DATA(unicode)); #endif break; -- cgit v0.12