("tuple", "PyTuple_Type", []),
- ("list", "PyList_Type", [("insert", "OzO", "i", "PyList_Insert")]),
+ ("list", "PyList_Type", [("insert", "TzO", "i", "PyList_Insert")]),
- ("dict", "PyDict_Type", [("items", "O", "O", "PyDict_Items"),
- ("keys", "O", "O", "PyDict_Keys"),
- ("values","O", "O", "PyDict_Values"),
- ("copy", "O", "O", "PyDict_Copy")]),
+ ("dict", "PyDict_Type", [("items", "T", "O", "PyDict_Items"),
+ ("keys", "T", "O", "PyDict_Keys"),
+ ("values","T", "O", "PyDict_Values"),
+ ("copy", "T", "O", "PyDict_Copy")]),
("slice", "PySlice_Type", []),
# ("file", "PyFile_Type", []), # not in Py3
- ("set", "PySet_Type", [("clear", "O", "i", "PySet_Clear"),
- ("discard", "OO", "i", "PySet_Discard"),
- ("add", "OO", "i", "PySet_Add"),
- ("pop", "O", "O", "PySet_Pop")]),
+ ("set", "PySet_Type", [("clear", "T", "i", "PySet_Clear"),
+ ("discard", "TO", "i", "PySet_Discard"),
+ ("add", "TO", "i", "PySet_Add"),
+ ("pop", "T", "O", "PySet_Pop")]),
("frozenset", "PyFrozenSet_Type", []),
]
builtin_types[name] = the_type
for name, args, ret, cname in funcs:
sig = Signature(args, ret)
- the_type.scope.declare_cfunction(name, sig.function_type(), None, cname)
+ # override 'self' type (first argument)
+ self_arg = PyrexTypes.CFuncTypeArg("", the_type, None)
+ self_arg.not_none = True
+ method_type = sig.function_type(self_arg)
+ the_type.scope.declare_cfunction(name, method_type, None, cname)
def init_builtin_structs():
for name, cname, attribute_types in builtin_structs_table:
def exception_value(self):
return self.error_value_map.get(self.ret_format)
- def function_type(self):
+ def function_type(self, self_arg_override=None):
# Construct a C function type descriptor for this signature
args = []
for i in xrange(self.num_fixed_args()):
- arg_type = self.fixed_arg_type(i)
- args.append(PyrexTypes.CFuncTypeArg("", arg_type, None))
+ if self_arg_override is not None and self.is_self_arg(i):
+ assert isinstance(self_arg_override, PyrexTypes.CFuncTypeArg)
+ args.append(self_arg_override)
+ else:
+ arg_type = self.fixed_arg_type(i)
+ args.append(PyrexTypes.CFuncTypeArg("", arg_type, None))
ret_type = self.return_type()
exc_value = self.exception_value()
return PyrexTypes.CFuncType(ret_type, args, exception_value = exc_value)