Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Include/internal/pycore_typeobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
extern "C" {
#endif

#include "pycore_moduleobject.h"

#ifndef Py_BUILD_CORE
# error "this header requires Py_BUILD_CORE define"
#endif
Expand Down Expand Up @@ -62,6 +64,20 @@ _PyStaticType_GET_WEAKREFS_LISTPTR(static_builtin_state *state)
return &state->tp_weaklist;
}

/* Like PyType_GetModuleState, but skips verification
* that type is a heap type with an associated module */
static inline void *
_PyType_GetModuleState(PyTypeObject *type)
Comment thread
erlend-aasland marked this conversation as resolved.
Resolved
{
assert(PyType_Check(type));
assert(type->tp_flags & Py_TPFLAGS_HEAPTYPE);
PyHeapTypeObject *et = (PyHeapTypeObject *)type;
assert(et->ht_module);
PyModuleObject *mod = (PyModuleObject *)(et->ht_module);
assert(mod != NULL);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assertion is the same than assert(et->ht_module);, no? If you only keep one, I suggest keeping assert(mod != NULL); since we use mod below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... or the first assert could be changed to assert(et != NULL).

return mod->md_state;
}

struct types_state {
struct type_cache type_cache;
size_t num_builtins_initialized;
Expand Down
3 changes: 2 additions & 1 deletion Modules/itertoolsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_long.h" // _PyLong_GetZero()
#include "pycore_moduleobject.h" // _PyModule_GetState()
#include "pycore_typeobject.h" // _PyType_GetModuleState()
#include "pycore_object.h" // _PyObject_GC_TRACK()
#include "pycore_tuple.h" // _PyTuple_ITEMS()
#include "structmember.h" // PyMemberDef
Expand Down Expand Up @@ -48,7 +49,7 @@ get_module_state(PyObject *mod)
static inline itertools_state *
get_module_state_by_cls(PyTypeObject *cls)
{
void *state = PyType_GetModuleState(cls);
void *state = _PyType_GetModuleState(cls);
assert(state != NULL);
return (itertools_state *)state;
}
Expand Down