[ctypes-commit] ctypes/source cfield.c,1.52,1.53
Brought to you by:
theller
From: Thomas H. <th...@us...> - 2004-10-12 10:38:13
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26220 Modified Files: cfield.c Log Message: Fully implement the Z_set function, even if HAVE_USABLE_WCHAR_T is not defined. Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.52 retrieving revision 1.53 diff -C2 -d -r1.52 -r1.53 *** cfield.c 12 Oct 2004 09:43:06 -0000 1.52 --- cfield.c 12 Oct 2004 10:38:04 -0000 1.53 *************** *** 865,874 **** } else Py_INCREF(value); - *(wchar_t **)ptr = PyUnicode_AS_UNICODE(value); #ifdef HAVE_USABLE_WCHAR_T #else ! //#error FIXME #endif - return value; } --- 865,904 ---- } 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 + terminated in Python, internally? + */ + *(wchar_t **)ptr = PyUnicode_AS_UNICODE(value); + return value; #else ! { ! /* We must create a wchar_t* buffer from the unicode object, ! and keep it alive */ ! PyObject *keep; ! wchar_t *buffer; ! ! int size = PyUnicode_GET_SIZE(value); ! size += 1; /* terminating NUL */ ! size *= sizeof(wchar_t); ! buffer = (wchar_t *)PyMem_Malloc(size); ! if (!buffer) ! return NULL; ! memset(buffer, 0, size); ! keep = PyCObject_FromVoidPtr(buffer, PyMem_Free); ! if (!keep) { ! PyMem_Free(buffer); ! return NULL; ! } ! *(wchar_t **)ptr = (wchar_t *)buffer; ! if (-1 == PyUnicode_AsWideChar((PyUnicodeObject *)value, ! buffer, PyUnicode_GET_SIZE(value))) { ! Py_DECREF(value); ! return NULL; ! } ! Py_DECREF(value); ! return keep; ! } #endif } |