From e68fdf2b628bad2b122e7bcd047af5c4bab13f2d Mon Sep 17 00:00:00 2001 From: Bernie Hackett Date: Wed, 20 Aug 2014 13:15:26 -0700 Subject: [PATCH] PYTHON-505 - Fix C extension build with VC++. --- bson/_cbsonmodule.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/bson/_cbsonmodule.c b/bson/_cbsonmodule.c index 92805d567..7f1b727f7 100644 --- a/bson/_cbsonmodule.c +++ b/bson/_cbsonmodule.c @@ -1032,7 +1032,7 @@ static int _write_element_to_buffer(PyObject* self, buffer_t buffer, mapping_type = _get_object(state->Mapping, "collections", "Mapping"); if (mapping_type && PyObject_IsInstance(value, mapping_type)) { Py_DECREF(mapping_type); - // PyObject_IsInstance returns -1 on error + /* PyObject_IsInstance returns -1 on error */ if (PyErr_Occurred()) { return 0; } @@ -1042,11 +1042,6 @@ static int _write_element_to_buffer(PyObject* self, buffer_t buffer, uuid_type = _get_object(state->UUID, "uuid", "UUID"); if (uuid_type && PyObject_IsInstance(value, uuid_type)) { - Py_DECREF(uuid_type); - // PyObject_IsInstance returns -1 on error - if (PyErr_Occurred()) { - return 0; - } /* Just a special case of Binary above, but * simpler to do as a separate case. */ PyObject* bytes; @@ -1056,6 +1051,12 @@ static int _write_element_to_buffer(PyObject* self, buffer_t buffer, int size = 16; int subtype; + Py_DECREF(uuid_type); + /* PyObject_IsInstance returns -1 on error */ + if (PyErr_Occurred()) { + return 0; + } + if (uuid_subtype == JAVA_LEGACY || uuid_subtype == CSHARP_LEGACY) { subtype = 3; } @@ -1329,9 +1330,9 @@ int write_dict(PyObject* self, buffer_t buffer, if (mapping_type) { if (!PyObject_IsInstance(dict, mapping_type)) { + PyObject* repr; Py_DECREF(mapping_type); - PyObject* repr = PyObject_Repr(dict); - if (repr) { + if ((repr = PyObject_Repr(dict))) { #if PY_MAJOR_VERSION >= 3 PyObject* errmsg = PyUnicode_FromString( "encoder expected a mapping type but got: "); @@ -1366,7 +1367,7 @@ int write_dict(PyObject* self, buffer_t buffer, return 0; } Py_DECREF(mapping_type); - // PyObject_IsInstance returns -1 on error + /* PyObject_IsInstance returns -1 on error */ if (PyErr_Occurred()) { return 0; } @@ -1534,7 +1535,7 @@ static PyObject* get_value(PyObject* self, const char* buffer, unsigned* positio PyObject* database; collection = PyMapping_GetItemString(value, "$ref"); - // PyMapping_GetItemString returns NULL to indicate error. + /* PyMapping_GetItemString returns NULL to indicate error. */ if (!collection) { goto invalid; }