[ctypes-commit] ctypes/source cfield.c,1.47,1.48
Brought to you by:
theller
From: Thomas H. <th...@us...> - 2004-10-12 08:47:42
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5348 Modified Files: cfield.c Log Message: Make the code more general, to work with any size of wchar_t. Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.47 retrieving revision 1.48 diff -C2 -d -r1.47 -r1.48 *** cfield.c 12 Oct 2004 08:29:11 -0000 1.47 --- cfield.c 12 Oct 2004 08:46:36 -0000 1.48 *************** *** 720,723 **** --- 720,726 ---- unsigned int size; + /* It's easier to calculate in characters than in bytes */ + length /= sizeof(wchar_t); + if (PyString_Check(value)) { value = PyUnicode_FromEncodedObject(value, *************** *** 733,751 **** } else Py_INCREF(value); ! size = PyUnicode_GET_DATA_SIZE(value); if (size > length) { PyErr_Format(PyExc_ValueError, ! "too long (%d instead of less than %d)", size, length); Py_DECREF(value); return NULL; ! } else if (size < length-sizeof(wchar_t)) /* copy terminating NUL character */ ! size += sizeof(wchar_t); ! #ifdef HAVE_USABLE_WCHAR_T ! memcpy((wchar_t *)ptr, PyUnicode_AS_UNICODE(value), size); ! #else ! #error FIXME: use PyUnicode_FromWideChar() ! #endif return value; } --- 736,750 ---- } else Py_INCREF(value); ! size = PyUnicode_GET_SIZE(value); if (size > length) { PyErr_Format(PyExc_ValueError, ! "too long (%d chars instead of less than %d)", size, length); Py_DECREF(value); return NULL; ! } else if (size < length-1) /* copy terminating NUL character */ ! size += 1; ! PyUnicode_AsWideChar(value, (wchar_t *)ptr, size); return value; } |