Skip to content

Commit add6a30

Browse files
authored
PYTHON-4285 Fix PyModule_GetState check (#1565)
1 parent 372b5d6 commit add6a30

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

bson/_cbsonmodule.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -862,20 +862,21 @@ static int _write_element_to_buffer(PyObject* self, buffer_t buffer,
862862
const codec_options_t* options,
863863
unsigned char in_custom_call,
864864
unsigned char in_fallback_call) {
865-
struct module_state *state = GETSTATE(self);
866865
PyObject* new_value = NULL;
867866
int retval;
868867
int is_list;
868+
long type;
869+
struct module_state *state = GETSTATE(self);
870+
if (!state) {
871+
return 0;
872+
}
869873
/*
870874
* Use _type_marker attribute instead of PyObject_IsInstance for better perf.
871875
*/
872-
long type = _type_marker(value, state->_type_marker_str);
876+
type = _type_marker(value, state->_type_marker_str);
873877
if (type < 0) {
874878
return 0;
875879
}
876-
if (!state) {
877-
return 0;
878-
}
879880

880881
switch (type) {
881882
case 5:

0 commit comments

Comments
 (0)