Projet

Général

Profil

0014-python-return-NULL-if-set_list_of_strings-fails-4428.patch

Benjamin Dauvergne, 20 juin 2020 12:44

Télécharger (4,02 ko)

Voir les différences:

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

 bindings/python/lang.py                |  4 ++--
 bindings/python/tests/binding_tests.py |  4 ++++
 bindings/python/wrapper_top.c          | 13 +++++++++----
 3 files changed, 15 insertions(+), 6 deletions(-)
bindings/python/lang.py
818 818
            elif is_glist(m):
819 819
                el_type = element_type(m)
820 820
                if is_cstring(el_type):
821
                    print_('    set_list_of_strings(&this->%s, cvt_value);' % name, file=fd)
821
                    print_('    RETURN_IF_FAIL(set_list_of_strings(&this->%s, cvt_value));' % name, file=fd)
822 822
                elif is_xml_node(el_type):
823 823
                    print_('    set_list_of_xml_nodes(&this->%s, cvt_value);' % name, file=fd)
824 824
                elif is_object(el_type):
......
981 981
            if is_list(arg):
982 982
                qualifier = element_type(arg)
983 983
                if is_cstring(qualifier):
984
                    print_('    set_list_of_strings(&%s, cvt_%s);' % (arg[1], arg[1]), file=fd)
984
                    print_('    EXIT_IF_FAIL(set_list_of_strings(&%s, cvt_%s));' % (arg[1], arg[1]), file=fd)
985 985
                elif is_xml_node(qualifier):
986 986
                    print_('    set_list_of_xml_nodes(&%s, cvt_%s);' % (arg[1], arg[1]), file=fd)
987 987
                elif isinstance(qualifier, str) and qualifier.startswith('Lasso'):
bindings/python/tests/binding_tests.py
329 329
        node.sessionIndexes = ()
330 330
        assert node.sessionIndexes == (), node.sessionIndexes
331 331

  
332
    def test_set_list_of_strings(self):
333
        node = lasso.Samlp2RequestedAuthnContext()
334
        with self.assertRaises(TypeError, msg='value should be a tuple of strings'):
335
            node.authnContextClassRef = [None]
332 336

  
333 337

  
334 338

  
bindings/python/wrapper_top.c
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 93
G_GNUC_UNUSED static int set_hashtable_of_strings(GHashTable *a_hash, PyObject *dict);
94
G_GNUC_UNUSED static void set_list_of_strings(GList **a_list, PyObject *seq);
94
G_GNUC_UNUSED static int 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);
97 97
G_GNUC_UNUSED static PyObject *get_list_of_strings(const GList *a_list);
......
324 324
/** Set the GList* pointer, pointed by a_list, to a pointer on a new GList
325 325
 * created by converting the python seq into a GList of char*.
326 326
 */
327
static void
327
int
328 328
set_list_of_strings(GList **a_list, PyObject *seq) {
329 329
	GList *list = NULL;
330 330
	int l = 0,i;
331 331

  
332
	lasso_return_if_fail(valid_seq(seq));
332
	if (! valid_seq(seq)) {
333
		PyErr_SetString(PyExc_TypeError,
334
				"value should be a tuple of strings");
335
		return 0;
336
	}
333 337
	if (seq != Py_None) {
334 338
		l = PySequence_Length(seq);
335 339
	}
......
348 352
	}
349 353
	free_list(a_list, (GFunc)g_free);
350 354
	*a_list = list;
351
	return;
355
	return 1;
352 356
failure:
353 357
	free_list(&list, (GFunc)g_free);
358
	return 0;
354 359
}
355 360

  
356 361
/** Set the GList* pointer, pointed by a_list, to a pointer on a new GList
357
-