diff options
Diffstat (limited to 'Modules/_ctypes/_ctypes.c')
-rw-r--r-- | Modules/_ctypes/_ctypes.c | 48 |
1 files changed, 20 insertions, 28 deletions
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c index b32a0ce9e8..df3aedec6e 100644 --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -111,12 +111,6 @@ bytes(cdata) #ifndef IS_INTRESOURCE #define IS_INTRESOURCE(x) (((size_t)(x) >> 16) == 0) #endif -# ifdef _WIN32_WCE -/* Unlike desktop Windows, WinCE has both W and A variants of - GetProcAddress, but the default W version is not what we want */ -# undef GetProcAddress -# define GetProcAddress GetProcAddressA -# endif #else #include "ctypes_dlfcn.h" #endif @@ -435,7 +429,7 @@ UnionType_new(PyTypeObject *type, PyObject *args, PyObject *kwds) return StructUnionType_new(type, args, kwds, 0); } -static char from_address_doc[] = +static const char from_address_doc[] = "C.from_address(integer) -> C instance\naccess a C instance at the specified address"; static PyObject * @@ -453,7 +447,7 @@ CDataType_from_address(PyObject *type, PyObject *value) return PyCData_AtAddress(type, buf); } -static char from_buffer_doc[] = +static const char from_buffer_doc[] = "C.from_buffer(object, offset=0) -> C instance\ncreate a C instance from a writeable buffer"; static int @@ -527,7 +521,7 @@ CDataType_from_buffer(PyObject *type, PyObject *args) return result; } -static char from_buffer_copy_doc[] = +static const char from_buffer_copy_doc[] = "C.from_buffer_copy(object, offset=0) -> C instance\ncreate a C instance from a readable buffer"; static PyObject * @@ -572,7 +566,7 @@ CDataType_from_buffer_copy(PyObject *type, PyObject *args) return result; } -static char in_dll_doc[] = +static const char in_dll_doc[] = "C.in_dll(dll, name) -> C instance\naccess a C instance in a dll"; static PyObject * @@ -629,7 +623,7 @@ CDataType_in_dll(PyObject *type, PyObject *args) return PyCData_AtAddress(type, address); } -static char from_param_doc[] = +static const char from_param_doc[] = "Convert a Python object into a function call parameter."; static PyObject * @@ -1494,7 +1488,7 @@ _type_ attribute. */ -static char *SIMPLE_TYPE_CHARS = "cbBhHiIlLdfuzZqQPXOv?g"; +static const char SIMPLE_TYPE_CHARS[] = "cbBhHiIlLdfuzZqQPXOv?g"; static PyObject * c_wchar_p_from_param(PyObject *type, PyObject *value) @@ -1735,7 +1729,7 @@ c_void_p_from_param(PyObject *type, PyObject *value) if (stgd && CDataObject_Check(value) && stgd->proto && PyUnicode_Check(stgd->proto)) { PyCArgObject *parg; - switch (_PyUnicode_AsString(stgd->proto)[0]) { + switch (PyUnicode_AsUTF8(stgd->proto)[0]) { case 'z': /* c_char_p */ case 'Z': /* c_wchar_p */ parg = PyCArgObject_new(); @@ -1847,7 +1841,7 @@ PyCSimpleType_paramfunc(CDataObject *self) dict = PyObject_stgdict((PyObject *)self); assert(dict); /* Cannot be NULL for CDataObject instances */ - fmt = _PyUnicode_AsString(dict->proto); + fmt = PyUnicode_AsUTF8(dict->proto); assert(fmt); fd = _ctypes_get_fielddesc(fmt); @@ -2071,7 +2065,7 @@ PyCSimpleType_from_param(PyObject *type, PyObject *value) assert(dict); /* I think we can rely on this being a one-character string */ - fmt = _PyUnicode_AsString(dict->proto); + fmt = PyUnicode_AsUTF8(dict->proto); assert(fmt); fd = _ctypes_get_fielddesc(fmt); @@ -2419,7 +2413,7 @@ unique_key(CDataObject *target, Py_ssize_t index) char *cp = string; size_t bytes_left; - assert(sizeof(string) - 1 > sizeof(Py_ssize_t) * 2); + Py_BUILD_ASSERT(sizeof(string) - 1 > sizeof(Py_ssize_t) * 2); cp += sprintf(cp, "%x", Py_SAFE_DOWNCAST(index, Py_ssize_t, int)); while (target->b_base) { bytes_left = sizeof(string) - (cp - string) - 1; @@ -3080,7 +3074,7 @@ static PyGetSetDef PyCFuncPtr_getsets[] = { }; #ifdef MS_WIN32 -static PPROC FindAddress(void *handle, char *name, PyObject *type) +static PPROC FindAddress(void *handle, const char *name, PyObject *type) { #ifdef MS_WIN64 /* win64 has no stdcall calling conv, so it should @@ -3140,7 +3134,7 @@ _check_outarg_type(PyObject *arg, Py_ssize_t index) /* simple pointer types, c_void_p, c_wchar_p, BSTR, ... */ && PyUnicode_Check(dict->proto) /* We only allow c_void_p, c_char_p and c_wchar_p as a simple output parameter type */ - && (strchr("PzZ", _PyUnicode_AsString(dict->proto)[0]))) { + && (strchr("PzZ", PyUnicode_AsUTF8(dict->proto)[0]))) { return 1; } @@ -3214,7 +3208,7 @@ _validate_paramflags(PyTypeObject *type, PyObject *paramflags) } static int -_get_name(PyObject *obj, char **pname) +_get_name(PyObject *obj, const char **pname) { #ifdef MS_WIN32 if (PyLong_Check(obj)) { @@ -3230,7 +3224,7 @@ _get_name(PyObject *obj, char **pname) return *pname ? 1 : 0; } if (PyUnicode_Check(obj)) { - *pname = _PyUnicode_AsString(obj); + *pname = PyUnicode_AsUTF8(obj); return *pname ? 1 : 0; } PyErr_SetString(PyExc_TypeError, @@ -3242,7 +3236,7 @@ _get_name(PyObject *obj, char **pname) static PyObject * PyCFuncPtr_FromDll(PyTypeObject *type, PyObject *args, PyObject *kwds) { - char *name; + const char *name; int (* address)(void); PyObject *ftuple; PyObject *dll; @@ -5132,13 +5126,12 @@ static const char module_docs[] = #ifdef MS_WIN32 -static char comerror_doc[] = "Raised when a COM method call failed."; +static const char comerror_doc[] = "Raised when a COM method call failed."; int comerror_init(PyObject *self, PyObject *args, PyObject *kwds) { PyObject *hresult, *text, *details; - PyBaseExceptionObject *bself; PyObject *a; int status; @@ -5165,9 +5158,8 @@ comerror_init(PyObject *self, PyObject *args, PyObject *kwds) if (PyObject_SetAttrString(self, "details", details) < 0) return -1; - bself = (PyBaseExceptionObject *)self; Py_INCREF(args); - Py_SETREF(bself->args, args); + Py_SETREF(((PyBaseExceptionObject *)self)->args, args); return 0; } @@ -5247,7 +5239,7 @@ cast_check_pointertype(PyObject *arg) dict = PyType_stgdict(arg); if (dict) { if (PyUnicode_Check(dict->proto) - && (strchr("sPzUZXO", _PyUnicode_AsString(dict->proto)[0]))) { + && (strchr("sPzUZXO", PyUnicode_AsUTF8(dict->proto)[0]))) { /* simple pointer types, c_void_p, c_wchar_p, BSTR, ... */ return 1; } @@ -5497,14 +5489,14 @@ PyInit__ctypes(void) #endif /* If RTLD_LOCAL is not defined (Windows!), set it to zero. */ -#ifndef RTLD_LOCAL +#if !HAVE_DECL_RTLD_LOCAL #define RTLD_LOCAL 0 #endif /* If RTLD_GLOBAL is not defined (cygwin), set it to the same value as RTLD_LOCAL. */ -#ifndef RTLD_GLOBAL +#if !HAVE_DECL_RTLD_GLOBAL #define RTLD_GLOBAL RTLD_LOCAL #endif |