diff -r 7d826a6b92a1 Modules/_ctypes/_ctypes.c --- a/Modules/_ctypes/_ctypes.c Tue Feb 10 22:37:22 2015 -0600 +++ b/Modules/_ctypes/_ctypes.c Wed Feb 11 08:46:14 2015 +0200 @@ -1352,7 +1352,7 @@ PyCArrayType_new(PyTypeObject *type, PyO if (stgdict->format == NULL) goto error; stgdict->ndim = itemdict->ndim + 1; - stgdict->shape = PyMem_Malloc(sizeof(Py_ssize_t) * stgdict->ndim); + stgdict->shape = PyMem_New(Py_ssize_t, stgdict->ndim); if (stgdict->shape == NULL) { PyErr_NoMemory(); goto error; @@ -4305,8 +4305,7 @@ Array_subscript(PyObject *myself, PyObje slicelen); } - dest = (wchar_t *)PyMem_Malloc( - slicelen * sizeof(wchar_t)); + dest = PyMem_New(wchar_t, slicelen); for (cur = start, i = 0; i < slicelen; cur += step, i++) { @@ -4986,7 +4985,7 @@ Pointer_subscript(PyObject *myself, PyOb 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 -r 7d826a6b92a1 Modules/_ctypes/stgdict.c --- a/Modules/_ctypes/stgdict.c Tue Feb 10 22:37:22 2015 -0600 +++ b/Modules/_ctypes/stgdict.c Wed Feb 11 08:46:14 2015 +0200 @@ -81,7 +81,7 @@ PyCStgDict_clone(StgDictObject *dst, Stg strcpy(dst->format, src->format); } if (src->shape) { - dst->shape = PyMem_Malloc(sizeof(Py_ssize_t) * src->ndim); + dst->shape = PyMem_New(Py_ssize_t, src->ndim); if (dst->shape == NULL) return -1; memcpy(dst->shape, src->shape, @@ -380,7 +380,7 @@ PyCStructUnionType_update_stgdict(PyObje 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 +398,7 @@ PyCStructUnionType_update_stgdict(PyObje 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 -r 7d826a6b92a1 Modules/_localemodule.c --- a/Modules/_localemodule.c Tue Feb 10 22:37:22 2015 -0600 +++ b/Modules/_localemodule.c Wed Feb 11 08:46:14 2015 +0200 @@ -254,7 +254,7 @@ PyLocale_strxfrm(PyObject* self, PyObjec /* 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 -r 7d826a6b92a1 Modules/_ssl.c --- a/Modules/_ssl.c Tue Feb 10 22:37:22 2015 -0600 +++ b/Modules/_ssl.c Wed Feb 11 08:46:14 2015 +0200 @@ -4287,8 +4287,7 @@ 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); + _ssl_locks = PyMem_New(PyThread_type_lock, _ssl_locks_count); if (_ssl_locks == NULL) return 0; memset(_ssl_locks, 0, diff -r 7d826a6b92a1 Modules/_testbuffer.c --- a/Modules/_testbuffer.c Tue Feb 10 22:37:22 2015 -0600 +++ b/Modules/_testbuffer.c Wed Feb 11 08:46:14 2015 +0200 @@ -850,7 +850,7 @@ seq_as_ssize_array(PyObject *seq, Py_ssi 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; @@ -888,7 +888,7 @@ strides_from_shape(const ndbuf_t *ndbuf, const Py_buffer *base = &ndbuf->base; Py_ssize_t *s, i; - s = PyMem_Malloc(base->ndim * (sizeof *s)); + s = PyMem_New(Py_ssize_t, base->ndim); if (s == NULL) { PyErr_NoMemory(); return NULL; @@ -1079,7 +1079,7 @@ init_suboffsets(ndbuf_t *ndbuf) ((char **)base->buf)[n] = (char *)base->buf + start + n*step; /* Initialize suboffsets. */ - base->suboffsets = PyMem_Malloc(base->ndim * (sizeof *base->suboffsets)); + base->suboffsets = PyMem_New(Py_ssize_t, base->ndim); if (base->suboffsets == NULL) { PyErr_NoMemory(); return -1; @@ -1744,14 +1744,14 @@ copy_structure(Py_buffer *base) Py_ssize_t *shape = NULL, *strides = NULL, *suboffsets = NULL; Py_ssize_t i; - shape = PyMem_Malloc(base->ndim * (sizeof *shape)); - strides = PyMem_Malloc(base->ndim * (sizeof *strides)); + shape = PyMem_New(Py_ssize_t, base->ndim); + strides = PyMem_New(Py_ssize_t, base->ndim); if (shape == NULL || strides == NULL) goto err_nomem; suboffsets = NULL; if (base->suboffsets) { - suboffsets = PyMem_Malloc(base->ndim * (sizeof *suboffsets)); + suboffsets = PyMem_New(Py_ssize_t, base->ndim); if (suboffsets == NULL) goto err_nomem; } @@ -2210,7 +2210,7 @@ ndarray_add_suboffsets(PyObject *self, P return NULL; } - base->suboffsets = PyMem_Malloc(base->ndim * (sizeof *base->suboffsets)); + base->suboffsets = PyMem_New(Py_ssize_t, base->ndim); if (base->suboffsets == NULL) { PyErr_NoMemory(); return NULL; diff -r 7d826a6b92a1 Modules/_testcapimodule.c --- a/Modules/_testcapimodule.c Tue Feb 10 22:37:22 2015 -0600 +++ b/Modules/_testcapimodule.c Wed Feb 11 08:46:14 2015 +0200 @@ -1517,7 +1517,7 @@ unicode_aswidechar(PyObject *self, PyObj 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 -r 7d826a6b92a1 Modules/getpath.c --- a/Modules/getpath.c Tue Feb 10 22:37:22 2015 -0600 +++ b/Modules/getpath.c Wed Feb 11 08:46:14 2015 +0200 @@ -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 -r 7d826a6b92a1 Modules/posixmodule.c --- a/Modules/posixmodule.c Tue Feb 10 22:37:22 2015 -0600 +++ b/Modules/posixmodule.c Wed Feb 11 08:46:14 2015 +0200 @@ -1620,7 +1620,7 @@ get_target_path(HANDLE hdl, wchar_t **ta 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; @@ -4472,7 +4472,7 @@ static PyObject * 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; @@ -4809,7 +4809,7 @@ posix__getfullpathname(PyObject *self, P 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); @@ -4923,7 +4923,7 @@ os__getfinalpathname_impl(PyModuleDef *m if(!buf_size) return win32_error_object("GetFinalPathNameByHandle", path); - 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(); @@ -5041,7 +5041,7 @@ os__getvolumepathname_impl(PyModuleDef * return NULL; } - mountpath = (wchar_t *)PyMem_Malloc(buflen * sizeof(wchar_t)); + mountpath = PyMem_New(wchar_t, buflen); if (mountpath == NULL) return PyErr_NoMemory(); @@ -8421,9 +8421,9 @@ posix_getgrouplist(PyObject *self, PyObj #endif #ifdef __APPLE__ - groups = PyMem_Malloc(ngroups * sizeof(int)); -#else - groups = PyMem_Malloc(ngroups * sizeof(gid_t)); + groups = PyMem_New(int, ngroups); +#else + groups = PyMem_New(gid_t, ngroups); #endif if (groups == NULL) return PyErr_NoMemory(); @@ -8523,7 +8523,7 @@ os_getgroups_impl(PyModuleDef *module) /* 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(); @@ -8549,7 +8549,7 @@ os_getgroups_impl(PyModuleDef *module) /* 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 -r 7d826a6b92a1 Modules/pyexpat.c --- a/Modules/pyexpat.c Tue Feb 10 22:37:22 2015 -0600 +++ b/Modules/pyexpat.c Wed Feb 11 08:46:14 2015 +0200 @@ -1093,7 +1093,7 @@ pyexpat_xmlparser_ExternalEntityParserCr 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(); @@ -1416,7 +1416,7 @@ newxmlparseobject(const char *encoding, 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 -r 7d826a6b92a1 Modules/socketmodule.c --- a/Modules/socketmodule.c Tue Feb 10 22:37:22 2015 -0600 +++ b/Modules/socketmodule.c Wed Feb 11 08:46:14 2015 +0200 @@ -4213,7 +4213,7 @@ socket_gethostname(PyObject *self, PyObj /* MSDN says ERROR_MORE_DATA may occur because DNS allows longer names */ - name = PyMem_Malloc(size * sizeof(wchar_t)); + name = PyMem_New(wchar_t, size); if (!name) return NULL; if (!GetComputerNameExW(ComputerNamePhysicalDnsHostname, diff -r 7d826a6b92a1 Modules/unicodedata.c --- a/Modules/unicodedata.c Tue Feb 10 22:37:22 2015 -0600 +++ b/Modules/unicodedata.c Wed Feb 11 08:46:14 2015 +0200 @@ -556,7 +556,7 @@ nfd_nfkd(PyObject *self, PyObject *input /* 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 /* 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 -r 7d826a6b92a1 Modules/zipimport.c --- a/Modules/zipimport.c Tue Feb 10 22:37:22 2015 -0600 +++ b/Modules/zipimport.c Wed Feb 11 08:46:14 2015 +0200 @@ -233,7 +233,7 @@ make_filename(PyObject *prefix, PyObject 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; diff -r 7d826a6b92a1 Objects/unicodeobject.c --- a/Objects/unicodeobject.c Tue Feb 10 22:37:22 2015 -0600 +++ b/Objects/unicodeobject.c Wed Feb 11 08:46:14 2015 +0200 @@ -2186,7 +2186,7 @@ void* } switch (kind) { case PyUnicode_2BYTE_KIND: - result = PyMem_Malloc(len * sizeof(Py_UCS2)); + result = PyMem_New(Py_UCS2, len); if (!result) return PyErr_NoMemory(); assert(skind == PyUnicode_1BYTE_KIND); @@ -2197,7 +2197,7 @@ void* result); return result; case PyUnicode_4BYTE_KIND: - result = PyMem_Malloc(len * sizeof(Py_UCS4)); + result = PyMem_New(Py_UCS4, len); if (!result) return PyErr_NoMemory(); if (skind == PyUnicode_2BYTE_KIND) { @@ -2239,11 +2239,7 @@ as_ucs4(PyObject *string, Py_UCS4 *targe if (copy_null) targetlen++; if (!target) { - if (PY_SSIZE_T_MAX / (Py_ssize_t)sizeof(Py_UCS4) < targetlen) { - PyErr_NoMemory(); - return NULL; - } - target = PyMem_Malloc(targetlen * sizeof(Py_UCS4)); + target = PyMem_New(Py_UCS4, targetlen); if (!target) { PyErr_NoMemory(); return NULL; @@ -2817,12 +2813,7 @@ PyUnicode_AsWideCharString(PyObject *uni buflen = unicode_aswidechar(unicode, NULL, 0); if (buflen == -1) return NULL; - if (PY_SSIZE_T_MAX / (Py_ssize_t)sizeof(wchar_t) < buflen) { - PyErr_NoMemory(); - return NULL; - } - - buffer = PyMem_MALLOC(buflen * sizeof(wchar_t)); + buffer = PyMem_NEW(wchar_t, buflen); if (buffer == NULL) { PyErr_NoMemory(); return NULL; @@ -3515,10 +3506,7 @@ PyUnicode_DecodeLocaleAndSize(const char wstr = smallbuf; } else { - if (wlen > PY_SSIZE_T_MAX / sizeof(wchar_t) - 1) - return PyErr_NoMemory(); - - wstr = PyMem_Malloc((wlen+1) * sizeof(wchar_t)); + wstr = PyMem_New(wchar_t, wlen+1); if (!wstr) return PyErr_NoMemory(); } diff -r 7d826a6b92a1 PC/winreg.c --- a/PC/winreg.c Tue Feb 10 22:37:22 2015 -0600 +++ b/PC/winreg.c Wed Feb 11 08:46:14 2015 +0200 @@ -939,7 +939,7 @@ Reg2Py(BYTE *retDataBuf, DWORD retDataSi wchar_t *data = (wchar_t *)retDataBuf; int len = retDataSize / 2; int s = countStrings(data, len); - wchar_t **str = (wchar_t **)PyMem_Malloc(sizeof(wchar_t *)*s); + wchar_t **str = PyMem_New(wchar_t *, s); if (str == NULL) return PyErr_NoMemory(); @@ -1206,7 +1206,7 @@ PyEnumValue(PyObject *self, PyObject *ar ++retDataSize; bufDataSize = retDataSize; bufValueSize = retValueSize; - retValueBuf = (wchar_t *)PyMem_Malloc(sizeof(wchar_t) * retValueSize); + retValueBuf = PyMem_New(wchar_t, retValueSize); if (retValueBuf == NULL) return PyErr_NoMemory(); retDataBuf = (BYTE *)PyMem_Malloc(retDataSize); @@ -1277,7 +1277,7 @@ PyExpandEnvironmentStrings(PyObject *sel return PyErr_SetFromWindowsErrWithFunction(retValueSize, "ExpandEnvironmentStrings"); } - retValue = (wchar_t *)PyMem_Malloc(retValueSize * sizeof(wchar_t)); + retValue = PyMem_New(wchar_t, retValueSize); if (retValue == NULL) { return PyErr_NoMemory(); } diff -r 7d826a6b92a1 Python/peephole.c --- a/Python/peephole.c Tue Feb 10 22:37:22 2015 -0600 +++ b/Python/peephole.c Wed Feb 11 08:46:14 2015 +0200 @@ -290,7 +290,7 @@ fold_unaryops_on_constants(unsigned char static unsigned int * markblocks(unsigned char *code, Py_ssize_t len) { - unsigned int *blocks = (unsigned int *)PyMem_Malloc(len*sizeof(int)); + unsigned int *blocks = PyMem_New(unsigned int, len); int i,j, opcode, blockcnt = 0; if (blocks == NULL) { @@ -398,7 +398,7 @@ PyCode_Optimize(PyObject *code, PyObject goto exitUnchanged; /* Mapping to new jump targets after NOPs are removed */ - addrmap = (int *)PyMem_Malloc(codelen * sizeof(int)); + addrmap = PyMem_New(int, codelen); if (addrmap == NULL) { PyErr_NoMemory(); goto exitError;