diff options
author | Simon McVittie <smcv@debian.org> | 2010-12-02 16:31:07 +0000 |
---|---|---|
committer | Simon McVittie <smcv@debian.org> | 2010-12-02 16:31:07 +0000 |
commit | 56ad64cd14e52b479489549f76343f19e3842139 (patch) | |
tree | 645b786f39e8fa58247a3b69d9e5754ed18c9319 | |
parent | cb1bbd2414e892469023653ea7ddd5d39cd76b84 (diff) | |
download | dbus-python-56ad64cd14e52b479489549f76343f19e3842139.tar.gz |
Use Py_CLEAR for greater robustness
-rw-r--r-- | _dbus_bindings/abstract.c | 36 | ||||
-rw-r--r-- | _dbus_bindings/bus.c | 10 | ||||
-rw-r--r-- | _dbus_bindings/bytes.c | 6 | ||||
-rw-r--r-- | _dbus_bindings/conn-methods.c | 60 | ||||
-rw-r--r-- | _dbus_bindings/conn.c | 18 | ||||
-rw-r--r-- | _dbus_bindings/containers.c | 78 | ||||
-rw-r--r-- | _dbus_bindings/exceptions.c | 8 | ||||
-rw-r--r-- | _dbus_bindings/generic.c | 2 | ||||
-rw-r--r-- | _dbus_bindings/int.c | 32 | ||||
-rw-r--r-- | _dbus_bindings/message-append.c | 59 | ||||
-rw-r--r-- | _dbus_bindings/message-get-args.c | 42 | ||||
-rw-r--r-- | _dbus_bindings/message.c | 14 | ||||
-rw-r--r-- | _dbus_bindings/module.c | 2 | ||||
-rw-r--r-- | _dbus_bindings/pending-call.c | 16 | ||||
-rw-r--r-- | _dbus_bindings/server.c | 18 | ||||
-rw-r--r-- | _dbus_bindings/signature.c | 6 | ||||
-rw-r--r-- | _dbus_bindings/string.c | 4 | ||||
-rw-r--r-- | _dbus_glib_bindings/module.c | 10 | ||||
-rw-r--r-- | test/dbus_py_test.c | 8 |
19 files changed, 209 insertions, 220 deletions
diff --git a/_dbus_bindings/abstract.c b/_dbus_bindings/abstract.c index 9a4f350..303cb57 100644 --- a/_dbus_bindings/abstract.c +++ b/_dbus_bindings/abstract.c @@ -50,7 +50,7 @@ dbus_py_variant_level_get(PyObject *obj) } vl_obj = PyDict_GetItem(_dbus_py_variant_levels, key); - Py_DECREF(key); + Py_CLEAR(key); if (!vl_obj) return 0; @@ -70,7 +70,7 @@ dbus_py_variant_level_set(PyObject *obj, long variant_level) if (variant_level <= 0) { if (PyDict_GetItem (_dbus_py_variant_levels, key)) { if (PyDict_DelItem (_dbus_py_variant_levels, key) < 0) { - Py_DECREF(key); + Py_CLEAR(key); return FALSE; } } @@ -78,15 +78,15 @@ dbus_py_variant_level_set(PyObject *obj, long variant_level) else { PyObject *vl_obj = PyInt_FromLong(variant_level); if (!vl_obj) { - Py_DECREF(key); + Py_CLEAR(key); return FALSE; } if (PyDict_SetItem (_dbus_py_variant_levels, key, vl_obj) < 0) { - Py_DECREF(key); + Py_CLEAR(key); return FALSE; } } - Py_DECREF(key); + Py_CLEAR(key); return TRUE; } @@ -111,11 +111,11 @@ dbus_py_variant_level_getattro(PyObject *obj, PyObject *name) if (strcmp(PyString_AS_STRING(name), "variant_level")) { value = PyObject_GenericGetAttr(obj, name); - Py_DECREF(name); + Py_CLEAR(name); return value; } - Py_DECREF(name); + Py_CLEAR(name); key = PyLong_FromVoidPtr(obj); @@ -124,7 +124,7 @@ dbus_py_variant_level_getattro(PyObject *obj, PyObject *name) } value = PyDict_GetItem(_dbus_py_variant_levels, key); - Py_DECREF(key); + Py_CLEAR(key); if (!value) return PyInt_FromLong(0); @@ -210,7 +210,7 @@ DBusPythonInt_tp_repr(PyObject *self) PyString_AS_STRING(parent_repr)); } /* whether my_repr is NULL or not: */ - Py_DECREF(parent_repr); + Py_CLEAR(parent_repr); return my_repr; } @@ -322,7 +322,7 @@ DBusPythonFloat_tp_repr(PyObject *self) PyString_AS_STRING(parent_repr)); } /* whether my_repr is NULL or not: */ - Py_DECREF(parent_repr); + Py_CLEAR(parent_repr); return my_repr; } @@ -399,7 +399,7 @@ DBusPythonString_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) self = (PyString_Type.tp_new)(cls, args, NULL); if (self) { if (!dbus_py_variant_level_set(self, variantness)) { - Py_DECREF(self); + Py_CLEAR(self); return NULL; } } @@ -417,11 +417,11 @@ DBusPythonString_tp_repr(PyObject *self) if (!parent_repr) return NULL; vl_obj = PyObject_GetAttr(self, dbus_py_variant_level_const); if (!vl_obj) { - Py_DECREF(parent_repr); + Py_CLEAR(parent_repr); return NULL; } variant_level = PyInt_AsLong(vl_obj); - Py_DECREF(vl_obj); + Py_CLEAR(vl_obj); if (variant_level > 0) { my_repr = PyString_FromFormat("%s(%s, variant_level=%ld)", self->ob_type->tp_name, @@ -433,7 +433,7 @@ DBusPythonString_tp_repr(PyObject *self) PyString_AS_STRING(parent_repr)); } /* whether my_repr is NULL or not: */ - Py_DECREF(parent_repr); + Py_CLEAR(parent_repr); return my_repr; } @@ -517,7 +517,7 @@ DBusPythonLong_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) self = (PyLong_Type.tp_new)(cls, args, NULL); if (self) { if (!dbus_py_variant_level_set(self, variantness)) { - Py_DECREF(self); + Py_CLEAR(self); return NULL; } } @@ -535,11 +535,11 @@ DBusPythonLong_tp_repr(PyObject *self) if (!parent_repr) return NULL; vl_obj = PyObject_GetAttr(self, dbus_py_variant_level_const); if (!vl_obj) { - Py_DECREF(parent_repr); + Py_CLEAR(parent_repr); return NULL; } variant_level = PyInt_AsLong(vl_obj); - Py_DECREF(vl_obj); + Py_CLEAR(vl_obj); if (variant_level) { my_repr = PyString_FromFormat("%s(%s, variant_level=%ld)", self->ob_type->tp_name, @@ -551,7 +551,7 @@ DBusPythonLong_tp_repr(PyObject *self) PyString_AS_STRING(parent_repr)); } /* whether my_repr is NULL or not: */ - Py_DECREF(parent_repr); + Py_CLEAR(parent_repr); return my_repr; } diff --git a/_dbus_bindings/bus.c b/_dbus_bindings/bus.c index 7ab0d95..0ffe62b 100644 --- a/_dbus_bindings/bus.c +++ b/_dbus_bindings/bus.c @@ -56,7 +56,7 @@ DBusPyConnection_NewForBus(PyTypeObject *cls, PyObject *args, PyObject *kwargs) Py_END_ALLOW_THREADS if (!ret) { DBusPyException_ConsumeError(&error); - Py_DECREF(self); + Py_CLEAR(self); return NULL; } @@ -101,7 +101,7 @@ DBusPyConnection_NewForBus(PyTypeObject *cls, PyObject *args, PyObject *kwargs) return NULL; new_args = PyTuple_Pack(2, libdbusconn, mainloop ? mainloop : Py_None); - Py_DECREF(libdbusconn); + Py_CLEAR(libdbusconn); if (!new_args) { return NULL; @@ -110,14 +110,14 @@ DBusPyConnection_NewForBus(PyTypeObject *cls, PyObject *args, PyObject *kwargs) new_kwargs = PyDict_New(); if (!new_kwargs) { - Py_DECREF(new_args); + Py_CLEAR(new_args); return NULL; } self = (Connection *)(DBusPyConnection_Type.tp_new)(cls, new_args, new_kwargs); - Py_DECREF(new_args); - Py_DECREF(new_kwargs); + Py_CLEAR(new_args); + Py_CLEAR(new_kwargs); return (PyObject *)self; /* whether NULL or not */ } diff --git a/_dbus_bindings/bytes.c b/_dbus_bindings/bytes.c index a5648fe..bc12a14 100644 --- a/_dbus_bindings/bytes.c +++ b/_dbus_bindings/bytes.c @@ -104,12 +104,10 @@ Byte_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) tuple = Py_BuildValue("(O)", obj); if (!tuple) return NULL; - Py_DECREF(obj); - obj = NULL; + Py_CLEAR(obj); obj = DBusPyIntBase_Type.tp_new(cls, tuple, kwargs); - Py_DECREF(tuple); - tuple = NULL; + Py_CLEAR(tuple); return obj; bad_arg: diff --git a/_dbus_bindings/conn-methods.c b/_dbus_bindings/conn-methods.c index 81c4514..98356c4 100644 --- a/_dbus_bindings/conn-methods.c +++ b/_dbus_bindings/conn-methods.c @@ -55,10 +55,10 @@ _object_path_unregister(DBusConnection *conn, void *user_data) Py_XDECREF(PyObject_CallFunctionObjArgs(callable, conn_obj, NULL)); } out: - Py_XDECREF(conn_obj); - Py_XDECREF(tuple); + Py_CLEAR(conn_obj); + Py_CLEAR(tuple); /* the user_data (a Python str) is no longer ref'd by the DBusConnection */ - Py_XDECREF((PyObject *)user_data); + Py_CLEAR(user_data); if (PyErr_Occurred()) { PyErr_Print(); } @@ -118,9 +118,9 @@ _object_path_message(DBusConnection *conn, DBusMessage *message, } out: - Py_XDECREF(msg_obj); - Py_XDECREF(conn_obj); - Py_XDECREF(tuple); + Py_CLEAR(msg_obj); + Py_CLEAR(conn_obj); + Py_CLEAR(tuple); if (PyErr_Occurred()) { PyErr_Print(); } @@ -196,9 +196,9 @@ _filter_message(DBusConnection *conn, DBusMessage *message, void *user_data) ret = DBusPyConnection_HandleMessage(conn_obj, msg_obj, callable); out: - Py_XDECREF(msg_obj); - Py_XDECREF(conn_obj); - Py_XDECREF(callable); + Py_CLEAR(msg_obj); + Py_CLEAR(conn_obj); + Py_CLEAR(callable); PyGILState_Release(gil); return ret; } @@ -643,7 +643,7 @@ Connection_remove_message_filter(Connection *self, PyObject *callable) * to it. */ obj = PyObject_CallMethod(self->filters, "remove", "(O)", callable); if (!obj) return NULL; - Py_DECREF(obj); + Py_CLEAR(obj); Py_BEGIN_ALLOW_THREADS dbus_connection_remove_filter(self->conn, _filter_message, callable); @@ -720,13 +720,13 @@ Connection__register_object_path(Connection *self, PyObject *args, } if (!dbus_py_validate_object_path(PyString_AS_STRING(path))) { - Py_DECREF(path); + Py_CLEAR(path); return NULL; } tuple = Py_BuildValue("(OO)", on_unregister, on_message); if (!tuple) { - Py_DECREF(path); + Py_CLEAR(path); return NULL; } @@ -736,8 +736,8 @@ Connection__register_object_path(Connection *self, PyObject *args, PyErr_Format(PyExc_KeyError, "Can't register the object-path " "handler for '%s': there is already a handler", PyString_AS_STRING(path)); - Py_DECREF(tuple); - Py_DECREF(path); + Py_CLEAR(tuple); + Py_CLEAR(path); return NULL; } @@ -746,8 +746,8 @@ Connection__register_object_path(Connection *self, PyObject *args, * This ensures we can keep libdbus' opinion of whether those * paths are handled in sync with our own. */ if (PyDict_SetItem(self->object_paths, path, Py_None) < 0) { - Py_DECREF(tuple); - Py_DECREF(path); + Py_CLEAR(tuple); + Py_CLEAR(path); return NULL; } @@ -779,15 +779,15 @@ Connection__register_object_path(Connection *self, PyObject *args, return NULL; } /* don't DECREF path: libdbus owns a ref now */ - Py_DECREF(tuple); + Py_CLEAR(tuple); Py_RETURN_NONE; } else { /* Oops, OOM. Tidy up, if we can, ignoring any error. */ PyDict_DelItem(self->object_paths, path); PyErr_Clear(); - Py_DECREF(tuple); - Py_DECREF(path); + Py_CLEAR(tuple); + Py_CLEAR(path); PyErr_NoMemory(); return NULL; } @@ -842,7 +842,7 @@ Connection__unregister_object_path(Connection *self, PyObject *args, PyErr_Format(PyExc_KeyError, "Can't unregister the object-path " "handler for '%s': there is no such handler", PyString_AS_STRING(path)); - Py_DECREF(path); + Py_CLEAR(path); return NULL; } @@ -860,8 +860,8 @@ Connection__unregister_object_path(Connection *self, PyObject *args, /* If that failed, there's no need to be paranoid as below - the callbacks are still set, so we failed, but at least everything is in sync. */ - Py_DECREF(callbacks); - Py_DECREF(path); + Py_CLEAR(callbacks); + Py_CLEAR(path); return NULL; } @@ -881,12 +881,12 @@ Connection__unregister_object_path(Connection *self, PyObject *args, Py_END_ALLOW_THREADS if (ok) { - Py_DECREF(callbacks); + Py_CLEAR(callbacks); PyDict_DelItem(self->object_paths, path); /* END PARANOIA on successful code path */ /* The above can't fail unless by some strange trickery the key is no longer present. Ignore any errors. */ - Py_DECREF(path); + Py_CLEAR(path); PyErr_Clear(); Py_RETURN_NONE; } @@ -899,8 +899,8 @@ Connection__unregister_object_path(Connection *self, PyObject *args, /* If the SetItem failed, there's nothing we can do about it - but since we know it's an existing entry, it shouldn't be able to fail anyway. */ - Py_DECREF(path); - Py_DECREF(callbacks); + Py_CLEAR(path); + Py_CLEAR(callbacks); return PyErr_NoMemory(); } } @@ -950,15 +950,15 @@ Connection_list_exported_child_objects (Connection *self, PyObject *args, PyObject *tmp = PyString_FromString(*kid_ptr); if (!tmp) { - Py_DECREF(ret); + Py_CLEAR(ret); return NULL; } if (PyList_Append(ret, tmp) < 0) { - Py_DECREF(tmp); - Py_DECREF(ret); + Py_CLEAR(tmp); + Py_CLEAR(ret); return NULL; } - Py_DECREF(tmp); + Py_CLEAR(tmp); } dbus_free_string_array(kids); diff --git a/_dbus_bindings/conn.c b/_dbus_bindings/conn.c index e7c5338..36e8dc8 100644 --- a/_dbus_bindings/conn.c +++ b/_dbus_bindings/conn.c @@ -80,13 +80,13 @@ DBusPyConnection_HandleMessage(Connection *conn, NULL); if (obj == Py_None) { DBG("%p: OK, handler %p returned None", conn, callable); - Py_DECREF(obj); + Py_CLEAR(obj); return DBUS_HANDLER_RESULT_HANDLED; } else if (obj == Py_NotImplemented) { DBG("%p: handler %p returned NotImplemented, continuing", conn, callable); - Py_DECREF(obj); + Py_CLEAR(obj); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } else if (!obj) { @@ -101,7 +101,7 @@ DBusPyConnection_HandleMessage(Connection *conn, else { long i = PyInt_AsLong(obj); DBG("%p: handler %p returned %ld", conn, callable, i); - Py_DECREF(obj); + Py_CLEAR(obj); if (i == -1 && PyErr_Occurred()) { PyErr_SetString(PyExc_TypeError, "Return from D-Bus message " "handler callback should be None, " @@ -269,7 +269,7 @@ DBusPyConnection_NewConsumingDBusConnection(PyTypeObject *cls, goto err; } - Py_DECREF(mainloop); + Py_CLEAR(mainloop); DBG("%s() -> %p", __func__, self); TRACE(self); @@ -277,9 +277,9 @@ DBusPyConnection_NewConsumingDBusConnection(PyTypeObject *cls, err: DBG("Failed to construct Connection from DBusConnection at %p", conn); - Py_XDECREF(mainloop); - Py_XDECREF(self); - Py_XDECREF(ref); + Py_CLEAR(mainloop); + Py_CLEAR(self); + Py_CLEAR(ref); if (conn) { Py_BEGIN_ALLOW_THREADS dbus_connection_close(conn); @@ -371,9 +371,9 @@ static void Connection_tp_dealloc(Connection *self) DBG("Connection at %p: deleting callbacks", self); self->filters = NULL; - Py_XDECREF(filters); + Py_CLEAR(filters); self->object_paths = NULL; - Py_XDECREF(object_paths); + Py_CLEAR(object_paths); if (conn) { /* Might trigger callbacks if we're unlucky... */ diff --git a/_dbus_bindings/containers.c b/_dbus_bindings/containers.c index 319ebe1..0fb9e4b 100644 --- a/_dbus_bindings/containers.c +++ b/_dbus_bindings/containers.c @@ -77,8 +77,7 @@ static struct PyMemberDef Array_tp_members[] = { static void Array_tp_dealloc (DBusPyArray *self) { - Py_XDECREF(self->signature); - self->signature = NULL; + Py_CLEAR(self->signature); (PyList_Type.tp_dealloc)((PyObject *)self); } @@ -107,8 +106,8 @@ Array_tp_repr(DBusPyArray *self) PyString_AS_STRING(sig_repr)); } finally: - Py_XDECREF(parent_repr); - Py_XDECREF(sig_repr); + Py_CLEAR(parent_repr); + Py_CLEAR(sig_repr); return my_repr; } @@ -130,7 +129,7 @@ Array_tp_new (PyTypeObject *cls, PyObject *args, PyObject *kwargs) if (variant_level) { self->variant_level = PyInt_AsLong(variant_level); if (PyErr_Occurred()) { - Py_DECREF((PyObject *)self); + Py_CLEAR(self); return NULL; } } @@ -170,7 +169,7 @@ Array_tp_init (DBusPyArray *self, PyObject *args, PyObject *kwargs) const char *c_str = PyString_AS_STRING(signature); if (!dbus_signature_validate_single(c_str, NULL)) { - Py_DECREF(signature); + Py_CLEAR(signature); PyErr_SetString(PyExc_ValueError, "There must be exactly one complete type in " "an Array's signature parameter"); @@ -180,17 +179,17 @@ Array_tp_init (DBusPyArray *self, PyObject *args, PyObject *kwargs) tuple = Py_BuildValue("(O)", obj); if (!tuple) { - Py_DECREF(signature); + Py_CLEAR(signature); return -1; } if ((PyList_Type.tp_init)((PyObject *)self, tuple, NULL) < 0) { - Py_DECREF(tuple); - Py_DECREF(signature); + Py_CLEAR(tuple); + Py_CLEAR(signature); return -1; } - Py_DECREF(tuple); + Py_CLEAR(tuple); - Py_XDECREF(self->signature); + Py_CLEAR(self->signature); self->signature = signature; return 0; } @@ -286,8 +285,7 @@ static struct PyMemberDef Dict_tp_members[] = { static void Dict_tp_dealloc (DBusPyDict *self) { - Py_XDECREF(self->signature); - self->signature = NULL; + Py_CLEAR(self->signature); (PyDict_Type.tp_dealloc)((PyObject *)self); } @@ -316,8 +314,8 @@ Dict_tp_repr(DBusPyDict *self) PyString_AS_STRING(sig_repr)); } finally: - Py_XDECREF(parent_repr); - Py_XDECREF(sig_repr); + Py_CLEAR(parent_repr); + Py_CLEAR(sig_repr); return my_repr; } @@ -339,7 +337,7 @@ Dict_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) if (variant_level) { self->variant_level = PyInt_AsLong(variant_level); if (PyErr_Occurred()) { - Py_DECREF((PyObject *)self); + Py_CLEAR(self); return NULL; } } @@ -395,7 +393,7 @@ Dict_tp_init(DBusPyDict *self, PyObject *args, PyObject *kwargs) case DBUS_TYPE_SIGNATURE: break; default: - Py_DECREF(signature); + Py_CLEAR(signature); PyErr_SetString(PyExc_ValueError, "The key type in a Dictionary's signature " "must be a primitive type"); @@ -403,7 +401,7 @@ Dict_tp_init(DBusPyDict *self, PyObject *args, PyObject *kwargs) } if (!dbus_signature_validate_single(c_str + 1, NULL)) { - Py_DECREF(signature); + Py_CLEAR(signature); PyErr_SetString(PyExc_ValueError, "There must be exactly two complete types in " "a Dictionary's signature parameter"); @@ -413,18 +411,18 @@ Dict_tp_init(DBusPyDict *self, PyObject *args, PyObject *kwargs) tuple = Py_BuildValue("(O)", obj); if (!tuple) { - Py_DECREF(signature); + Py_CLEAR(signature); return -1; } if ((PyDict_Type.tp_init((PyObject *)self, tuple, NULL)) < 0) { - Py_DECREF(tuple); - Py_DECREF(signature); + Py_CLEAR(tuple); + Py_CLEAR(signature); return -1; } - Py_DECREF(tuple); + Py_CLEAR(tuple); - Py_XDECREF(self->signature); + Py_CLEAR(self->signature); self->signature = signature; return 0; } @@ -516,7 +514,7 @@ Struct_tp_repr(PyObject *self) key = PyLong_FromVoidPtr(self); if (!key) goto finally; sig = PyDict_GetItem(struct_signatures, key); - Py_DECREF(key); + Py_CLEAR(key); if (!sig) sig = Py_None; sig_repr = PyObject_Repr(sig); if (!sig_repr) goto finally; @@ -537,8 +535,8 @@ Struct_tp_repr(PyObject *self) } finally: - Py_XDECREF(parent_repr); - Py_XDECREF(sig_repr); + Py_CLEAR(parent_repr); + Py_CLEAR(sig_repr); return my_repr; } @@ -571,12 +569,12 @@ Struct_tp_new (PyTypeObject *cls, PyObject *args, PyObject *kwargs) return NULL; if (PyTuple_Size(self) < 1) { PyErr_SetString(PyExc_ValueError, "D-Bus structs may not be empty"); - Py_DECREF(self); + Py_CLEAR(self); return NULL; } if (!dbus_py_variant_level_set(self, variantness)) { - Py_DECREF(self); + Py_CLEAR(self); return NULL; } @@ -591,26 +589,26 @@ Struct_tp_new (PyTypeObject *cls, PyObject *args, PyObject *kwargs) signature = PyObject_CallFunction((PyObject *)&DBusPySignature_Type, "(O)", signature); if (!signature) { - Py_DECREF(self); + Py_CLEAR(self); return NULL; } } key = PyLong_FromVoidPtr(self); if (!key) { - Py_DECREF(self); - Py_DECREF(signature); + Py_CLEAR(self); + Py_CLEAR(signature); return NULL; } if (PyDict_SetItem(struct_signatures, key, signature) < 0) { - Py_DECREF(key); - Py_DECREF(self); - Py_DECREF(signature); + Py_CLEAR(key); + Py_CLEAR(self); + Py_CLEAR(signature); return NULL; } - Py_DECREF(key); - Py_DECREF(signature); + Py_CLEAR(key); + Py_CLEAR(signature); return self; } @@ -630,7 +628,7 @@ Struct_tp_dealloc(PyObject *self) PyErr_WriteUnraisable(self); } } - Py_DECREF(key); + Py_CLEAR(key); } else { /* not enough memory to free all the memory... leak the signature, @@ -663,11 +661,11 @@ Struct_tp_getattro(PyObject *obj, PyObject *name) if (strcmp(PyString_AS_STRING(name), "signature")) { value = dbus_py_variant_level_getattro(obj, name); - Py_DECREF(name); + Py_CLEAR(name); return value; } - Py_DECREF(name); + Py_CLEAR(name); key = PyLong_FromVoidPtr(obj); @@ -676,7 +674,7 @@ Struct_tp_getattro(PyObject *obj, PyObject *name) } value = PyDict_GetItem(struct_signatures, key); - Py_DECREF(key); + Py_CLEAR(key); if (!value) value = Py_None; diff --git a/_dbus_bindings/exceptions.c b/_dbus_bindings/exceptions.c index 141ce9e..3b42227 100644 --- a/_dbus_bindings/exceptions.c +++ b/_dbus_bindings/exceptions.c @@ -42,13 +42,13 @@ import_exception(void) return FALSE; } exceptions = PyImport_Import(name); - Py_DECREF(name); + Py_CLEAR(name); if (exceptions == NULL) { return FALSE; } imported_dbus_exception = PyObject_GetAttrString(exceptions, "DBusException"); - Py_DECREF(exceptions); + Py_CLEAR(exceptions); return (imported_dbus_exception != NULL); } @@ -82,7 +82,7 @@ DBusPyException_ConsumeError(DBusError *error) if (!name) goto finally; ret = PyObject_SetAttrString(exc_value, "_dbus_error_name", name); - Py_DECREF(name); + Py_CLEAR(name); if (ret < 0) { goto finally; } @@ -91,7 +91,7 @@ DBusPyException_ConsumeError(DBusError *error) PyErr_SetObject(imported_dbus_exception, exc_value); finally: - Py_XDECREF(exc_value); + Py_CLEAR(exc_value); dbus_error_free(error); return NULL; } diff --git a/_dbus_bindings/generic.c b/_dbus_bindings/generic.c index cda138d..05906ae 100644 --- a/_dbus_bindings/generic.c +++ b/_dbus_bindings/generic.c @@ -69,7 +69,7 @@ void dbus_py_take_gil_and_xdecref(PyObject *obj) { PyGILState_STATE gil = PyGILState_Ensure(); - Py_XDECREF(obj); + Py_CLEAR(obj); PyGILState_Release(gil); } diff --git a/_dbus_bindings/int.c b/_dbus_bindings/int.c index b669d57..a1ee697 100644 --- a/_dbus_bindings/int.c +++ b/_dbus_bindings/int.c @@ -66,7 +66,7 @@ Boolean_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) tuple = Py_BuildValue("(i)", PyObject_IsTrue(value) ? 1 : 0); if (!tuple) return NULL; self = (DBusPyIntBase_Type.tp_new)(cls, tuple, kwargs); - Py_DECREF(tuple); + Py_CLEAR(tuple); return self; } @@ -168,7 +168,7 @@ Int16_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) { PyObject *self = (DBusPyIntBase_Type.tp_new)(cls, args, kwargs); if (self && dbus_py_int16_range_check(self) == -1 && PyErr_Occurred()) { - Py_DECREF(self); + Py_CLEAR(self); return NULL; } return self; @@ -258,7 +258,7 @@ UInt16_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) PyObject *self = (DBusPyIntBase_Type.tp_new)(cls, args, kwargs); if (self && dbus_py_uint16_range_check(self) == (dbus_uint16_t)(-1) && PyErr_Occurred()) { - Py_DECREF (self); + Py_CLEAR (self); return NULL; } return self; @@ -347,7 +347,7 @@ Int32_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) { PyObject *self = (DBusPyIntBase_Type.tp_new)(cls, args, kwargs); if (self && dbus_py_int32_range_check(self) == -1 && PyErr_Occurred()) { - Py_DECREF(self); + Py_CLEAR(self); return NULL; } return self; @@ -430,16 +430,16 @@ dbus_py_uint32_range_check(PyObject *obj) if (!long_obj) return (dbus_uint32_t)(-1); i = PyLong_AsUnsignedLong(long_obj); if (i == (unsigned long)(-1) && PyErr_Occurred()) { - Py_DECREF(long_obj); + Py_CLEAR(long_obj); return (dbus_uint32_t)(-1); } if (i > UINT32_MAX) { PyErr_Format(PyExc_OverflowError, "Value %d out of range for UInt32", (int)i); - Py_DECREF(long_obj); + Py_CLEAR(long_obj); return (dbus_uint32_t)(-1); } - Py_DECREF(long_obj); + Py_CLEAR(long_obj); return i; } @@ -449,7 +449,7 @@ UInt32_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) PyObject *self = (DBusPyLongBase_Type.tp_new)(cls, args, kwargs); if (self && dbus_py_uint32_range_check(self) == (dbus_uint32_t)(-1) && PyErr_Occurred()) { - Py_DECREF(self); + Py_CLEAR(self); return NULL; } return self; @@ -536,15 +536,15 @@ dbus_py_int64_range_check(PyObject *obj) if (!long_obj) return -1; i = PyLong_AsLongLong(long_obj); if (i == -1 && PyErr_Occurred()) { - Py_DECREF(long_obj); + Py_CLEAR(long_obj); return -1; } if (i < INT64_MIN || i > INT64_MAX) { PyErr_SetString(PyExc_OverflowError, "Value out of range for Int64"); - Py_DECREF(long_obj); + Py_CLEAR(long_obj); return -1; } - Py_DECREF(long_obj); + Py_CLEAR(long_obj); return i; } #endif @@ -555,7 +555,7 @@ Int64_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) #ifdef DBUS_PYTHON_64_BIT_WORKS PyObject *self = (DBusPyLongBase_Type.tp_new)(cls, args, kwargs); if (self && dbus_py_int64_range_check(self) == -1 && PyErr_Occurred()) { - Py_DECREF(self); + Py_CLEAR(self); return NULL; } return self; @@ -643,15 +643,15 @@ dbus_py_uint64_range_check(PyObject *obj) if (!long_obj) return (dbus_uint64_t)(-1); i = PyLong_AsUnsignedLongLong(long_obj); if (i == (unsigned PY_LONG_LONG)(-1) && PyErr_Occurred()) { - Py_DECREF(long_obj); + Py_CLEAR(long_obj); return (dbus_uint64_t)(-1); } if (i > UINT64_MAX) { PyErr_SetString(PyExc_OverflowError, "Value out of range for UInt64"); - Py_DECREF(long_obj); + Py_CLEAR(long_obj); return (dbus_uint64_t)(-1); } - Py_DECREF(long_obj); + Py_CLEAR(long_obj); return i; } @@ -662,7 +662,7 @@ UInt64_tp_new (PyTypeObject *cls, PyObject *args, PyObject *kwargs) PyObject *self = (DBusPyLongBase_Type.tp_new)(cls, args, kwargs); if (self && dbus_py_uint64_range_check(self) == (dbus_uint64_t)(-1) && PyErr_Occurred()) { - Py_DECREF(self); + Py_CLEAR(self); return NULL; } return self; diff --git a/_dbus_bindings/message-append.c b/_dbus_bindings/message-append.c index d1ab57a..03ff926 100644 --- a/_dbus_bindings/message-append.c +++ b/_dbus_bindings/message-append.c @@ -147,7 +147,7 @@ get_object_path(PyObject *obj) return magic_attr; } else { - Py_DECREF(magic_attr); + Py_CLEAR(magic_attr); PyErr_SetString(PyExc_TypeError, "__dbus_object_path__ must be " "a string"); return NULL; @@ -186,10 +186,10 @@ _signature_string_from_pyobject(PyObject *obj, long *variant_level_ptr) if (!magic_attr) return NULL; if (magic_attr != Py_None) { - Py_DECREF(magic_attr); + Py_CLEAR(magic_attr); return PyString_FromString(DBUS_TYPE_OBJECT_PATH_AS_STRING); } - Py_DECREF(magic_attr); + Py_CLEAR(magic_attr); /* Ordering is important: some of these are subclasses of each other. */ if (PyInt_Check(obj)) { @@ -250,22 +250,22 @@ _signature_string_from_pyobject(PyObject *obj, long *variant_level_ptr) if (!list) return NULL; if (len == 0) { PyErr_SetString(PyExc_ValueError, "D-Bus structs cannot be empty"); - Py_DECREF(list); + Py_CLEAR(list); return NULL; } /* Set the first and last elements of list to be the parentheses */ item = PyString_FromString(DBUS_STRUCT_BEGIN_CHAR_AS_STRING); if (PyList_SetItem(list, 0, item) < 0) { - Py_DECREF(list); + Py_CLEAR(list); return NULL; } item = PyString_FromString(DBUS_STRUCT_END_CHAR_AS_STRING); if (PyList_SetItem(list, len + 1, item) < 0) { - Py_DECREF(list); + Py_CLEAR(list); return NULL; } if (!item || !PyList_GET_ITEM(list, 0)) { - Py_DECREF(list); + Py_CLEAR(list); return NULL; } item = NULL; @@ -273,16 +273,16 @@ _signature_string_from_pyobject(PyObject *obj, long *variant_level_ptr) for (i = 0; i < len; i++) { item = PyTuple_GetItem(obj, i); if (!item) { - Py_DECREF(list); + Py_CLEAR(list); return NULL; } item = _signature_string_from_pyobject(item, NULL); if (!item) { - Py_DECREF(list); + Py_CLEAR(list); return NULL; } if (PyList_SetItem(list, i + 1, item) < 0) { - Py_DECREF(list); + Py_CLEAR(list); return NULL; } item = NULL; @@ -290,13 +290,13 @@ _signature_string_from_pyobject(PyObject *obj, long *variant_level_ptr) empty_str = PyString_FromString(""); if (!empty_str) { /* really shouldn't happen */ - Py_DECREF(list); + Py_CLEAR(list); return NULL; } ret = PyObject_CallMethod(empty_str, "join", "(O)", list); /* new ref */ /* whether ret is NULL or not, */ - Py_DECREF(empty_str); - Py_DECREF(list); + Py_CLEAR(empty_str); + Py_CLEAR(list); return ret; } else if (PyList_Check(obj)) { @@ -349,8 +349,8 @@ _signature_string_from_pyobject(PyObject *obj, long *variant_level_ptr) PyString_AS_STRING(keysig), PyString_AS_STRING(valuesig)); } - Py_XDECREF(keysig); - Py_XDECREF(valuesig); + Py_CLEAR(keysig); + Py_CLEAR(valuesig); return ret; } else { @@ -403,7 +403,7 @@ dbus_py_Message_guess_signature(PyObject *unused UNUSED, PyObject *args) PyErr_SetString(PyExc_RuntimeError, "Internal error: " "_signature_string_from_pyobject returned " "a bad result"); - Py_DECREF(tmp); + Py_CLEAR(tmp); return NULL; } ret = PyObject_CallFunction((PyObject *)&DBusPySignature_Type, "(s#)", @@ -411,7 +411,7 @@ dbus_py_Message_guess_signature(PyObject *unused UNUSED, PyObject *args) PyString_GET_SIZE(tmp) - 2); DBG("Message_guess_signature: returning Signature at %p \"%s\"", ret, ret ? PyString_AS_STRING(ret) : "(NULL)"); - Py_DECREF(tmp); + Py_CLEAR(tmp); return ret; } @@ -433,7 +433,7 @@ _message_iter_append_string(DBusMessageIter *appender, PyObject *object_path = get_object_path (obj); if (object_path == Py_None) { - Py_DECREF(object_path); + Py_CLEAR(object_path); } else if (!object_path) { return -1; @@ -441,7 +441,7 @@ _message_iter_append_string(DBusMessageIter *appender, else { int ret = _message_iter_append_string(appender, sig_type, object_path, FALSE); - Py_DECREF(object_path); + Py_CLEAR(object_path); return ret; } } @@ -458,8 +458,7 @@ _message_iter_append_string(DBusMessageIter *appender, "to be sent over D-Bus must be valid UTF-8"); return -1; } - Py_DECREF(unicode); - unicode = NULL; + Py_CLEAR(unicode); DBG("Performing actual append: string %s", s); if (!dbus_message_iter_append_basic(appender, sig_type, @@ -478,7 +477,7 @@ _message_iter_append_string(DBusMessageIter *appender, PyErr_NoMemory(); return -1; } - Py_DECREF(utf8); + Py_CLEAR(utf8); } else { PyErr_SetString(PyExc_TypeError, @@ -588,7 +587,7 @@ _message_iter_append_dictentry(DBusMessageIter *appender, ret = -1; } out: - Py_DECREF(value); + Py_CLEAR(value); return ret; } @@ -697,11 +696,11 @@ _message_iter_append_multi(DBusMessageIter *appender, if (!args) break; byte = PyObject_Call((PyObject *)&DBusPyByte_Type, args, NULL); - Py_DECREF(args); + Py_CLEAR(args); if (!byte) break; ret = _message_iter_append_variant(&sub_appender, byte); - Py_DECREF(byte); + Py_CLEAR(byte); } else { /* advances sub_sig_iter and sets more on success - for array @@ -710,7 +709,7 @@ _message_iter_append_multi(DBusMessageIter *appender, contents, &more); } - Py_DECREF(contents); + Py_CLEAR(contents); if (ret < 0) { break; } @@ -733,7 +732,7 @@ _message_iter_append_multi(DBusMessageIter *appender, } out: - Py_XDECREF(iterator); + Py_CLEAR(iterator); dbus_free(sig); return ret; } @@ -851,7 +850,7 @@ _message_iter_append_variant(DBusMessageIter *appender, PyObject *obj) } out: - Py_XDECREF(obj_sig); + Py_CLEAR(obj_sig); return ret; } @@ -1114,7 +1113,7 @@ dbus_py_Message_append(Message *self, PyObject *args, PyObject *kwargs) } /* success! */ - Py_XDECREF(signature_obj); + Py_CLEAR(signature_obj); Py_RETURN_NONE; hosed: @@ -1125,7 +1124,7 @@ hosed: dbus_message_unref(self->msg); self->msg = NULL; err: - Py_XDECREF(signature_obj); + Py_CLEAR(signature_obj); return NULL; } diff --git a/_dbus_bindings/message-get-args.c b/_dbus_bindings/message-get-args.c index d6b7aba..7fc0ca4 100644 --- a/_dbus_bindings/message-get-args.c +++ b/_dbus_bindings/message-get-args.c @@ -97,8 +97,7 @@ _message_iter_append_all_to_list(DBusMessageIter *iter, PyObject *list, fprintf(stderr, " of type %p\n", item->ob_type); #endif ret = PyList_Append(list, item); - Py_DECREF(item); - item = NULL; + Py_CLEAR(item); if (ret < 0) return -1; #ifdef USING_DBG fprintf(stderr, "DBG/%ld: list now contains: ", (long)getpid()); @@ -133,7 +132,7 @@ _message_iter_get_dict(DBusMessageIter *iter, return NULL; } status = PyDict_SetItem(kwargs, dbus_py_signature_const, sig); - Py_DECREF(sig); + Py_CLEAR(sig); if (status < 0) { return NULL; } @@ -155,24 +154,24 @@ _message_iter_get_dict(DBusMessageIter *iter, key = _message_iter_get_pyobject(&kv, opts, 0); if (!key) { - Py_DECREF(ret); + Py_CLEAR(ret); return NULL; } dbus_message_iter_next(&kv); value = _message_iter_get_pyobject(&kv, opts, 0); if (!value) { - Py_DECREF(key); - Py_DECREF(ret); + Py_CLEAR(key); + Py_CLEAR(ret); return NULL; } status = PyDict_SetItem(ret, key, value); - Py_DECREF(key); - Py_DECREF(value); + Py_CLEAR(key); + Py_CLEAR(value); if (status < 0) { - Py_DECREF(ret); + Py_CLEAR(ret); return NULL; } dbus_message_iter_next(&entries); @@ -219,16 +218,16 @@ _message_iter_get_pyobject(DBusMessageIter *iter, } kwargs = PyDict_New(); if (!kwargs) { - Py_DECREF(variant_level_int); + Py_CLEAR(variant_level_int); return NULL; } if (PyDict_SetItem(kwargs, dbus_py_variant_level_const, variant_level_int) < 0) { - Py_DECREF(variant_level_int); - Py_DECREF(kwargs); + Py_CLEAR(variant_level_int); + Py_CLEAR(kwargs); return NULL; } - Py_DECREF(variant_level_int); + Py_CLEAR(variant_level_int); } /* From here down you need to break from the switch to exit, so the * dict is freed if necessary @@ -417,14 +416,13 @@ _message_iter_get_pyobject(DBusMessageIter *iter, dbus_free(sig); if (!sig_obj) break; status = PyDict_SetItem(kwargs, dbus_py_signature_const, sig_obj); - Py_DECREF(sig_obj); + Py_CLEAR(sig_obj); if (status < 0) break; ret = PyObject_Call((PyObject *)&DBusPyArray_Type, dbus_py_empty_tuple, kwargs); if (!ret) break; if (_message_iter_append_all_to_list(&sub, ret, opts) < 0) { - Py_DECREF(ret); - ret = NULL; + Py_CLEAR(ret); } } break; @@ -439,7 +437,7 @@ _message_iter_get_pyobject(DBusMessageIter *iter, if (!list) break; dbus_message_iter_recurse(iter, &sub); if (_message_iter_append_all_to_list(&sub, list, opts) < 0) { - Py_DECREF(list); + Py_CLEAR(list); break; } tuple = Py_BuildValue("(O)", list); @@ -450,8 +448,8 @@ _message_iter_get_pyobject(DBusMessageIter *iter, ret = NULL; } /* whether successful or not, we take the same action: */ - Py_DECREF(list); - Py_XDECREF(tuple); + Py_CLEAR(list); + Py_CLEAR(tuple); } break; @@ -470,8 +468,8 @@ _message_iter_get_pyobject(DBusMessageIter *iter, "message", type); } - Py_XDECREF(args); - Py_XDECREF(kwargs); + Py_CLEAR(args); + Py_CLEAR(kwargs); return ret; } @@ -511,7 +509,7 @@ dbus_py_Message_get_args_list(Message *self, PyObject *args, PyObject *kwargs) /* Iterate over args, if any, appending to list */ if (dbus_message_iter_init(self->msg, &iter)) { if (_message_iter_append_all_to_list(&iter, list, &opts) < 0) { - Py_DECREF(list); + Py_CLEAR(list); DBG_EXC("%s", "Message_get_args: appending all to list failed:"); return NULL; } diff --git a/_dbus_bindings/message.c b/_dbus_bindings/message.c index a2c04c3..af74d95 100644 --- a/_dbus_bindings/message.c +++ b/_dbus_bindings/message.c @@ -478,31 +478,29 @@ Message_get_path_decomposed(Message *self, PyObject *unused UNUSED) if (!ret) return NULL; if (!self->msg) { - Py_DECREF(ret); + Py_CLEAR(ret); return DBusPy_RaiseUnusableMessage(); } if (!dbus_message_get_path_decomposed(self->msg, &paths)) { - Py_DECREF(ret); + Py_CLEAR(ret); return PyErr_NoMemory(); } if (!paths) { - Py_DECREF(ret); + Py_CLEAR(ret); Py_RETURN_NONE; } for (ptr = paths; *ptr; ptr++) { PyObject *str = PyString_FromString(*ptr); if (!str) { - Py_DECREF(ret); - ret = NULL; + Py_CLEAR(ret); break; } if (PyList_Append(ret, str) < 0) { - Py_DECREF(ret); - ret = NULL; + Py_CLEAR(ret); break; } - Py_DECREF(str); + Py_CLEAR(str); str = NULL; } dbus_free_string_array(paths); diff --git a/_dbus_bindings/module.c b/_dbus_bindings/module.c index a4c2a66..453df6f 100644 --- a/_dbus_bindings/module.c +++ b/_dbus_bindings/module.c @@ -214,7 +214,7 @@ set_default_main_loop(PyObject *always_null UNUSED, old_loop = default_main_loop; Py_INCREF(new_loop); default_main_loop = new_loop; - Py_XDECREF(old_loop); + Py_CLEAR(old_loop); Py_RETURN_NONE; } diff --git a/_dbus_bindings/pending-call.c b/_dbus_bindings/pending-call.c index ad18fd7..6970f22 100644 --- a/_dbus_bindings/pending-call.c +++ b/_dbus_bindings/pending-call.c @@ -113,15 +113,15 @@ _pending_call_notify_function(DBusPendingCall *pc, if (!ret) { PyErr_Print(); } - Py_XDECREF(ret); - Py_DECREF(msg_obj); + Py_CLEAR(ret); + Py_CLEAR(msg_obj); } /* else OOM has happened - not a lot we can do about that, * except possibly making it fatal (FIXME?) */ } release: - Py_XDECREF(handler); + Py_CLEAR(handler); PyGILState_Release(gil); } @@ -151,8 +151,8 @@ DBusPyPendingCall_ConsumeDBusPendingCall(DBusPendingCall *pc, PendingCall *self = PyObject_New(PendingCall, &PendingCallType); if (!list || !self) { - Py_XDECREF(list); - Py_XDECREF(self); + Py_CLEAR(list); + Py_CLEAR(self); Py_BEGIN_ALLOW_THREADS dbus_pending_call_cancel(pc); dbus_pending_call_unref(pc); @@ -177,8 +177,8 @@ DBusPyPendingCall_ConsumeDBusPendingCall(DBusPendingCall *pc, PyErr_NoMemory(); /* DECREF twice - one for the INCREF and one for the allocation */ Py_DECREF(list); - Py_DECREF(list); - Py_DECREF(self); + Py_CLEAR(list); + Py_CLEAR(self); Py_BEGIN_ALLOW_THREADS dbus_pending_call_cancel(pc); dbus_pending_call_unref(pc); @@ -206,7 +206,7 @@ DBusPyPendingCall_ConsumeDBusPendingCall(DBusPendingCall *pc, _pending_call_notify_function(pc, list); } - Py_DECREF(list); + Py_CLEAR(list); self->pc = pc; return (PyObject *)self; } diff --git a/_dbus_bindings/server.c b/_dbus_bindings/server.c index 7fc4f70..14d41de 100644 --- a/_dbus_bindings/server.c +++ b/_dbus_bindings/server.c @@ -183,21 +183,21 @@ DBusPyServer_new_connection_cb(DBusServer *server, conn_obj = PyObject_CallFunctionObjArgs((PyObject *)conn_class, wrapper, ((Server*) self)->mainloop, NULL); - Py_DECREF(wrapper); + Py_CLEAR(wrapper); if (!conn_obj) goto out; result = PyObject_CallFunctionObjArgs(method, conn_obj, NULL); - Py_XDECREF (conn_obj); + Py_CLEAR (conn_obj); /* discard result if not NULL, and fall through regardless */ - Py_XDECREF(result); + Py_CLEAR(result); } out: - Py_XDECREF(method); - Py_XDECREF(self); + Py_CLEAR(method); + Py_CLEAR(self); if (PyErr_Occurred()) PyErr_Print(); @@ -329,9 +329,9 @@ DBusPyServer_NewConsumingDBusServer(PyTypeObject *cls, err: DBG("Failed to construct Server from DBusServer at %p", server); - Py_XDECREF(mainloop); - Py_XDECREF(self); - Py_XDECREF(ref); + Py_CLEAR(mainloop); + Py_CLEAR(self); + Py_CLEAR(ref); if (server) { Py_BEGIN_ALLOW_THREADS @@ -414,7 +414,7 @@ static void Server_tp_dealloc(Server *self) Py_END_ALLOW_THREADS } - Py_DECREF(self->mainloop); + Py_CLEAR(self->mainloop); /* make sure to do this last to preserve the invariant that * self->server is always non-NULL for any referenced Server. diff --git a/_dbus_bindings/signature.c b/_dbus_bindings/signature.c index 6b31ab4..b15261c 100644 --- a/_dbus_bindings/signature.c +++ b/_dbus_bindings/signature.c @@ -62,8 +62,7 @@ typedef struct { static void SignatureIter_tp_dealloc (SignatureIter *self) { - Py_XDECREF(self->string); - self->string = NULL; + Py_CLEAR(self->string); PyObject_Del(self); } @@ -84,8 +83,7 @@ SignatureIter_tp_iternext (SignatureIter *self) if (!dbus_signature_iter_next(&(self->iter))) { /* mark object as having been finished with */ - Py_DECREF(self->string); - self->string = NULL; + Py_CLEAR(self->string); } return obj; diff --git a/_dbus_bindings/string.c b/_dbus_bindings/string.c index 19eab2c..d68af4e 100644 --- a/_dbus_bindings/string.c +++ b/_dbus_bindings/string.c @@ -77,7 +77,7 @@ UTF8String_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) &str, &variantness)) return NULL; unicode = PyUnicode_DecodeUTF8(str, strlen(str), NULL); if (!unicode) return NULL; - Py_DECREF(unicode); + Py_CLEAR(unicode); return (DBusPyStrBase_Type.tp_new)(cls, args, kwargs); } @@ -285,7 +285,7 @@ String_tp_repr(PyObject *self) PyString_AS_STRING(parent_repr)); } /* whether my_repr is NULL or not: */ - Py_DECREF(parent_repr); + Py_CLEAR(parent_repr); return my_repr; } diff --git a/_dbus_glib_bindings/module.c b/_dbus_glib_bindings/module.c index 93503d5..a685421 100644 --- a/_dbus_glib_bindings/module.c +++ b/_dbus_glib_bindings/module.c @@ -115,22 +115,22 @@ DBusGMainLoop (PyObject *always_null UNUSED, PyObject *args, PyObject *kwargs) if (mainloop && set_as_default) { if (!_dbus_bindings_module) { PyErr_SetString(PyExc_ImportError, "_dbus_bindings not imported"); - Py_DECREF(mainloop); + Py_CLEAR(mainloop); return NULL; } function = PyObject_GetAttrString(_dbus_bindings_module, "set_default_main_loop"); if (!function) { - Py_DECREF(mainloop); + Py_CLEAR(mainloop); return NULL; } result = PyObject_CallFunctionObjArgs(function, mainloop, NULL); - Py_DECREF(function); + Py_CLEAR(function); if (!result) { - Py_DECREF(mainloop); + Py_CLEAR(mainloop); return NULL; } - Py_DECREF(result); + Py_CLEAR(result); } return mainloop; } diff --git a/test/dbus_py_test.c b/test/dbus_py_test.c index 5604e32..a98c4d7 100644 --- a/test/dbus_py_test.c +++ b/test/dbus_py_test.c @@ -88,19 +88,19 @@ UnusableMainLoop (PyObject *always_null UNUSED, PyObject *args, PyObject *kwargs if (mainloop && set_as_default) { if (!_dbus_bindings_module) { PyErr_SetString(PyExc_ImportError, "_dbus_bindings not imported"); - Py_DECREF(mainloop); + Py_CLEAR(mainloop); return NULL; } function = PyObject_GetAttrString(_dbus_bindings_module, "set_default_main_loop"); if (!function) { - Py_DECREF(mainloop); + Py_CLEAR(mainloop); return NULL; } result = PyObject_CallFunctionObjArgs(function, mainloop, NULL); - Py_DECREF(function); + Py_CLEAR(function); if (!result) { - Py_DECREF(mainloop); + Py_CLEAR(mainloop); return NULL; } } |