From b67d7bd127409e50594bf2fb17c69980743c282e Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Wed, 17 Apr 2024 19:22:56 +0200 Subject: [PATCH] Apply suggestion from code review --- Objects/typeobject.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 18f3867f07d81e..0b38069151f432 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -116,10 +116,18 @@ type_from_ref(PyObject *ref) /* helpers for for static builtin types */ +#ifndef NDEBUG +static inline int +static_builtin_index_is_set(PyTypeObject *self) +{ + return self->tp_subclasses != NULL; +} +#endif + static inline size_t static_builtin_index_get(PyTypeObject *self) { - assert(self->tp_subclasses != NULL); + assert(static_builtin_index_is_set(self)); /* We store a 1-based index so 0 can mean "not initialized". */ return (size_t)self->tp_subclasses - 1; } @@ -157,7 +165,7 @@ static void static_builtin_state_init(PyInterpreterState *interp, PyTypeObject *self) { if (_Py_IsMainInterpreter(interp)) { - assert(self->tp_subclasses == NULL); + assert(!static_builtin_index_is_set(self)); static_builtin_index_set(self, interp->types.num_builtins_initialized); } else {