]> granicus.if.org Git - python/commitdiff
Issue 8781: On systems a signed 4-byte wchar_t and a 4-byte Py_UNICODE, use memcpy...
authorDaniel Stutzbach <daniel@stutzbachenterprises.com>
Tue, 24 Aug 2010 21:57:33 +0000 (21:57 +0000)
committerDaniel Stutzbach <daniel@stutzbachenterprises.com>
Tue, 24 Aug 2010 21:57:33 +0000 (21:57 +0000)
Modules/_ctypes/callproc.c
Modules/_ctypes/cfield.c
Modules/_localemodule.c
Objects/unicodeobject.c

index 44b2d117bd10ce5810b72df1454acbb2d96a8413..81d3294e7353b142d27e6d423420e09ef8ac85c1 100644 (file)
@@ -658,7 +658,7 @@ static int ConvParam(PyObject *obj, Py_ssize_t index, struct argument *pa)
 
 #ifdef CTYPES_UNICODE
     if (PyUnicode_Check(obj)) {
-#ifdef HAVE_USABLE_WCHAR_T
+#if Py_UNICODE_SIZE == SIZEOF_WCHAR_T
         pa->ffi_type = &ffi_type_pointer;
         pa->value.p = PyUnicode_AS_UNICODE(obj);
         Py_INCREF(obj);
index b83447b71c7cac1451602c50046231d87cb017ea..3d7d0bca891f7686b5e54e150aa80354bc8cd57f 100644 (file)
@@ -1420,12 +1420,11 @@ Z_set(void *ptr, PyObject *value, Py_ssize_t size)
         return NULL;
     } else
         Py_INCREF(value);
-#ifdef HAVE_USABLE_WCHAR_T
-    /* HAVE_USABLE_WCHAR_T means that Py_UNICODE and wchar_t is the same
-       type.  So we can copy directly.  Hm, are unicode objects always NUL
+#if Py_UNICODE_SIZE == SIZEOF_WCHAR_T
+    /* We can copy directly.  Hm, are unicode objects always NUL
        terminated in Python, internally?
      */
-    *(wchar_t **)ptr = PyUnicode_AS_UNICODE(value);
+    *(wchar_t **)ptr = (wchar_t *) PyUnicode_AS_UNICODE(value);
     return value;
 #else
     {
index 88f6addd44cc08ccd803293b465a9bbeb5928d62..2394206823eb44ba62dbd6c4116e362b88889aba 100644 (file)
@@ -289,15 +289,15 @@ PyLocale_strxfrm(PyObject* self, PyObject* args)
     wchar_t *s, *buf = NULL;
     size_t n1, n2;
     PyObject *result = NULL;
-#ifndef HAVE_USABLE_WCHAR_T
+#if Py_UNICODE_SIZE != SIZEOF_WCHAR_T
     Py_ssize_t i;
 #endif
 
     if (!PyArg_ParseTuple(args, "u#:strxfrm", &s0, &n0))
         return NULL;
 
-#ifdef HAVE_USABLE_WCHAR_T
-    s = s0;
+#if Py_UNICODE_SIZE == SIZEOF_WCHAR_T
+    s = (wchar_t *) s0;
 #else
     s = PyMem_Malloc((n0+1)*sizeof(wchar_t));
     if (!s)
@@ -326,7 +326,7 @@ PyLocale_strxfrm(PyObject* self, PyObject* args)
     result = PyUnicode_FromWideChar(buf, n2);
  exit:
     if (buf) PyMem_Free(buf);
-#ifndef HAVE_USABLE_WCHAR_T
+#if Py_UNICODE_SIZE != SIZEOF_WCHAR_T
     PyMem_Free(s);
 #endif
     return result;
index c50f60165bf6526173a6bb56ad859ec9840487f5..4c4b43c0e18dc9b30bb470860e152353813d835f 100644 (file)
@@ -664,7 +664,7 @@ PyObject *PyUnicode_FromWideChar(register const wchar_t *w,
         return NULL;
 
     /* 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));
 #else
     {
@@ -1167,7 +1167,7 @@ Py_ssize_t PyUnicode_AsWideChar(PyUnicodeObject *unicode,
     if (size > PyUnicode_GET_SIZE(unicode))
         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));
 #else
     {