diff options
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_ctypes/callbacks.c | 23 | ||||
-rw-r--r-- | Modules/_ctypes/callproc.c | 30 | ||||
-rw-r--r-- | Modules/_ctypes/cfield.c | 16 | ||||
-rw-r--r-- | Modules/_ctypes/ctypes.h | 6 | ||||
-rw-r--r-- | Modules/_ctypes/libffi_msvc/ffitarget.h | 4 | ||||
-rw-r--r-- | Modules/_ctypes/stgdict.c | 12 | ||||
-rw-r--r-- | Modules/datetimemodule.c | 2 | ||||
-rw-r--r-- | Modules/getbuildinfo.c | 11 | ||||
-rw-r--r-- | Modules/itertoolsmodule.c | 4 | ||||
-rw-r--r-- | Modules/posixmodule.c | 3 |
10 files changed, 79 insertions, 32 deletions
diff --git a/Modules/_ctypes/callbacks.c b/Modules/_ctypes/callbacks.c index 89b44aa0d9..cbcf2b8cdd 100644 --- a/Modules/_ctypes/callbacks.c +++ b/Modules/_ctypes/callbacks.c @@ -384,8 +384,27 @@ long Call_GetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv) return E_FAIL; } - result = PyObject_CallFunction(func, - "iii", rclsid, riid, ppv); + { + PyObject *py_rclsid = PyLong_FromVoidPtr(rclsid); + PyObject *py_riid = PyLong_FromVoidPtr(riid); + PyObject *py_ppv = PyLong_FromVoidPtr(ppv); + if (!py_rclsid || !py_riid || !py_ppv) { + Py_XDECREF(py_rclsid); + Py_XDECREF(py_riid); + Py_XDECREF(py_ppv); + Py_DECREF(func); + PyErr_WriteUnraisable(context ? context : Py_None); + return E_FAIL; + } + result = PyObject_CallFunctionObjArgs(func, + py_rclsid, + py_riid, + py_ppv, + NULL); + Py_DECREF(py_rclsid); + Py_DECREF(py_riid); + Py_DECREF(py_ppv); + } Py_DECREF(func); if (!result) { PyErr_WriteUnraisable(context ? context : Py_None); diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c index fb70963c88..94cd6f7861 100644 --- a/Modules/_ctypes/callproc.c +++ b/Modules/_ctypes/callproc.c @@ -533,8 +533,10 @@ static int ConvParam(PyObject *obj, int index, struct argument *pa) size += 1; /* terminating NUL */ size *= sizeof(wchar_t); pa->value.p = PyMem_Malloc(size); - if (!pa->value.p) + if (!pa->value.p) { + PyErr_NoMemory(); return -1; + } memset(pa->value.p, 0, size); pa->keep = PyCObject_FromVoidPtr(pa->value.p, PyMem_Free); if (!pa->keep) { @@ -1120,10 +1122,10 @@ static char free_library_doc[] = Free the handle of an executable previously loaded by LoadLibrary.\n"; static PyObject *free_library(PyObject *self, PyObject *args) { - HMODULE hMod; - if (!PyArg_ParseTuple(args, "i:FreeLibrary", &hMod)) + void *hMod; + if (!PyArg_ParseTuple(args, PY_VOID_P_CODE ":FreeLibrary", &hMod)) return NULL; - if (!FreeLibrary(hMod)) + if (!FreeLibrary((HMODULE)hMod)) return PyErr_SetFromWindowsErr(GetLastError()); Py_INCREF(Py_None); return Py_None; @@ -1242,11 +1244,11 @@ static PyObject *py_dl_open(PyObject *self, PyObject *args) static PyObject *py_dl_close(PyObject *self, PyObject *args) { - int handle; + void *handle; - if (!PyArg_ParseTuple(args, "i:dlclose", &handle)) + if (!PyArg_ParseTuple(args, PY_VOID_P_CODE ":dlclose", &handle)) return NULL; - if (dlclose((void*)handle)) { + if (dlclose(handle)) { PyErr_SetString(PyExc_OSError, ctypes_dlerror()); return NULL; @@ -1258,10 +1260,10 @@ static PyObject *py_dl_close(PyObject *self, PyObject *args) static PyObject *py_dl_sym(PyObject *self, PyObject *args) { char *name; - int handle; + void *handle; void *ptr; - if (!PyArg_ParseTuple(args, "is:dlsym", &handle, &name)) + if (!PyArg_ParseTuple(args, PY_VOID_P_CODE "s:dlsym", &handle, &name)) return NULL; ptr = ctypes_dlsym((void*)handle, name); if (!ptr) { @@ -1269,7 +1271,7 @@ static PyObject *py_dl_sym(PyObject *self, PyObject *args) ctypes_dlerror()); return NULL; } - return Py_BuildValue("i", ptr); + return PyLong_FromVoidPtr(ptr); } #endif @@ -1281,12 +1283,12 @@ static PyObject *py_dl_sym(PyObject *self, PyObject *args) static PyObject * call_function(PyObject *self, PyObject *args) { - int func; + void *func; PyObject *arguments; PyObject *result; if (!PyArg_ParseTuple(args, - "iO!", + PY_VOID_P_CODE "O!", &func, &PyTuple_Type, &arguments)) return NULL; @@ -1312,12 +1314,12 @@ call_function(PyObject *self, PyObject *args) static PyObject * call_cdeclfunction(PyObject *self, PyObject *args) { - int func; + void *func; PyObject *arguments; PyObject *result; if (!PyArg_ParseTuple(args, - "iO!", + PY_VOID_P_CODE "O!", &func, &PyTuple_Type, &arguments)) return NULL; diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c index 9b9088259b..6b0a526aca 100644 --- a/Modules/_ctypes/cfield.c +++ b/Modules/_ctypes/cfield.c @@ -1366,7 +1366,7 @@ z_get(void *ptr, unsigned size) if (IsBadStringPtrA(*(char **)ptr, -1)) { PyErr_Format(PyExc_ValueError, "invalid string pointer %p", - ptr); + *(char **)ptr); return NULL; } #endif @@ -1426,7 +1426,7 @@ Z_set(void *ptr, PyObject *value, unsigned size) size *= sizeof(wchar_t); buffer = (wchar_t *)PyMem_Malloc(size); if (!buffer) - return NULL; + return PyErr_NoMemory(); memset(buffer, 0, size); keep = PyCObject_FromVoidPtr(buffer, PyMem_Free); if (!keep) { @@ -1451,9 +1451,17 @@ Z_get(void *ptr, unsigned size) { wchar_t *p; p = *(wchar_t **)ptr; - if (p) + if (p) { +#if defined(MS_WIN32) && !defined(_WIN32_WCE) + if (IsBadStringPtrW(*(wchar_t **)ptr, -1)) { + PyErr_Format(PyExc_ValueError, + "invalid string pointer %p", + *(wchar_t **)ptr); + return NULL; + } +#endif return PyUnicode_FromWideChar(p, wcslen(p)); - else { + } else { Py_INCREF(Py_None); return Py_None; } diff --git a/Modules/_ctypes/ctypes.h b/Modules/_ctypes/ctypes.h index 0af7851020..5fb603075d 100644 --- a/Modules/_ctypes/ctypes.h +++ b/Modules/_ctypes/ctypes.h @@ -23,6 +23,12 @@ typedef int Py_ssize_t; #define PY_LONG_LONG LONG_LONG #endif +#if SIZEOF_VOID_P == SIZEOF_LONG +#define PY_VOID_P_CODE "k" +#elif defined(HAVE_LONG_LONG) && (SIZEOF_VOID_P == SIZEOF_LONG_LONG) +#define PY_VOID_P_CODE "K" +#endif + typedef struct tagPyCArgObject PyCArgObject; typedef struct tagCDataObject CDataObject; typedef PyObject *(* GETFUNC)(void *, unsigned size); diff --git a/Modules/_ctypes/libffi_msvc/ffitarget.h b/Modules/_ctypes/libffi_msvc/ffitarget.h index 0da79d4c1a..85f5ee81bb 100644 --- a/Modules/_ctypes/libffi_msvc/ffitarget.h +++ b/Modules/_ctypes/libffi_msvc/ffitarget.h @@ -36,7 +36,11 @@ /* ---- Generic type definitions ----------------------------------------- */ #ifndef LIBFFI_ASM +#ifndef _WIN64 typedef unsigned long ffi_arg; +#else +typedef unsigned __int64 ffi_arg; +#endif typedef signed long ffi_sarg; typedef enum ffi_abi { diff --git a/Modules/_ctypes/stgdict.c b/Modules/_ctypes/stgdict.c index c34ae01b96..4241d3cc4c 100644 --- a/Modules/_ctypes/stgdict.c +++ b/Modules/_ctypes/stgdict.c @@ -72,8 +72,10 @@ StgDict_clone(StgDictObject *dst, StgDictObject *src) return 0; size = sizeof(ffi_type *) * (src->length + 1); dst->ffi_type_pointer.elements = PyMem_Malloc(size); - if (dst->ffi_type_pointer.elements == NULL) + if (dst->ffi_type_pointer.elements == NULL) { + PyErr_NoMemory(); return -1; + } memcpy(dst->ffi_type_pointer.elements, src->ffi_type_pointer.elements, size); @@ -355,6 +357,10 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct) total_align = align ? align : 1; stgdict->ffi_type_pointer.type = FFI_TYPE_STRUCT; stgdict->ffi_type_pointer.elements = PyMem_Malloc(sizeof(ffi_type *) * (basedict->length + len + 1)); + if (stgdict->ffi_type_pointer.elements == NULL) { + PyErr_NoMemory(); + return -1; + } memset(stgdict->ffi_type_pointer.elements, 0, sizeof(ffi_type *) * (basedict->length + len + 1)); memcpy(stgdict->ffi_type_pointer.elements, @@ -369,6 +375,10 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct) total_align = 1; stgdict->ffi_type_pointer.type = FFI_TYPE_STRUCT; stgdict->ffi_type_pointer.elements = PyMem_Malloc(sizeof(ffi_type *) * (len + 1)); + if (stgdict->ffi_type_pointer.elements == NULL) { + PyErr_NoMemory(); + return -1; + } memset(stgdict->ffi_type_pointer.elements, 0, sizeof(ffi_type *) * (len + 1)); ffi_ofs = 0; diff --git a/Modules/datetimemodule.c b/Modules/datetimemodule.c index 9872685fdc..c31d8e6458 100644 --- a/Modules/datetimemodule.c +++ b/Modules/datetimemodule.c @@ -13,7 +13,9 @@ /* Differentiate between building the core module and building extension * modules. */ +#ifndef Py_BUILD_CORE #define Py_BUILD_CORE +#endif #include "datetime.h" #undef Py_BUILD_CORE diff --git a/Modules/getbuildinfo.c b/Modules/getbuildinfo.c index a017dab062..0f71ca03d0 100644 --- a/Modules/getbuildinfo.c +++ b/Modules/getbuildinfo.c @@ -20,10 +20,7 @@ #endif #endif -#ifdef SUBWCREV #define SVNVERSION "$WCRANGE$$WCMODS?M:$" -#endif - const char * Py_GetBuildInfo(void) { @@ -40,9 +37,9 @@ Py_GetBuildInfo(void) const char * _Py_svnversion(void) { -#ifdef SVNVERSION - return SVNVERSION; -#else + /* the following string can be modified by subwcrev.exe */ + static const char svnversion[] = SVNVERSION; + if (!strstr(svnversion, "$")) + return svnversion; /* it was interpolated */ return "exported"; -#endif } diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c index 1b8f51c5ac..eb73f07f36 100644 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -2073,9 +2073,9 @@ count_new(PyTypeObject *type, PyObject *args, PyObject *kwds) static PyObject * count_next(countobject *lz) { - if (lz->cnt == LONG_MAX) { + if (lz->cnt == PY_SSIZE_T_MAX) { PyErr_SetString(PyExc_OverflowError, - "cannot count beyond LONG_MAX"); + "cannot count beyond PY_SSIZE_T_MAX"); return NULL; } return PyInt_FromSsize_t(lz->cnt++); diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 425fa5a118..1900656ff3 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -259,7 +259,6 @@ extern int lstat(const char *, struct stat *); #include <process.h> #endif #include "osdefs.h" -#define _WIN32_WINNT 0x0400 /* Needed for CryptoAPI on some systems */ #include <windows.h> #include <shellapi.h> /* for ShellExecute() */ #define popen _popen @@ -6272,8 +6271,8 @@ posix_fdopen(PyObject *self, PyObject *args) #else fp = fdopen(fd, mode); #endif - PyMem_FREE(mode); Py_END_ALLOW_THREADS + PyMem_FREE(mode); if (fp == NULL) return posix_error(); f = PyFile_FromFile(fp, "<fdopen>", orgmode, fclose); |