if arg.is_generic and arg.type.is_extension_type:
arg.needs_type_test = 1
any_type_tests_needed = 1
+ elif arg.type is PyrexTypes.c_py_ssize_t_type:
+ # Want to use __index__ rather than __int__ method
+ # that PyArg_ParseTupleAndKeywords calls
+ arg.needs_conversion = 1
+ arg.hdr_type = PyrexTypes.py_object_type
+ arg.hdr_cname = Naming.arg_prefix + arg.name
if any_type_tests_needed:
env.use_utility_code(arg_type_test_utility_code)
def generate_argument_declarations(self, env, code):
for arg in self.args:
if arg.is_generic: # or arg.needs_conversion:
- code.put_var_declaration(arg.entry)
+ if arg.needs_conversion:
+ code.putln("PyObject *%s = 0;" % arg.hdr_cname)
+ else:
+ code.put_var_declaration(arg.entry)
+
def generate_keyword_list(self, code):
if self.entry.signature.has_generic_args:
arg.name)
code.putln(
"0};")
-
+
def generate_argument_parsing_code(self, code):
# Generate PyArg_ParseTuple call for generic
# arguments, if any.
default_seen = 1
elif default_seen:
error(arg.pos, "Non-default argument following default argument")
- arg_addrs.append("&" + arg_entry.cname)
- format = arg_entry.type.parsetuple_format
+ if arg.needs_conversion:
+ arg_addrs.append("&" + arg.hdr_cname)
+ format = arg.hdr_type.parsetuple_format
+ else:
+ arg_addrs.append("&" + arg_entry.cname)
+ format = arg_entry.type.parsetuple_format
if format:
arg_formats.append(format)
else:
old_type = arg.hdr_type
new_type = arg.type
if old_type.is_pyobject:
+ code.putln("if (%s) {" % arg.hdr_cname)
self.generate_arg_conversion_from_pyobject(arg, code)
+ code.putln("}")
elif new_type.is_pyobject:
self.generate_arg_conversion_to_pyobject(arg, code)
else:
typedef struct {PyObject **p; char *s;} __Pyx_InternTabEntry; /*proto*/
typedef struct {PyObject **p; char *s; long n;} __Pyx_StringTabEntry; /*proto*/
+#define __pyx_PyIndex_AsSsize_t(b) PyInt_AsSsize_t(PyNumber_Index(b))
+
#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
static INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
if (x == Py_True) return 1;