mirror of https://github.com/python/cpython.git
Issue 8781: On systems a signed 4-byte wchar_t and a 4-byte Py_UNICODE, use memcpy to convert between the two (as already done when wchar_t is unsigned)
This commit is contained in:
parent
16925e8539
commit
8515eaefda
|
@ -658,7 +658,7 @@ static int ConvParam(PyObject *obj, Py_ssize_t index, struct argument *pa)
|
||||||
|
|
||||||
#ifdef CTYPES_UNICODE
|
#ifdef CTYPES_UNICODE
|
||||||
if (PyUnicode_Check(obj)) {
|
if (PyUnicode_Check(obj)) {
|
||||||
#ifdef HAVE_USABLE_WCHAR_T
|
#if Py_UNICODE_SIZE == SIZEOF_WCHAR_T
|
||||||
pa->ffi_type = &ffi_type_pointer;
|
pa->ffi_type = &ffi_type_pointer;
|
||||||
pa->value.p = PyUnicode_AS_UNICODE(obj);
|
pa->value.p = PyUnicode_AS_UNICODE(obj);
|
||||||
Py_INCREF(obj);
|
Py_INCREF(obj);
|
||||||
|
|
|
@ -1420,12 +1420,11 @@ Z_set(void *ptr, PyObject *value, Py_ssize_t size)
|
||||||
return NULL;
|
return NULL;
|
||||||
} else
|
} else
|
||||||
Py_INCREF(value);
|
Py_INCREF(value);
|
||||||
#ifdef HAVE_USABLE_WCHAR_T
|
#if Py_UNICODE_SIZE == SIZEOF_WCHAR_T
|
||||||
/* HAVE_USABLE_WCHAR_T means that Py_UNICODE and wchar_t is the same
|
/* We can copy directly. Hm, are unicode objects always NUL
|
||||||
type. So we can copy directly. Hm, are unicode objects always NUL
|
|
||||||
terminated in Python, internally?
|
terminated in Python, internally?
|
||||||
*/
|
*/
|
||||||
*(wchar_t **)ptr = PyUnicode_AS_UNICODE(value);
|
*(wchar_t **)ptr = (wchar_t *) PyUnicode_AS_UNICODE(value);
|
||||||
return value;
|
return value;
|
||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
|
|
|
@ -289,15 +289,15 @@ PyLocale_strxfrm(PyObject* self, PyObject* args)
|
||||||
wchar_t *s, *buf = NULL;
|
wchar_t *s, *buf = NULL;
|
||||||
size_t n1, n2;
|
size_t n1, n2;
|
||||||
PyObject *result = NULL;
|
PyObject *result = NULL;
|
||||||
#ifndef HAVE_USABLE_WCHAR_T
|
#if Py_UNICODE_SIZE != SIZEOF_WCHAR_T
|
||||||
Py_ssize_t i;
|
Py_ssize_t i;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "u#:strxfrm", &s0, &n0))
|
if (!PyArg_ParseTuple(args, "u#:strxfrm", &s0, &n0))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
#ifdef HAVE_USABLE_WCHAR_T
|
#if Py_UNICODE_SIZE == SIZEOF_WCHAR_T
|
||||||
s = s0;
|
s = (wchar_t *) s0;
|
||||||
#else
|
#else
|
||||||
s = PyMem_Malloc((n0+1)*sizeof(wchar_t));
|
s = PyMem_Malloc((n0+1)*sizeof(wchar_t));
|
||||||
if (!s)
|
if (!s)
|
||||||
|
@ -326,7 +326,7 @@ PyLocale_strxfrm(PyObject* self, PyObject* args)
|
||||||
result = PyUnicode_FromWideChar(buf, n2);
|
result = PyUnicode_FromWideChar(buf, n2);
|
||||||
exit:
|
exit:
|
||||||
if (buf) PyMem_Free(buf);
|
if (buf) PyMem_Free(buf);
|
||||||
#ifndef HAVE_USABLE_WCHAR_T
|
#if Py_UNICODE_SIZE != SIZEOF_WCHAR_T
|
||||||
PyMem_Free(s);
|
PyMem_Free(s);
|
||||||
#endif
|
#endif
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -664,7 +664,7 @@ PyObject *PyUnicode_FromWideChar(register const wchar_t *w,
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* Copy the wchar_t data into the new object */
|
/* Copy the wchar_t data into the new object */
|
||||||
#ifdef HAVE_USABLE_WCHAR_T
|
#if Py_UNICODE_SIZE == SIZEOF_WCHAR_T
|
||||||
memcpy(unicode->str, w, size * sizeof(wchar_t));
|
memcpy(unicode->str, w, size * sizeof(wchar_t));
|
||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
|
@ -1167,7 +1167,7 @@ Py_ssize_t PyUnicode_AsWideChar(PyUnicodeObject *unicode,
|
||||||
if (size > PyUnicode_GET_SIZE(unicode))
|
if (size > PyUnicode_GET_SIZE(unicode))
|
||||||
size = PyUnicode_GET_SIZE(unicode) + 1;
|
size = PyUnicode_GET_SIZE(unicode) + 1;
|
||||||
|
|
||||||
#ifdef HAVE_USABLE_WCHAR_T
|
#if Py_UNICODE_SIZE == SIZEOF_WCHAR_T
|
||||||
memcpy(w, unicode->str, size * sizeof(wchar_t));
|
memcpy(w, unicode->str, size * sizeof(wchar_t));
|
||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue