Projet

Général

Profil

0013-python-return-NULL-if-set_hashtable_of_strings-fails.patch

Benjamin Dauvergne, 20 juin 2020 12:44

Télécharger (3,5 ko)

Voir les différences:

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(-)
bindings/python/lang.py
830 830
                if is_object(el_type):
831 831
                    print_('    RETURN_IF_FAIL(set_hashtable_of_pygobject(this->%s, cvt_value));' % name, file=fd)
832 832
                else:
833
                    print_('    set_hashtable_of_strings(this->%s, cvt_value);' % name, file=fd)
833
                    print_('    RETURN_IF_FAIL(set_hashtable_of_strings(this->%s, cvt_value));' % name, file=fd)
834 834
            elif is_object(m):
835 835
                print_('    set_object_field((GObject**)&this->%s, cvt_value);' % name, file=fd)
836 836
            else:
......
999 999
                if is_cstring(el_type) or (is_cstring(k_type) and is_cstring(v_type)):
1000 1000

  
1001 1001
                    print_('    %s = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);' % arg[1], file=fd)
1002
                    print_('    set_hashtable_of_strings(%s, cvt_%s);' % (arg[1], arg[1]), file=fd)
1002
                    print_('    EXIT_IF_FAIL(set_hashtable_of_strings(%s, cvt_%s));' % (arg[1], arg[1]), file=fd)
1003 1003
            elif f == 'O':
1004 1004
                if is_optional(arg):
1005 1005
                    print_('    if (PyObject_TypeCheck((PyObject*)cvt_%s, &PyGObjectPtrType)) {' % arg[1], file=fd)
bindings/python/wrapper_top.c
90 90
G_GNUC_UNUSED static PyObject* get_dict_from_hashtable_of_strings(GHashTable *value);
91 91
G_GNUC_UNUSED static PyObject* PyGObjectPtr_New(GObject *obj);
92 92
G_GNUC_UNUSED static int set_hashtable_of_pygobject(GHashTable *a_hash, PyObject *dict);
93
G_GNUC_UNUSED static void set_hashtable_of_strings(GHashTable *a_hash, PyObject *dict);
93
G_GNUC_UNUSED static int set_hashtable_of_strings(GHashTable *a_hash, PyObject *dict);
94 94
G_GNUC_UNUSED static void set_list_of_strings(GList **a_list, PyObject *seq);
95 95
G_GNUC_UNUSED static void set_list_of_xml_nodes(GList **a_list, PyObject *seq);
96 96
G_GNUC_UNUSED static void set_list_of_pygobject(GList **a_list, PyObject *seq);
......
280 280
	return 0;
281 281
}
282 282

  
283
static void 
283
int
284 284
set_hashtable_of_strings(GHashTable *a_hash, PyObject *dict)
285 285
{
286 286
	PyObject *key, *value;
......
288 288

  
289 289
	if (! a_hash) {
290 290
		 PyErr_SetString(PyExc_TypeError, "hashtable does not exist");
291
		 return;
291
		 return 0;
292 292
	}
293 293
	if (dict != Py_None && ! PyDict_Check(dict)) {
294 294
		 PyErr_SetString(PyExc_TypeError, "value should be a frozen dict");
295
		 return;
295
		 return 0;
296 296
	}
297 297
	i = 0;
298 298
	// Increase ref count of common object between old and new
......
316 316
		PyStringFree(ckey);
317 317
		PyStringFree(cvalue);
318 318
	}
319
	return 1;
319 320
failure:
320
	return;
321
	return 0;
321 322
}
322 323

  
323 324
/** Set the GList* pointer, pointed by a_list, to a pointer on a new GList
324
-