Allow tp_len slot to support overloaded methods
This commit is contained in:
1 parent
defacaade6
commit
18e2fa57d2
2 files changed
+32
-5
No files matched your search
+10
-5
@@ -1712,13 +1712,18 @@ typedef struct {
|
||||
|
||||
def try_wrap_sequence_method(py_name, slot_name):
|
||||
if py_name in self.methods:
|
||||
assert len(self.methods[py_name].wrappers) == 1
|
||||
meth = self.methods[py_name].wrappers[0]
|
||||
numwraps = len(self.methods[py_name].wrappers)
|
||||
some_wrapper_is_function = max([isinstance(x, function.Function) for x in self.methods[py_name].wrappers])
|
||||
meth_wrapper_actual_name = self.methods[py_name].wrapper_actual_name
|
||||
wrapper_name = "%s__%s" % (self.mangled_full_name, slot_name)
|
||||
pysequencemethods.slots[slot_name] = wrapper_name
|
||||
code_sink.writeln(pysequencemethods.FUNCTION_TEMPLATES[slot_name] % {'wrapper_name' : wrapper_name,
|
||||
'py_struct' : self._pystruct,
|
||||
'method_name' : meth.wrapper_actual_name})
|
||||
if py_name == "__len__" and (numwraps > 1 or some_wrapper_is_function):
|
||||
template = pysequencemethods.FUNCTION_TEMPLATES[slot_name + "_ARGS"]
|
||||
else:
|
||||
template = pysequencemethods.FUNCTION_TEMPLATES[slot_name]
|
||||
code_sink.writeln(template % {'wrapper_name' : wrapper_name,
|
||||
'py_struct' : self._pystruct,
|
||||
'method_name' : meth_wrapper_actual_name})
|
||||
return
|
||||
|
||||
for (py_name, slot_name) in [("__len__", "sq_length"),
|
||||
|
||||
@@ -244,6 +244,28 @@ static Py_ssize_t
|
||||
return result;
|
||||
}
|
||||
|
||||
''',
|
||||
|
||||
# This hacky version is necessary 'cause if we're calling a function rather than a method
|
||||
# or an overloaded wrapper the args parameter gets tacked into the call sequence.
|
||||
"sq_length_ARGS" : '''
|
||||
static Py_ssize_t
|
||||
%(wrapper_name)s (%(py_struct)s *py_self)
|
||||
{
|
||||
PyObject *py_result;
|
||||
PyObject *args;
|
||||
|
||||
Py_ssize_t result;
|
||||
|
||||
py_result = %(method_name)s(py_self, args, NULL);
|
||||
if (py_result == NULL) {
|
||||
return -1;
|
||||
}
|
||||
result = PyInt_AsSsize_t(py_result);
|
||||
Py_DECREF(py_result);
|
||||
return result;
|
||||
}
|
||||
|
||||
''',
|
||||
|
||||
"sq_item" : '''
|
||||
|
||||
Reference in new issue
Block a user