diff --git a/Misc/NEWS.d/next/Build/2020-11-12-13-45-15.bpo-38823.C0z_Fe.rst b/Misc/NEWS.d/next/Build/2020-11-12-13-45-15.bpo-38823.C0z_Fe.rst new file mode 100644 index 00000000000..4a0f11de5e4 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2020-11-12-13-45-15.bpo-38823.C0z_Fe.rst @@ -0,0 +1,3 @@ +It is no longer possible to build the ``_ctypes`` extension module without +:c:type:`wchar_t` type: remove ``CTYPES_UNICODE`` macro. Anyway, the +:c:type:`wchar_t` type is required to build Python. Patch by Victor Stinner. diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c index 29907088110..8bb34877c53 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 13b2fb0da57..9b629877a8a 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 98939290fb9..5bd96f1eb8c 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 3f20031d671..61100279808 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 443951a6b03..747339dee35 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 */