Skip to content

Commit 2528e7d

Browse files
committed
Attempt to fix code.Code encoding issue.
1 parent 6ba63dd commit 2528e7d

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

bson/_cbsonmodule.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -400,14 +400,14 @@ static int _write_element_to_buffer(buffer_t buffer, int type_byte,
400400
} else if (PyObject_IsInstance(value, Code)) {
401401
int start_position,
402402
length_location,
403-
length,
404-
no_scope;
405-
PyObject* scope;
403+
length;
406404

407-
scope = PyObject_GetAttrString(value, "scope");
408-
no_scope = PyObject_Not(scope);
405+
PyObject* scope = PyObject_GetAttrString(value, "scope");
406+
if (!scope) {
407+
return 0;
408+
}
409409

410-
if (no_scope) {
410+
if (!PyObject_Size(scope)) {
411411
Py_DECREF(scope);
412412

413413
*(buffer_get_buffer(buffer) + type_byte) = 0x0D;
@@ -428,9 +428,6 @@ static int _write_element_to_buffer(buffer_t buffer, int type_byte,
428428
return 0;
429429
}
430430

431-
if (!scope) {
432-
return 0;
433-
}
434431
if (!write_dict(buffer, scope, 0, uuid_subtype, 0)) {
435432
Py_DECREF(scope);
436433
return 0;

0 commit comments

Comments
 (0)