python: return NULL if set_list_of_strings fails (#44287)
This commit is contained in:
parent
ed528ce26a
commit
c53b6b5a73
|
@ -821,7 +821,7 @@ register_constants(PyObject *d)
|
|||
elif is_glist(m):
|
||||
el_type = element_type(m)
|
||||
if is_cstring(el_type):
|
||||
print_(' set_list_of_strings(&this->%s, cvt_value);' % name, file=fd)
|
||||
print_(' RETURN_IF_FAIL(set_list_of_strings(&this->%s, cvt_value));' % name, file=fd)
|
||||
elif is_xml_node(el_type):
|
||||
print_(' set_list_of_xml_nodes(&this->%s, cvt_value);' % name, file=fd)
|
||||
elif is_object(el_type):
|
||||
|
@ -984,7 +984,7 @@ register_constants(PyObject *d)
|
|||
if is_list(arg):
|
||||
qualifier = element_type(arg)
|
||||
if is_cstring(qualifier):
|
||||
print_(' set_list_of_strings(&%s, cvt_%s);' % (arg[1], arg[1]), file=fd)
|
||||
print_(' EXIT_IF_FAIL(set_list_of_strings(&%s, cvt_%s));' % (arg[1], arg[1]), file=fd)
|
||||
elif is_xml_node(qualifier):
|
||||
print_(' set_list_of_xml_nodes(&%s, cvt_%s);' % (arg[1], arg[1]), file=fd)
|
||||
elif isinstance(qualifier, str) and qualifier.startswith('Lasso'):
|
||||
|
|
|
@ -336,9 +336,13 @@ class BindingTestCase(unittest.TestCase):
|
|||
assert isinstance(str(cm.exception), str)
|
||||
with self.assertRaises(lasso.Error) as cm:
|
||||
lasso.Error.raise_on_rc(lasso._lasso.XML_ERROR_SCHEMA_INVALID_FRAGMENT)
|
||||
self.assertEqual(str(cm.exception), '<lasso.XmlSchemaInvalidFragmentError(17): An XML tree does not respect at least an XML schema of its namespaces.>')
|
||||
|
||||
self.assertEqual(str(cm.exception),
|
||||
'<lasso.XmlSchemaInvalidFragmentError(17): An XML tree does not respect at least an XML schema of its namespaces.>')
|
||||
|
||||
def test_set_list_of_strings(self):
|
||||
node = lasso.Samlp2RequestedAuthnContext()
|
||||
with self.assertRaises(TypeError, msg='value should be a tuple of strings'):
|
||||
node.authnContextClassRef = [None]
|
||||
|
||||
bindingSuite = unittest.makeSuite(BindingTestCase, 'test')
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ G_GNUC_UNUSED static PyObject* get_dict_from_hashtable_of_strings(GHashTable *va
|
|||
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 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 int 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);
|
||||
G_GNUC_UNUSED static PyObject *get_list_of_strings(const GList *a_list);
|
||||
|
@ -324,12 +324,16 @@ failure:
|
|||
/** Set the GList* pointer, pointed by a_list, to a pointer on a new GList
|
||||
* created by converting the python seq into a GList of char*.
|
||||
*/
|
||||
static void
|
||||
static int
|
||||
set_list_of_strings(GList **a_list, PyObject *seq) {
|
||||
GList *list = NULL;
|
||||
int l = 0,i;
|
||||
|
||||
lasso_return_if_fail(valid_seq(seq));
|
||||
if (! valid_seq(seq)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"value should be a tuple of strings");
|
||||
return 0;
|
||||
}
|
||||
if (seq != Py_None) {
|
||||
l = PySequence_Length(seq);
|
||||
}
|
||||
|
@ -348,9 +352,10 @@ set_list_of_strings(GList **a_list, PyObject *seq) {
|
|||
}
|
||||
free_list(a_list, (GFunc)g_free);
|
||||
*a_list = list;
|
||||
return;
|
||||
return 1;
|
||||
failure:
|
||||
free_list(&list, (GFunc)g_free);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Set the GList* pointer, pointed by a_list, to a pointer on a new GList
|
||||
|
|
Loading…
Reference in New Issue