[Python-checkins] cpython: Closes #22336: attemptckalloc() with PyMem_Malloc() in _tkinter

victor.stinner python-checkins at python.org
Thu Sep 11 17:52:37 CEST 2014


http://hg.python.org/cpython/rev/9f1d3e6e6ce6
changeset: 92405:9f1d3e6e6ce6
user: Victor Stinner <victor.stinner at gmail.com>
date: Thu Sep 11 17:50:21 2014 +0200
summary:
 Closes #22336: attemptckalloc() with PyMem_Malloc() in _tkinter
The PyMem_Malloc(size) function has a well defined behaviour: if size is 0, a
pointer different than NULL is returned. PyMem_Malloc() allocations are
tracked by tracemalloc, attemptckalloc() allocations are not tracked.
files:
 Modules/_tkinter.c | 24 ++++++++++++------------
 1 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -605,7 +605,7 @@
 Tcl_SetVar(v->interp, "tcl_interactive", "0", TCL_GLOBAL_ONLY);
 
 /* This is used to get the application class for Tk 4.1 and up */
- argv0 = (char*)attemptckalloc(strlen(className) + 1);
+ argv0 = (char*)PyMem_Malloc(strlen(className) + 1);
 if (!argv0) {
 PyErr_NoMemory();
 Py_DECREF(v);
@@ -616,7 +616,7 @@
 if (Py_ISUPPER(Py_CHARMASK(argv0[0])))
 argv0[0] = Py_TOLOWER(Py_CHARMASK(argv0[0]));
 Tcl_SetVar(v->interp, "argv0", argv0, TCL_GLOBAL_ONLY);
- ckfree(argv0);
+ PyMem_Free(argv0);
 
 if (! wantTk) {
 Tcl_SetVar(v->interp,
@@ -639,7 +639,7 @@
 if (use)
 len += strlen(use) + sizeof "-use ";
 
- args = (char*)attemptckalloc(len);
+ args = (char*)PyMem_Malloc(len);
 if (!args) {
 PyErr_NoMemory();
 Py_DECREF(v);
@@ -657,7 +657,7 @@
 }
 
 Tcl_SetVar(v->interp, "argv", args, TCL_GLOBAL_ONLY);
- ckfree(args);
+ PyMem_Free(args);
 }
 
 if (Tcl_AppInit(v->interp) != TCL_OK) {
@@ -914,15 +914,15 @@
 "list is too long");
 return NULL;
 }
- argv = (Tcl_Obj **) attemptckalloc(((size_t)size) * sizeof(Tcl_Obj *));
- if(!argv) {
+ argv = (Tcl_Obj **) PyMem_Malloc(((size_t)size) * sizeof(Tcl_Obj *));
+ if (!argv) {
 PyErr_NoMemory();
 return NULL;
 }
 for (i = 0; i < size; i++)
 argv[i] = AsObj(PySequence_Fast_GET_ITEM(value,i));
 result = Tcl_NewListObj(size, argv);
- ckfree(FREECAST argv);
+ PyMem_Free(argv);
 return result;
 }
 else if (PyUnicode_Check(value)) {
@@ -948,7 +948,7 @@
 if (kind == sizeof(Tcl_UniChar))
 return Tcl_NewUnicodeObj(inbuf, size);
 allocsize = ((size_t)size) * sizeof(Tcl_UniChar);
- outbuf = (Tcl_UniChar*)attemptckalloc(allocsize);
+ outbuf = (Tcl_UniChar*)PyMem_Malloc(allocsize);
 /* Else overflow occurred, and we take the next exit */
 if (!outbuf) {
 PyErr_NoMemory();
@@ -965,14 +965,14 @@
 "character U+%x is above the range "
 "(U+0000-U+FFFF) allowed by Tcl",
 ch);
- ckfree(FREECAST outbuf);
+ PyMem_Free(outbuf);
 return NULL;
 }
 #endif
 outbuf[i] = ch;
 }
 result = Tcl_NewUnicodeObj(outbuf, size);
- ckfree(FREECAST outbuf);
+ PyMem_Free(outbuf);
 return result;
 }
 else if(PyTclObject_Check(value)) {
@@ -1084,7 +1084,7 @@
 for (i = 0; i < objc; i++)
 Tcl_DecrRefCount(objv[i]);
 if (objv != objStore)
- ckfree(FREECAST objv);
+ PyMem_Free(objv);
 }
 
 /* Convert Python objects to Tcl objects. This must happen in the
@@ -1115,7 +1115,7 @@
 "list is too long");
 return NULL;
 }
- objv = (Tcl_Obj **)attemptckalloc(((size_t)objc) * sizeof(Tcl_Obj *));
+ objv = (Tcl_Obj **)PyMem_Malloc(((size_t)objc) * sizeof(Tcl_Obj *));
 if (objv == NULL) {
 PyErr_NoMemory();
 objc = 0;
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /