Python-checkins
Threads by month
- ----- 2026 -----
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2003 -----
- December
- November
- October
- September
- August
December 2020
- 1 participants
- 398 discussions
https://github.com/python/cpython/commit/bc662c0bd7def052e9edbf504bb468860c…
commit: bc662c0bd7def052e9edbf504bb468860c83f371
branch: master
author: Andre Delfino <adelfino(a)gmail.com>
committer: miss-islington <31488909+miss-islington(a)users.noreply.github.com>
date: 2020-12-01T01:45:11-08:00
summary:
[doc] Fix abc.update_abstractmethods markup (GH-23576)
Add link to ABCMeta while at it.
files:
M Doc/library/abc.rst
diff --git a/Doc/library/abc.rst b/Doc/library/abc.rst
index 3a7414d7358e7..1a6ed474ff21d 100644
--- a/Doc/library/abc.rst
+++ b/Doc/library/abc.rst
@@ -336,6 +336,7 @@ The :mod:`abc` module also provides the following functions:
.. versionadded:: 3.4
.. function:: update_abstractmethods(cls)
+
A function to recalculate an abstract class's abstraction status. This
function should be called if a class's abstract methods have been
implemented or changed after it was created. Usually, this function should
@@ -343,7 +344,7 @@ The :mod:`abc` module also provides the following functions:
Returns *cls*, to allow usage as a class decorator.
- If *cls* is not an instance of ABCMeta, does nothing.
+ If *cls* is not an instance of :class:`ABCMeta`, does nothing.
.. note::
1
0
Dec. 1, 2020
https://github.com/python/cpython/commit/32bd68c839adb7b42af12366ab08923031…
commit: 32bd68c839adb7b42af12366ab0892303115d1d1
branch: master
author: Victor Stinner <vstinner(a)python.org>
committer: vstinner <vstinner(a)python.org>
date: 2020-12-01T10:37:39+01:00
summary:
bpo-42519: Replace PyObject_MALLOC() with PyObject_Malloc() (GH-23587)
No longer use deprecated aliases to functions:
* Replace PyObject_MALLOC() with PyObject_Malloc()
* Replace PyObject_REALLOC() with PyObject_Realloc()
* Replace PyObject_FREE() with PyObject_Free()
* Replace PyObject_Del() with PyObject_Free()
* Replace PyObject_DEL() with PyObject_Free()
files:
M Include/objimpl.h
M Include/pymem.h
M Modules/_blake2/blake2b_impl.c
M Modules/_blake2/blake2s_impl.c
M Modules/_ctypes/callproc.c
M Modules/_curses_panel.c
M Modules/_cursesmodule.c
M Modules/_decimal/_decimal.c
M Modules/_functoolsmodule.c
M Modules/_hashopenssl.c
M Modules/_multiprocessing/semaphore.c
M Modules/_pickle.c
M Modules/_sha3/sha3module.c
M Modules/_sre.c
M Modules/_ssl.c
M Modules/_testbuffer.c
M Modules/_testcapimodule.c
M Modules/_threadmodule.c
M Modules/_tkinter.c
M Modules/cjkcodecs/multibytecodec.c
M Modules/gcmodule.c
M Modules/md5module.c
M Modules/ossaudiodev.c
M Modules/overlapped.c
M Modules/selectmodule.c
M Modules/sha1module.c
M Modules/sha256module.c
M Modules/sha512module.c
M Modules/sre_lib.h
M Modules/unicodedata.c
M Modules/xxmodule.c
M Modules/zlibmodule.c
M Objects/bytesobject.c
M Objects/capsule.c
M Objects/codeobject.c
M Objects/complexobject.c
M Objects/dictobject.c
M Objects/floatobject.c
M Objects/longobject.c
M Objects/object.c
M Objects/odictobject.c
M Objects/rangeobject.c
M Objects/stringlib/unicode_format.h
M Objects/typeobject.c
M Objects/unicodeobject.c
M PC/_msi.c
M PC/winreg.c
M Python/symtable.c
diff --git a/Include/objimpl.h b/Include/objimpl.h
index 464b1bf93ba2c..1408d051ba7ef 100644
--- a/Include/objimpl.h
+++ b/Include/objimpl.h
@@ -38,7 +38,7 @@ Functions and macros for modules that implement new object types.
object with room for n items. In addition to the refcount and type pointer
fields, this also fills in the ob_size field.
- - PyObject_Del(op) releases the memory allocated for an object. It does not
+ - PyObject_Free(op) releases the memory allocated for an object. It does not
run a destructor -- it only frees the memory. PyObject_Free is identical.
- PyObject_Init(op, typeobj) and PyObject_InitVar(op, typeobj, n) don't
@@ -103,6 +103,8 @@ PyAPI_FUNC(void) PyObject_Free(void *ptr);
// Deprecated aliases only kept for backward compatibility.
+// PyObject_Del and PyObject_DEL are defined with no parameter to be able to
+// use them as function pointers (ex: tp_free = PyObject_Del).
#define PyObject_MALLOC PyObject_Malloc
#define PyObject_REALLOC PyObject_Realloc
#define PyObject_FREE PyObject_Free
diff --git a/Include/pymem.h b/Include/pymem.h
index 5b9dd4219948a..92cd5369589ed 100644
--- a/Include/pymem.h
+++ b/Include/pymem.h
@@ -79,13 +79,15 @@ PyAPI_FUNC(void) PyMem_Free(void *ptr);
// Deprecated aliases only kept for backward compatibility.
+// PyMem_Del and PyMem_DEL are defined with no parameter to be able to use
+// them as function pointers (ex: dealloc = PyMem_Del).
#define PyMem_MALLOC(n) PyMem_Malloc(n)
#define PyMem_NEW(type, n) PyMem_New(type, n)
#define PyMem_REALLOC(p, n) PyMem_Realloc(p, n)
#define PyMem_RESIZE(p, type, n) PyMem_Resize(p, type, n)
#define PyMem_FREE(p) PyMem_Free(p)
-#define PyMem_Del(p) PyMem_Free(p)
-#define PyMem_DEL(p) PyMem_Free(p)
+#define PyMem_Del PyMem_Free
+#define PyMem_DEL PyMem_Free
#ifndef Py_LIMITED_API
diff --git a/Modules/_blake2/blake2b_impl.c b/Modules/_blake2/blake2b_impl.c
index 8e1acce56b1d2..5d108ed008a8a 100644
--- a/Modules/_blake2/blake2b_impl.c
+++ b/Modules/_blake2/blake2b_impl.c
@@ -393,7 +393,7 @@ py_blake2b_dealloc(PyObject *self)
}
PyTypeObject *type = Py_TYPE(self);
- PyObject_Del(self);
+ PyObject_Free(self);
Py_DECREF(type);
}
diff --git a/Modules/_blake2/blake2s_impl.c b/Modules/_blake2/blake2s_impl.c
index e1de5df37d098..85c2d4edad7ee 100644
--- a/Modules/_blake2/blake2s_impl.c
+++ b/Modules/_blake2/blake2s_impl.c
@@ -392,7 +392,7 @@ py_blake2s_dealloc(PyObject *self)
}
PyTypeObject *type = Py_TYPE(self);
- PyObject_Del(self);
+ PyObject_Free(self);
Py_DECREF(type);
}
diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c
index 9b629877a8a53..40a05a44edd4c 100644
--- a/Modules/_ctypes/callproc.c
+++ b/Modules/_ctypes/callproc.c
@@ -475,7 +475,7 @@ static void
PyCArg_dealloc(PyCArgObject *self)
{
Py_XDECREF(self->obj);
- PyObject_Del(self);
+ PyObject_Free(self);
}
static int
diff --git a/Modules/_curses_panel.c b/Modules/_curses_panel.c
index 1a8f0b636821f..7d252244e2405 100644
--- a/Modules/_curses_panel.c
+++ b/Modules/_curses_panel.c
@@ -282,7 +282,7 @@ PyCursesPanel_Dealloc(PyCursesPanelObject *po)
Py_DECREF(po->wo);
remove_lop(po);
}
- PyObject_DEL(po);
+ PyObject_Free(po);
Py_DECREF(tp);
}
diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c
index a59858632e76f..1f4789baf7a68 100644
--- a/Modules/_cursesmodule.c
+++ b/Modules/_cursesmodule.c
@@ -689,7 +689,7 @@ PyCursesWindow_Dealloc(PyCursesWindowObject *wo)
if (wo->win != stdscr) delwin(wo->win);
if (wo->encoding != NULL)
PyMem_Free(wo->encoding);
- PyObject_DEL(wo);
+ PyObject_Free(wo);
}
/* Addch, Addstr, Addnstr */
diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c
index ea16c5a6cd9cd..9c85d76c6b5b8 100644
--- a/Modules/_decimal/_decimal.c
+++ b/Modules/_decimal/_decimal.c
@@ -1765,7 +1765,7 @@ ctxmanager_dealloc(PyDecContextManagerObject *self)
{
Py_XDECREF(self->local);
Py_XDECREF(self->global);
- PyObject_Del(self);
+ PyObject_Free(self);
}
static PyObject *
diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c
index 9fad21fc33213..ff03c334766b8 100644
--- a/Modules/_functoolsmodule.c
+++ b/Modules/_functoolsmodule.c
@@ -478,7 +478,7 @@ keyobject_dealloc(keyobject *ko)
{
Py_DECREF(ko->cmp);
Py_XDECREF(ko->object);
- PyObject_FREE(ko);
+ PyObject_Free(ko);
}
static int
@@ -742,7 +742,7 @@ lru_list_elem_dealloc(lru_list_elem *link)
{
Py_XDECREF(link->key);
Py_XDECREF(link->result);
- PyObject_Del(link);
+ PyObject_Free(link);
}
static PyTypeObject lru_list_elem_type = {
diff --git a/Modules/_hashopenssl.c b/Modules/_hashopenssl.c
index 7e176cf21d629..d4295d7c3638d 100644
--- a/Modules/_hashopenssl.c
+++ b/Modules/_hashopenssl.c
@@ -341,7 +341,7 @@ EVP_dealloc(EVPobject *self)
if (self->lock != NULL)
PyThread_free_lock(self->lock);
EVP_MD_CTX_free(self->ctx);
- PyObject_Del(self);
+ PyObject_Free(self);
Py_DECREF(tp);
}
@@ -1453,7 +1453,7 @@ _hashlib_hmac_new_impl(PyObject *module, Py_buffer *key, PyObject *msg_obj,
error:
if (ctx) HMAC_CTX_free(ctx);
- if (self) PyObject_Del(self);
+ if (self) PyObject_Free(self);
return NULL;
}
@@ -1546,7 +1546,7 @@ _hmac_dealloc(HMACobject *self)
PyThread_free_lock(self->lock);
}
HMAC_CTX_free(self->ctx);
- PyObject_Del(self);
+ PyObject_Free(self);
Py_DECREF(tp);
}
diff --git a/Modules/_multiprocessing/semaphore.c b/Modules/_multiprocessing/semaphore.c
index 8732750e11be8..9a2d1f85c92fa 100644
--- a/Modules/_multiprocessing/semaphore.c
+++ b/Modules/_multiprocessing/semaphore.c
@@ -571,7 +571,7 @@ semlock_dealloc(SemLockObject* self)
if (self->handle != SEM_FAILED)
SEM_CLOSE(self->handle);
PyMem_Free(self->name);
- PyObject_Del(self);
+ PyObject_Free(self);
}
/*[clinic input]
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
index 7ecaeea18c611..5a8aad9de7679 100644
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -443,7 +443,7 @@ Pdata_dealloc(Pdata *self)
Py_DECREF(self->data[i]);
}
PyMem_Free(self->data);
- PyObject_Del(self);
+ PyObject_Free(self);
}
static PyTypeObject Pdata_Type = {
diff --git a/Modules/_sha3/sha3module.c b/Modules/_sha3/sha3module.c
index da6dde6812f26..cae10f99d5b8d 100644
--- a/Modules/_sha3/sha3module.c
+++ b/Modules/_sha3/sha3module.c
@@ -274,7 +274,7 @@ SHA3_dealloc(SHA3object *self)
}
PyTypeObject *tp = Py_TYPE(self);
- PyObject_Del(self);
+ PyObject_Free(self);
Py_DECREF(tp);
}
diff --git a/Modules/_sre.c b/Modules/_sre.c
index c67f38d75b809..57faf7bdaae4e 100644
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -571,7 +571,7 @@ pattern_dealloc(PatternObject* self)
Py_XDECREF(self->pattern);
Py_XDECREF(self->groupindex);
Py_XDECREF(self->indexgroup);
- PyObject_DEL(self);
+ PyObject_Free(self);
Py_DECREF(tp);
}
@@ -1944,7 +1944,7 @@ match_dealloc(MatchObject* self)
Py_XDECREF(self->regs);
Py_XDECREF(self->string);
Py_DECREF(self->pattern);
- PyObject_DEL(self);
+ PyObject_Free(self);
Py_DECREF(tp);
}
@@ -2450,7 +2450,7 @@ scanner_dealloc(ScannerObject* self)
state_fini(&self->state);
Py_XDECREF(self->pattern);
- PyObject_DEL(self);
+ PyObject_Free(self);
Py_DECREF(tp);
}
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
index 87fe3a16078fa..edb850ee46103 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -2295,7 +2295,7 @@ PySSL_dealloc(PySSLSocket *self)
Py_XDECREF(self->ctx);
Py_XDECREF(self->server_hostname);
Py_XDECREF(self->owner);
- PyObject_Del(self);
+ PyObject_Free(self);
Py_DECREF(tp);
}
diff --git a/Modules/_testbuffer.c b/Modules/_testbuffer.c
index d8321768bc972..1b4fb09fb8fbc 100644
--- a/Modules/_testbuffer.c
+++ b/Modules/_testbuffer.c
@@ -236,7 +236,7 @@ ndarray_dealloc(NDArrayObject *self)
ndbuf_pop(self);
}
}
- PyObject_Del(self);
+ PyObject_Free(self);
}
static int
@@ -2734,7 +2734,7 @@ staticarray_init(PyObject *self, PyObject *args, PyObject *kwds)
static void
staticarray_dealloc(StaticArrayObject *self)
{
- PyObject_Del(self);
+ PyObject_Free(self);
}
/* Return a buffer for a PyBUF_FULL_RO request. Flags are not checked,
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 916d10a1e413b..d2104423c5890 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -6010,7 +6010,7 @@ test_structmembers_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
static void
test_structmembers_free(PyObject *ob)
{
- PyObject_FREE(ob);
+ PyObject_Free(ob);
}
static PyTypeObject test_structmembersType = {
@@ -6664,7 +6664,7 @@ static void
heapctype_dealloc(HeapCTypeObject *self)
{
PyTypeObject *tp = Py_TYPE(self);
- PyObject_Del(self);
+ PyObject_Free(self);
Py_DECREF(tp);
}
@@ -6854,7 +6854,7 @@ heapctypewithdict_dealloc(HeapCTypeWithDictObject* self)
PyTypeObject *tp = Py_TYPE(self);
Py_XDECREF(self->dict);
- PyObject_DEL(self);
+ PyObject_Free(self);
Py_DECREF(tp);
}
@@ -6925,7 +6925,7 @@ heapctypewithweakref_dealloc(HeapCTypeWithWeakrefObject* self)
if (self->weakreflist != NULL)
PyObject_ClearWeakRefs((PyObject *) self);
Py_XDECREF(self->weakreflist);
- PyObject_DEL(self);
+ PyObject_Free(self);
Py_DECREF(tp);
}
@@ -6968,7 +6968,7 @@ static void
heapctypesetattr_dealloc(HeapCTypeSetattrObject *self)
{
PyTypeObject *tp = Py_TYPE(self);
- PyObject_Del(self);
+ PyObject_Free(self);
Py_DECREF(tp);
}
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
index dcefa8dbaa91b..86d5f544fcf0f 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -34,7 +34,7 @@ lock_dealloc(lockobject *self)
PyThread_release_lock(self->lock_lock);
PyThread_free_lock(self->lock_lock);
}
- PyObject_Del(self);
+ PyObject_Free(self);
}
/* Helper to acquire an interruptible lock with a timeout. If the lock acquire
diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c
index 24aeb3da94c70..46d6a6e0954f5 100644
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -904,7 +904,7 @@ PyTclObject_dealloc(PyTclObject *self)
PyObject *tp = (PyObject *) Py_TYPE(self);
Tcl_DecrRefCount(self->value);
Py_XDECREF(self->string);
- PyObject_Del(self);
+ PyObject_Free(self);
Py_DECREF(tp);
}
@@ -2823,7 +2823,7 @@ Tktt_Dealloc(PyObject *self)
Py_XDECREF(func);
- PyObject_Del(self);
+ PyObject_Free(self);
Py_DECREF(tp);
}
@@ -3096,7 +3096,7 @@ Tkapp_Dealloc(PyObject *self)
ENTER_TCL
Tcl_DeleteInterp(Tkapp_Interp(self));
LEAVE_TCL
- PyObject_Del(self);
+ PyObject_Free(self);
Py_DECREF(tp);
DisableEventHook();
}
diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c
index 37a80a781da6f..9208b86b0c905 100644
--- a/Modules/cjkcodecs/multibytecodec.c
+++ b/Modules/cjkcodecs/multibytecodec.c
@@ -691,7 +691,7 @@ static struct PyMethodDef multibytecodec_methods[] = {
static void
multibytecodec_dealloc(MultibyteCodecObject *self)
{
- PyObject_Del(self);
+ PyObject_Free(self);
}
static PyTypeObject MultibyteCodec_Type = {
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
index 45201435f2460..fdbba6a7afc29 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -2290,7 +2290,7 @@ _PyObject_GC_Resize(PyVarObject *op, Py_ssize_t nitems)
}
PyGC_Head *g = AS_GC(op);
- g = (PyGC_Head *)PyObject_REALLOC(g, sizeof(PyGC_Head) + basicsize);
+ g = (PyGC_Head *)PyObject_Realloc(g, sizeof(PyGC_Head) + basicsize);
if (g == NULL)
return (PyVarObject *)PyErr_NoMemory();
op = (PyVarObject *) FROM_GC(g);
@@ -2309,7 +2309,7 @@ PyObject_GC_Del(void *op)
if (gcstate->generations[0].count > 0) {
gcstate->generations[0].count--;
}
- PyObject_FREE(g);
+ PyObject_Free(g);
}
int
diff --git a/Modules/md5module.c b/Modules/md5module.c
index 9bd2bd17e4fbf..1c401e884389f 100644
--- a/Modules/md5module.c
+++ b/Modules/md5module.c
@@ -342,7 +342,7 @@ static void
MD5_dealloc(PyObject *ptr)
{
PyTypeObject *tp = Py_TYPE(ptr);
- PyObject_Del(ptr);
+ PyObject_Free(ptr);
Py_DECREF(tp);
}
diff --git a/Modules/ossaudiodev.c b/Modules/ossaudiodev.c
index 2a1ac10814a69..4f2d9cb8b7c9c 100644
--- a/Modules/ossaudiodev.c
+++ b/Modules/ossaudiodev.c
@@ -154,7 +154,7 @@ oss_dealloc(oss_audio_t *self)
/* if already closed, don't reclose it */
if (self->fd != -1)
close(self->fd);
- PyObject_Del(self);
+ PyObject_Free(self);
}
@@ -199,7 +199,7 @@ oss_mixer_dealloc(oss_mixer_t *self)
/* if already closed, don't reclose it */
if (self->fd != -1)
close(self->fd);
- PyObject_Del(self);
+ PyObject_Free(self);
}
diff --git a/Modules/overlapped.c b/Modules/overlapped.c
index 3829932070a96..38dd98f084849 100644
--- a/Modules/overlapped.c
+++ b/Modules/overlapped.c
@@ -722,7 +722,7 @@ Overlapped_dealloc(OverlappedObject *self)
SetLastError(olderr);
PyTypeObject *tp = Py_TYPE(self);
- PyObject_Del(self);
+ PyObject_Free(self);
Py_DECREF(tp);
}
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c
index 0b9f20d6bbd9d..f80da5895401f 100644
--- a/Modules/selectmodule.c
+++ b/Modules/selectmodule.c
@@ -742,7 +742,7 @@ poll_dealloc(pollObject *self)
if (self->ufds != NULL)
PyMem_Free(self->ufds);
Py_XDECREF(self->dict);
- PyObject_Del(self);
+ PyObject_Free(self);
Py_DECREF(type);
}
@@ -1130,7 +1130,7 @@ devpoll_dealloc(devpollObject *self)
PyObject *type = (PyObject *)Py_TYPE(self);
(void)devpoll_internal_close(self);
PyMem_Free(self->fds);
- PyObject_Del(self);
+ PyObject_Free(self);
Py_DECREF(type);
}
diff --git a/Modules/sha1module.c b/Modules/sha1module.c
index c22437de256b6..5209857041d90 100644
--- a/Modules/sha1module.c
+++ b/Modules/sha1module.c
@@ -320,7 +320,7 @@ static void
SHA1_dealloc(PyObject *ptr)
{
PyTypeObject *tp = Py_TYPE(ptr);
- PyObject_Del(ptr);
+ PyObject_Free(ptr);
Py_DECREF(tp);
}
diff --git a/Modules/sha256module.c b/Modules/sha256module.c
index edd4d010928f3..6b8bd8f1d27fb 100644
--- a/Modules/sha256module.c
+++ b/Modules/sha256module.c
@@ -397,7 +397,7 @@ static void
SHA_dealloc(PyObject *ptr)
{
PyTypeObject *tp = Py_TYPE(ptr);
- PyObject_Del(ptr);
+ PyObject_Free(ptr);
Py_DECREF(tp);
}
diff --git a/Modules/sha512module.c b/Modules/sha512module.c
index 725098def4d06..3fd9fa4c8d16f 100644
--- a/Modules/sha512module.c
+++ b/Modules/sha512module.c
@@ -453,7 +453,7 @@ static void
SHA512_dealloc(PyObject *ptr)
{
PyTypeObject *tp = Py_TYPE(ptr);
- PyObject_Del(ptr);
+ PyObject_Free(ptr);
Py_DECREF(tp);
}
diff --git a/Modules/sre_lib.h b/Modules/sre_lib.h
index cfe0a4af2c483..322f66fb4da6c 100644
--- a/Modules/sre_lib.h
+++ b/Modules/sre_lib.h
@@ -986,7 +986,7 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
ctx->pattern[1], ctx->pattern[2]));
/* install new repeat context */
- ctx->u.rep = (SRE_REPEAT*) PyObject_MALLOC(sizeof(*ctx->u.rep));
+ ctx->u.rep = (SRE_REPEAT*) PyObject_Malloc(sizeof(*ctx->u.rep));
if (!ctx->u.rep) {
PyErr_NoMemory();
RETURN_FAILURE;
@@ -1000,7 +1000,7 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
state->ptr = ctx->ptr;
DO_JUMP(JUMP_REPEAT, jump_repeat, ctx->pattern+ctx->pattern[0]);
state->repeat = ctx->u.rep->prev;
- PyObject_FREE(ctx->u.rep);
+ PyObject_Free(ctx->u.rep);
if (ret) {
RETURN_ON_ERROR(ret);
diff --git a/Modules/unicodedata.c b/Modules/unicodedata.c
index fcf801dc9e4ad..4b8c46c779766 100644
--- a/Modules/unicodedata.c
+++ b/Modules/unicodedata.c
@@ -1418,7 +1418,7 @@ static void
ucd_dealloc(PreviousDBVersion *self)
{
PyTypeObject *tp = Py_TYPE(self);
- PyObject_Del(self);
+ PyObject_Free(self);
Py_DECREF(tp);
}
diff --git a/Modules/xxmodule.c b/Modules/xxmodule.c
index 17b049c4b9a37..edcd62157c02f 100644
--- a/Modules/xxmodule.c
+++ b/Modules/xxmodule.c
@@ -44,7 +44,7 @@ static void
Xxo_dealloc(XxoObject *self)
{
Py_XDECREF(self->x_attr);
- PyObject_Del(self);
+ PyObject_Free(self);
}
static PyObject *
diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c
index def617671f18f..a537087d19d83 100644
--- a/Modules/zlibmodule.c
+++ b/Modules/zlibmodule.c
@@ -591,7 +591,7 @@ Dealloc(compobject *self)
Py_XDECREF(self->unused_data);
Py_XDECREF(self->unconsumed_tail);
Py_XDECREF(self->zdict);
- PyObject_Del(self);
+ PyObject_Free(self);
Py_DECREF(type);
}
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index bb844090b8622..13216b9bb21a5 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -198,7 +198,7 @@ PyBytes_FromString(const char *str)
}
/* Inline PyObject_NewVar */
- op = (PyBytesObject *)PyObject_MALLOC(PyBytesObject_SIZE + size);
+ op = (PyBytesObject *)PyObject_Malloc(PyBytesObject_SIZE + size);
if (op == NULL) {
return PyErr_NoMemory();
}
@@ -1475,7 +1475,7 @@ bytes_repeat(PyBytesObject *a, Py_ssize_t n)
"repeated bytes are too long");
return NULL;
}
- op = (PyBytesObject *)PyObject_MALLOC(PyBytesObject_SIZE + nbytes);
+ op = (PyBytesObject *)PyObject_Malloc(PyBytesObject_SIZE + nbytes);
if (op == NULL) {
return PyErr_NoMemory();
}
@@ -3054,9 +3054,9 @@ _PyBytes_Resize(PyObject **pv, Py_ssize_t newsize)
_Py_ForgetReference(v);
#endif
*pv = (PyObject *)
- PyObject_REALLOC(v, PyBytesObject_SIZE + newsize);
+ PyObject_Realloc(v, PyBytesObject_SIZE + newsize);
if (*pv == NULL) {
- PyObject_Del(v);
+ PyObject_Free(v);
PyErr_NoMemory();
return -1;
}
diff --git a/Objects/capsule.c b/Objects/capsule.c
index a2ff642526cd0..800a6c4b25c6d 100644
--- a/Objects/capsule.c
+++ b/Objects/capsule.c
@@ -260,7 +260,7 @@ capsule_dealloc(PyObject *o)
if (capsule->destructor) {
capsule->destructor(o);
}
- PyObject_DEL(o);
+ PyObject_Free(o);
}
diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index 0257295f1e996..0b0b8f98ae4f3 100644
--- a/Objects/codeobject.c
+++ b/Objects/codeobject.c
@@ -669,7 +669,7 @@ code_dealloc(PyCodeObject *co)
PyObject_GC_Del(co->co_zombieframe);
if (co->co_weakreflist != NULL)
PyObject_ClearWeakRefs((PyObject*)co);
- PyObject_DEL(co);
+ PyObject_Free(co);
}
static PyObject *
diff --git a/Objects/complexobject.c b/Objects/complexobject.c
index a481d9ad8bbaa..a65ebdfa6cdf9 100644
--- a/Objects/complexobject.c
+++ b/Objects/complexobject.c
@@ -233,7 +233,7 @@ PyObject *
PyComplex_FromCComplex(Py_complex cval)
{
/* Inline PyObject_New */
- PyComplexObject *op = PyObject_MALLOC(sizeof(PyComplexObject));
+ PyComplexObject *op = PyObject_Malloc(sizeof(PyComplexObject));
if (op == NULL) {
return PyErr_NoMemory();
}
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index ee1a9d1d7e71e..7a37313df8a6b 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -269,7 +269,7 @@ _PyDict_ClearFreeList(PyThreadState *tstate)
PyObject_GC_Del(op);
}
while (state->keys_numfree) {
- PyObject_FREE(state->keys_free_list[--state->keys_numfree]);
+ PyObject_Free(state->keys_free_list[--state->keys_numfree]);
}
}
@@ -597,7 +597,7 @@ new_keys_object(Py_ssize_t size)
}
else
{
- dk = PyObject_MALLOC(sizeof(PyDictKeysObject)
+ dk = PyObject_Malloc(sizeof(PyDictKeysObject)
+ es * size
+ sizeof(PyDictKeyEntry) * usable);
if (dk == NULL) {
@@ -636,7 +636,7 @@ free_keys_object(PyDictKeysObject *keys)
state->keys_free_list[state->keys_numfree++] = keys;
return;
}
- PyObject_FREE(keys);
+ PyObject_Free(keys);
}
#define new_values(size) PyMem_NEW(PyObject *, size)
@@ -1303,7 +1303,7 @@ dictresize(PyDictObject *mp, Py_ssize_t newsize)
state->keys_free_list[state->keys_numfree++] = oldkeys;
}
else {
- PyObject_FREE(oldkeys);
+ PyObject_Free(oldkeys);
}
}
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 1550b2eedc862..34fb57a946afa 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -237,7 +237,7 @@ float_dealloc(PyFloatObject *op)
assert(state->numfree != -1);
#endif
if (state->numfree >= PyFloat_MAXFREELIST) {
- PyObject_FREE(op);
+ PyObject_Free(op);
return;
}
state->numfree++;
@@ -2032,7 +2032,7 @@ _PyFloat_ClearFreeList(PyThreadState *tstate)
PyFloatObject *f = state->free_list;
while (f != NULL) {
PyFloatObject *next = (PyFloatObject*) Py_TYPE(f);
- PyObject_FREE(f);
+ PyObject_Free(f);
f = next;
}
state->free_list = NULL;
diff --git a/Objects/longobject.c b/Objects/longobject.c
index e0d6410fe6818..240e92a41e0ec 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -131,7 +131,7 @@ _PyLong_New(Py_ssize_t size)
"too many digits in integer");
return NULL;
}
- result = PyObject_MALLOC(offsetof(PyLongObject, ob_digit) +
+ result = PyObject_Malloc(offsetof(PyLongObject, ob_digit) +
size*sizeof(digit));
if (!result) {
PyErr_NoMemory();
diff --git a/Objects/object.c b/Objects/object.c
index 2e8717f506ca0..0a8621b3503b3 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -161,7 +161,7 @@ PyObject_InitVar(PyVarObject *op, PyTypeObject *tp, Py_ssize_t size)
PyObject *
_PyObject_New(PyTypeObject *tp)
{
- PyObject *op = (PyObject *) PyObject_MALLOC(_PyObject_SIZE(tp));
+ PyObject *op = (PyObject *) PyObject_Malloc(_PyObject_SIZE(tp));
if (op == NULL) {
return PyErr_NoMemory();
}
@@ -174,7 +174,7 @@ _PyObject_NewVar(PyTypeObject *tp, Py_ssize_t nitems)
{
PyVarObject *op;
const size_t size = _PyObject_VAR_SIZE(tp, nitems);
- op = (PyVarObject *) PyObject_MALLOC(size);
+ op = (PyVarObject *) PyObject_Malloc(size);
if (op == NULL) {
return (PyVarObject *)PyErr_NoMemory();
}
diff --git a/Objects/odictobject.c b/Objects/odictobject.c
index 83b326b2067a8..4eb15f999bd1e 100644
--- a/Objects/odictobject.c
+++ b/Objects/odictobject.c
@@ -459,7 +459,7 @@ Potential Optimizations
- implement a fuller MutableMapping API in C?
- move the MutableMapping implementation to abstract.c?
- optimize mutablemapping_update
-- use PyObject_MALLOC (small object allocator) for odict nodes?
+- use PyObject_Malloc (small object allocator) for odict nodes?
- support subclasses better (e.g. in odict_richcompare)
*/
diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c
index 787d1138009a0..530426c8ac904 100644
--- a/Objects/rangeobject.c
+++ b/Objects/rangeobject.c
@@ -171,7 +171,7 @@ range_dealloc(rangeobject *r)
Py_DECREF(r->stop);
Py_DECREF(r->step);
Py_DECREF(r->length);
- PyObject_Del(r);
+ PyObject_Free(r);
}
/* Return number of items in range (lo, hi, step) as a PyLong object,
@@ -1021,7 +1021,7 @@ longrangeiter_dealloc(longrangeiterobject *r)
Py_XDECREF(r->start);
Py_XDECREF(r->step);
Py_XDECREF(r->len);
- PyObject_Del(r);
+ PyObject_Free(r);
}
static PyObject *
diff --git a/Objects/stringlib/unicode_format.h b/Objects/stringlib/unicode_format.h
index b526ad21b8205..7152ec6ebe712 100644
--- a/Objects/stringlib/unicode_format.h
+++ b/Objects/stringlib/unicode_format.h
@@ -983,7 +983,7 @@ static void
formatteriter_dealloc(formatteriterobject *it)
{
Py_XDECREF(it->str);
- PyObject_FREE(it);
+ PyObject_Free(it);
}
/* returns a tuple:
@@ -1147,7 +1147,7 @@ static void
fieldnameiter_dealloc(fieldnameiterobject *it)
{
Py_XDECREF(it->str);
- PyObject_FREE(it);
+ PyObject_Free(it);
}
/* returns a tuple:
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index fbadd31f1a46c..83bc877eb7d05 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -1059,7 +1059,7 @@ PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems)
obj = _PyObject_GC_Malloc(size);
}
else {
- obj = (PyObject *)PyObject_MALLOC(size);
+ obj = (PyObject *)PyObject_Malloc(size);
}
if (obj == NULL) {
@@ -2707,7 +2707,7 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
goto error;
/* Silently truncate the docstring if it contains null bytes. */
len = strlen(doc_str);
- tp_doc = (char *)PyObject_MALLOC(len + 1);
+ tp_doc = (char *)PyObject_Malloc(len + 1);
if (tp_doc == NULL) {
PyErr_NoMemory();
goto error;
@@ -3047,7 +3047,7 @@ PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases)
continue;
}
size_t len = strlen(slot->pfunc)+1;
- char *tp_doc = PyObject_MALLOC(len);
+ char *tp_doc = PyObject_Malloc(len);
if (tp_doc == NULL) {
type->tp_doc = NULL;
PyErr_NoMemory();
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index ba6d07a67d2da..f6473c02d30fd 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -1061,7 +1061,7 @@ resize_compact(PyObject *unicode, Py_ssize_t length)
new_size = (struct_size + (length + 1) * char_size);
if (_PyUnicode_HAS_UTF8_MEMORY(unicode)) {
- PyObject_DEL(_PyUnicode_UTF8(unicode));
+ PyObject_Free(_PyUnicode_UTF8(unicode));
_PyUnicode_UTF8(unicode) = NULL;
_PyUnicode_UTF8_LENGTH(unicode) = 0;
}
@@ -1072,7 +1072,7 @@ resize_compact(PyObject *unicode, Py_ssize_t length)
_Py_ForgetReference(unicode);
#endif
- new_unicode = (PyObject *)PyObject_REALLOC(unicode, new_size);
+ new_unicode = (PyObject *)PyObject_Realloc(unicode, new_size);
if (new_unicode == NULL) {
_Py_NewReference(unicode);
PyErr_NoMemory();
@@ -1088,7 +1088,7 @@ resize_compact(PyObject *unicode, Py_ssize_t length)
_PyUnicode_WSTR_LENGTH(unicode) = length;
}
else if (_PyUnicode_HAS_WSTR_MEMORY(unicode)) {
- PyObject_DEL(_PyUnicode_WSTR(unicode));
+ PyObject_Free(_PyUnicode_WSTR(unicode));
_PyUnicode_WSTR(unicode) = NULL;
if (!PyUnicode_IS_ASCII(unicode))
_PyUnicode_WSTR_LENGTH(unicode) = 0;
@@ -1131,12 +1131,12 @@ resize_inplace(PyObject *unicode, Py_ssize_t length)
if (!share_utf8 && _PyUnicode_HAS_UTF8_MEMORY(unicode))
{
- PyObject_DEL(_PyUnicode_UTF8(unicode));
+ PyObject_Free(_PyUnicode_UTF8(unicode));
_PyUnicode_UTF8(unicode) = NULL;
_PyUnicode_UTF8_LENGTH(unicode) = 0;
}
- data = (PyObject *)PyObject_REALLOC(data, new_size);
+ data = (PyObject *)PyObject_Realloc(data, new_size);
if (data == NULL) {
PyErr_NoMemory();
return -1;
@@ -1169,7 +1169,7 @@ resize_inplace(PyObject *unicode, Py_ssize_t length)
}
new_size = sizeof(wchar_t) * (length + 1);
wstr = _PyUnicode_WSTR(unicode);
- wstr = PyObject_REALLOC(wstr, new_size);
+ wstr = PyObject_Realloc(wstr, new_size);
if (!wstr) {
PyErr_NoMemory();
return -1;
@@ -1259,7 +1259,7 @@ _PyUnicode_New(Py_ssize_t length)
_PyUnicode_UTF8(unicode) = NULL;
_PyUnicode_UTF8_LENGTH(unicode) = 0;
- _PyUnicode_WSTR(unicode) = (Py_UNICODE*) PyObject_MALLOC(new_size);
+ _PyUnicode_WSTR(unicode) = (Py_UNICODE*) PyObject_Malloc(new_size);
if (!_PyUnicode_WSTR(unicode)) {
Py_DECREF(unicode);
PyErr_NoMemory();
@@ -1456,7 +1456,7 @@ PyUnicode_New(Py_ssize_t size, Py_UCS4 maxchar)
* PyObject_New() so we are able to allocate space for the object and
* it's data buffer.
*/
- obj = (PyObject *) PyObject_MALLOC(struct_size + (size + 1) * char_size);
+ obj = (PyObject *) PyObject_Malloc(struct_size + (size + 1) * char_size);
if (obj == NULL) {
return PyErr_NoMemory();
}
@@ -1838,7 +1838,7 @@ _PyUnicode_Ready(PyObject *unicode)
return -1;
if (maxchar < 256) {
- _PyUnicode_DATA_ANY(unicode) = PyObject_MALLOC(_PyUnicode_WSTR_LENGTH(unicode) + 1);
+ _PyUnicode_DATA_ANY(unicode) = PyObject_Malloc(_PyUnicode_WSTR_LENGTH(unicode) + 1);
if (!_PyUnicode_DATA_ANY(unicode)) {
PyErr_NoMemory();
return -1;
@@ -1859,7 +1859,7 @@ _PyUnicode_Ready(PyObject *unicode)
_PyUnicode_UTF8(unicode) = NULL;
_PyUnicode_UTF8_LENGTH(unicode) = 0;
}
- PyObject_FREE(_PyUnicode_WSTR(unicode));
+ PyObject_Free(_PyUnicode_WSTR(unicode));
_PyUnicode_WSTR(unicode) = NULL;
_PyUnicode_WSTR_LENGTH(unicode) = 0;
}
@@ -1879,7 +1879,7 @@ _PyUnicode_Ready(PyObject *unicode)
_PyUnicode_UTF8_LENGTH(unicode) = 0;
#else
/* sizeof(wchar_t) == 4 */
- _PyUnicode_DATA_ANY(unicode) = PyObject_MALLOC(
+ _PyUnicode_DATA_ANY(unicode) = PyObject_Malloc(
2 * (_PyUnicode_WSTR_LENGTH(unicode) + 1));
if (!_PyUnicode_DATA_ANY(unicode)) {
PyErr_NoMemory();
@@ -1893,7 +1893,7 @@ _PyUnicode_Ready(PyObject *unicode)
_PyUnicode_STATE(unicode).kind = PyUnicode_2BYTE_KIND;
_PyUnicode_UTF8(unicode) = NULL;
_PyUnicode_UTF8_LENGTH(unicode) = 0;
- PyObject_FREE(_PyUnicode_WSTR(unicode));
+ PyObject_Free(_PyUnicode_WSTR(unicode));
_PyUnicode_WSTR(unicode) = NULL;
_PyUnicode_WSTR_LENGTH(unicode) = 0;
#endif
@@ -1908,7 +1908,7 @@ _PyUnicode_Ready(PyObject *unicode)
PyErr_NoMemory();
return -1;
}
- _PyUnicode_DATA_ANY(unicode) = PyObject_MALLOC(4 * (length_wo_surrogates + 1));
+ _PyUnicode_DATA_ANY(unicode) = PyObject_Malloc(4 * (length_wo_surrogates + 1));
if (!_PyUnicode_DATA_ANY(unicode)) {
PyErr_NoMemory();
return -1;
@@ -1920,7 +1920,7 @@ _PyUnicode_Ready(PyObject *unicode)
/* unicode_convert_wchar_to_ucs4() requires a ready string */
_PyUnicode_STATE(unicode).ready = 1;
unicode_convert_wchar_to_ucs4(_PyUnicode_WSTR(unicode), end, unicode);
- PyObject_FREE(_PyUnicode_WSTR(unicode));
+ PyObject_Free(_PyUnicode_WSTR(unicode));
_PyUnicode_WSTR(unicode) = NULL;
_PyUnicode_WSTR_LENGTH(unicode) = 0;
#else
@@ -1973,13 +1973,13 @@ unicode_dealloc(PyObject *unicode)
}
if (_PyUnicode_HAS_WSTR_MEMORY(unicode)) {
- PyObject_DEL(_PyUnicode_WSTR(unicode));
+ PyObject_Free(_PyUnicode_WSTR(unicode));
}
if (_PyUnicode_HAS_UTF8_MEMORY(unicode)) {
- PyObject_DEL(_PyUnicode_UTF8(unicode));
+ PyObject_Free(_PyUnicode_UTF8(unicode));
}
if (!PyUnicode_IS_COMPACT(unicode) && _PyUnicode_DATA_ANY(unicode)) {
- PyObject_DEL(_PyUnicode_DATA_ANY(unicode));
+ PyObject_Free(_PyUnicode_DATA_ANY(unicode));
}
Py_TYPE(unicode)->tp_free(unicode);
@@ -4199,7 +4199,7 @@ PyUnicode_AsUnicodeAndSize(PyObject *unicode, Py_ssize_t *size)
PyErr_NoMemory();
return NULL;
}
- w = (wchar_t *) PyObject_MALLOC(sizeof(wchar_t) * (wlen + 1));
+ w = (wchar_t *) PyObject_Malloc(sizeof(wchar_t) * (wlen + 1));
if (w == NULL) {
PyErr_NoMemory();
return NULL;
@@ -5627,7 +5627,7 @@ unicode_fill_utf8(PyObject *unicode)
PyBytes_AS_STRING(writer.buffer);
Py_ssize_t len = end - start;
- char *cache = PyObject_MALLOC(len + 1);
+ char *cache = PyObject_Malloc(len + 1);
if (cache == NULL) {
_PyBytesWriter_Dealloc(&writer);
PyErr_NoMemory();
@@ -8544,7 +8544,7 @@ PyUnicode_BuildEncodingMap(PyObject* string)
}
/* Create a three-level trie */
- result = PyObject_MALLOC(sizeof(struct encoding_map) +
+ result = PyObject_Malloc(sizeof(struct encoding_map) +
16*count2 + 128*count3 - 1);
if (!result) {
return PyErr_NoMemory();
@@ -15567,7 +15567,7 @@ unicode_subtype_new(PyTypeObject *type, PyObject *unicode)
PyErr_NoMemory();
goto onError;
}
- data = PyObject_MALLOC((length + 1) * char_size);
+ data = PyObject_Malloc((length + 1) * char_size);
if (data == NULL) {
PyErr_NoMemory();
goto onError;
diff --git a/PC/_msi.c b/PC/_msi.c
index 504899d0757b7..01516e85ccff3 100644
--- a/PC/_msi.c
+++ b/PC/_msi.c
@@ -351,7 +351,7 @@ msiobj_dealloc(msiobj* msidb)
{
MsiCloseHandle(msidb->h);
msidb->h = 0;
- PyObject_Del(msidb);
+ PyObject_Free(msidb);
}
static PyObject*
diff --git a/PC/winreg.c b/PC/winreg.c
index fee51ac1bbe0a..d62a7be28d3fa 100644
--- a/PC/winreg.c
+++ b/PC/winreg.c
@@ -145,7 +145,7 @@ PyHKEY_deallocFunc(PyObject *ob)
PyHKEYObject *obkey = (PyHKEYObject *)ob;
if (obkey->hkey)
RegCloseKey((HKEY)obkey->hkey);
- PyObject_DEL(ob);
+ PyObject_Free(ob);
}
static int
@@ -459,7 +459,7 @@ PyObject *
PyHKEY_FromHKEY(HKEY h)
{
/* Inline PyObject_New */
- PyHKEYObject *op = (PyHKEYObject *) PyObject_MALLOC(sizeof(PyHKEYObject));
+ PyHKEYObject *op = (PyHKEYObject *) PyObject_Malloc(sizeof(PyHKEYObject));
if (op == NULL) {
return PyErr_NoMemory();
}
diff --git a/Python/symtable.c b/Python/symtable.c
index 0464cd898b27f..cce1b1b5f3226 100644
--- a/Python/symtable.c
+++ b/Python/symtable.c
@@ -128,7 +128,7 @@ ste_dealloc(PySTEntryObject *ste)
Py_XDECREF(ste->ste_varnames);
Py_XDECREF(ste->ste_children);
Py_XDECREF(ste->ste_directives);
- PyObject_Del(ste);
+ PyObject_Free(ste);
}
#define OFF(x) offsetof(PySTEntryObject, x)
1
0
Dec. 1, 2020
https://github.com/python/cpython/commit/00d7abd7ef588fc4ff0571c8579ab4aba8…
commit: 00d7abd7ef588fc4ff0571c8579ab4aba8ada1c0
branch: master
author: Victor Stinner <vstinner(a)python.org>
committer: vstinner <vstinner(a)python.org>
date: 2020-12-01T09:56:42+01:00
summary:
bpo-42519: Replace PyMem_MALLOC() with PyMem_Malloc() (GH-23586)
No longer use deprecated aliases to functions:
* Replace PyMem_MALLOC() with PyMem_Malloc()
* Replace PyMem_REALLOC() with PyMem_Realloc()
* Replace PyMem_FREE() with PyMem_Free()
* Replace PyMem_Del() with PyMem_Free()
* Replace PyMem_DEL() with PyMem_Free()
Modify also the PyMem_DEL() macro to use directly PyMem_Free().
files:
M Include/objimpl.h
M Include/pymem.h
M Modules/_localemodule.c
M Modules/_pickle.c
M Modules/_sre.c
M Modules/_ssl.c
M Modules/_struct.c
M Modules/_testcapimodule.c
M Modules/_threadmodule.c
M Modules/_tkinter.c
M Modules/arraymodule.c
M Modules/cjkcodecs/multibytecodec.c
M Modules/posixmodule.c
M Modules/selectmodule.c
M Objects/capsule.c
M Objects/codeobject.c
M Objects/dictobject.c
M Objects/listobject.c
M Objects/moduleobject.c
M Objects/odictobject.c
M Objects/setobject.c
M Objects/stringlib/join.h
M Objects/structseq.c
M Objects/typeobject.c
M Objects/unicodeobject.c
M PC/winreg.c
M Parser/string_parser.c
M Parser/tokenizer.c
M Python/bltinmodule.c
M Python/getargs.c
M Python/marshal.c
M Python/pystrtod.c
M Python/traceback.c
diff --git a/Include/objimpl.h b/Include/objimpl.h
index af537175bfed8..464b1bf93ba2c 100644
--- a/Include/objimpl.h
+++ b/Include/objimpl.h
@@ -102,7 +102,7 @@ PyAPI_FUNC(void *) PyObject_Realloc(void *ptr, size_t new_size);
PyAPI_FUNC(void) PyObject_Free(void *ptr);
-/* Macros */
+// Deprecated aliases only kept for backward compatibility.
#define PyObject_MALLOC PyObject_Malloc
#define PyObject_REALLOC PyObject_Realloc
#define PyObject_FREE PyObject_Free
@@ -138,8 +138,8 @@ PyAPI_FUNC(PyVarObject *) _PyObject_NewVar(PyTypeObject *, Py_ssize_t);
#define PyObject_NewVar(type, typeobj, n) \
( (type *) _PyObject_NewVar((typeobj), (n)) )
-// Alias to PyObject_New(). In Python 3.8, PyObject_NEW() called directly
-// PyObject_MALLOC() with _PyObject_VAR_SIZE().
+// Alias to PyObject_NewVar(). In Python 3.8, PyObject_NEW_VAR() called
+// directly PyObject_MALLOC() with _PyObject_VAR_SIZE().
#define PyObject_NEW_VAR(type, typeobj, n) PyObject_NewVar(type, typeobj, n)
diff --git a/Include/pymem.h b/Include/pymem.h
index 607feb9484f24..5b9dd4219948a 100644
--- a/Include/pymem.h
+++ b/Include/pymem.h
@@ -53,18 +53,6 @@ PyAPI_FUNC(void *) PyMem_Malloc(size_t size);
PyAPI_FUNC(void *) PyMem_Realloc(void *ptr, size_t new_size);
PyAPI_FUNC(void) PyMem_Free(void *ptr);
-/* Macros. */
-
-/* PyMem_MALLOC(0) means malloc(1). Some systems would return NULL
- for malloc(0), which would be treated as an error. Some platforms
- would return a pointer with no memory behind it, which would break
- pymalloc. To solve these problems, allocate an extra byte. */
-/* Returns NULL to indicate error if a negative size or size larger than
- Py_ssize_t can represent is supplied. Helps prevents security holes. */
-#define PyMem_MALLOC(n) PyMem_Malloc(n)
-#define PyMem_REALLOC(p, n) PyMem_Realloc(p, n)
-#define PyMem_FREE(p) PyMem_Free(p)
-
/*
* Type-oriented memory interface
* ==============================
@@ -78,9 +66,6 @@ PyAPI_FUNC(void) PyMem_Free(void *ptr);
#define PyMem_New(type, n) \
( ((size_t)(n) > PY_SSIZE_T_MAX / sizeof(type)) ? NULL : \
( (type *) PyMem_Malloc((n) * sizeof(type)) ) )
-#define PyMem_NEW(type, n) \
- ( ((size_t)(n) > PY_SSIZE_T_MAX / sizeof(type)) ? NULL : \
- ( (type *) PyMem_MALLOC((n) * sizeof(type)) ) )
/*
* The value of (p) is always clobbered by this macro regardless of success.
@@ -91,15 +76,16 @@ PyAPI_FUNC(void) PyMem_Free(void *ptr);
#define PyMem_Resize(p, type, n) \
( (p) = ((size_t)(n) > PY_SSIZE_T_MAX / sizeof(type)) ? NULL : \
(type *) PyMem_Realloc((p), (n) * sizeof(type)) )
-#define PyMem_RESIZE(p, type, n) \
- ( (p) = ((size_t)(n) > PY_SSIZE_T_MAX / sizeof(type)) ? NULL : \
- (type *) PyMem_REALLOC((p), (n) * sizeof(type)) )
-/* PyMem{Del,DEL} are left over from ancient days, and shouldn't be used
- * anymore. They're just confusing aliases for PyMem_{Free,FREE} now.
- */
-#define PyMem_Del PyMem_Free
-#define PyMem_DEL PyMem_FREE
+
+// Deprecated aliases only kept for backward compatibility.
+#define PyMem_MALLOC(n) PyMem_Malloc(n)
+#define PyMem_NEW(type, n) PyMem_New(type, n)
+#define PyMem_REALLOC(p, n) PyMem_Realloc(p, n)
+#define PyMem_RESIZE(p, type, n) PyMem_Resize(p, type, n)
+#define PyMem_FREE(p) PyMem_Free(p)
+#define PyMem_Del(p) PyMem_Free(p)
+#define PyMem_DEL(p) PyMem_Free(p)
#ifndef Py_LIMITED_API
diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c
index 869e3f80f3f9e..564f5598edcc6 100644
--- a/Modules/_localemodule.c
+++ b/Modules/_localemodule.c
@@ -370,8 +370,8 @@ _locale_strcoll_impl(PyObject *module, PyObject *os1, PyObject *os2)
result = PyLong_FromLong(wcscoll(ws1, ws2));
done:
/* Deallocate everything. */
- if (ws1) PyMem_FREE(ws1);
- if (ws2) PyMem_FREE(ws2);
+ if (ws1) PyMem_Free(ws1);
+ if (ws2) PyMem_Free(ws2);
return result;
}
#endif
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
index ed8afefe4c74c..7ecaeea18c611 100644
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -442,7 +442,7 @@ Pdata_dealloc(Pdata *self)
while (--i >= 0) {
Py_DECREF(self->data[i]);
}
- PyMem_FREE(self->data);
+ PyMem_Free(self->data);
PyObject_Del(self);
}
@@ -465,7 +465,7 @@ Pdata_New(void)
self->mark_set = 0;
self->fence = 0;
self->allocated = 8;
- self->data = PyMem_MALLOC(self->allocated * sizeof(PyObject *));
+ self->data = PyMem_Malloc(self->allocated * sizeof(PyObject *));
if (self->data)
return (PyObject *)self;
Py_DECREF(self);
@@ -726,7 +726,7 @@ static PyTypeObject Unpickler_Type;
static PyMemoTable *
PyMemoTable_New(void)
{
- PyMemoTable *memo = PyMem_MALLOC(sizeof(PyMemoTable));
+ PyMemoTable *memo = PyMem_Malloc(sizeof(PyMemoTable));
if (memo == NULL) {
PyErr_NoMemory();
return NULL;
@@ -735,9 +735,9 @@ PyMemoTable_New(void)
memo->mt_used = 0;
memo->mt_allocated = MT_MINSIZE;
memo->mt_mask = MT_MINSIZE - 1;
- memo->mt_table = PyMem_MALLOC(MT_MINSIZE * sizeof(PyMemoEntry));
+ memo->mt_table = PyMem_Malloc(MT_MINSIZE * sizeof(PyMemoEntry));
if (memo->mt_table == NULL) {
- PyMem_FREE(memo);
+ PyMem_Free(memo);
PyErr_NoMemory();
return NULL;
}
@@ -758,10 +758,10 @@ PyMemoTable_Copy(PyMemoTable *self)
new->mt_mask = self->mt_mask;
/* The table we get from _New() is probably smaller than we wanted.
Free it and allocate one that's the right size. */
- PyMem_FREE(new->mt_table);
+ PyMem_Free(new->mt_table);
new->mt_table = PyMem_NEW(PyMemoEntry, self->mt_allocated);
if (new->mt_table == NULL) {
- PyMem_FREE(new);
+ PyMem_Free(new);
PyErr_NoMemory();
return NULL;
}
@@ -800,8 +800,8 @@ PyMemoTable_Del(PyMemoTable *self)
return;
PyMemoTable_Clear(self);
- PyMem_FREE(self->mt_table);
- PyMem_FREE(self);
+ PyMem_Free(self->mt_table);
+ PyMem_Free(self);
}
/* Since entries cannot be deleted from this hashtable, _PyMemoTable_Lookup()
@@ -880,7 +880,7 @@ _PyMemoTable_ResizeTable(PyMemoTable *self, size_t min_size)
}
/* Deallocate the old table. */
- PyMem_FREE(oldtable);
+ PyMem_Free(oldtable);
return 0;
}
@@ -1582,7 +1582,7 @@ _Unpickler_MemoCleanup(UnpicklerObject *self)
while (--i >= 0) {
Py_XDECREF(memo[i]);
}
- PyMem_FREE(memo);
+ PyMem_Free(memo);
}
static UnpicklerObject *
@@ -7544,7 +7544,7 @@ Unpickler_set_memo(UnpicklerObject *self, PyObject *obj, void *Py_UNUSED(ignored
for (size_t i = new_memo_size - 1; i != SIZE_MAX; i--) {
Py_XDECREF(new_memo[i]);
}
- PyMem_FREE(new_memo);
+ PyMem_Free(new_memo);
}
return -1;
}
diff --git a/Modules/_sre.c b/Modules/_sre.c
index 0a5ca60097af3..c67f38d75b809 100644
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -197,7 +197,7 @@ static void
data_stack_dealloc(SRE_STATE* state)
{
if (state->data_stack) {
- PyMem_FREE(state->data_stack);
+ PyMem_Free(state->data_stack);
state->data_stack = NULL;
}
state->data_stack_size = state->data_stack_base = 0;
@@ -213,7 +213,7 @@ data_stack_grow(SRE_STATE* state, Py_ssize_t size)
void* stack;
cursize = minsize+minsize/4+1024;
TRACE(("allocate/grow stack %zd\n", cursize));
- stack = PyMem_REALLOC(state->data_stack, cursize);
+ stack = PyMem_Realloc(state->data_stack, cursize);
if (!stack) {
data_stack_dealloc(state);
return SRE_ERROR_MEMORY;
@@ -472,7 +472,7 @@ state_init(SRE_STATE* state, PatternObject* pattern, PyObject* string,
/* We add an explicit cast here because MSVC has a bug when
compiling C code where it believes that `const void**` cannot be
safely casted to `void*`, see bpo-39943 for details. */
- PyMem_Del((void*) state->mark);
+ PyMem_Free((void*) state->mark);
state->mark = NULL;
if (state->buffer.buf)
PyBuffer_Release(&state->buffer);
@@ -487,7 +487,7 @@ state_fini(SRE_STATE* state)
Py_XDECREF(state->string);
data_stack_dealloc(state);
/* See above PyMem_Del for why we explicitly cast here. */
- PyMem_Del((void*) state->mark);
+ PyMem_Free((void*) state->mark);
state->mark = NULL;
}
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
index 6f799ee661852..87fe3a16078fa 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -3306,10 +3306,10 @@ context_dealloc(PySSLContext *self)
context_clear(self);
SSL_CTX_free(self->ctx);
#if HAVE_NPN
- PyMem_FREE(self->npn_protocols);
+ PyMem_Free(self->npn_protocols);
#endif
#if HAVE_ALPN
- PyMem_FREE(self->alpn_protocols);
+ PyMem_Free(self->alpn_protocols);
#endif
Py_TYPE(self)->tp_free(self);
Py_DECREF(tp);
@@ -3510,7 +3510,7 @@ _ssl__SSLContext__set_alpn_protocols_impl(PySSLContext *self,
return NULL;
}
- PyMem_FREE(self->alpn_protocols);
+ PyMem_Free(self->alpn_protocols);
self->alpn_protocols = PyMem_Malloc(protos->len);
if (!self->alpn_protocols)
return PyErr_NoMemory();
diff --git a/Modules/_struct.c b/Modules/_struct.c
index eeccc17965468..c95c76f8ae039 100644
--- a/Modules/_struct.c
+++ b/Modules/_struct.c
@@ -1373,14 +1373,14 @@ prepare_s(PyStructObject *self)
self->s_size = size;
self->s_len = len;
- codes = PyMem_MALLOC((ncodes + 1) * sizeof(formatcode));
+ codes = PyMem_Malloc((ncodes + 1) * sizeof(formatcode));
if (codes == NULL) {
PyErr_NoMemory();
return -1;
}
/* Free any s_codes value left over from a previous initialization. */
if (self->s_codes != NULL)
- PyMem_FREE(self->s_codes);
+ PyMem_Free(self->s_codes);
self->s_codes = codes;
s = fmt;
@@ -1502,7 +1502,7 @@ s_dealloc(PyStructObject *s)
if (s->weakreflist != NULL)
PyObject_ClearWeakRefs((PyObject *)s);
if (s->s_codes != NULL) {
- PyMem_FREE(s->s_codes);
+ PyMem_Free(s->s_codes);
}
Py_XDECREF(s->s_format);
freefunc free_func = PyType_GetSlot(Py_TYPE(s), Py_tp_free);
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index a1d4c929b0205..916d10a1e413b 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -1988,12 +1988,12 @@ unicode_asucs4(PyObject *self, PyObject *args)
buffer[str_len] = 0xffffU;
if (!PyUnicode_AsUCS4(unicode, buffer, buf_len, copy_null)) {
- PyMem_FREE(buffer);
+ PyMem_Free(buffer);
return NULL;
}
result = PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND, buffer, buf_len);
- PyMem_FREE(buffer);
+ PyMem_Free(buffer);
return result;
}
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
index 56ed8a2e2d3f1..dcefa8dbaa91b 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -1056,7 +1056,7 @@ t_bootstrap(void *boot_raw)
Py_DECREF(boot->func);
Py_DECREF(boot->args);
Py_XDECREF(boot->keyw);
- PyMem_DEL(boot_raw);
+ PyMem_Free(boot_raw);
tstate->interp->num_threads--;
PyThreadState_Clear(tstate);
_PyThreadState_DeleteCurrent(tstate);
@@ -1107,7 +1107,7 @@ thread_PyThread_start_new_thread(PyObject *self, PyObject *fargs)
boot->tstate = _PyThreadState_Prealloc(boot->interp);
boot->runtime = runtime;
if (boot->tstate == NULL) {
- PyMem_DEL(boot);
+ PyMem_Free(boot);
return PyErr_NoMemory();
}
Py_INCREF(func);
@@ -1121,7 +1121,7 @@ thread_PyThread_start_new_thread(PyObject *self, PyObject *fargs)
Py_DECREF(args);
Py_XDECREF(keyw);
PyThreadState_Clear(boot->tstate);
- PyMem_DEL(boot);
+ PyMem_Free(boot);
return NULL;
}
return PyLong_FromUnsignedLong(ident);
diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c
index b30141d4497bd..24aeb3da94c70 100644
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -2472,7 +2472,7 @@ PythonCmdDelete(ClientData clientData)
ENTER_PYTHON
Py_XDECREF(data->self);
Py_XDECREF(data->func);
- PyMem_DEL(data);
+ PyMem_Free(data);
LEAVE_PYTHON
}
@@ -2545,7 +2545,7 @@ _tkinter_tkapp_createcommand_impl(TkappObject *self, const char *name,
CommandEvent *ev = (CommandEvent*)attemptckalloc(sizeof(CommandEvent));
if (ev == NULL) {
PyErr_NoMemory();
- PyMem_DEL(data);
+ PyMem_Free(data);
return NULL;
}
ev->ev.proc = (Tcl_EventProc*)Tkapp_CommandProc;
@@ -2568,7 +2568,7 @@ _tkinter_tkapp_createcommand_impl(TkappObject *self, const char *name,
}
if (err) {
PyErr_SetString(Tkinter_TclError, "can't create Tcl command");
- PyMem_DEL(data);
+ PyMem_Free(data);
return NULL;
}
@@ -2666,7 +2666,7 @@ DeleteFHCD(int id)
*pp = p->next;
Py_XDECREF(p->func);
Py_XDECREF(p->file);
- PyMem_DEL(p);
+ PyMem_Free(p);
}
else
pp = &p->next;
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index 2ba2ff43aa8b8..6583e66611959 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -133,7 +133,7 @@ array_resize(arrayobject *self, Py_ssize_t newsize)
}
if (newsize == 0) {
- PyMem_FREE(self->ob_item);
+ PyMem_Free(self->ob_item);
self->ob_item = NULL;
Py_SET_SIZE(self, 0);
self->allocated = 0;
@@ -652,7 +652,7 @@ array_dealloc(arrayobject *op)
if (op->weakreflist != NULL)
PyObject_ClearWeakRefs((PyObject *) op);
if (op->ob_item != NULL)
- PyMem_DEL(op->ob_item);
+ PyMem_Free(op->ob_item);
Py_TYPE(op)->tp_free((PyObject *)op);
}
diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c
index 86402768b6ee6..37a80a781da6f 100644
--- a/Modules/cjkcodecs/multibytecodec.c
+++ b/Modules/cjkcodecs/multibytecodec.c
@@ -1191,13 +1191,13 @@ _multibytecodec_MultibyteIncrementalDecoder_decode_impl(MultibyteIncrementalDeco
goto errorexit;
if (wdata != data)
- PyMem_Del(wdata);
+ PyMem_Free(wdata);
Py_XDECREF(buf.excobj);
return res;
errorexit:
if (wdata != NULL && wdata != data)
- PyMem_Del(wdata);
+ PyMem_Free(wdata);
Py_XDECREF(buf.excobj);
_PyUnicodeWriter_Dealloc(&buf.writer);
return NULL;
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index efa96531d49c1..3e6e6585b880c 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -5480,7 +5480,7 @@ free_string_array(EXECV_CHAR **array, Py_ssize_t count)
Py_ssize_t i;
for (i = 0; i < count; i++)
PyMem_Free(array[i]);
- PyMem_DEL(array);
+ PyMem_Free(array);
}
static int
@@ -6510,9 +6510,10 @@ os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
res = Py_BuildValue(_Py_PARSE_INTPTR, spawnval);
fail_2:
- while (--envc >= 0)
- PyMem_DEL(envlist[envc]);
- PyMem_DEL(envlist);
+ while (--envc >= 0) {
+ PyMem_Free(envlist[envc]);
+ }
+ PyMem_Free(envlist);
fail_1:
free_string_array(argvlist, lastarg);
fail_0:
@@ -7444,7 +7445,7 @@ os_getgrouplist_impl(PyObject *module, const char *user, gid_t basegid)
list = PyList_New(ngroups);
if (list == NULL) {
- PyMem_Del(groups);
+ PyMem_Free(groups);
return NULL;
}
@@ -7456,13 +7457,13 @@ os_getgrouplist_impl(PyObject *module, const char *user, gid_t basegid)
#endif
if (o == NULL) {
Py_DECREF(list);
- PyMem_Del(groups);
+ PyMem_Free(groups);
return NULL;
}
PyList_SET_ITEM(list, i, o);
}
- PyMem_Del(groups);
+ PyMem_Free(groups);
return list;
}
@@ -9407,7 +9408,7 @@ iov_setup(struct iovec **iov, Py_buffer **buf, PyObject *seq, Py_ssize_t cnt, in
*buf = PyMem_New(Py_buffer, cnt);
if (*buf == NULL) {
- PyMem_Del(*iov);
+ PyMem_Free(*iov);
PyErr_NoMemory();
return -1;
}
@@ -9427,11 +9428,11 @@ iov_setup(struct iovec **iov, Py_buffer **buf, PyObject *seq, Py_ssize_t cnt, in
return 0;
fail:
- PyMem_Del(*iov);
+ PyMem_Free(*iov);
for (j = 0; j < i; j++) {
PyBuffer_Release(&(*buf)[j]);
}
- PyMem_Del(*buf);
+ PyMem_Free(*buf);
return -1;
}
@@ -9439,11 +9440,11 @@ static void
iov_cleanup(struct iovec *iov, Py_buffer *buf, int cnt)
{
int i;
- PyMem_Del(iov);
+ PyMem_Free(iov);
for (i = 0; i < cnt; i++) {
PyBuffer_Release(&buf[i]);
}
- PyMem_Del(buf);
+ PyMem_Free(buf);
}
#endif
@@ -12815,7 +12816,7 @@ os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks)
path_error(path);
break;
}
- buffer = PyMem_MALLOC(buffer_size);
+ buffer = PyMem_Malloc(buffer_size);
if (!buffer) {
PyErr_NoMemory();
break;
@@ -12832,7 +12833,7 @@ os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks)
if (length < 0) {
if (errno == ERANGE) {
- PyMem_FREE(buffer);
+ PyMem_Free(buffer);
buffer = NULL;
continue;
}
@@ -12870,7 +12871,7 @@ os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks)
}
exit:
if (buffer)
- PyMem_FREE(buffer);
+ PyMem_Free(buffer);
return result;
}
#endif /* USE_XATTRS */
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c
index 693a833caea77..0b9f20d6bbd9d 100644
--- a/Modules/selectmodule.c
+++ b/Modules/selectmodule.c
@@ -294,9 +294,9 @@ select_select_impl(PyObject *module, PyObject *rlist, PyObject *wlist,
wfd2obj = PyMem_NEW(pylist, FD_SETSIZE + 1);
efd2obj = PyMem_NEW(pylist, FD_SETSIZE + 1);
if (rfd2obj == NULL || wfd2obj == NULL || efd2obj == NULL) {
- if (rfd2obj) PyMem_DEL(rfd2obj);
- if (wfd2obj) PyMem_DEL(wfd2obj);
- if (efd2obj) PyMem_DEL(efd2obj);
+ if (rfd2obj) PyMem_Free(rfd2obj);
+ if (wfd2obj) PyMem_Free(wfd2obj);
+ if (efd2obj) PyMem_Free(efd2obj);
return PyErr_NoMemory();
}
#endif /* SELECT_USES_HEAP */
@@ -381,9 +381,9 @@ select_select_impl(PyObject *module, PyObject *rlist, PyObject *wlist,
reap_obj(wfd2obj);
reap_obj(efd2obj);
#ifdef SELECT_USES_HEAP
- PyMem_DEL(rfd2obj);
- PyMem_DEL(wfd2obj);
- PyMem_DEL(efd2obj);
+ PyMem_Free(rfd2obj);
+ PyMem_Free(wfd2obj);
+ PyMem_Free(efd2obj);
#endif /* SELECT_USES_HEAP */
return ret;
}
@@ -740,7 +740,7 @@ poll_dealloc(pollObject *self)
{
PyObject* type = (PyObject *)Py_TYPE(self);
if (self->ufds != NULL)
- PyMem_DEL(self->ufds);
+ PyMem_Free(self->ufds);
Py_XDECREF(self->dict);
PyObject_Del(self);
Py_DECREF(type);
@@ -1106,7 +1106,7 @@ newDevPollObject(PyObject *module)
self = PyObject_New(devpollObject, get_select_state(module)->devpoll_Type);
if (self == NULL) {
close(fd_devpoll);
- PyMem_DEL(fds);
+ PyMem_Free(fds);
return NULL;
}
self->fd_devpoll = fd_devpoll;
@@ -1129,7 +1129,7 @@ devpoll_dealloc(devpollObject *self)
{
PyObject *type = (PyObject *)Py_TYPE(self);
(void)devpoll_internal_close(self);
- PyMem_DEL(self->fds);
+ PyMem_Free(self->fds);
PyObject_Del(self);
Py_DECREF(type);
}
diff --git a/Objects/capsule.c b/Objects/capsule.c
index ed24cc1d6a2eb..a2ff642526cd0 100644
--- a/Objects/capsule.c
+++ b/Objects/capsule.c
@@ -198,7 +198,7 @@ PyCapsule_Import(const char *name, int no_block)
void *return_value = NULL;
char *trace;
size_t name_length = (strlen(name) + 1) * sizeof(char);
- char *name_dup = (char *)PyMem_MALLOC(name_length);
+ char *name_dup = (char *)PyMem_Malloc(name_length);
if (!name_dup) {
return PyErr_NoMemory();
@@ -247,7 +247,7 @@ PyCapsule_Import(const char *name, int no_block)
EXIT:
Py_XDECREF(object);
if (name_dup) {
- PyMem_FREE(name_dup);
+ PyMem_Free(name_dup);
}
return return_value;
}
diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index 7b224cc145e47..0257295f1e996 100644
--- a/Objects/codeobject.c
+++ b/Objects/codeobject.c
@@ -213,7 +213,7 @@ PyCode_NewWithPosOnlyArgs(int argcount, int posonlyargcount, int kwonlyargcount,
PyObject *arg = PyTuple_GET_ITEM(varnames, j);
int cmp = PyUnicode_Compare(cell, arg);
if (cmp == -1 && PyErr_Occurred()) {
- PyMem_FREE(cell2arg);
+ PyMem_Free(cell2arg);
return NULL;
}
if (cmp == 0) {
@@ -224,14 +224,14 @@ PyCode_NewWithPosOnlyArgs(int argcount, int posonlyargcount, int kwonlyargcount,
}
}
if (!used_cell2arg) {
- PyMem_FREE(cell2arg);
+ PyMem_Free(cell2arg);
cell2arg = NULL;
}
}
co = PyObject_New(PyCodeObject, &PyCode_Type);
if (co == NULL) {
if (cell2arg)
- PyMem_FREE(cell2arg);
+ PyMem_Free(cell2arg);
return NULL;
}
co->co_argcount = argcount;
@@ -314,12 +314,12 @@ _PyCode_InitOpcache(PyCodeObject *co)
if (opts) {
co->co_opcache = (_PyOpcache *)PyMem_Calloc(opts, sizeof(_PyOpcache));
if (co->co_opcache == NULL) {
- PyMem_FREE(co->co_opcache_map);
+ PyMem_Free(co->co_opcache_map);
return -1;
}
}
else {
- PyMem_FREE(co->co_opcache_map);
+ PyMem_Free(co->co_opcache_map);
co->co_opcache_map = NULL;
co->co_opcache = NULL;
}
@@ -631,10 +631,10 @@ static void
code_dealloc(PyCodeObject *co)
{
if (co->co_opcache != NULL) {
- PyMem_FREE(co->co_opcache);
+ PyMem_Free(co->co_opcache);
}
if (co->co_opcache_map != NULL) {
- PyMem_FREE(co->co_opcache_map);
+ PyMem_Free(co->co_opcache_map);
}
co->co_opcache_flag = 0;
co->co_opcache_size = 0;
@@ -664,7 +664,7 @@ code_dealloc(PyCodeObject *co)
Py_XDECREF(co->co_name);
Py_XDECREF(co->co_linetable);
if (co->co_cell2arg != NULL)
- PyMem_FREE(co->co_cell2arg);
+ PyMem_Free(co->co_cell2arg);
if (co->co_zombieframe != NULL)
PyObject_GC_Del(co->co_zombieframe);
if (co->co_weakreflist != NULL)
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index faa8696153cb8..ee1a9d1d7e71e 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -640,7 +640,7 @@ free_keys_object(PyDictKeysObject *keys)
}
#define new_values(size) PyMem_NEW(PyObject *, size)
-#define free_values(values) PyMem_FREE(values)
+#define free_values(values) PyMem_Free(values)
/* Consumes a reference to the keys object */
static PyObject *
diff --git a/Objects/listobject.c b/Objects/listobject.c
index aac87ea1b61c9..ca9df599a0bd4 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -341,7 +341,7 @@ list_dealloc(PyListObject *op)
while (--i >= 0) {
Py_XDECREF(op->ob_item[i]);
}
- PyMem_FREE(op->ob_item);
+ PyMem_Free(op->ob_item);
}
struct _Py_list_state *state = get_list_state();
#ifdef Py_DEBUG
@@ -592,7 +592,7 @@ _list_clear(PyListObject *a)
while (--i >= 0) {
Py_XDECREF(item[i]);
}
- PyMem_FREE(item);
+ PyMem_Free(item);
}
/* Never fails; the return value can be ignored.
Note that there is no guarantee that the list is actually empty
@@ -668,7 +668,7 @@ list_ass_slice(PyListObject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v)
/* If norig == 0, item might be NULL, in which case we may not memcpy from it. */
if (s) {
if (s > sizeof(recycle_on_stack)) {
- recycle = (PyObject **)PyMem_MALLOC(s);
+ recycle = (PyObject **)PyMem_Malloc(s);
if (recycle == NULL) {
PyErr_NoMemory();
goto Error;
@@ -706,7 +706,7 @@ list_ass_slice(PyListObject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v)
result = 0;
Error:
if (recycle != recycle_on_stack)
- PyMem_FREE(recycle);
+ PyMem_Free(recycle);
Py_XDECREF(v_as_SF);
return result;
#undef b
@@ -2230,7 +2230,7 @@ list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse)
/* Leverage stack space we allocated but won't otherwise use */
keys = &ms.temparray[saved_ob_size+1];
else {
- keys = PyMem_MALLOC(sizeof(PyObject *) * saved_ob_size);
+ keys = PyMem_Malloc(sizeof(PyObject *) * saved_ob_size);
if (keys == NULL) {
PyErr_NoMemory();
goto keyfunc_fail;
@@ -2243,7 +2243,7 @@ list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse)
for (i=i-1 ; i>=0 ; i--)
Py_DECREF(keys[i]);
if (saved_ob_size >= MERGESTATE_TEMP_SIZE/2)
- PyMem_FREE(keys);
+ PyMem_Free(keys);
goto keyfunc_fail;
}
}
@@ -2414,7 +2414,7 @@ list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse)
for (i = 0; i < saved_ob_size; i++)
Py_DECREF(keys[i]);
if (saved_ob_size >= MERGESTATE_TEMP_SIZE/2)
- PyMem_FREE(keys);
+ PyMem_Free(keys);
}
if (self->allocated != -1 && result != NULL) {
@@ -2442,7 +2442,7 @@ list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse)
while (--i >= 0) {
Py_XDECREF(final_ob_item[i]);
}
- PyMem_FREE(final_ob_item);
+ PyMem_Free(final_ob_item);
}
Py_XINCREF(result);
return result;
@@ -2908,7 +2908,7 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value)
}
garbage = (PyObject**)
- PyMem_MALLOC(slicelength*sizeof(PyObject*));
+ PyMem_Malloc(slicelength*sizeof(PyObject*));
if (!garbage) {
PyErr_NoMemory();
return -1;
@@ -2949,7 +2949,7 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value)
for (i = 0; i < slicelength; i++) {
Py_DECREF(garbage[i]);
}
- PyMem_FREE(garbage);
+ PyMem_Free(garbage);
return res;
}
@@ -2990,7 +2990,7 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value)
}
garbage = (PyObject**)
- PyMem_MALLOC(slicelength*sizeof(PyObject*));
+ PyMem_Malloc(slicelength*sizeof(PyObject*));
if (!garbage) {
Py_DECREF(seq);
PyErr_NoMemory();
@@ -3011,7 +3011,7 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value)
Py_DECREF(garbage[i]);
}
- PyMem_FREE(garbage);
+ PyMem_Free(garbage);
Py_DECREF(seq);
return 0;
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c
index c3ceb788e8e69..6590387dac531 100644
--- a/Objects/moduleobject.c
+++ b/Objects/moduleobject.c
@@ -211,7 +211,7 @@ _PyModule_CreateInitialized(struct PyModuleDef* module, int module_api_version)
return NULL;
if (module->m_size > 0) {
- m->md_state = PyMem_MALLOC(module->m_size);
+ m->md_state = PyMem_Malloc(module->m_size);
if (!m->md_state) {
PyErr_NoMemory();
Py_DECREF(m);
@@ -377,7 +377,7 @@ PyModule_ExecDef(PyObject *module, PyModuleDef *def)
if (md->md_state == NULL) {
/* Always set a state pointer; this serves as a marker to skip
* multiple initialization (importlib.reload() is no-op) */
- md->md_state = PyMem_MALLOC(def->m_size);
+ md->md_state = PyMem_Malloc(def->m_size);
if (!md->md_state) {
PyErr_NoMemory();
return -1;
@@ -681,7 +681,7 @@ module_dealloc(PyModuleObject *m)
Py_XDECREF(m->md_dict);
Py_XDECREF(m->md_name);
if (m->md_state != NULL)
- PyMem_FREE(m->md_state);
+ PyMem_Free(m->md_state);
Py_TYPE(m)->tp_free((PyObject *)m);
}
diff --git a/Objects/odictobject.c b/Objects/odictobject.c
index b4ac560d23581..83b326b2067a8 100644
--- a/Objects/odictobject.c
+++ b/Objects/odictobject.c
@@ -567,14 +567,14 @@ _odict_resize(PyODictObject *od)
i = _odict_get_index_raw(od, _odictnode_KEY(node),
_odictnode_HASH(node));
if (i < 0) {
- PyMem_FREE(fast_nodes);
+ PyMem_Free(fast_nodes);
return -1;
}
fast_nodes[i] = node;
}
/* Replace the old fast nodes table. */
- PyMem_FREE(od->od_fast_nodes);
+ PyMem_Free(od->od_fast_nodes);
od->od_fast_nodes = fast_nodes;
od->od_fast_nodes_size = size;
od->od_resize_sentinel = ((PyDictObject *)od)->ma_keys;
@@ -683,7 +683,7 @@ _odict_add_new_node(PyODictObject *od, PyObject *key, Py_hash_t hash)
}
/* must not be added yet */
- node = (_ODictNode *)PyMem_MALLOC(sizeof(_ODictNode));
+ node = (_ODictNode *)PyMem_Malloc(sizeof(_ODictNode));
if (node == NULL) {
Py_DECREF(key);
PyErr_NoMemory();
@@ -701,7 +701,7 @@ _odict_add_new_node(PyODictObject *od, PyObject *key, Py_hash_t hash)
#define _odictnode_DEALLOC(node) \
do { \
Py_DECREF(_odictnode_KEY(node)); \
- PyMem_FREE((void *)node); \
+ PyMem_Free((void *)node); \
} while (0)
/* Repeated calls on the same node are no-ops. */
@@ -776,7 +776,7 @@ _odict_clear_nodes(PyODictObject *od)
{
_ODictNode *node, *next;
- PyMem_FREE(od->od_fast_nodes);
+ PyMem_Free(od->od_fast_nodes);
od->od_fast_nodes = NULL;
od->od_fast_nodes_size = 0;
od->od_resize_sentinel = NULL;
diff --git a/Objects/setobject.c b/Objects/setobject.c
index af8ee03d831d6..79e84511926e1 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -289,7 +289,7 @@ set_table_resize(PySetObject *so, Py_ssize_t minused)
}
if (is_oldtable_malloced)
- PyMem_DEL(oldtable);
+ PyMem_Free(oldtable);
return 0;
}
@@ -424,7 +424,7 @@ set_clear_internal(PySetObject *so)
}
if (table_is_malloced)
- PyMem_DEL(table);
+ PyMem_Free(table);
return 0;
}
@@ -484,7 +484,7 @@ set_dealloc(PySetObject *so)
}
}
if (so->table != so->smalltable)
- PyMem_DEL(so->table);
+ PyMem_Free(so->table);
Py_TYPE(so)->tp_free(so);
Py_TRASHCAN_END
}
diff --git a/Objects/stringlib/join.h b/Objects/stringlib/join.h
index 53bcbdea7ade9..62e4c98de7f25 100644
--- a/Objects/stringlib/join.h
+++ b/Objects/stringlib/join.h
@@ -155,7 +155,7 @@ STRINGLIB(bytes_join)(PyObject *sep, PyObject *iterable)
for (i = 0; i < nbufs; i++)
PyBuffer_Release(&buffers[i]);
if (buffers != static_buffers)
- PyMem_FREE(buffers);
+ PyMem_Free(buffers);
return res;
}
diff --git a/Objects/structseq.c b/Objects/structseq.c
index bb28e113978b3..5d71fcff3461a 100644
--- a/Objects/structseq.c
+++ b/Objects/structseq.c
@@ -467,14 +467,14 @@ PyStructSequence_InitType2(PyTypeObject *type, PyStructSequence_Desc *desc)
type->tp_members = members;
if (PyType_Ready(type) < 0) {
- PyMem_FREE(members);
+ PyMem_Free(members);
return -1;
}
Py_INCREF(type);
if (initialize_structseq_dict(
desc, type->tp_dict, n_members, n_unnamed_members) < 0) {
- PyMem_FREE(members);
+ PyMem_Free(members);
Py_DECREF(type);
return -1;
}
@@ -526,7 +526,7 @@ PyStructSequence_NewType(PyStructSequence_Desc *desc)
spec.slots = slots;
type = (PyTypeObject *)PyType_FromSpecWithBases(&spec, (PyObject *)&PyTuple_Type);
- PyMem_FREE(members);
+ PyMem_Free(members);
if (type == NULL) {
return NULL;
}
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 3a6143a8ad613..fbadd31f1a46c 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -1779,7 +1779,7 @@ pmerge(PyObject *acc, PyObject **to_merge, Py_ssize_t to_merge_size)
}
out:
- PyMem_Del(remain);
+ PyMem_Free(remain);
return res;
}
@@ -1859,7 +1859,7 @@ mro_implementation(PyTypeObject *type)
result = PyList_New(1);
if (result == NULL) {
- PyMem_Del(to_merge);
+ PyMem_Free(to_merge);
return NULL;
}
@@ -1869,7 +1869,7 @@ mro_implementation(PyTypeObject *type)
Py_CLEAR(result);
}
- PyMem_Del(to_merge);
+ PyMem_Free(to_merge);
return result;
}
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 70688c8c01381..ba6d07a67d2da 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -3298,7 +3298,7 @@ PyUnicode_AsWideCharString(PyObject *unicode,
*size = buflen;
}
else if (wcslen(buffer) != (size_t)buflen) {
- PyMem_FREE(buffer);
+ PyMem_Free(buffer);
PyErr_SetString(PyExc_ValueError,
"embedded null character");
return NULL;
@@ -10211,7 +10211,7 @@ case_operation(PyObject *self,
PyErr_SetString(PyExc_OverflowError, "string is too long");
return NULL;
}
- tmp = PyMem_MALLOC(sizeof(Py_UCS4) * 3 * length);
+ tmp = PyMem_Malloc(sizeof(Py_UCS4) * 3 * length);
if (tmp == NULL)
return PyErr_NoMemory();
newlength = perform(kind, data, length, tmp, &maxchar);
@@ -10235,7 +10235,7 @@ case_operation(PyObject *self,
Py_UNREACHABLE();
}
leave:
- PyMem_FREE(tmp);
+ PyMem_Free(tmp);
return res;
}
@@ -11050,11 +11050,11 @@ replace(PyObject *self, PyObject *str1,
assert(release1 == (buf1 != PyUnicode_DATA(str1)));
assert(release2 == (buf2 != PyUnicode_DATA(str2)));
if (srelease)
- PyMem_FREE((void *)sbuf);
+ PyMem_Free((void *)sbuf);
if (release1)
- PyMem_FREE((void *)buf1);
+ PyMem_Free((void *)buf1);
if (release2)
- PyMem_FREE((void *)buf2);
+ PyMem_Free((void *)buf2);
assert(_PyUnicode_CheckConsistency(u, 1));
return u;
@@ -11064,11 +11064,11 @@ replace(PyObject *self, PyObject *str1,
assert(release1 == (buf1 != PyUnicode_DATA(str1)));
assert(release2 == (buf2 != PyUnicode_DATA(str2)));
if (srelease)
- PyMem_FREE((void *)sbuf);
+ PyMem_Free((void *)sbuf);
if (release1)
- PyMem_FREE((void *)buf1);
+ PyMem_Free((void *)buf1);
if (release2)
- PyMem_FREE((void *)buf2);
+ PyMem_Free((void *)buf2);
return unicode_result_unchanged(self);
error:
@@ -11076,11 +11076,11 @@ replace(PyObject *self, PyObject *str1,
assert(release1 == (buf1 != PyUnicode_DATA(str1)));
assert(release2 == (buf2 != PyUnicode_DATA(str2)));
if (srelease)
- PyMem_FREE((void *)sbuf);
+ PyMem_Free((void *)sbuf);
if (release1)
- PyMem_FREE((void *)buf1);
+ PyMem_Free((void *)buf1);
if (release2)
- PyMem_FREE((void *)buf2);
+ PyMem_Free((void *)buf2);
return NULL;
}
diff --git a/PC/winreg.c b/PC/winreg.c
index 78c08693a8ace..fee51ac1bbe0a 100644
--- a/PC/winreg.c
+++ b/PC/winreg.c
@@ -1818,7 +1818,7 @@ winreg_SetValueEx_impl(PyObject *module, HKEY key,
Py_BEGIN_ALLOW_THREADS
rc = RegSetValueExW(key, value_name, 0, type, data, len);
Py_END_ALLOW_THREADS
- PyMem_DEL(data);
+ PyMem_Free(data);
if (rc != ERROR_SUCCESS)
return PyErr_SetFromWindowsErrWithFunction(rc,
"RegSetValueEx");
diff --git a/Parser/string_parser.c b/Parser/string_parser.c
index 8f6433dbcec13..09b8c35106e76 100644
--- a/Parser/string_parser.c
+++ b/Parser/string_parser.c
@@ -384,7 +384,7 @@ fstring_compile_expr(Parser *p, const char *expr_start, const char *expr_end,
int lines, cols;
if (!fstring_find_expr_location(t, str, &lines, &cols)) {
- PyMem_FREE(str);
+ PyMem_Free(str);
return NULL;
}
diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c
index f3c1d9b20ade1..96539bd556529 100644
--- a/Parser/tokenizer.c
+++ b/Parser/tokenizer.c
@@ -51,7 +51,7 @@ static const char* type_comment_prefix = "# type: ";
static struct tok_state *
tok_new(void)
{
- struct tok_state *tok = (struct tok_state *)PyMem_MALLOC(
+ struct tok_state *tok = (struct tok_state *)PyMem_Malloc(
sizeof(struct tok_state));
if (tok == NULL)
return NULL;
@@ -93,7 +93,7 @@ tok_new(void)
static char *
new_string(const char *s, Py_ssize_t len, struct tok_state *tok)
{
- char* result = (char *)PyMem_MALLOC(len + 1);
+ char* result = (char *)PyMem_Malloc(len + 1);
if (!result) {
tok->done = E_NOMEM;
return NULL;
@@ -108,7 +108,7 @@ error_ret(struct tok_state *tok) /* XXX */
{
tok->decoding_erred = 1;
if (tok->fp != NULL && tok->buf != NULL) /* see PyTokenizer_Free */
- PyMem_FREE(tok->buf);
+ PyMem_Free(tok->buf);
tok->buf = tok->cur = tok->inp = NULL;
tok->start = NULL;
tok->end = NULL;
@@ -184,7 +184,7 @@ get_coding_spec(const char *s, char **spec, Py_ssize_t size, struct tok_state *t
return 0;
q = get_normal_name(r);
if (r != q) {
- PyMem_FREE(r);
+ PyMem_Free(r);
r = new_string(q, strlen(q), tok);
if (!r)
return 0;
@@ -244,7 +244,7 @@ check_coding_spec(const char* line, Py_ssize_t size, struct tok_state *tok,
else {
PyErr_Format(PyExc_SyntaxError,
"encoding problem: %s", cs);
- PyMem_FREE(cs);
+ PyMem_Free(cs);
}
}
} else { /* then, compare cs with BOM */
@@ -252,7 +252,7 @@ check_coding_spec(const char* line, Py_ssize_t size, struct tok_state *tok,
if (!r)
PyErr_Format(PyExc_SyntaxError,
"encoding problem: %s with BOM", cs);
- PyMem_FREE(cs);
+ PyMem_Free(cs);
}
return r;
}
@@ -315,7 +315,7 @@ check_bom(int get_char(struct tok_state *),
return 1;
}
if (tok->encoding != NULL)
- PyMem_FREE(tok->encoding);
+ PyMem_Free(tok->encoding);
tok->encoding = new_string("utf-8", 5, tok);
if (!tok->encoding)
return 0;
@@ -620,7 +620,7 @@ translate_newlines(const char *s, int exec_input, struct tok_state *tok) {
size_t needed_length = strlen(s) + 2, final_length;
char *buf, *current;
char c = '\0';
- buf = PyMem_MALLOC(needed_length);
+ buf = PyMem_Malloc(needed_length);
if (buf == NULL) {
tok->done = E_NOMEM;
return NULL;
@@ -651,9 +651,9 @@ translate_newlines(const char *s, int exec_input, struct tok_state *tok) {
final_length = current - buf + 1;
if (final_length < needed_length && final_length) {
/* should never fail */
- char* result = PyMem_REALLOC(buf, final_length);
+ char* result = PyMem_Realloc(buf, final_length);
if (result == NULL) {
- PyMem_FREE(buf);
+ PyMem_Free(buf);
}
buf = result;
}
@@ -757,7 +757,7 @@ PyTokenizer_FromUTF8(const char *str, int exec_input)
tok->read_coding_spec = 1;
tok->enc = NULL;
tok->str = translated;
- tok->encoding = (char *)PyMem_MALLOC(6);
+ tok->encoding = (char *)PyMem_Malloc(6);
if (!tok->encoding) {
PyTokenizer_Free(tok);
return NULL;
@@ -778,7 +778,7 @@ PyTokenizer_FromFile(FILE *fp, const char* enc,
struct tok_state *tok = tok_new();
if (tok == NULL)
return NULL;
- if ((tok->buf = (char *)PyMem_MALLOC(BUFSIZ)) == NULL) {
+ if ((tok->buf = (char *)PyMem_Malloc(BUFSIZ)) == NULL) {
PyTokenizer_Free(tok);
return NULL;
}
@@ -790,7 +790,7 @@ PyTokenizer_FromFile(FILE *fp, const char* enc,
if (enc != NULL) {
/* Must copy encoding declaration since it
gets copied into the parse tree. */
- tok->encoding = PyMem_MALLOC(strlen(enc)+1);
+ tok->encoding = PyMem_Malloc(strlen(enc)+1);
if (!tok->encoding) {
PyTokenizer_Free(tok);
return NULL;
@@ -808,15 +808,15 @@ void
PyTokenizer_Free(struct tok_state *tok)
{
if (tok->encoding != NULL)
- PyMem_FREE(tok->encoding);
+ PyMem_Free(tok->encoding);
Py_XDECREF(tok->decoding_readline);
Py_XDECREF(tok->decoding_buffer);
Py_XDECREF(tok->filename);
if (tok->fp != NULL && tok->buf != NULL)
- PyMem_FREE(tok->buf);
+ PyMem_Free(tok->buf);
if (tok->input)
- PyMem_FREE(tok->input);
- PyMem_FREE(tok);
+ PyMem_Free(tok->input);
+ PyMem_Free(tok);
}
/* Get next char, updating state; error code goes into tok->done */
@@ -852,7 +852,7 @@ tok_nextc(struct tok_state *tok)
char *newtok = PyOS_Readline(stdin, stdout, tok->prompt);
if (newtok != NULL) {
char *translated = translate_newlines(newtok, 0, tok);
- PyMem_FREE(newtok);
+ PyMem_Free(newtok);
if (translated == NULL)
return EOF;
newtok = translated;
@@ -862,14 +862,14 @@ tok_nextc(struct tok_state *tok)
Py_ssize_t buflen;
const char* buf;
PyObject *u = translate_into_utf8(newtok, tok->encoding);
- PyMem_FREE(newtok);
+ PyMem_Free(newtok);
if (!u) {
tok->done = E_DECODE;
return EOF;
}
buflen = PyBytes_GET_SIZE(u);
buf = PyBytes_AS_STRING(u);
- newtok = PyMem_MALLOC(buflen+1);
+ newtok = PyMem_Malloc(buflen+1);
if (newtok == NULL) {
Py_DECREF(u);
tok->done = E_NOMEM;
@@ -883,7 +883,7 @@ tok_nextc(struct tok_state *tok)
if (newtok == NULL)
tok->done = E_INTR;
else if (*newtok == '\0') {
- PyMem_FREE(newtok);
+ PyMem_Free(newtok);
tok->done = E_EOF;
}
else if (tok->start != NULL) {
@@ -892,12 +892,12 @@ tok_nextc(struct tok_state *tok)
size_t newlen = oldlen + strlen(newtok);
Py_ssize_t cur_multi_line_start = tok->multi_line_start - tok->buf;
char *buf = tok->buf;
- buf = (char *)PyMem_REALLOC(buf, newlen+1);
+ buf = (char *)PyMem_Realloc(buf, newlen+1);
tok->lineno++;
if (buf == NULL) {
- PyMem_FREE(tok->buf);
+ PyMem_Free(tok->buf);
tok->buf = NULL;
- PyMem_FREE(newtok);
+ PyMem_Free(newtok);
tok->done = E_NOMEM;
return EOF;
}
@@ -906,7 +906,7 @@ tok_nextc(struct tok_state *tok)
tok->multi_line_start = tok->buf + cur_multi_line_start;
tok->line_start = tok->cur;
strcpy(tok->buf + oldlen, newtok);
- PyMem_FREE(newtok);
+ PyMem_Free(newtok);
tok->inp = tok->buf + newlen;
tok->end = tok->inp + 1;
tok->start = tok->buf + start;
@@ -914,7 +914,7 @@ tok_nextc(struct tok_state *tok)
else {
tok->lineno++;
if (tok->buf != NULL)
- PyMem_FREE(tok->buf);
+ PyMem_Free(tok->buf);
tok->buf = newtok;
tok->cur = tok->buf;
tok->line_start = tok->buf;
@@ -929,7 +929,7 @@ tok_nextc(struct tok_state *tok)
if (tok->start == NULL) {
if (tok->buf == NULL) {
tok->buf = (char *)
- PyMem_MALLOC(BUFSIZ);
+ PyMem_Malloc(BUFSIZ);
if (tok->buf == NULL) {
tok->done = E_NOMEM;
return EOF;
@@ -966,7 +966,7 @@ tok_nextc(struct tok_state *tok)
Py_ssize_t curvalid = tok->inp - tok->buf;
Py_ssize_t newsize = curvalid + BUFSIZ;
char *newbuf = tok->buf;
- newbuf = (char *)PyMem_REALLOC(newbuf,
+ newbuf = (char *)PyMem_Realloc(newbuf,
newsize);
if (newbuf == NULL) {
tok->done = E_NOMEM;
@@ -1851,7 +1851,7 @@ PyTokenizer_Get(struct tok_state *tok, const char **p_start, const char **p_end)
encoding in the first or second line of the file (in which case the encoding
should be assumed to be UTF-8).
- The char* returned is malloc'ed via PyMem_MALLOC() and thus must be freed
+ The char* returned is malloc'ed via PyMem_Malloc() and thus must be freed
by the caller. */
char *
@@ -1894,7 +1894,7 @@ PyTokenizer_FindEncodingFilename(int fd, PyObject *filename)
}
fclose(fp);
if (tok->encoding) {
- encoding = (char *)PyMem_MALLOC(strlen(tok->encoding) + 1);
+ encoding = (char *)PyMem_Malloc(strlen(tok->encoding) + 1);
if (encoding)
strcpy(encoding, tok->encoding);
}
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 1ce55b6ec5a1c..a73b8cb320e97 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -2089,7 +2089,7 @@ builtin_input_impl(PyObject *module, PyObject *prompt)
Py_DECREF(stdin_encoding);
Py_DECREF(stdin_errors);
Py_XDECREF(po);
- PyMem_FREE(s);
+ PyMem_Free(s);
if (result != NULL) {
if (PySys_Audit("builtins.input/result", "O", result) < 0) {
diff --git a/Python/getargs.c b/Python/getargs.c
index c85ff6d4777d2..8839492e5ef41 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -202,7 +202,7 @@ static int
cleanup_ptr(PyObject *self, void *ptr)
{
if (ptr) {
- PyMem_FREE(ptr);
+ PyMem_Free(ptr);
}
return 0;
}
@@ -246,7 +246,7 @@ cleanreturn(int retval, freelist_t *freelist)
}
}
if (freelist->entries_malloced)
- PyMem_FREE(freelist->entries);
+ PyMem_Free(freelist->entries);
return retval;
}
diff --git a/Python/marshal.c b/Python/marshal.c
index d292987ce05f4..fa4ec9eb605f0 100644
--- a/Python/marshal.c
+++ b/Python/marshal.c
@@ -638,7 +638,7 @@ r_string(Py_ssize_t n, RFILE *p)
return res;
}
if (p->buf == NULL) {
- p->buf = PyMem_MALLOC(n);
+ p->buf = PyMem_Malloc(n);
if (p->buf == NULL) {
PyErr_NoMemory();
return NULL;
@@ -646,7 +646,7 @@ r_string(Py_ssize_t n, RFILE *p)
p->buf_size = n;
}
else if (p->buf_size < n) {
- char *tmp = PyMem_REALLOC(p->buf, n);
+ char *tmp = PyMem_Realloc(p->buf, n);
if (tmp == NULL) {
PyErr_NoMemory();
return NULL;
@@ -1453,7 +1453,7 @@ PyMarshal_ReadShortFromFile(FILE *fp)
rf.buf = NULL;
res = r_short(&rf);
if (rf.buf != NULL)
- PyMem_FREE(rf.buf);
+ PyMem_Free(rf.buf);
return res;
}
@@ -1468,7 +1468,7 @@ PyMarshal_ReadLongFromFile(FILE *fp)
rf.buf = NULL;
res = r_long(&rf);
if (rf.buf != NULL)
- PyMem_FREE(rf.buf);
+ PyMem_Free(rf.buf);
return res;
}
@@ -1501,11 +1501,11 @@ PyMarshal_ReadLastObjectFromFile(FILE *fp)
off_t filesize;
filesize = getfilesize(fp);
if (filesize > 0 && filesize <= REASONABLE_FILE_LIMIT) {
- char* pBuf = (char *)PyMem_MALLOC(filesize);
+ char* pBuf = (char *)PyMem_Malloc(filesize);
if (pBuf != NULL) {
size_t n = fread(pBuf, 1, (size_t)filesize, fp);
PyObject* v = PyMarshal_ReadObjectFromString(pBuf, n);
- PyMem_FREE(pBuf);
+ PyMem_Free(pBuf);
return v;
}
@@ -1534,7 +1534,7 @@ PyMarshal_ReadObjectFromFile(FILE *fp)
result = r_object(&rf);
Py_DECREF(rf.refs);
if (rf.buf != NULL)
- PyMem_FREE(rf.buf);
+ PyMem_Free(rf.buf);
return result;
}
@@ -1555,7 +1555,7 @@ PyMarshal_ReadObjectFromString(const char *str, Py_ssize_t len)
result = r_object(&rf);
Py_DECREF(rf.refs);
if (rf.buf != NULL)
- PyMem_FREE(rf.buf);
+ PyMem_Free(rf.buf);
return result;
}
@@ -1684,7 +1684,7 @@ marshal_load(PyObject *module, PyObject *file)
result = read_object(&rf);
Py_DECREF(rf.refs);
if (rf.buf != NULL)
- PyMem_FREE(rf.buf);
+ PyMem_Free(rf.buf);
} else
result = NULL;
}
diff --git a/Python/pystrtod.c b/Python/pystrtod.c
index 1c8202c776188..9145d4eba121e 100644
--- a/Python/pystrtod.c
+++ b/Python/pystrtod.c
@@ -255,7 +255,7 @@ _PyOS_ascii_strtod(const char *nptr, char **endptr)
char *copy, *c;
/* Create a copy of the input, with the '.' converted to the
locale-specific decimal point */
- copy = (char *)PyMem_MALLOC(end - digits_pos +
+ copy = (char *)PyMem_Malloc(end - digits_pos +
1 + decimal_point_len);
if (copy == NULL) {
*endptr = (char *)nptr;
@@ -286,7 +286,7 @@ _PyOS_ascii_strtod(const char *nptr, char **endptr)
(fail_pos - copy);
}
- PyMem_FREE(copy);
+ PyMem_Free(copy);
}
else {
diff --git a/Python/traceback.c b/Python/traceback.c
index 99b63af11f8be..708678facf7c3 100644
--- a/Python/traceback.c
+++ b/Python/traceback.c
@@ -419,12 +419,12 @@ _Py_DisplaySourceLine(PyObject *f, PyObject *filename, int lineno, int indent)
if (lseek(fd, 0, SEEK_SET) == (off_t)-1) {
Py_DECREF(io);
Py_DECREF(binary);
- PyMem_FREE(found_encoding);
+ PyMem_Free(found_encoding);
return 0;
}
fob = _PyObject_CallMethodId(io, &PyId_TextIOWrapper, "Os", binary, encoding);
Py_DECREF(io);
- PyMem_FREE(found_encoding);
+ PyMem_Free(found_encoding);
if (fob == NULL) {
PyErr_Clear();
1
0
https://github.com/python/cpython/commit/b2d0c66e881301ed8908da3cb41bbf253c…
commit: b2d0c66e881301ed8908da3cb41bbf253c449b0c
branch: master
author: pxinwr <peixing.xin(a)windriver.com>
committer: vstinner <vstinner(a)python.org>
date: 2020-12-01T09:20:50+01:00
summary:
bpo-31904: Fix fifo test cases for VxWorks (GH-20254)
files:
A Misc/NEWS.d/next/Tests/2020-05-20-14-28-48.bpo-31904.yJik6k.rst
M Lib/test/test_posix.py
M Lib/test/test_stat.py
diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py
index a522717751ac1..18afbef082bff 100644
--- a/Lib/test/test_posix.py
+++ b/Lib/test/test_posix.py
@@ -642,12 +642,17 @@ def test_stat(self):
@unittest.skipUnless(hasattr(posix, 'mkfifo'), "don't have mkfifo()")
def test_mkfifo(self):
- os_helper.unlink(os_helper.TESTFN)
+ if sys.platform == "vxworks":
+ fifo_path = os.path.join("/fifos/", os_helper.TESTFN)
+ else:
+ fifo_path = os_helper.TESTFN
+ os_helper.unlink(fifo_path)
+ self.addCleanup(os_helper.unlink, fifo_path)
try:
- posix.mkfifo(os_helper.TESTFN, stat.S_IRUSR | stat.S_IWUSR)
+ posix.mkfifo(fifo_path, stat.S_IRUSR | stat.S_IWUSR)
except PermissionError as e:
self.skipTest('posix.mkfifo(): %s' % e)
- self.assertTrue(stat.S_ISFIFO(posix.stat(os_helper.TESTFN).st_mode))
+ self.assertTrue(stat.S_ISFIFO(posix.stat(fifo_path).st_mode))
@unittest.skipUnless(hasattr(posix, 'mknod') and hasattr(stat, 'S_IFIFO'),
"don't have mknod()/S_IFIFO")
@@ -1929,7 +1934,7 @@ def test_posix_spawnp(self):
class TestPosixWeaklinking(unittest.TestCase):
# These test cases verify that weak linking support on macOS works
# as expected. These cases only test new behaviour introduced by weak linking,
- # regular behaviour is tested by the normal test cases.
+ # regular behaviour is tested by the normal test cases.
#
# See the section on Weak Linking in Mac/README.txt for more information.
def setUp(self):
diff --git a/Lib/test/test_stat.py b/Lib/test/test_stat.py
index 83d09e17f93c5..2e1e2c349c8d0 100644
--- a/Lib/test/test_stat.py
+++ b/Lib/test/test_stat.py
@@ -2,6 +2,7 @@
import os
import socket
import sys
+from test.support import os_helper
from test.support import socket_helper
from test.support.import_helper import import_fresh_module
from test.support.os_helper import TESTFN
@@ -173,11 +174,16 @@ def test_link(self):
@unittest.skipUnless(hasattr(os, 'mkfifo'), 'os.mkfifo not available')
def test_fifo(self):
+ if sys.platform == "vxworks":
+ fifo_path = os.path.join("/fifos/", TESTFN)
+ else:
+ fifo_path = TESTFN
+ self.addCleanup(os_helper.unlink, fifo_path)
try:
- os.mkfifo(TESTFN, 0o700)
+ os.mkfifo(fifo_path, 0o700)
except PermissionError as e:
self.skipTest('os.mkfifo(): %s' % e)
- st_mode, modestr = self.get_mode()
+ st_mode, modestr = self.get_mode(fifo_path)
self.assertEqual(modestr, 'prwx------')
self.assertS_IS("FIFO", st_mode)
diff --git a/Misc/NEWS.d/next/Tests/2020-05-20-14-28-48.bpo-31904.yJik6k.rst b/Misc/NEWS.d/next/Tests/2020-05-20-14-28-48.bpo-31904.yJik6k.rst
new file mode 100644
index 0000000000000..40caa88d689a2
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2020-05-20-14-28-48.bpo-31904.yJik6k.rst
@@ -0,0 +1 @@
+Fix fifo test cases for VxWorks RTOS.
1
0
[3.9] [doc] Fix smtplib and xml.dom.minidom mark-up (GH-22769) (GH-23380)
by JulienPalard Dec. 1, 2020
by JulienPalard Dec. 1, 2020
Dec. 1, 2020
https://github.com/python/cpython/commit/7e80c0f40e0458fd1b2c879c031594388f…
commit: 7e80c0f40e0458fd1b2c879c031594388fc6dea6
branch: 3.9
author: Julien Palard <julien(a)palard.fr>
committer: JulienPalard <julien(a)palard.fr>
date: 2020-12-01T08:58:36+01:00
summary:
[3.9] [doc] Fix smtplib and xml.dom.minidom mark-up (GH-22769) (GH-23380)
files:
M Doc/library/smtplib.rst
M Doc/library/xml.dom.minidom.rst
diff --git a/Doc/library/smtplib.rst b/Doc/library/smtplib.rst
index a88e358eae5fd..c1a20fee6cf02 100644
--- a/Doc/library/smtplib.rst
+++ b/Doc/library/smtplib.rst
@@ -115,7 +115,7 @@ Protocol) and :rfc:`1869` (SMTP Service Extensions).
If the *timeout* parameter is set to be zero, it will raise a
:class:`ValueError` to prevent the creation of a non-blocking socket
-.. class:: LMTP(host='', port=LMTP_PORT, local_hostname=None,
+.. class:: LMTP(host='', port=LMTP_PORT, local_hostname=None, \
source_address=None[, timeout])
The LMTP protocol, which is very similar to ESMTP, is heavily based on the
diff --git a/Doc/library/xml.dom.minidom.rst b/Doc/library/xml.dom.minidom.rst
index 2c78cd939243a..bf72c46561b7c 100644
--- a/Doc/library/xml.dom.minidom.rst
+++ b/Doc/library/xml.dom.minidom.rst
@@ -132,7 +132,7 @@ module documentation. This section lists the differences between the API and
... # Work with dom.
-.. method:: Node.writexml(writer, indent="", addindent="", newl="",
+.. method:: Node.writexml(writer, indent="", addindent="", newl="", \
encoding=None, standalone=None)
Write XML to the writer object. The writer receives texts but not bytes as input,
@@ -174,7 +174,7 @@ module documentation. This section lists the differences between the API and
The :meth:`toxml` method now preserves the attribute order specified
by the user.
-.. method:: Node.toprettyxml(indent="\\t", newl="\\n", encoding=None,
+.. method:: Node.toprettyxml(indent="\\t", newl="\\n", encoding=None, \
standalone=None)
Return a pretty-printed version of the document. *indent* specifies the
1
0
https://github.com/python/cpython/commit/cc061d0e6fb2569efa91531686f75b89e9…
commit: cc061d0e6fb2569efa91531686f75b89e94ec865
branch: master
author: Raymond Hettinger <rhettinger(a)users.noreply.github.com>
committer: rhettinger <rhettinger(a)users.noreply.github.com>
date: 2020-11-30T20:42:54-08:00
summary:
bpo-38200: Add itertools.pairwise() (GH-23549)
files:
A Misc/NEWS.d/next/Library/2020-11-28-22-52-57.bpo-38200.DuWGlW.rst
M Doc/library/itertools.rst
M Lib/test/test_itertools.py
M Modules/clinic/itertoolsmodule.c.h
M Modules/itertoolsmodule.c
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst
index 3de66c9349281..44728b42287bc 100644
--- a/Doc/library/itertools.rst
+++ b/Doc/library/itertools.rst
@@ -55,6 +55,7 @@ Iterator Arguments Results
:func:`filterfalse` pred, seq elements of seq where pred(elem) is false ``filterfalse(lambda x: x%2, range(10)) --> 0 2 4 6 8``
:func:`groupby` iterable[, key] sub-iterators grouped by value of key(v)
:func:`islice` seq, [start,] stop [, step] elements from seq[start:stop:step] ``islice('ABCDEFG', 2, None) --> C D E F G``
+:func:`pairwise` iterable (p[0], p[1]), (p[1], p[2]) ``pairwise('ABCDEFG') --> AB BC CD DE EF FG``
:func:`starmap` func, seq func(\*seq[0]), func(\*seq[1]), ... ``starmap(pow, [(2,5), (3,2), (10,3)]) --> 32 9 1000``
:func:`takewhile` pred, seq seq[0], seq[1], until pred fails ``takewhile(lambda x: x<5, [1,4,6,4,1]) --> 1 4``
:func:`tee` it, n it1, it2, ... itn splits one iterator into n
@@ -475,6 +476,22 @@ loops that truncate the stream.
If *start* is ``None``, then iteration starts at zero. If *step* is ``None``,
then the step defaults to one.
+.. function:: pairwise(iterable)
+
+ Return successive overlapping pairs taken from the input *iterable*.
+
+ The number of 2-tuples in the output iterator will be one fewer than the
+ number of inputs. It will be empty if the input iterable has fewer than
+ two values.
+
+ Roughly equivalent to::
+
+ def pairwise(iterable):
+ # pairwise('ABCDEFG') --> AB BC CD DE EF FG
+ a, b = tee(iterable)
+ next(b, None)
+ return zip(a, b)
+
.. function:: permutations(iterable, r=None)
@@ -782,12 +799,6 @@ which incur interpreter overhead.
return starmap(func, repeat(args))
return starmap(func, repeat(args, times))
- def pairwise(iterable):
- "s -> (s0,s1), (s1,s2), (s2, s3), ..."
- a, b = tee(iterable)
- next(b, None)
- return zip(a, b)
-
def grouper(iterable, n, fillvalue=None):
"Collect data into fixed-length chunks or blocks"
# grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx"
diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py
index 702cf0820316b..df2997e87d494 100644
--- a/Lib/test/test_itertools.py
+++ b/Lib/test/test_itertools.py
@@ -1024,6 +1024,25 @@ def run(r1, r2):
self.assertEqual(next(it), (1, 2))
self.assertRaises(RuntimeError, next, it)
+ def test_pairwise(self):
+ self.assertEqual(list(pairwise('')), [])
+ self.assertEqual(list(pairwise('a')), [])
+ self.assertEqual(list(pairwise('ab')),
+ [('a', 'b')]),
+ self.assertEqual(list(pairwise('abcde')),
+ [('a', 'b'), ('b', 'c'), ('c', 'd'), ('d', 'e')])
+ self.assertEqual(list(pairwise(range(10_000))),
+ list(zip(range(10_000), range(1, 10_000))))
+
+ with self.assertRaises(TypeError):
+ pairwise() # too few arguments
+ with self.assertRaises(TypeError):
+ pairwise('abc', 10) # too many arguments
+ with self.assertRaises(TypeError):
+ pairwise(iterable='abc') # keyword arguments
+ with self.assertRaises(TypeError):
+ pairwise(None) # non-iterable argument
+
def test_product(self):
for args, result in [
([], [()]), # zero iterables
@@ -1787,6 +1806,10 @@ def test_islice(self):
a = []
self.makecycle(islice([a]*2, None), a)
+ def test_pairwise(self):
+ a = []
+ self.makecycle(pairwise([a]*5), a)
+
def test_permutations(self):
a = []
self.makecycle(permutations([1,2,a,3], 3), a)
@@ -1995,6 +2018,17 @@ def test_islice(self):
self.assertRaises(TypeError, islice, N(s), 10)
self.assertRaises(ZeroDivisionError, list, islice(E(s), 10))
+ def test_pairwise(self):
+ for s in ("123", "", range(1000), ('do', 1.2), range(2000,2200,5)):
+ for g in (G, I, Ig, S, L, R):
+ seq = list(g(s))
+ expected = list(zip(seq, seq[1:]))
+ actual = list(pairwise(g(s)))
+ self.assertEqual(actual, expected)
+ self.assertRaises(TypeError, pairwise, X(s))
+ self.assertRaises(TypeError, pairwise, N(s))
+ self.assertRaises(ZeroDivisionError, list, pairwise(E(s)))
+
def test_starmap(self):
for s in (range(10), range(0), range(100), (7,11), range(20,50,5)):
for g in (G, I, Ig, S, L, R):
@@ -2312,15 +2346,6 @@ def test_permutations_sizeof(self):
... else:
... return starmap(func, repeat(args, times))
->>> def pairwise(iterable):
-... "s -> (s0,s1), (s1,s2), (s2, s3), ..."
-... a, b = tee(iterable)
-... try:
-... next(b)
-... except StopIteration:
-... pass
-... return zip(a, b)
-
>>> def grouper(n, iterable, fillvalue=None):
... "grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx"
... args = [iter(iterable)] * n
@@ -2451,15 +2476,6 @@ def test_permutations_sizeof(self):
>>> take(5, map(int, repeatfunc(random.random)))
[0, 0, 0, 0, 0]
->>> list(pairwise('abcd'))
-[('a', 'b'), ('b', 'c'), ('c', 'd')]
-
->>> list(pairwise([]))
-[]
-
->>> list(pairwise('a'))
-[]
-
>>> list(islice(pad_none('abc'), 0, 6))
['a', 'b', 'c', None, None, None]
diff --git a/Misc/NEWS.d/next/Library/2020-11-28-22-52-57.bpo-38200.DuWGlW.rst b/Misc/NEWS.d/next/Library/2020-11-28-22-52-57.bpo-38200.DuWGlW.rst
new file mode 100644
index 0000000000000..b4bc5551b2532
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-11-28-22-52-57.bpo-38200.DuWGlW.rst
@@ -0,0 +1 @@
+Added itertools.pairwise()
diff --git a/Modules/clinic/itertoolsmodule.c.h b/Modules/clinic/itertoolsmodule.c.h
index c1192bbcb0d79..82729eeb56bce 100644
--- a/Modules/clinic/itertoolsmodule.c.h
+++ b/Modules/clinic/itertoolsmodule.c.h
@@ -2,6 +2,37 @@
preserve
[clinic start generated code]*/
+PyDoc_STRVAR(pairwise_new__doc__,
+"pairwise(iterable, /)\n"
+"--\n"
+"\n"
+"Return an iterator of overlapping pairs taken from the input iterator.\n"
+"\n"
+" s -> (s0,s1), (s1,s2), (s2, s3), ...");
+
+static PyObject *
+pairwise_new_impl(PyTypeObject *type, PyObject *iterable);
+
+static PyObject *
+pairwise_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
+{
+ PyObject *return_value = NULL;
+ PyObject *iterable;
+
+ if ((type == &pairwise_type) &&
+ !_PyArg_NoKeywords("pairwise", kwargs)) {
+ goto exit;
+ }
+ if (!_PyArg_CheckPositional("pairwise", PyTuple_GET_SIZE(args), 1, 1)) {
+ goto exit;
+ }
+ iterable = PyTuple_GET_ITEM(args, 0);
+ return_value = pairwise_new_impl(type, iterable);
+
+exit:
+ return return_value;
+}
+
PyDoc_STRVAR(itertools_groupby__doc__,
"groupby(iterable, key=None)\n"
"--\n"
@@ -627,4 +658,4 @@ itertools_count(PyTypeObject *type, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=d7f58dc477814b45 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=889c4afc3b13574f input=a9049054013a1b77]*/
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index ce8b4347ef220..7144856c352f8 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -1,4 +1,5 @@
+
#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "pycore_long.h" // _PyLong_GetZero()
@@ -27,8 +28,9 @@ class itertools.accumulate "accumulateobject *" "&accumulate_type"
class itertools.compress "compressobject *" "&compress_type"
class itertools.filterfalse "filterfalseobject *" "&filterfalse_type"
class itertools.count "countobject *" "&count_type"
+class itertools.pairwise "pairwiseobject *" "&pairwise_type"
[clinic start generated code]*/
-/*[clinic end generated code: output=da39a3ee5e6b4b0d input=ea05c93c6d94726a]*/
+/*[clinic end generated code: output=da39a3ee5e6b4b0d input=6498ed21fbe1bf94]*/
static PyTypeObject groupby_type;
static PyTypeObject _grouper_type;
@@ -45,9 +47,140 @@ static PyTypeObject accumulate_type;
static PyTypeObject compress_type;
static PyTypeObject filterfalse_type;
static PyTypeObject count_type;
+static PyTypeObject pairwise_type;
#include "clinic/itertoolsmodule.c.h"
+/* pairwise object ***********************************************************/
+
+typedef struct {
+ PyObject_HEAD
+ PyObject *it;
+ PyObject *old;
+} pairwiseobject;
+
+/*[clinic input]
+@classmethod
+itertools.pairwise.__new__ as pairwise_new
+ iterable: object
+ /
+Return an iterator of overlapping pairs taken from the input iterator.
+
+ s -> (s0,s1), (s1,s2), (s2, s3), ...
+
+[clinic start generated code]*/
+
+static PyObject *
+pairwise_new_impl(PyTypeObject *type, PyObject *iterable)
+/*[clinic end generated code: output=9f0267062d384456 input=6e7c3cddb431a8d6]*/
+{
+ PyObject *it;
+ pairwiseobject *po;
+
+ it = PyObject_GetIter(iterable);
+ if (it == NULL) {
+ return NULL;
+ }
+ po = (pairwiseobject *)type->tp_alloc(type, 0);
+ if (po == NULL) {
+ Py_DECREF(it);
+ return NULL;
+ }
+ po->it = it;
+ po->old = NULL;
+ return (PyObject *)po;
+}
+
+static void
+pairwise_dealloc(pairwiseobject *po)
+{
+ PyObject_GC_UnTrack(po);
+ Py_XDECREF(po->it);
+ Py_XDECREF(po->old);
+ Py_TYPE(po)->tp_free(po);
+}
+
+static int
+pairwise_traverse(pairwiseobject *po, visitproc visit, void *arg)
+{
+ Py_VISIT(po->it);
+ Py_VISIT(po->old);
+ return 0;
+}
+
+static PyObject *
+pairwise_next(pairwiseobject *po)
+{
+ PyObject *it = po->it;
+ PyObject *old = po->old;
+ PyObject *new, *result;
+
+ if (it == NULL) {
+ return NULL;
+ }
+ if (old == NULL) {
+ po->old = old = (*Py_TYPE(it)->tp_iternext)(it);
+ if (old == NULL) {
+ Py_CLEAR(po->it);
+ return NULL;
+ }
+ }
+ new = (*Py_TYPE(it)->tp_iternext)(it);
+ if (new == NULL) {
+ Py_CLEAR(po->it);
+ Py_CLEAR(po->old);
+ return NULL;
+ }
+ /* Future optimization: Reuse the result tuple as we do in enumerate() */
+ result = PyTuple_Pack(2, old, new);
+ Py_SETREF(po->old, new);
+ return result;
+}
+
+static PyTypeObject pairwise_type = {
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ "itertools.pairwise", /* tp_name */
+ sizeof(pairwiseobject), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ /* methods */
+ (destructor)pairwise_dealloc, /* tp_dealloc */
+ 0, /* tp_vectorcall_offset */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_as_async */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ PyObject_GenericGetAttr, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
+ Py_TPFLAGS_BASETYPE, /* tp_flags */
+ pairwise_new__doc__, /* tp_doc */
+ (traverseproc)pairwise_traverse, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ PyObject_SelfIter, /* tp_iter */
+ (iternextfunc)pairwise_next, /* tp_iternext */
+ 0, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ PyType_GenericAlloc, /* tp_alloc */
+ pairwise_new, /* tp_new */
+ PyObject_GC_Del, /* tp_free */
+};
+
/* groupby object ************************************************************/
@@ -4666,6 +4799,7 @@ groupby(iterable[, keyfunc]) --> sub-iterators grouped by value of keyfunc(v)\n\
filterfalse(pred, seq) --> elements of seq where pred(elem) is False\n\
islice(seq, [start,] stop [, step]) --> elements from\n\
seq[start:stop:step]\n\
+pairwise(s) --> (s[0],s[1]), (s[1],s[2]), (s[2], s[3]), ...\n\
starmap(fun, seq) --> fun(*seq[0]), fun(*seq[1]), ...\n\
tee(it, n=2) --> (it1, it2 , ... itn) splits one iterator into n\n\
takewhile(pred, seq) --> seq[0], seq[1], until pred fails\n\
@@ -4695,6 +4829,7 @@ itertoolsmodule_exec(PyObject *m)
&filterfalse_type,
&count_type,
&ziplongest_type,
+ &pairwise_type,
&permutations_type,
&product_type,
&repeat_type,
1
0
bpo-42482: remove reference to exc_traceback from TracebackException (GH-23531)
by miss-islington Dec. 1, 2020
by miss-islington Dec. 1, 2020
Dec. 1, 2020
https://github.com/python/cpython/commit/1cc5c943c007b92116f06b3ec8e71f2a51…
commit: 1cc5c943c007b92116f06b3ec8e71f2a510d1898
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: miss-islington <31488909+miss-islington(a)users.noreply.github.com>
date: 2020-11-30T17:53:40-08:00
summary:
bpo-42482: remove reference to exc_traceback from TracebackException (GH-23531)
(cherry picked from commit 427613f005f0f412d12f0d775d2b609bae0ae1ad)
Co-authored-by: Irit Katriel <iritkatriel(a)yahoo.com>
files:
A Misc/NEWS.d/next/Library/2020-11-27-16-46-58.bpo-42482.EJC3sd.rst
M Lib/test/test_traceback.py
M Lib/traceback.py
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py
index 8a80d5802bb41..a5ba6090cf08d 100644
--- a/Lib/test/test_traceback.py
+++ b/Lib/test/test_traceback.py
@@ -1083,6 +1083,18 @@ def test_context(self):
self.assertEqual(exc_info[0], exc.exc_type)
self.assertEqual(str(exc_info[1]), str(exc))
+ def test_no_refs_to_exception_and_traceback_objects(self):
+ try:
+ 1/0
+ except Exception:
+ exc_info = sys.exc_info()
+
+ refcnt1 = sys.getrefcount(exc_info[1])
+ refcnt2 = sys.getrefcount(exc_info[2])
+ exc = traceback.TracebackException(*exc_info)
+ self.assertEqual(sys.getrefcount(exc_info[1]), refcnt1)
+ self.assertEqual(sys.getrefcount(exc_info[2]), refcnt2)
+
def test_comparison_basic(self):
try:
1/0
@@ -1133,6 +1145,16 @@ def raise_with_locals():
exc7 = traceback.TracebackException(*exc_info, limit=-2, capture_locals=True)
self.assertNotEqual(exc6, exc7)
+ def test_comparison_equivalent_exceptions_are_equal(self):
+ excs = []
+ for _ in range(2):
+ try:
+ 1/0
+ except:
+ excs.append(traceback.TracebackException(*sys.exc_info()))
+ self.assertEqual(excs[0], excs[1])
+ self.assertEqual(list(excs[0].format()), list(excs[1].format()))
+
def test_unhashable(self):
class UnhashableException(Exception):
def __eq__(self, other):
diff --git a/Lib/traceback.py b/Lib/traceback.py
index 5ef3be74be74a..19de84b26bf35 100644
--- a/Lib/traceback.py
+++ b/Lib/traceback.py
@@ -500,7 +500,6 @@ def __init__(self, exc_type, exc_value, exc_traceback, *, limit=None,
_seen=_seen)
else:
context = None
- self.exc_traceback = exc_traceback
self.__cause__ = cause
self.__context__ = context
self.__suppress_context__ = \
@@ -608,7 +607,7 @@ def format(self, *, chain=True):
not self.__suppress_context__):
yield from self.__context__.format(chain=chain)
yield _context_message
- if self.exc_traceback is not None:
+ if self.stack:
yield 'Traceback (most recent call last):\n'
- yield from self.stack.format()
+ yield from self.stack.format()
yield from self.format_exception_only()
diff --git a/Misc/NEWS.d/next/Library/2020-11-27-16-46-58.bpo-42482.EJC3sd.rst b/Misc/NEWS.d/next/Library/2020-11-27-16-46-58.bpo-42482.EJC3sd.rst
new file mode 100644
index 0000000000000..79afa654f352e
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-11-27-16-46-58.bpo-42482.EJC3sd.rst
@@ -0,0 +1 @@
+:class:`~traceback.TracebackException` no longer holds a reference to the exception's traceback object. Consequently, instances of TracebackException for equivalent but non-equal exceptions now compare as equal.
\ No newline at end of file
1
0
bpo-42482: remove reference to exc_traceback from TracebackException (GH-23531)
by miss-islington Dec. 1, 2020
by miss-islington Dec. 1, 2020
Dec. 1, 2020
https://github.com/python/cpython/commit/427613f005f0f412d12f0d775d2b609bae…
commit: 427613f005f0f412d12f0d775d2b609bae0ae1ad
branch: master
author: Irit Katriel <iritkatriel(a)yahoo.com>
committer: miss-islington <31488909+miss-islington(a)users.noreply.github.com>
date: 2020-11-30T17:35:25-08:00
summary:
bpo-42482: remove reference to exc_traceback from TracebackException (GH-23531)
files:
A Misc/NEWS.d/next/Library/2020-11-27-16-46-58.bpo-42482.EJC3sd.rst
M Lib/test/test_traceback.py
M Lib/traceback.py
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py
index f86afc673d86e..5df701caf0f01 100644
--- a/Lib/test/test_traceback.py
+++ b/Lib/test/test_traceback.py
@@ -1123,6 +1123,18 @@ def test_context(self):
self.assertEqual(exc_info[0], exc.exc_type)
self.assertEqual(str(exc_info[1]), str(exc))
+ def test_no_refs_to_exception_and_traceback_objects(self):
+ try:
+ 1/0
+ except Exception:
+ exc_info = sys.exc_info()
+
+ refcnt1 = sys.getrefcount(exc_info[1])
+ refcnt2 = sys.getrefcount(exc_info[2])
+ exc = traceback.TracebackException(*exc_info)
+ self.assertEqual(sys.getrefcount(exc_info[1]), refcnt1)
+ self.assertEqual(sys.getrefcount(exc_info[2]), refcnt2)
+
def test_comparison_basic(self):
try:
1/0
@@ -1172,6 +1184,16 @@ def raise_with_locals():
exc7 = traceback.TracebackException(*exc_info, limit=-2, capture_locals=True)
self.assertNotEqual(exc6, exc7)
+ def test_comparison_equivalent_exceptions_are_equal(self):
+ excs = []
+ for _ in range(2):
+ try:
+ 1/0
+ except:
+ excs.append(traceback.TracebackException(*sys.exc_info()))
+ self.assertEqual(excs[0], excs[1])
+ self.assertEqual(list(excs[0].format()), list(excs[1].format()))
+
def test_unhashable(self):
class UnhashableException(Exception):
def __eq__(self, other):
diff --git a/Lib/traceback.py b/Lib/traceback.py
index d2d93c8a32ac2..457d92511af05 100644
--- a/Lib/traceback.py
+++ b/Lib/traceback.py
@@ -510,7 +510,6 @@ def __init__(self, exc_type, exc_value, exc_traceback, *, limit=None,
_seen=_seen)
else:
context = None
- self.exc_traceback = exc_traceback
self.__cause__ = cause
self.__context__ = context
self.__suppress_context__ = \
@@ -627,7 +626,7 @@ def format(self, *, chain=True):
not self.__suppress_context__):
yield from self.__context__.format(chain=chain)
yield _context_message
- if self.exc_traceback is not None:
+ if self.stack:
yield 'Traceback (most recent call last):\n'
- yield from self.stack.format()
+ yield from self.stack.format()
yield from self.format_exception_only()
diff --git a/Misc/NEWS.d/next/Library/2020-11-27-16-46-58.bpo-42482.EJC3sd.rst b/Misc/NEWS.d/next/Library/2020-11-27-16-46-58.bpo-42482.EJC3sd.rst
new file mode 100644
index 0000000000000..79afa654f352e
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-11-27-16-46-58.bpo-42482.EJC3sd.rst
@@ -0,0 +1 @@
+:class:`~traceback.TracebackException` no longer holds a reference to the exception's traceback object. Consequently, instances of TracebackException for equivalent but non-equal exceptions now compare as equal.
\ No newline at end of file
1
0