From 63824e977e1cb1f2d00332fe7836a4e84e64febd Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Sat, 20 Jun 2020 07:36:23 +0200 Subject: [PATCH 13/21] python: return NULL if set_hashtable_of_strings fails (#44287) --- bindings/python/lang.py | 4 ++-- bindings/python/wrapper_top.c | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/bindings/python/lang.py b/bindings/python/lang.py index 426420a3..376a0e41 100644 --- a/bindings/python/lang.py +++ b/bindings/python/lang.py @@ -830,7 +830,7 @@ register_constants(PyObject *d) if is_object(el_type): print_(' RETURN_IF_FAIL(set_hashtable_of_pygobject(this->%s, cvt_value));' % name, file=fd) else: - print_(' set_hashtable_of_strings(this->%s, cvt_value);' % name, file=fd) + print_(' RETURN_IF_FAIL(set_hashtable_of_strings(this->%s, cvt_value));' % name, file=fd) elif is_object(m): print_(' set_object_field((GObject**)&this->%s, cvt_value);' % name, file=fd) else: @@ -999,7 +999,7 @@ register_constants(PyObject *d) if is_cstring(el_type) or (is_cstring(k_type) and is_cstring(v_type)): print_(' %s = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);' % arg[1], file=fd) - print_(' set_hashtable_of_strings(%s, cvt_%s);' % (arg[1], arg[1]), file=fd) + print_(' EXIT_IF_FAIL(set_hashtable_of_strings(%s, cvt_%s));' % (arg[1], arg[1]), file=fd) elif f == 'O': if is_optional(arg): print_(' if (PyObject_TypeCheck((PyObject*)cvt_%s, &PyGObjectPtrType)) {' % arg[1], file=fd) diff --git a/bindings/python/wrapper_top.c b/bindings/python/wrapper_top.c index a25d1e18..aa5f60a3 100644 --- a/bindings/python/wrapper_top.c +++ b/bindings/python/wrapper_top.c @@ -90,7 +90,7 @@ G_GNUC_UNUSED static PyObject* get_dict_from_hashtable_of_objects(GHashTable *va G_GNUC_UNUSED static PyObject* get_dict_from_hashtable_of_strings(GHashTable *value); G_GNUC_UNUSED static PyObject* PyGObjectPtr_New(GObject *obj); G_GNUC_UNUSED static int set_hashtable_of_pygobject(GHashTable *a_hash, PyObject *dict); -G_GNUC_UNUSED static void set_hashtable_of_strings(GHashTable *a_hash, PyObject *dict); +G_GNUC_UNUSED static int set_hashtable_of_strings(GHashTable *a_hash, PyObject *dict); G_GNUC_UNUSED static void set_list_of_strings(GList **a_list, PyObject *seq); G_GNUC_UNUSED static void set_list_of_xml_nodes(GList **a_list, PyObject *seq); G_GNUC_UNUSED static void set_list_of_pygobject(GList **a_list, PyObject *seq); @@ -280,7 +280,7 @@ failure: return 0; } -static void +int set_hashtable_of_strings(GHashTable *a_hash, PyObject *dict) { PyObject *key, *value; @@ -288,11 +288,11 @@ set_hashtable_of_strings(GHashTable *a_hash, PyObject *dict) if (! a_hash) { PyErr_SetString(PyExc_TypeError, "hashtable does not exist"); - return; + return 0; } if (dict != Py_None && ! PyDict_Check(dict)) { PyErr_SetString(PyExc_TypeError, "value should be a frozen dict"); - return; + return 0; } i = 0; // Increase ref count of common object between old and new @@ -316,8 +316,9 @@ set_hashtable_of_strings(GHashTable *a_hash, PyObject *dict) PyStringFree(ckey); PyStringFree(cvalue); } + return 1; failure: - return; + return 0; } /** Set the GList* pointer, pointed by a_list, to a pointer on a new GList -- 2.26.2