diff options
author | Thomas Heller <theller@ctypes.org> | 2007-07-12 15:41:51 (GMT) |
---|---|---|
committer | Thomas Heller <theller@ctypes.org> | 2007-07-12 15:41:51 (GMT) |
commit | 2c5e96465faa2e79b60f21b10422a6a30281cdb8 (patch) | |
tree | 7489bd6a38337fc58946eb5e6a6146c40d970d05 /Modules | |
parent | 3af4266d07c38a136858acd63fe663d24590400c (diff) | |
download | cpython-2c5e96465faa2e79b60f21b10422a6a30281cdb8.zip cpython-2c5e96465faa2e79b60f21b10422a6a30281cdb8.tar.gz cpython-2c5e96465faa2e79b60f21b10422a6a30281cdb8.tar.bz2 |
Accept bytes in c_char_p and c_wchar_p types.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_ctypes/cfield.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c index 75b00b6..a8d0d4b 100644 --- a/Modules/_ctypes/cfield.c +++ b/Modules/_ctypes/cfield.c @@ -1354,8 +1354,8 @@ z_set(void *ptr, PyObject *value, Py_ssize_t size) Py_INCREF(value); return value; } - if (PyString_Check(value)) { - *(char **)ptr = PyString_AS_STRING(value); + if (PyBytes_Check(value)) { + *(char **)ptr = PyBytes_AsString(value); Py_INCREF(value); return value; } else if (PyUnicode_Check(value)) { @@ -1410,13 +1410,7 @@ Z_set(void *ptr, PyObject *value, Py_ssize_t size) Py_INCREF(value); return value; } - if (PyString_Check(value)) { - value = PyUnicode_FromEncodedObject(value, - conversion_mode_encoding, - conversion_mode_errors); - if (!value) - return NULL; - } else if (PyInt_Check(value) || PyLong_Check(value)) { + if (PyInt_Check(value) || PyLong_Check(value)) { #if SIZEOF_VOID_P == SIZEOF_LONG_LONG *(wchar_t **)ptr = (wchar_t *)PyInt_AsUnsignedLongLongMask(value); #else @@ -1424,6 +1418,13 @@ Z_set(void *ptr, PyObject *value, Py_ssize_t size) #endif Py_INCREF(Py_None); return Py_None; + } + if (PyBytes_Check(value)) { + value = PyUnicode_FromEncodedObject(value, + conversion_mode_encoding, + conversion_mode_errors); + if (!value) + return NULL; } else if (!PyUnicode_Check(value)) { PyErr_Format(PyExc_TypeError, "unicode string or integer address expected instead of %s instance", |