@@ -1032,7 +1032,7 @@ static int _write_element_to_buffer(PyObject* self, buffer_t buffer,
10321032 mapping_type = _get_object (state -> Mapping , "collections" , "Mapping" );
10331033 if (mapping_type && PyObject_IsInstance (value , mapping_type )) {
10341034 Py_DECREF (mapping_type );
1035- // PyObject_IsInstance returns -1 on error
1035+ /* PyObject_IsInstance returns -1 on error */
10361036 if (PyErr_Occurred ()) {
10371037 return 0 ;
10381038 }
@@ -1042,11 +1042,6 @@ static int _write_element_to_buffer(PyObject* self, buffer_t buffer,
10421042
10431043 uuid_type = _get_object (state -> UUID , "uuid" , "UUID" );
10441044 if (uuid_type && PyObject_IsInstance (value , uuid_type )) {
1045- Py_DECREF (uuid_type );
1046- // PyObject_IsInstance returns -1 on error
1047- if (PyErr_Occurred ()) {
1048- return 0 ;
1049- }
10501045 /* Just a special case of Binary above, but
10511046 * simpler to do as a separate case. */
10521047 PyObject * bytes ;
@@ -1056,6 +1051,12 @@ static int _write_element_to_buffer(PyObject* self, buffer_t buffer,
10561051 int size = 16 ;
10571052 int subtype ;
10581053
1054+ Py_DECREF (uuid_type );
1055+ /* PyObject_IsInstance returns -1 on error */
1056+ if (PyErr_Occurred ()) {
1057+ return 0 ;
1058+ }
1059+
10591060 if (uuid_subtype == JAVA_LEGACY || uuid_subtype == CSHARP_LEGACY ) {
10601061 subtype = 3 ;
10611062 }
@@ -1329,9 +1330,9 @@ int write_dict(PyObject* self, buffer_t buffer,
13291330
13301331 if (mapping_type ) {
13311332 if (!PyObject_IsInstance (dict , mapping_type )) {
1333+ PyObject * repr ;
13321334 Py_DECREF (mapping_type );
1333- PyObject * repr = PyObject_Repr (dict );
1334- if (repr ) {
1335+ if ((repr = PyObject_Repr (dict ))) {
13351336#if PY_MAJOR_VERSION >= 3
13361337 PyObject * errmsg = PyUnicode_FromString (
13371338 "encoder expected a mapping type but got: " );
@@ -1366,7 +1367,7 @@ int write_dict(PyObject* self, buffer_t buffer,
13661367 return 0 ;
13671368 }
13681369 Py_DECREF (mapping_type );
1369- // PyObject_IsInstance returns -1 on error
1370+ /* PyObject_IsInstance returns -1 on error */
13701371 if (PyErr_Occurred ()) {
13711372 return 0 ;
13721373 }
@@ -1534,7 +1535,7 @@ static PyObject* get_value(PyObject* self, const char* buffer, unsigned* positio
15341535 PyObject * database ;
15351536
15361537 collection = PyMapping_GetItemString (value , "$ref" );
1537- // PyMapping_GetItemString returns NULL to indicate error.
1538+ /* PyMapping_GetItemString returns NULL to indicate error. */
15381539 if (!collection ) {
15391540 goto invalid ;
15401541 }
0 commit comments