python: return NULL if set_list_of_xml_nodes fails (#44287)

This commit is contained in:
Benjamin Dauvergne 2020-06-20 08:18:30 +02:00
parent c53b6b5a73
commit c844abd8e4
2 changed files with 17 additions and 7 deletions

View File

@ -823,7 +823,7 @@ register_constants(PyObject *d)
if is_cstring(el_type):
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)
print_(' RETURN_IF_FAIL(set_list_of_xml_nodes(&this->%s, cvt_value));' % name, file=fd)
elif is_object(el_type):
print_(' set_list_of_pygobject(&this->%s, cvt_value);' % name, file=fd)
else:
@ -986,7 +986,7 @@ register_constants(PyObject *d)
if is_cstring(qualifier):
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)
print_(' EXIT_IF_FAIL(set_list_of_xml_nodes(&%s, cvt_%s));' % (arg[1], arg[1]), file=fd)
elif isinstance(qualifier, str) and qualifier.startswith('Lasso'):
print_(' set_list_of_pygobject(&%s, cvt_%s);' % (arg[1], arg[1]), file=fd)
else:

View File

@ -92,7 +92,7 @@ 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 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 int 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);
G_GNUC_UNUSED static PyObject *get_list_of_xml_nodes(const GList *a_list);
@ -361,12 +361,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 xmlNode*.
*/
static void
static int
set_list_of_xml_nodes(GList **a_list, PyObject *seq) {
GList *list = NULL;
int l = 0,i;
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);
}
@ -379,13 +383,19 @@ set_list_of_xml_nodes(GList **a_list, PyObject *seq) {
goto failure;
}
item_node = get_xml_node_from_pystring(item);
if (! item_node) {
PyErr_SetString(PyExc_TypeError,
"values should be valid XML fragments");
goto failure;
}
list = g_list_append(list, item_node);
}
free_list(a_list, (GFunc)xmlFreeNode);
*a_list = list;
return;
return 1;
failure:
free_list(&list, (GFunc)xmlFreeNode);
return 0;
}
/** Set the GList* pointer, pointed by a_list, to a pointer on a new GList