Issue 1517947: assert for NULL in Py_INCREF Py_DECREF (original) (raw)

Issue1517947

Created on 2006-07-06 06:43 by illume, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg50621 - (view) Author: Rene Dudfield (illume) Date: 2006-07-06 06:43
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))
msg50622 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2006-07-07 00:21
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.
msg50623 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-03-13 21:55
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.
History
Date User Action Args
2022-04-11 14:56:18 admin set github: 43622
2006-07-06 06:43:16 illume create