Projet

Général

Profil

0016-python-return-NULL-if-set_list_of_pygobject-fails-44.patch

Benjamin Dauvergne, 20 juin 2020 12:44

Télécharger (4,22 ko)

Voir les différences:

Subject: [PATCH 16/21] python: return NULL if set_list_of_pygobject fails
 (#44287)

 bindings/python/lang.py                |  4 ++--
 bindings/python/tests/binding_tests.py |  8 ++++++++
 bindings/python/wrapper_top.c          | 13 +++++++++----
 3 files changed, 19 insertions(+), 6 deletions(-)
bindings/python/lang.py
822 822
                elif is_xml_node(el_type):
823 823
                    print_('    RETURN_IF_FAIL(set_list_of_xml_nodes(&this->%s, cvt_value));' % name, file=fd)
824 824
                elif is_object(el_type):
825
                    print_('    set_list_of_pygobject(&this->%s, cvt_value);' % name, file=fd)
825
                    print_('    RETURN_IF_FAIL(set_list_of_pygobject(&this->%s, cvt_value));' % name, file=fd)
826 826
                else:
827 827
                    raise Exception('Unsupported setter for %s' % (m,))
828 828
            elif is_hashtable(m):
......
985 985
                elif is_xml_node(qualifier):
986 986
                    print_('    EXIT_IF_FAIL(set_list_of_xml_nodes(&%s, cvt_%s));' % (arg[1], arg[1]), file=fd)
987 987
                elif isinstance(qualifier, str) and qualifier.startswith('Lasso'):
988
                    print_('    set_list_of_pygobject(&%s, cvt_%s);' % (arg[1], arg[1]), file=fd)
988
                    print_('    EXIT_IF_FAIL(set_list_of_pygobject(&%s, cvt_%s));' % (arg[1], arg[1]), file=fd)
989 989
                else:
990 990
                    print_('E: unqualified GList argument in', name, qualifier, arg, file=sys.stderr)
991 991
            elif is_xml_node(arg):
bindings/python/tests/binding_tests.py
334 334
        with self.assertRaises(TypeError, msg='value should be a tuple of strings'):
335 335
            node.authnContextClassRef = [None]
336 336

  
337
    def test_set_list_of_pygobject(self):
338
        node = lasso.Saml2Attribute()
339

  
340
        class A:
341
            _cptr = None
342
        value = [A()]
343
        with self.assertRaises(TypeError, msg='value should be a tuple of PyGobject'):
344
            node.attributeValue = value
337 345

  
338 346

  
339 347
bindingSuite = unittest.makeSuite(BindingTestCase, 'test')
bindings/python/wrapper_top.c
93 93
G_GNUC_UNUSED static int set_hashtable_of_strings(GHashTable *a_hash, PyObject *dict);
94 94
G_GNUC_UNUSED static int set_list_of_strings(GList **a_list, PyObject *seq);
95 95
G_GNUC_UNUSED static int set_list_of_xml_nodes(GList **a_list, PyObject *seq);
96
G_GNUC_UNUSED static void set_list_of_pygobject(GList **a_list, PyObject *seq);
96
G_GNUC_UNUSED static int set_list_of_pygobject(GList **a_list, PyObject *seq);
97 97
G_GNUC_UNUSED static PyObject *get_list_of_strings(const GList *a_list);
98 98
G_GNUC_UNUSED static PyObject *get_list_of_xml_nodes(const GList *a_list);
99 99
G_GNUC_UNUSED static PyObject *get_list_of_pygobject(const GList *a_list);
......
401 401
/** Set the GList* pointer, pointed by a_list, to a pointer on a new GList
402 402
 * created by converting the python seq into a GList of GObject*.
403 403
 */
404
static void
404
int
405 405
set_list_of_pygobject(GList **a_list, PyObject *seq) {
406 406
	GList *list = NULL;
407 407
	int l = 0,i;
408 408

  
409
	lasso_return_if_fail(valid_seq(seq));
409
	if (!valid_seq(seq)) {
410
		PyErr_SetString(PyExc_TypeError,
411
				"value should be a tuple of PyGobject");
412
		return 0;
413
	}
410 414
	if (seq != Py_None) {
411 415
		l = PySequence_Length(seq);
412 416
	}
......
423 427
	}
424 428
	free_list(a_list, (GFunc)g_object_unref);
425 429
	*a_list = list;
426
	return;
430
	return 1;
427 431
failure:
428 432
	free_list(&list, (GFunc)g_object_unref);
433
	return 0;
429 434
}
430 435

  
431 436
static xmlNode*
432
-