diff options
author | Victor Stinner <vstinner@python.org> | 2020-11-12 14:38:13 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-12 14:38:13 (GMT) |
commit | b5cc05bbe681dbe06d5ec6d34318815d1c1ad6c5 (patch) | |
tree | 60ff911a1dd1ebcbf8a06488e1f76123b1145e6c /Modules/_ctypes | |
parent | ef75a625cdf8377d687a04948b4db9bc1917bf19 (diff) | |
download | cpython-b5cc05bbe681dbe06d5ec6d34318815d1c1ad6c5.zip cpython-b5cc05bbe681dbe06d5ec6d34318815d1c1ad6c5.tar.gz cpython-b5cc05bbe681dbe06d5ec6d34318815d1c1ad6c5.tar.bz2 |
bpo-38823: Always build _ctypes with wchar_t (GH-23248)
It is no longer possible to build the _ctypes extension module
without wchar_t type: remove CTYPES_UNICODE macro. Anyway, the
wchar_t type is required to build Python.
Diffstat (limited to 'Modules/_ctypes')
-rw-r--r-- | Modules/_ctypes/_ctypes.c | 16 | ||||
-rw-r--r-- | Modules/_ctypes/callproc.c | 2 | ||||
-rw-r--r-- | Modules/_ctypes/cfield.c | 11 | ||||
-rw-r--r-- | Modules/_ctypes/ctypes.h | 4 | ||||
-rw-r--r-- | Modules/_ctypes/stgdict.c | 2 |
5 files changed, 4 insertions, 31 deletions
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c index 2990708..8bb3487 100644 --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -1358,7 +1358,6 @@ static PyGetSetDef CharArray_getsets[] = { { NULL, NULL } }; -#ifdef CTYPES_UNICODE static PyObject * WCharArray_get_value(CDataObject *self, void *Py_UNUSED(ignored)) { @@ -1408,7 +1407,6 @@ static PyGetSetDef WCharArray_getsets[] = { "string value"}, { NULL, NULL } }; -#endif /* The next three functions copied from Python's typeobject.c. @@ -1615,11 +1613,10 @@ PyCArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds) if (itemdict->getfunc == _ctypes_get_fielddesc("c")->getfunc) { if (-1 == add_getset(result, CharArray_getsets)) goto error; -#ifdef CTYPES_UNICODE - } else if (itemdict->getfunc == _ctypes_get_fielddesc("u")->getfunc) { + } + else if (itemdict->getfunc == _ctypes_get_fielddesc("u")->getfunc) { if (-1 == add_getset(result, WCharArray_getsets)) goto error; -#endif } return (PyObject *)result; @@ -4654,7 +4651,6 @@ Array_subscript(PyObject *myself, PyObject *item) PyMem_Free(dest); return np; } -#ifdef CTYPES_UNICODE if (itemdict->getfunc == _ctypes_get_fielddesc("u")->getfunc) { wchar_t *ptr = (wchar_t *)self->b_ptr; wchar_t *dest; @@ -4681,7 +4677,6 @@ Array_subscript(PyObject *myself, PyObject *item) PyMem_Free(dest); return np; } -#endif np = PyList_New(slicelen); if (np == NULL) @@ -5350,7 +5345,6 @@ Pointer_subscript(PyObject *myself, PyObject *item) PyMem_Free(dest); return np; } -#ifdef CTYPES_UNICODE if (itemdict->getfunc == _ctypes_get_fielddesc("u")->getfunc) { wchar_t *ptr = *(wchar_t **)self->b_ptr; wchar_t *dest; @@ -5371,7 +5365,6 @@ Pointer_subscript(PyObject *myself, PyObject *item) PyMem_Free(dest); return np; } -#endif np = PyList_New(len); if (np == NULL) @@ -5653,7 +5646,7 @@ cast(void *ptr, PyObject *src, PyObject *ctype) return NULL; } -#ifdef CTYPES_UNICODE + static PyObject * wstring_at(const wchar_t *ptr, int size) { @@ -5665,7 +5658,6 @@ wstring_at(const wchar_t *ptr, int size) ssize = wcslen(ptr); return PyUnicode_FromWideChar(ptr, ssize); } -#endif static struct PyModuleDef _ctypesmodule = { @@ -5796,9 +5788,7 @@ _ctypes_add_objects(PyObject *mod) MOD_ADD("_memset_addr", PyLong_FromVoidPtr(memset)); MOD_ADD("_string_at_addr", PyLong_FromVoidPtr(string_at)); MOD_ADD("_cast_addr", PyLong_FromVoidPtr(cast)); -#ifdef CTYPES_UNICODE MOD_ADD("_wstring_at_addr", PyLong_FromVoidPtr(wstring_at)); -#endif /* If RTLD_LOCAL is not defined (Windows!), set it to zero. */ #if !HAVE_DECL_RTLD_LOCAL diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c index 13b2fb0..9b62987 100644 --- a/Modules/_ctypes/callproc.c +++ b/Modules/_ctypes/callproc.c @@ -713,7 +713,6 @@ static int ConvParam(PyObject *obj, Py_ssize_t index, struct argument *pa) return 0; } -#ifdef CTYPES_UNICODE if (PyUnicode_Check(obj)) { pa->ffi_type = &ffi_type_pointer; pa->value.p = PyUnicode_AsWideCharString(obj, NULL); @@ -726,7 +725,6 @@ static int ConvParam(PyObject *obj, Py_ssize_t index, struct argument *pa) } return 0; } -#endif { _Py_IDENTIFIER(_as_parameter_); diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c index 9893929..5bd96f1 100644 --- a/Modules/_ctypes/cfield.c +++ b/Modules/_ctypes/cfield.c @@ -125,13 +125,11 @@ PyCField_FromDesc(PyObject *desc, Py_ssize_t index, getfunc = fd->getfunc; setfunc = fd->setfunc; } -#ifdef CTYPES_UNICODE if (idict->getfunc == _ctypes_get_fielddesc("u")->getfunc) { struct fielddesc *fd = _ctypes_get_fielddesc("U"); getfunc = fd->getfunc; setfunc = fd->setfunc; } -#endif } } @@ -1137,7 +1135,6 @@ c_get(void *ptr, Py_ssize_t size) return PyBytes_FromStringAndSize((char *)ptr, 1); } -#ifdef CTYPES_UNICODE /* u - a single wchar_t character */ static PyObject * u_set(void *ptr, PyObject *value, Py_ssize_t size) @@ -1232,7 +1229,6 @@ U_set(void *ptr, PyObject *value, Py_ssize_t length) return value; } -#endif static PyObject * s_get(void *ptr, Py_ssize_t size) @@ -1321,7 +1317,6 @@ z_get(void *ptr, Py_ssize_t size) } } -#ifdef CTYPES_UNICODE static PyObject * Z_set(void *ptr, PyObject *value, Py_ssize_t size) { @@ -1373,7 +1368,7 @@ Z_get(void *ptr, Py_ssize_t size) Py_RETURN_NONE; } } -#endif + #ifdef MS_WIN32 static PyObject * @@ -1507,11 +1502,9 @@ static struct fielddesc formattable[] = { #endif { 'P', P_set, P_get, &ffi_type_pointer}, { 'z', z_set, z_get, &ffi_type_pointer}, -#ifdef CTYPES_UNICODE { 'u', u_set, u_get, NULL}, /* ffi_type set later */ { 'U', U_set, U_get, &ffi_type_pointer}, { 'Z', Z_set, Z_get, &ffi_type_pointer}, -#endif #ifdef MS_WIN32 { 'X', BSTR_set, BSTR_get, &ffi_type_pointer}, #endif @@ -1544,14 +1537,12 @@ _ctypes_get_fielddesc(const char *fmt) if (!initialized) { initialized = 1; -#ifdef CTYPES_UNICODE if (sizeof(wchar_t) == sizeof(short)) _ctypes_get_fielddesc("u")->pffi_type = &ffi_type_sshort; else if (sizeof(wchar_t) == sizeof(int)) _ctypes_get_fielddesc("u")->pffi_type = &ffi_type_sint; else if (sizeof(wchar_t) == sizeof(long)) _ctypes_get_fielddesc("u")->pffi_type = &ffi_type_slong; -#endif } for (; table->code; ++table) { diff --git a/Modules/_ctypes/ctypes.h b/Modules/_ctypes/ctypes.h index 3f20031..6110027 100644 --- a/Modules/_ctypes/ctypes.h +++ b/Modules/_ctypes/ctypes.h @@ -343,10 +343,6 @@ extern PyObject *PyExc_ArgError; extern char *_ctypes_conversion_encoding; extern char *_ctypes_conversion_errors; -#if defined(HAVE_WCHAR_H) -# define CTYPES_UNICODE -#endif - extern void _ctypes_free_closure(void *); extern void *_ctypes_alloc_closure(void); diff --git a/Modules/_ctypes/stgdict.c b/Modules/_ctypes/stgdict.c index 443951a..747339d 100644 --- a/Modules/_ctypes/stgdict.c +++ b/Modules/_ctypes/stgdict.c @@ -538,9 +538,7 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct case FFI_TYPE_SINT16: case FFI_TYPE_SINT32: if (dict->getfunc != _ctypes_get_fielddesc("c")->getfunc -#ifdef CTYPES_UNICODE && dict->getfunc != _ctypes_get_fielddesc("u")->getfunc -#endif ) break; /* else fall through */ |