From: Serhiy Storchaka Date: Thu, 11 Sep 2014 07:40:44 +0000 (+0300) Subject: Issue #21951: Use attemptckalloc() instead of ckalloc() in Tkinter. X-Git-Tag: v3.5.0a1~934 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=979f80b8da091c596f5e602accfb91962a816056;p=python Issue #21951: Use attemptckalloc() instead of ckalloc() in Tkinter. ckalloc() causes the Tcl interpreter to panic, attemptckalloc() returns NULL if the memory allocation fails. --- 979f80b8da091c596f5e602accfb91962a816056 diff --cc Misc/NEWS index 49909a103b,666887773b..079a0eb6a5 --- a/Misc/NEWS +++ b/Misc/NEWS @@@ -132,17 -32,11 +132,20 @@@ Core and Builtin Library ------- + - Issue #21951: Tkinter now most likely raises MemoryError instead of crash + if the memory allocation fails. + - Issue #22338: Fix a crash in the json module on memory allocation failure. +- Issue #12410: imaplib.IMAP4 now supports the context management protocol. + Original patch by Tarek Ziadé. + +- Issue #16662: load_tests() is now unconditionally run when it is present in + a package's __init__.py. TestLoader.loadTestsFromModule() still accepts + use_load_tests, but it is deprecated and ignored. A new keyword-only + attribute `pattern` is added and documented. Patch given by Robert Collins, + tweaked by Barry Warsaw. + - Issue #22226: First letter no longer is stripped from the "status" key in the result of Treeview.heading(). diff --cc Modules/_tkinter.c index d54ebb47a3,7871dec8d4..a8e6d9828c --- a/Modules/_tkinter.c +++ b/Modules/_tkinter.c @@@ -905,21 -898,17 +905,21 @@@ AsObj(PyObject *value Tcl_Obj **argv; Py_ssize_t size, i; - size = PyTuple_Size(value); + size = PySequence_Fast_GET_SIZE(value); if (!CHECK_SIZE(size, sizeof(Tcl_Obj *))) { - PyErr_SetString(PyExc_OverflowError, "tuple is too long"); + PyErr_SetString(PyExc_OverflowError, + PyTuple_Check(value) ? "tuple is too long" : + "list is too long"); return NULL; } - argv = (Tcl_Obj **) ckalloc(((size_t)size) * sizeof(Tcl_Obj *)); + argv = (Tcl_Obj **) attemptckalloc(((size_t)size) * sizeof(Tcl_Obj *)); - if(!argv) - return 0; + if(!argv) { + PyErr_NoMemory(); + return NULL; + } for (i = 0; i < size; i++) - argv[i] = AsObj(PyTuple_GetItem(value,i)); - result = Tcl_NewListObj(PyTuple_Size(value), argv); + argv[i] = AsObj(PySequence_Fast_GET_ITEM(value,i)); + result = Tcl_NewListObj(size, argv); ckfree(FREECAST argv); return result; } @@@ -1106,12 -1095,10 +1106,12 @@@ Tkapp_CallArgs(PyObject *args, Tcl_Obj* if (objc > ARGSZ) { if (!CHECK_SIZE(objc, sizeof(Tcl_Obj *))) { - PyErr_SetString(PyExc_OverflowError, "tuple is too long"); + PyErr_SetString(PyExc_OverflowError, + PyTuple_Check(args) ? "tuple is too long" : + "list is too long"); return NULL; } - objv = (Tcl_Obj **)ckalloc(((size_t)objc) * sizeof(Tcl_Obj *)); + objv = (Tcl_Obj **)attemptckalloc(((size_t)objc) * sizeof(Tcl_Obj *)); if (objv == NULL) { PyErr_NoMemory(); objc = 0;