Projet

Général

Profil

0009-python-add-a-failure-label-to-method-wrappers-44287.patch

Benjamin Dauvergne, 20 juin 2020 12:44

Télécharger (2,62 ko)

Voir les différences:

Subject: [PATCH 09/21] python: add a failure label to method wrappers (#44287)

To separate wrapping code from unwinding and error handling code.
 bindings/python/lang.py       | 17 ++++++++++++++---
 bindings/python/wrapper_top.c |  1 +
 2 files changed, 15 insertions(+), 3 deletions(-)
bindings/python/lang.py
908 908
        self.wrapper_list.append(name)
909 909
        print_('''static PyObject*
910 910
%s(G_GNUC_UNUSED PyObject *self, PyObject *args)
911
{''' % name, file=fd)
911
{
912
    int ok = 1;''' % name, file=fd)
912 913
        parse_tuple_format = []
913 914
        parse_tuple_args = []
914 915
        for arg in m.args:
......
1034 1035

  
1035 1036
            if is_transfer_full(m.return_arg, default=True):
1036 1037
                self.free_value(fd, m.return_arg, name = 'return_value')
1038

  
1037 1039
        for f, arg in zip(parse_tuple_format, m.args):
1038 1040
            if is_out(arg):
1039 1041
                self.return_value(fd, arg, return_var_name = arg[1], return_pyvar_name = 'out_pyvalue')
......
1053 1055
            elif not is_transfer_full(arg) and is_xml_node(arg):
1054 1056
                self.free_value(fd, arg)
1055 1057

  
1058
        print_('failure:', file=fd)
1059

  
1056 1060
        if not m.return_type:
1057
            print_('    return noneRef();', file=fd)
1061
            print_('    if (ok) {', file=fd)
1062
            print_('        return noneRef();', file=fd)
1058 1063
        else:
1059
            print_('    return return_pyvalue;', file=fd)
1064
            print_('    if (ok && return_pyvalue) {', file=fd)
1065
            print_('        return return_pyvalue;', file=fd)
1066
        print_('    } else {', file=fd)
1067
        if m.return_type:
1068
            print_('        Py_XDECREF(return_pyvalue);', file=fd)
1069
        print_('        return NULL;', file=fd)
1070
        print_('    }', file=fd)
1060 1071
        print_('}', file=fd)
1061 1072
        print_('', file=fd)
1062 1073

  
bindings/python/wrapper_top.c
74 74
#endif
75 75

  
76 76
#define RETURN_IF_FAIL(op) do { if (! (op)) { return NULL; } } while(0)
77
#define EXIT_IF_FAIL(op) do { if (! (op)) { ok = 0; goto failure; } } while(0)
77 78

  
78 79
GQuark lasso_wrapper_key;
79 80

  
80
-