Commit 8d85f180 authored by Stefan Behnel's avatar Stefan Behnel

split up __Pyx_GetStarArgs() into two separate functions for *args and...

split up __Pyx_GetStarArgs() into two separate functions for *args and **kwargs to prepare their independent use
parent f669064a
...@@ -961,7 +961,8 @@ class DefNode(FuncDefNode): ...@@ -961,7 +961,8 @@ class DefNode(FuncDefNode):
self.analyse_signature(env) self.analyse_signature(env)
self.return_type = self.entry.signature.return_type() self.return_type = self.entry.signature.return_type()
if self.star_arg or self.starstar_arg or self.num_kwonly_args > 0: if self.star_arg or self.starstar_arg or self.num_kwonly_args > 0:
env.use_utility_code(get_starargs_utility_code) env.use_utility_code(get_stararg_utility_code)
env.use_utility_code(get_splitkeywords_utility_code)
def analyse_signature(self, env): def analyse_signature(self, env):
any_type_tests_needed = 0 any_type_tests_needed = 0
...@@ -1271,15 +1272,18 @@ class DefNode(FuncDefNode): ...@@ -1271,15 +1272,18 @@ class DefNode(FuncDefNode):
star_arg_addr = self.arg_address(self.star_arg) star_arg_addr = self.arg_address(self.star_arg)
starstar_arg_addr = self.arg_address(self.starstar_arg) starstar_arg_addr = self.arg_address(self.starstar_arg)
code.putln( code.putln(
"if (__Pyx_GetStarArgs(&%s, &%s, %s, %s, %s, %s, %s) < 0) return %s;" % ( "if (__Pyx_SplitKeywords(&%s, %s, %s, %s) < 0) return %s;" % (
Naming.args_cname,
Naming.kwds_cname, Naming.kwds_cname,
Naming.kwdlist_cname, Naming.kwdlist_cname,
nargs,
star_arg_addr,
starstar_arg_addr, starstar_arg_addr,
self.reqd_kw_flags_cname, self.reqd_kw_flags_cname,
self.error_value())) self.error_value()))
code.putln(
"if (__Pyx_GetStarArg(&%s, %s, %s) < 0) return %s;" % (
Naming.args_cname,
nargs,
star_arg_addr,
self.error_value()))
def generate_argument_conversion_code(self, code): def generate_argument_conversion_code(self, code):
# Generate code to convert arguments from # Generate code to convert arguments from
...@@ -3317,44 +3321,33 @@ static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed ...@@ -3317,44 +3321,33 @@ static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed
#------------------------------------------------------------------------------------ #------------------------------------------------------------------------------------
# #
# __Pyx_GetStarArgs splits the args tuple and kwds dict into two parts # __Pyx_GetStarArg splits the args tuple into two parts, one part
# each, one part suitable for passing to PyArg_ParseTupleAndKeywords, # suitable for passing to PyArg_ParseTupleAndKeywords, and the other
# and the other containing any extra arguments. On success, replaces # containing any extra arguments. On success, replaces the borrowed
# the borrowed references *args and *kwds with references to a new # reference *args with references to a new tuple, and passes back a
# tuple and dict, and passes back new references in *args2 and *kwds2. # new reference in *args2. Does not touch any of its arguments on
# Does not touch any of its arguments on failure. # failure.
# #
# Any of *kwds, args2 and kwds2 may be 0 (but not args or kwds). If # The parameter args2 may be 0, but not args or *args.
# *kwds == 0, it is not changed. If kwds2 == 0 and *kwds != 0, a new
# reference to the same dictionary is passed back in *kwds.
# #
# If rqd_kwds is not 0, it is an array of booleans corresponding to the # If rqd_kwds is not 0, it is an array of booleans corresponding to the
# names in kwd_list, indicating required keyword arguments. If any of # names in kwd_list, indicating required keyword arguments. If any of
# these are not present in kwds, an exception is raised. # these are not present in kwds, an exception is raised.
# #
get_starargs_utility_code = [ get_stararg_utility_code = [
""" """
static int __Pyx_GetStarArgs(PyObject **args, PyObject **kwds, char *kwd_list[], \ static int __Pyx_GetStarArg(PyObject **args, Py_ssize_t nargs, PyObject **args2); /*proto*/
Py_ssize_t nargs, PyObject **args2, PyObject **kwds2, char rqd_kwds[]); /*proto*/
""",""" ""","""
static int __Pyx_GetStarArgs( static int __Pyx_GetStarArg(
PyObject **args, PyObject **args,
PyObject **kwds,
char *kwd_list[],
Py_ssize_t nargs, Py_ssize_t nargs,
PyObject **args2, PyObject **args2)
PyObject **kwds2,
char rqd_kwds[])
{ {
PyObject *s = 0, *x = 0, *args1 = 0, *kwds1 = 0; PyObject *args1 = 0;
int i;
char **p;
if (args2) if (args2)
*args2 = 0; *args2 = 0;
if (kwds2)
*kwds2 = 0;
if (args2) { if (args2) {
args1 = PyTuple_GetSlice(*args, 0, nargs); args1 = PyTuple_GetSlice(*args, 0, nargs);
...@@ -3377,6 +3370,53 @@ static int __Pyx_GetStarArgs( ...@@ -3377,6 +3370,53 @@ static int __Pyx_GetStarArgs(
Py_INCREF(args1); Py_INCREF(args1);
} }
*args = args1;
return 0;
bad:
Py_XDECREF(args1);
if (args2) {
Py_XDECREF(*args2);
}
return -1;
}
"""]
#------------------------------------------------------------------------------------
#
# __Pyx_SplitKeywords splits the kwds dict into two parts one part
# suitable for passing to PyArg_ParseTupleAndKeywords, and the other
# containing any extra arguments. On success, replaces the borrowed
# reference *kwds with references to a new dict, and passes back a
# new reference in *kwds2. Does not touch any of its arguments on
# failure.
#
# Any of *kwds and kwds2 may be 0 (but not kwds). If *kwds == 0, it
# is not changed. If kwds2 == 0 and *kwds != 0, a new reference to
# the same dictionary is passed back in *kwds.
#
# If rqd_kwds is not 0, it is an array of booleans corresponding to
# the names in kwd_list, indicating required keyword arguments. If
# any of these are not present in kwds, an exception is raised.
#
get_splitkeywords_utility_code = [
"""
static int __Pyx_SplitKeywords(PyObject **kwds, char *kwd_list[], \
PyObject **kwds2, char rqd_kwds[]); /*proto*/
""","""
static int __Pyx_SplitKeywords(
PyObject **kwds,
char *kwd_list[],
PyObject **kwds2,
char rqd_kwds[])
{
PyObject *s = 0, *x = 0, *kwds1 = 0;
int i;
char **p;
if (kwds2)
*kwds2 = 0;
if (*kwds) { if (*kwds) {
if (kwds2) { if (kwds2) {
kwds1 = PyDict_New(); kwds1 = PyDict_New();
...@@ -3422,8 +3462,7 @@ static int __Pyx_GetStarArgs( ...@@ -3422,8 +3462,7 @@ static int __Pyx_GetStarArgs(
goto bad; goto bad;
} }
} }
*args = args1;
*kwds = kwds1; *kwds = kwds1;
return 0; return 0;
missing_kwarg: missing_kwarg:
...@@ -3431,11 +3470,7 @@ missing_kwarg: ...@@ -3431,11 +3470,7 @@ missing_kwarg:
"required keyword argument '%s' is missing", *p); "required keyword argument '%s' is missing", *p);
bad: bad:
Py_XDECREF(s); Py_XDECREF(s);
Py_XDECREF(args1);
Py_XDECREF(kwds1); Py_XDECREF(kwds1);
if (args2) {
Py_XDECREF(*args2);
}
if (kwds2) { if (kwds2) {
Py_XDECREF(*kwds2); Py_XDECREF(*kwds2);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment