Patches item #1517947, was opened at 2006-07-06 06:43 Message generated for change (Settings changed) made by gbrandl You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1517947&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None >Status: Closed >Resolution: Rejected Priority: 5 Private: No Submitted By: Rene Dudfield (illume) Assigned to: Nobody/Anonymous (nobody) Summary: assert for NULL in Py_INCREF Py_DECREF Initial Comment: Since Py_INCREF and Py_DECREF should not be able to take NULLs they should do an assert check for this. This would have caught at least one bug earlier in cPickle.loads() http://sourceforge.net/tracker/index.php?func=detail&aid=1512695&group_id=5470&atid=105470 It will also help other extension module authors find this error in their code more easily. Include/object.h #define Py_INCREF(op) ( \ (assert((op) != NULL)) , \ _Py_INC_REFTOTAL _Py_REF_DEBUG_COMMA \ (op)->ob_refcnt++) #define Py_DECREF(op) \ if ((assert((op) != NULL)) , _Py_DEC_REFTOTAL _Py_REF_DEBUG_COMMA \ --(op)->ob_refcnt != 0) \ _Py_CHECK_REFCNT(op) \ else \ _Py_Dealloc((PyObject *)(op)) ---------------------------------------------------------------------- >Comment By: Georg Brandl (gbrandl) Date: 2007-03-13 21:55 Message: Logged In: YES user_id=849994 Originator: NO Quoting Martin v. Löwis: """ I think it's pointless. If they ever be NULL, the INCRE/DECREF will crash right away, anyway, so you'll certainly notice. As you will have a debug build when the assertion triggers, you can just as well fine the location of the crash quickly in the debugger (e.g. using the core file on systems that support that, or the JIT-debugger on other systems). """ Rejecting on that basis. ---------------------------------------------------------------------- Comment By: Brett Cannon (bcannon) Date: 2006-07-07 00:21 Message: Logged In: YES user_id=357491 I don't think that the cPickle bug would have been any sooner. The segfault happens just as early as an assertion would have since both going to access bad memory. Regardless, the adding of the assert() in Py_DECREF might warrant using ``while{} do(0)`` to simplify the code. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1517947&group_id=5470 _______________________________________________ Patches mailing list Patches@python.org http://mail.python.org/mailman/listinfo/patches