summaryrefslogtreecommitdiff
path: root/Modules
diff options
context:
space:
mode:
authorLarry Hastings <larry@hastings.org>2015-02-26 05:58:48 -0800
committerLarry Hastings <larry@hastings.org>2015-02-26 05:58:48 -0800
commit8c3ec536e924002dc3afe4ff92e32fe9ed82ebab (patch)
treef141eec287584ba9d58d32461e1a7d92b5466e91 /Modules
parente287746401398ee81c8e8a1513a5fe828eb32559 (diff)
parent7b2c3c6840052ea6f8b41253faf38b9e24f9a453 (diff)
downloadcpython-git-8c3ec536e924002dc3afe4ff92e32fe9ed82ebab.tar.gz
Merge 3.4.3 release engineering changes back into 3.4.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_ctypes/_ctypes.c9
-rw-r--r--Modules/_ctypes/stgdict.c12
-rw-r--r--Modules/_io/fileio.c21
-rw-r--r--Modules/_localemodule.c2
-rw-r--r--Modules/_ssl.c7
-rw-r--r--Modules/_testbuffer.c2
-rw-r--r--Modules/_testcapimodule.c2
-rw-r--r--Modules/_tkinter.c2
-rw-r--r--Modules/_winapi.c14
-rw-r--r--Modules/binascii.c4
-rw-r--r--Modules/cjkcodecs/multibytecodec.c19
-rw-r--r--Modules/faulthandler.c9
-rw-r--r--Modules/getpath.c2
-rw-r--r--Modules/posixmodule.c18
-rw-r--r--Modules/pyexpat.c4
-rw-r--r--Modules/socketmodule.c6
-rw-r--r--Modules/unicodedata.c4
-rw-r--r--Modules/zipimport.c2
18 files changed, 85 insertions, 54 deletions
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index c2889d2ec3..14ec4ce60c 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -4305,8 +4305,11 @@ Array_subscript(PyObject *myself, PyObject *item)
slicelen);
}
- dest = (wchar_t *)PyMem_Malloc(
- slicelen * sizeof(wchar_t));
+ dest = PyMem_New(wchar_t, slicelen);
+ if (dest == NULL) {
+ PyErr_NoMemory();
+ return NULL;
+ }
for (cur = start, i = 0; i < slicelen;
cur += step, i++) {
@@ -4986,7 +4989,7 @@ Pointer_subscript(PyObject *myself, PyObject *item)
return PyUnicode_FromWideChar(ptr + start,
len);
}
- dest = (wchar_t *)PyMem_Malloc(len * sizeof(wchar_t));
+ dest = PyMem_New(wchar_t, len);
if (dest == NULL)
return PyErr_NoMemory();
for (cur = start, i = 0; i < len; cur += step, i++) {
diff --git a/Modules/_ctypes/stgdict.c b/Modules/_ctypes/stgdict.c
index 728f75183f..879afb8424 100644
--- a/Modules/_ctypes/stgdict.c
+++ b/Modules/_ctypes/stgdict.c
@@ -76,14 +76,18 @@ PyCStgDict_clone(StgDictObject *dst, StgDictObject *src)
if (src->format) {
dst->format = PyMem_Malloc(strlen(src->format) + 1);
- if (dst->format == NULL)
+ if (dst->format == NULL) {
+ PyErr_NoMemory();
return -1;
+ }
strcpy(dst->format, src->format);
}
if (src->shape) {
dst->shape = PyMem_Malloc(sizeof(Py_ssize_t) * src->ndim);
- if (dst->shape == NULL)
+ if (dst->shape == NULL) {
+ PyErr_NoMemory();
return -1;
+ }
memcpy(dst->shape, src->shape,
sizeof(Py_ssize_t) * src->ndim);
}
@@ -380,7 +384,7 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
union_size = 0;
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));
+ stgdict->ffi_type_pointer.elements = PyMem_New(ffi_type *, basedict->length + len + 1);
if (stgdict->ffi_type_pointer.elements == NULL) {
PyErr_NoMemory();
return -1;
@@ -398,7 +402,7 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
union_size = 0;
total_align = 1;
stgdict->ffi_type_pointer.type = FFI_TYPE_STRUCT;
- stgdict->ffi_type_pointer.elements = PyMem_Malloc(sizeof(ffi_type *) * (len + 1));
+ stgdict->ffi_type_pointer.elements = PyMem_New(ffi_type *, len + 1);
if (stgdict->ffi_type_pointer.elements == NULL) {
PyErr_NoMemory();
return -1;
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
index a2b253bd03..80ca99c5bc 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -126,11 +126,18 @@ internal_close(fileio *self)
static PyObject *
fileio_close(fileio *self)
{
+ PyObject *res;
+ PyObject *exc, *val, *tb;
+ int rc;
_Py_IDENTIFIER(close);
+ res = _PyObject_CallMethodId((PyObject*)&PyRawIOBase_Type,
+ &PyId_close, "O", self);
if (!self->closefd) {
self->fd = -1;
- Py_RETURN_NONE;
+ return res;
}
+ if (res == NULL)
+ PyErr_Fetch(&exc, &val, &tb);
if (self->finalizing) {
PyObject *r = fileio_dealloc_warn(self, (PyObject *) self);
if (r)
@@ -138,12 +145,12 @@ fileio_close(fileio *self)
else
PyErr_Clear();
}
- errno = internal_close(self);
- if (errno < 0)
- return NULL;
-
- return _PyObject_CallMethodId((PyObject*)&PyRawIOBase_Type,
- &PyId_close, "O", self);
+ rc = internal_close(self);
+ if (res == NULL)
+ _PyErr_ChainExceptions(exc, val, tb);
+ if (rc < 0)
+ Py_CLEAR(res);
+ return res;
}
static PyObject *
diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c
index 400c3448ba..b1d6add477 100644
--- a/Modules/_localemodule.c
+++ b/Modules/_localemodule.c
@@ -254,7 +254,7 @@ PyLocale_strxfrm(PyObject* self, PyObject* args)
/* assume no change in size, first */
n1 = n1 + 1;
- buf = PyMem_Malloc(n1 * sizeof(wchar_t));
+ buf = PyMem_New(wchar_t, n1);
if (!buf) {
PyErr_NoMemory();
goto exit;
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
index 914d5aa6fa..9539710602 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -3838,10 +3838,11 @@ static int _setup_ssl_threads(void) {
if (_ssl_locks == NULL) {
_ssl_locks_count = CRYPTO_num_locks();
- _ssl_locks = (PyThread_type_lock *)
- PyMem_Malloc(sizeof(PyThread_type_lock) * _ssl_locks_count);
- if (_ssl_locks == NULL)
+ _ssl_locks = PyMem_New(PyThread_type_lock, _ssl_locks_count);
+ if (_ssl_locks == NULL) {
+ PyErr_NoMemory();
return 0;
+ }
memset(_ssl_locks, 0,
sizeof(PyThread_type_lock) * _ssl_locks_count);
for (i = 0; i < _ssl_locks_count; i++) {
diff --git a/Modules/_testbuffer.c b/Modules/_testbuffer.c
index 0c6ef16f17..176df7c5ba 100644
--- a/Modules/_testbuffer.c
+++ b/Modules/_testbuffer.c
@@ -850,7 +850,7 @@ seq_as_ssize_array(PyObject *seq, Py_ssize_t len, int is_shape)
Py_ssize_t *dest;
Py_ssize_t x, i;
- dest = PyMem_Malloc(len * (sizeof *dest));
+ dest = PyMem_New(Py_ssize_t, len);
if (dest == NULL) {
PyErr_NoMemory();
return NULL;
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 625409e56f..cf4b0e14f0 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -1516,7 +1516,7 @@ unicode_aswidechar(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "Un", &unicode, &buflen))
return NULL;
- buffer = PyMem_Malloc(buflen * sizeof(wchar_t));
+ buffer = PyMem_New(wchar_t, buflen);
if (buffer == NULL)
return PyErr_NoMemory();
diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c
index 6d777d3f77..f5bade03cb 100644
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -34,7 +34,7 @@ Copyright (C) 1994 Steen Lumholt.
#endif
#define CHECK_SIZE(size, elemsize) \
- ((size_t)(size) <= Py_MAX((size_t)INT_MAX, UINT_MAX / (size_t)(elemsize)))
+ ((size_t)(size) <= Py_MIN((size_t)INT_MAX, UINT_MAX / (size_t)(elemsize)))
/* Starting with Tcl 8.4, many APIs offer const-correctness. Unfortunately,
making _tkinter correct for this API means to break earlier
diff --git a/Modules/_winapi.c b/Modules/_winapi.c
index b755178427..d472c9ee53 100644
--- a/Modules/_winapi.c
+++ b/Modules/_winapi.c
@@ -535,13 +535,23 @@ getenvironment(PyObject* environment)
"environment can only contain strings");
goto error;
}
+ if (totalsize > PY_SSIZE_T_MAX - PyUnicode_GET_LENGTH(key) - 1) {
+ PyErr_SetString(PyExc_OverflowError, "environment too long");
+ goto error;
+ }
totalsize += PyUnicode_GET_LENGTH(key) + 1; /* +1 for '=' */
+ if (totalsize > PY_SSIZE_T_MAX - PyUnicode_GET_LENGTH(value) - 1) {
+ PyErr_SetString(PyExc_OverflowError, "environment too long");
+ goto error;
+ }
totalsize += PyUnicode_GET_LENGTH(value) + 1; /* +1 for '\0' */
}
- buffer = PyMem_Malloc(totalsize * sizeof(Py_UCS4));
- if (! buffer)
+ buffer = PyMem_NEW(Py_UCS4, totalsize);
+ if (! buffer) {
+ PyErr_NoMemory();
goto error;
+ }
p = buffer;
end = buffer + totalsize;
diff --git a/Modules/binascii.c b/Modules/binascii.c
index 86b63bb4f5..4e6953b8ba 100644
--- a/Modules/binascii.c
+++ b/Modules/binascii.c
@@ -228,13 +228,13 @@ ascii_buffer_converter(PyObject *arg, Py_buffer *buf)
if (PyObject_GetBuffer(arg, buf, PyBUF_SIMPLE) != 0) {
PyErr_Format(PyExc_TypeError,
"argument should be bytes, buffer or ASCII string, "
- "not %R", Py_TYPE(arg));
+ "not '%.100s'", Py_TYPE(arg)->tp_name);
return 0;
}
if (!PyBuffer_IsContiguous(buf, 'C')) {
PyErr_Format(PyExc_TypeError,
"argument should be a contiguous buffer, "
- "not %R", Py_TYPE(arg));
+ "not '%.100s'", Py_TYPE(arg)->tp_name);
PyBuffer_Release(buf);
return 0;
}
diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c
index 087ae9b1af..435529fb0e 100644
--- a/Modules/cjkcodecs/multibytecodec.c
+++ b/Modules/cjkcodecs/multibytecodec.c
@@ -182,8 +182,10 @@ expand_encodebuffer(MultibyteEncodeBuffer *buf, Py_ssize_t esize)
orgsize = PyBytes_GET_SIZE(buf->outobj);
incsize = (esize < (orgsize >> 1) ? (orgsize >> 1) | 1 : esize);
- if (orgsize > PY_SSIZE_T_MAX - incsize)
+ if (orgsize > PY_SSIZE_T_MAX - incsize) {
+ PyErr_NoMemory();
return -1;
+ }
if (_PyBytes_Resize(&buf->outobj, orgsize + incsize) == -1)
return -1;
@@ -194,11 +196,11 @@ expand_encodebuffer(MultibyteEncodeBuffer *buf, Py_ssize_t esize)
return 0;
}
-#define REQUIRE_ENCODEBUFFER(buf, s) { \
- if ((s) < 1 || (buf)->outbuf + (s) > (buf)->outbuf_end) \
+#define REQUIRE_ENCODEBUFFER(buf, s) do { \
+ if ((s) < 0 || (s) > (buf)->outbuf_end - (buf)->outbuf) \
if (expand_encodebuffer(buf, s) == -1) \
goto errorexit; \
-}
+} while(0)
/**
@@ -332,10 +334,11 @@ multibytecodec_encerror(MultibyteCodec *codec,
assert(PyBytes_Check(retstr));
retstrsize = PyBytes_GET_SIZE(retstr);
- REQUIRE_ENCODEBUFFER(buf, retstrsize);
-
- memcpy(buf->outbuf, PyBytes_AS_STRING(retstr), retstrsize);
- buf->outbuf += retstrsize;
+ if (retstrsize > 0) {
+ REQUIRE_ENCODEBUFFER(buf, retstrsize);
+ memcpy(buf->outbuf, PyBytes_AS_STRING(retstr), retstrsize);
+ buf->outbuf += retstrsize;
+ }
newpos = PyLong_AsSsize_t(PyTuple_GET_ITEM(retobj, 1));
if (newpos < 0 && !PyErr_Occurred())
diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c
index c17ffd8aca..01e7beb255 100644
--- a/Modules/faulthandler.c
+++ b/Modules/faulthandler.c
@@ -911,12 +911,12 @@ faulthandler_fatal_error_py(PyObject *self, PyObject *args)
}
#if defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGACTION)
-static void*
-stack_overflow(void *min_sp, void *max_sp, size_t *depth)
+static Py_uintptr_t
+stack_overflow(Py_uintptr_t min_sp, Py_uintptr_t max_sp, size_t *depth)
{
/* allocate 4096 bytes on the stack at each call */
unsigned char buffer[4096];
- void *sp = &buffer;
+ Py_uintptr_t sp = (Py_uintptr_t)&buffer;
*depth += 1;
if (sp < min_sp || max_sp < sp)
return sp;
@@ -929,7 +929,8 @@ static PyObject *
faulthandler_stack_overflow(PyObject *self)
{
size_t depth, size;
- char *sp = (char *)&depth, *stop;
+ Py_uintptr_t sp = (Py_uintptr_t)&depth;
+ Py_uintptr_t stop;
depth = 0;
stop = stack_overflow(sp - STACK_OVERFLOW_MAX_SIZE,
diff --git a/Modules/getpath.c b/Modules/getpath.c
index c057737ec2..13e3817260 100644
--- a/Modules/getpath.c
+++ b/Modules/getpath.c
@@ -735,7 +735,7 @@ calculate_path(void)
bufsz += wcslen(zip_path) + 1;
bufsz += wcslen(exec_prefix) + 1;
- buf = (wchar_t *)PyMem_Malloc(bufsz * sizeof(wchar_t));
+ buf = PyMem_New(wchar_t, bufsz);
if (buf == NULL) {
Py_FatalError(
"Not enough memory for dynamic PYTHONPATH");
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 628dec29d7..d45f59e5f1 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -1638,7 +1638,7 @@ get_target_path(HANDLE hdl, wchar_t **target_path)
if(!buf_size)
return FALSE;
- buf = (wchar_t *)PyMem_Malloc((buf_size+1)*sizeof(wchar_t));
+ buf = PyMem_New(wchar_t, buf_size+1);
if (!buf) {
SetLastError(ERROR_OUTOFMEMORY);
return FALSE;
@@ -3627,7 +3627,7 @@ _listdir_windows_no_opendir(path_t *path, PyObject *list)
len = wcslen(path->wide);
}
/* The +5 is so we can append "\\*.*\0" */
- wnamebuf = PyMem_Malloc((len + 5) * sizeof(wchar_t));
+ wnamebuf = PyMem_New(wchar_t, len + 5);
if (!wnamebuf) {
PyErr_NoMemory();
goto exit;
@@ -3917,7 +3917,7 @@ posix__getfullpathname(PyObject *self, PyObject *args)
Py_ARRAY_LENGTH(woutbuf),
woutbuf, &wtemp);
if (result > Py_ARRAY_LENGTH(woutbuf)) {
- woutbufp = PyMem_Malloc(result * sizeof(wchar_t));
+ woutbufp = PyMem_New(wchar_t, result);
if (!woutbufp)
return PyErr_NoMemory();
result = GetFullPathNameW(wpath, result, woutbufp, &wtemp);
@@ -3997,7 +3997,7 @@ posix__getfinalpathname(PyObject *self, PyObject *args)
if(!buf_size)
return win32_error_object("GetFinalPathNameByHandle", po);
- target_path = (wchar_t *)PyMem_Malloc((buf_size+1)*sizeof(wchar_t));
+ target_path = PyMem_New(wchar_t, buf_size+1);
if(!target_path)
return PyErr_NoMemory();
@@ -4082,7 +4082,7 @@ posix__getvolumepathname(PyObject *self, PyObject *args)
return NULL;
}
- mountpath = (wchar_t *)PyMem_Malloc(buflen * sizeof(wchar_t));
+ mountpath = PyMem_New(wchar_t, buflen);
if (mountpath == NULL)
return PyErr_NoMemory();
@@ -6213,9 +6213,9 @@ posix_getgrouplist(PyObject *self, PyObject *args)
#endif
#ifdef __APPLE__
- groups = PyMem_Malloc(ngroups * sizeof(int));
+ groups = PyMem_New(int, ngroups);
#else
- groups = PyMem_Malloc(ngroups * sizeof(gid_t));
+ groups = PyMem_New(gid_t, ngroups);
#endif
if (groups == NULL)
return PyErr_NoMemory();
@@ -6293,7 +6293,7 @@ posix_getgroups(PyObject *self, PyObject *noargs)
/* groups will fit in existing array */
alt_grouplist = grouplist;
} else {
- alt_grouplist = PyMem_Malloc(n * sizeof(gid_t));
+ alt_grouplist = PyMem_New(gid_t, n);
if (alt_grouplist == NULL) {
errno = EINVAL;
return posix_error();
@@ -6319,7 +6319,7 @@ posix_getgroups(PyObject *self, PyObject *noargs)
/* Avoid malloc(0) */
alt_grouplist = grouplist;
} else {
- alt_grouplist = PyMem_Malloc(n * sizeof(gid_t));
+ alt_grouplist = PyMem_New(gid_t, n);
if (alt_grouplist == NULL) {
errno = EINVAL;
return posix_error();
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c
index 4ced53b611..19be0c7cc5 100644
--- a/Modules/pyexpat.c
+++ b/Modules/pyexpat.c
@@ -928,7 +928,7 @@ xmlparse_ExternalEntityParserCreate(xmlparseobject *self, PyObject *args)
for (i = 0; handler_info[i].name != NULL; i++)
/* do nothing */;
- new_parser->handlers = PyMem_Malloc(sizeof(PyObject *) * i);
+ new_parser->handlers = PyMem_New(PyObject *, i);
if (!new_parser->handlers) {
Py_DECREF(new_parser);
return PyErr_NoMemory();
@@ -1121,7 +1121,7 @@ newxmlparseobject(char *encoding, char *namespace_separator, PyObject *intern)
for (i = 0; handler_info[i].name != NULL; i++)
/* do nothing */;
- self->handlers = PyMem_Malloc(sizeof(PyObject *) * i);
+ self->handlers = PyMem_New(PyObject *, i);
if (!self->handlers) {
Py_DECREF(self);
return PyErr_NoMemory();
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index cb44d05b62..e9feba378e 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -4126,9 +4126,11 @@ socket_gethostname(PyObject *self, PyObject *unused)
/* MSDN says ERROR_MORE_DATA may occur because DNS allows longer
names */
- name = PyMem_Malloc(size * sizeof(wchar_t));
- if (!name)
+ name = PyMem_New(wchar_t, size);
+ if (!name) {
+ PyErr_NoMemory();
return NULL;
+ }
if (!GetComputerNameExW(ComputerNamePhysicalDnsHostname,
name,
&size))
diff --git a/Modules/unicodedata.c b/Modules/unicodedata.c
index ec70e7af9d..47d2937b81 100644
--- a/Modules/unicodedata.c
+++ b/Modules/unicodedata.c
@@ -556,7 +556,7 @@ nfd_nfkd(PyObject *self, PyObject *input, int k)
/* Overallocate at most 10 characters. */
space = (isize > 10 ? 10 : isize) + isize;
osize = space;
- output = PyMem_Malloc(space * sizeof(Py_UCS4));
+ output = PyMem_New(Py_UCS4, space);
if (!output) {
PyErr_NoMemory();
return NULL;
@@ -703,7 +703,7 @@ nfc_nfkc(PyObject *self, PyObject *input, int k)
/* We allocate a buffer for the output.
If we find that we made no changes, we still return
the NFD result. */
- output = PyMem_Malloc(len * sizeof(Py_UCS4));
+ output = PyMem_New(Py_UCS4, len);
if (!output) {
PyErr_NoMemory();
Py_DECREF(result);
diff --git a/Modules/zipimport.c b/Modules/zipimport.c
index 8fe919539f..f2cc245b7d 100644
--- a/Modules/zipimport.c
+++ b/Modules/zipimport.c
@@ -233,7 +233,7 @@ make_filename(PyObject *prefix, PyObject *name)
Py_ssize_t len;
len = PyUnicode_GET_LENGTH(prefix) + PyUnicode_GET_LENGTH(name) + 1;
- p = buf = PyMem_Malloc(sizeof(Py_UCS4) * len);
+ p = buf = PyMem_New(Py_UCS4, len);
if (buf == NULL) {
PyErr_NoMemory();
return NULL;