if self.signature_has_generic_args():
if self.star_arg:
env.use_utility_code(get_stararg_utility_code)
+ elif self.signature_has_generic_args():
+ env.use_utility_code(raise_argtuple_too_long_utility_code)
if not self.signature_has_nongeneric_args():
env.use_utility_code(get_keyword_string_check_utility_code)
elif self.starstar_arg:
def generate_positional_args_check(self, code, nargs):
code.putln("if (unlikely(PyTuple_GET_SIZE(%s) > %d)) {" % (
Naming.args_cname, nargs))
- error_message = "function takes at most %d positional arguments (%d given)"
- code.putln("PyErr_Format(PyExc_TypeError, \"%s\", %d, PyTuple_GET_SIZE(%s));" % (
- error_message, nargs, Naming.args_cname))
+ code.putln("__Pyx_RaiseArgtupleTooLong(%d, PyTuple_GET_SIZE(%s));" % (
+ nargs, Naming.args_cname))
code.putln("return %s;" % self.error_value())
code.putln("}")
}
"""]
+#------------------------------------------------------------------------------------
+#
+# __Pyx_RaiseArgtupleTooLong raises the correct exception when too
+# many positional arguments were found. This handles Py_ssize_t
+# formatting correctly.
+
+raise_argtuple_too_long_utility_code = [
+"""
+static INLINE void __Pyx_RaiseArgtupleTooLong(Py_ssize_t num_expected, Py_ssize_t num_found); /*proto*/
+""","""
+static INLINE void __Pyx_RaiseArgtupleTooLong(
+ Py_ssize_t num_expected,
+ Py_ssize_t num_found)
+{
+ const char* error_message =
+ #if PY_VERSION_HEX < 0x02050000
+ "function takes at most %d positional arguments (%d given)";
+ #else
+ "function takes at most %zd positional arguments (%zd given)";
+ #endif
+ PyErr_Format(PyExc_TypeError, error_message, num_expected, num_found);
+}
+"""]
+
#------------------------------------------------------------------------------------
#
# __Pyx_CheckKeywordStrings raises an error if non-string keywords