bpo-9263: Use _PyObject_ASSERT() in object.c (GH-10110) · python/cpython@2470204 (original) (raw)
`@@ -72,7 +72,7 @@ _Py_AddToAllObjects(PyObject *op, int force)
`
72
72
`/* If it's initialized memory, op must be in or out of
`
73
73
` * the list unambiguously.
`
74
74
` */
`
75
``
`-
assert((op->_ob_prev == NULL) == (op->_ob_next == NULL));
`
``
75
`+
_PyObject_ASSERT(op, (op->_ob_prev == NULL) == (op->_ob_next == NULL));
`
76
76
` }
`
77
77
`#endif
`
78
78
`if (force || op->_ob_prev == NULL) {
`
`@@ -305,7 +305,9 @@ PyObject_CallFinalizerFromDealloc(PyObject *self)
`
305
305
`/* Undo the temporary resurrection; can't use DECREF here, it would
`
306
306
` * cause a recursive call.
`
307
307
` */
`
308
``
`-
assert(self->ob_refcnt > 0);
`
``
308
`+
_PyObject_ASSERT_WITH_MSG(self,
`
``
309
`+
self->ob_refcnt > 0,
`
``
310
`+
"refcount is too small");
`
309
311
`if (--self->ob_refcnt == 0)
`
310
312
`return 0; /* this is the normal path out */
`
311
313
``
`@@ -316,7 +318,9 @@ PyObject_CallFinalizerFromDealloc(PyObject *self)
`
316
318
`_Py_NewReference(self);
`
317
319
`self->ob_refcnt = refcnt;
`
318
320
``
319
``
`-
assert(!PyType_IS_GC(Py_TYPE(self)) || _PyObject_GC_IS_TRACKED(self));
`
``
321
`+
_PyObject_ASSERT(self,
`
``
322
`+
(!PyType_IS_GC(Py_TYPE(self))
`
``
323
`+
|| _PyObject_GC_IS_TRACKED(self)));
`
320
324
`/* If Py_REF_DEBUG, _Py_NewReference bumped _Py_RefTotal, so
`
321
325
` * we need to undo that. */
`
322
326
`_Py_DEC_REFTOTAL;
`
`@@ -1020,7 +1024,7 @@ PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value)
`
1020
1024
`return err;
`
1021
1025
` }
`
1022
1026
`Py_DECREF(name);
`
1023
``
`-
assert(name->ob_refcnt >= 1);
`
``
1027
`+
_PyObject_ASSERT(name, name->ob_refcnt >= 1);
`
1024
1028
`if (tp->tp_getattr == NULL && tp->tp_getattro == NULL)
`
1025
1029
`PyErr_Format(PyExc_TypeError,
`
1026
1030
`"'%.100s' object has no attributes "
`
`@@ -1059,8 +1063,8 @@ _PyObject_GetDictPtr(PyObject *obj)
`
1059
1063
`size = _PyObject_VAR_SIZE(tp, tsize);
`
1060
1064
``
1061
1065
`dictoffset += (long)size;
`
1062
``
`-
assert(dictoffset > 0);
`
1063
``
`-
assert(dictoffset % SIZEOF_VOID_P == 0);
`
``
1066
`+
_PyObject_ASSERT(obj, dictoffset > 0);
`
``
1067
`+
_PyObject_ASSERT(obj, dictoffset % SIZEOF_VOID_P == 0);
`
1064
1068
` }
`
1065
1069
`return (PyObject **) ((char *)obj + dictoffset);
`
1066
1070
`}
`
`@@ -1247,11 +1251,11 @@ _PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name,
`
1247
1251
`if (tsize < 0)
`
1248
1252
`tsize = -tsize;
`
1249
1253
`size = _PyObject_VAR_SIZE(tp, tsize);
`
1250
``
`-
assert(size <= PY_SSIZE_T_MAX);
`
``
1254
`+
_PyObject_ASSERT(obj, size <= PY_SSIZE_T_MAX);
`
1251
1255
``
1252
1256
`dictoffset += (Py_ssize_t)size;
`
1253
``
`-
assert(dictoffset > 0);
`
1254
``
`-
assert(dictoffset % SIZEOF_VOID_P == 0);
`
``
1257
`+
_PyObject_ASSERT(obj, dictoffset > 0);
`
``
1258
`+
_PyObject_ASSERT(obj, dictoffset % SIZEOF_VOID_P == 0);
`
1255
1259
` }
`
1256
1260
`dictptr = (PyObject **) ((char *)obj + dictoffset);
`
1257
1261
`dict = *dictptr;
`
`@@ -1486,7 +1490,7 @@ _dir_object(PyObject *obj)
`
1486
1490
`PyObject *result, *sorted;
`
1487
1491
`PyObject *dirfunc = PyObject_LookupSpecial(obj, &PyId___dir_);
`
1488
1492
``
1489
``
`-
assert(obj);
`
``
1493
`+
assert(obj != NULL);
`
1490
1494
`if (dirfunc == NULL) {
`
1491
1495
`if (!PyErr_Occurred())
`
1492
1496
`PyErr_SetString(PyExc_TypeError, "object does not provide dir");
`
`@@ -2129,9 +2133,9 @@ Py_ReprLeave(PyObject *obj)
`
2129
2133
`void
`
2130
2134
`_PyTrash_deposit_object(PyObject *op)
`
2131
2135
`{
`
2132
``
`-
assert(PyObject_IS_GC(op));
`
2133
``
`-
assert(!_PyObject_GC_IS_TRACKED(op));
`
2134
``
`-
assert(op->ob_refcnt == 0);
`
``
2136
`+
_PyObject_ASSERT(op, PyObject_IS_GC(op));
`
``
2137
`+
_PyObject_ASSERT(op, !_PyObject_GC_IS_TRACKED(op));
`
``
2138
`+
_PyObject_ASSERT(op, op->ob_refcnt == 0);
`
2135
2139
`_PyGCHead_SET_PREV(_Py_AS_GC(op), _PyRuntime.gc.trash_delete_later);
`
2136
2140
`_PyRuntime.gc.trash_delete_later = op;
`
2137
2141
`}
`
`@@ -2141,9 +2145,9 @@ void
`
2141
2145
`_PyTrash_thread_deposit_object(PyObject *op)
`
2142
2146
`{
`
2143
2147
`PyThreadState *tstate = PyThreadState_GET();
`
2144
``
`-
assert(PyObject_IS_GC(op));
`
2145
``
`-
assert(!_PyObject_GC_IS_TRACKED(op));
`
2146
``
`-
assert(op->ob_refcnt == 0);
`
``
2148
`+
_PyObject_ASSERT(op, PyObject_IS_GC(op));
`
``
2149
`+
_PyObject_ASSERT(op, !_PyObject_GC_IS_TRACKED(op));
`
``
2150
`+
_PyObject_ASSERT(op, op->ob_refcnt == 0);
`
2147
2151
`_PyGCHead_SET_PREV(_Py_AS_GC(op), tstate->trash_delete_later);
`
2148
2152
`tstate->trash_delete_later = op;
`
2149
2153
`}
`
`@@ -2167,7 +2171,7 @@ _PyTrash_destroy_chain(void)
`
2167
2171
` * assorted non-release builds calling Py_DECREF again ends
`
2168
2172
` * up distorting allocation statistics.
`
2169
2173
` */
`
2170
``
`-
assert(op->ob_refcnt == 0);
`
``
2174
`+
_PyObject_ASSERT(op, op->ob_refcnt == 0);
`
2171
2175
`++_PyRuntime.gc.trash_delete_nesting;
`
2172
2176
` (*dealloc)(op);
`
2173
2177
`--_PyRuntime.gc.trash_delete_nesting;
`
`@@ -2205,7 +2209,7 @@ _PyTrash_thread_destroy_chain(void)
`
2205
2209
` * assorted non-release builds calling Py_DECREF again ends
`
2206
2210
` * up distorting allocation statistics.
`
2207
2211
` */
`
2208
``
`-
assert(op->ob_refcnt == 0);
`
``
2212
`+
_PyObject_ASSERT(op, op->ob_refcnt == 0);
`
2209
2213
` (*dealloc)(op);
`
2210
2214
`assert(tstate->trash_delete_nesting == 1);
`
2211
2215
` }
`