python: add a failure label to method wrappers (#44287)

To separate wrapping code from unwinding and error handling code.
This commit is contained in:
Benjamin Dauvergne 2020-06-20 12:33:39 +02:00
parent 35682272ec
commit 0289da907f
2 changed files with 15 additions and 3 deletions

View File

@ -911,7 +911,8 @@ register_constants(PyObject *d)
self.wrapper_list.append(name)
print_('''static PyObject*
%s(G_GNUC_UNUSED PyObject *self, PyObject *args)
{''' % name, file=fd)
{
int ok = 1;''' % name, file=fd)
parse_tuple_format = []
parse_tuple_args = []
for arg in m.args:
@ -1037,6 +1038,7 @@ register_constants(PyObject *d)
if is_transfer_full(m.return_arg, default=True):
self.free_value(fd, m.return_arg, name = 'return_value')
for f, arg in zip(parse_tuple_format, m.args):
if is_out(arg):
self.return_value(fd, arg, return_var_name = arg[1], return_pyvar_name = 'out_pyvalue')
@ -1056,10 +1058,19 @@ register_constants(PyObject *d)
elif not is_transfer_full(arg) and is_xml_node(arg):
self.free_value(fd, arg)
print_('failure:', file=fd)
if not m.return_type:
print_(' return noneRef();', file=fd)
print_(' if (ok) {', file=fd)
print_(' return noneRef();', file=fd)
else:
print_(' return return_pyvalue;', file=fd)
print_(' if (ok && return_pyvalue) {', file=fd)
print_(' return return_pyvalue;', file=fd)
print_(' } else {', file=fd)
if m.return_type:
print_(' Py_XDECREF(return_pyvalue);', file=fd)
print_(' return NULL;', file=fd)
print_(' }', file=fd)
print_('}', file=fd)
print_('', file=fd)

View File

@ -74,6 +74,7 @@ void PyErr_WarnFormat(PyObject *category, int stacklevel, const char *format, ..
#endif
#define RETURN_IF_FAIL(op) do { if (! (op)) { return NULL; } } while(0)
#define EXIT_IF_FAIL(op) do { if (! (op)) { ok = 0; goto failure; } } while(0)
GQuark lasso_wrapper_key;