Skip to content

Commit a3bc056

Browse files
emmatypingpicnixz
andauthored
Use a much more robust implementation...
... for `get_zstd_state_from_type` Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
1 parent dd536fd commit a3bc056

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Modules/_zstd/_zstdmodule.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ extern PyModuleDef _zstdmodule;
3030
static inline _zstd_state *
3131
get_zstd_state_from_type(PyTypeObject *type) {
3232
PyObject *module = PyType_GetModuleByDef(type, &_zstdmodule);
33-
return PyModule_GetState(module);
33+
if (module == NULL) {
34+
return NULL;
35+
}
36+
void *state = PyModule_GetState(module);
37+
assert(state != NULL);
38+
return (_zstd_state *)state;
3439
}
3540

3641
extern PyType_Spec zstddict_type_spec;

0 commit comments

Comments
 (0)