Author: Matti Picus <matti.pi...@gmail.com> Branch: call-via-pyobj Changeset: r85488:02ab445bf7f9 Date: 2016-07-01 16:01 +0300 http://bitbucket.org/pypy/pypy/changeset/02ab445bf7f9/
Log: use a list to make the offset lookup work (test passes) diff --git a/pypy/module/cpyext/methodobject.py b/pypy/module/cpyext/methodobject.py --- a/pypy/module/cpyext/methodobject.py +++ b/pypy/module/cpyext/methodobject.py @@ -152,7 +152,7 @@ class W_PyCWrapperObject(W_Root): def __init__(self, space, pto, method_name, wrapper_func, - wrapper_func_kwds, doc, func, offset=-1): + wrapper_func_kwds, doc, func, offset=None): self.space = space self.method_name = method_name self.wrapper_func = wrapper_func @@ -174,15 +174,15 @@ raise oefmt(space.w_TypeError, "wrapper %s doesn't take any keyword arguments", self.method_name) - if self.offset >= 0: - pto = rffi.cast(PyTypeObjectPtr, as_pyobj(space, self.w_objclass)) - pto_func_as_int = lltype.cast_ptr_to_int(pto) + self.offset - # XXX make pto_func the equivalent of this line - #lltype.cast_int_to_ptr(pto_func_as_int) - func_to_call = rffi.cast(rffi.VOIDP, pto.c_tp_as_number.c_nb_multiply) - # print '\ncalling', func_to_call, 'not', self.func + if self.offset: + ptr = pto = rffi.cast(PyTypeObjectPtr, as_pyobj(space, self.w_objclass)) + # make ptr the equivalent of this, using the offsets + #func_to_call = rffi.cast(rffi.VOIDP, pto.c_tp_as_number.c_nb_multiply) + for o in self.offset: + ptr_as_int = lltype.cast_ptr_to_int(ptr) + ptr = rffi.cast(rffi.VOIDPP, ptr_as_int + o)[0] + func_to_call = ptr else: - # print 'calling', self.method_name,'with no offset' func_to_call = self.func return self.wrapper_func(space, w_self, w_args, func_to_call) diff --git a/pypy/module/cpyext/typeobject.py b/pypy/module/cpyext/typeobject.py --- a/pypy/module/cpyext/typeobject.py +++ b/pypy/module/cpyext/typeobject.py @@ -296,7 +296,7 @@ for method_name, slot_names, wrapper_func, wrapper_func_kwds, doc in slotdefs_for_wrappers: if method_name in dict_w: continue - offset = rffi.offsetof(pto._T, slot_names[0]) + offset = [rffi.offsetof(pto._T, slot_names[0])] if len(slot_names) == 1: func = getattr(pto, slot_names[0]) else: @@ -304,21 +304,13 @@ struct = getattr(pto, slot_names[0]) if not struct: continue - offset += rffi.offsetof(struct._T, slot_names[1]) + offset.append(rffi.offsetof(struct._T, slot_names[1])) func = getattr(struct, slot_names[1]) func_voidp = rffi.cast(rffi.VOIDP, func) if not func: continue if wrapper_func is None and wrapper_func_kwds is None: continue - name = rffi.charp2str(pto.c_tp_name) - if method_name in ('__mul__', '__rmul__') and 'array' in name: - # print '\nsetting', name, method_name, 'from', slot_names - # print ' pto is', pto - # print ' func_voidp is', func_voidp - pass - else: - offset = -1 w_obj = W_PyCWrapperObject(space, pto, method_name, wrapper_func, wrapper_func_kwds, doc, func_voidp, offset=offset) dict_w[method_name] = space.wrap(w_obj) @@ -744,7 +736,6 @@ w_obj = _type_realize(space, py_obj) finally: name = rffi.charp2str(pto.c_tp_name) - print '_type_realize done', name pto.c_tp_flags &= ~Py_TPFLAGS_READYING pto.c_tp_flags |= Py_TPFLAGS_READY return w_obj _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit