Exemplo n.º 1
0
def getset_get(w_getset, space, w_self):
    state = space.fromcache(State)
    cfuncptr = w_getset.hpygetset.c_getter_impl
    func = llapi.cts.cast('HPyFunc_getter', cfuncptr)
    with handles.using(space, w_self) as h_self:
        h_result = func(state.ctx, h_self, w_getset.hpygetset.c_closure)
    return handles.consume(space, h_result)
Exemplo n.º 2
0
 def call_o(self, space, h_self, w_arg):
     state = space.fromcache(State)
     with handles.using(space, w_arg) as h_arg:
         func = llapi.cts.cast('HPyFunc_o', self.cfuncptr)
         h_result = func(state.ctx, h_self, h_arg)
     # XXX check for exceptions
     return handles.consume(space, h_result)
Exemplo n.º 3
0
def getset_set(w_getset, space, w_self, w_value):
    state = space.fromcache(State)
    cfuncptr = w_getset.hpygetset.c_setter_impl
    func = llapi.cts.cast('HPyFunc_setter', cfuncptr)
    with handles.using(space, w_self, w_value) as (h_self, h_value):
        h_result = func(state.ctx, h_self, h_value,
                        w_getset.hpygetset.c_closure)
Exemplo n.º 4
0
 def call(self, space, __args__):
     with handles.using(space, __args__.arguments_w[0]) as h_self:
         n = len(__args__.arguments_w) - 1
         with lltype.scoped_alloc(rffi.CArray(llapi.HPy), n) as args_h:
             i = 0
             while i < n:
                 args_h[i] = handles.new(space, __args__.arguments_w[i + 1])
                 i += 1
             h_kw = 0
             if __args__.keywords:
                 w_kw = space.newdict()
                 for i in range(len(__args__.keywords)):
                     key = __args__.keywords[i]
                     w_value = __args__.keywords_w[i]
                     space.setitem_str(w_kw, key, w_value)
                 h_kw = handles.new(space, w_kw)
             fptr = llapi.cts.cast('HPyFunc_initproc', self.cfuncptr)
             state = space.fromcache(State)
             try:
                 result = fptr(state.ctx, h_self, args_h, n, h_kw)
             finally:
                 if h_kw:
                     handles.close(space, h_kw)
                 for i in range(n):
                     handles.close(space, args_h[i])
     if rffi.cast(lltype.Signed, result) < 0:
         # If we're here, it means no exception was set
         raise oefmt(space.w_SystemError,
             "Function returned an error result without setting an exception")
     return space.w_None
Exemplo n.º 5
0
 def call(self, space, __args__):
     func = llapi.cts.cast("HPyFunc_unaryfunc", self.cfuncptr)
     self.check_args(space, __args__, 1)
     ctx = space.fromcache(State).ctx
     w_self = __args__.arguments_w[0]
     with handles.using(space, w_self) as h_self:
         h_result = func(ctx, h_self)
         return handles.consume(space, h_result)
Exemplo n.º 6
0
 def call(self, space, __args__):
     func = llapi.cts.cast("HPyFunc_ssizeargfunc", self.cfuncptr)
     self.check_args(space, __args__, 2)
     ctx = space.fromcache(State).ctx
     w_self = __args__.arguments_w[0]
     w_idx = __args__.arguments_w[1]
     idx = sq_getindex(space, w_self, w_idx)
     with handles.using(space, w_self) as h_self:
         h_result = func(ctx, h_self, idx)
         return handles.consume(space, h_result)
Exemplo n.º 7
0
 def call(self, space, __args__):
     func = llapi.cts.cast("HPyFunc_lenfunc", self.cfuncptr)
     self.check_args(space, __args__, 1)
     ctx = space.fromcache(State).ctx
     w_self = __args__.arguments_w[0]
     with handles.using(space, w_self) as h_self:
         result = func(ctx, h_self)
         if widen(result) == -1:
             raise NotImplementedError('write a test')
         return space.newint(result)
Exemplo n.º 8
0
 def call(self, space, h_self, __args__, skip_args=0):
     assert skip_args == 0
     # NOTE: h_self contains the type for which we are calling __new__, but
     # here is ignored. In CPython's tp_new_wrapper it is only used to fish
     # the ->tp_new to call, but here we already have the cfuncptr
     #
     # XXX: tp_new_wrapper does additional checks, we should write tests
     # and implement the same checks
     w_self = __args__.arguments_w[0]
     with handles.using(space, w_self) as h_self:
         return self.call_varargs_kw(space, h_self, __args__,
                                     skip_args=1, has_keywords=True)
Exemplo n.º 9
0
 def call(self, space, __args__):
     func = llapi.cts.cast("HPyFunc_objobjproc", self.cfuncptr)
     self.check_args(space, __args__, 2)
     ctx = space.fromcache(State).ctx
     w_self = __args__.arguments_w[0]
     w_key = __args__.arguments_w[1]
     with handles.using(space, w_self, w_key) as (h_self, h_key):
         res = func(ctx, h_self, h_key)
         res = widen(res)
         if res == -1:
             raise NotImplementedError('write a test')
         return space.newbool(bool(res))
Exemplo n.º 10
0
 def call(self, space, __args__):
     func = llapi.cts.cast("HPyFunc_ssizeobjargproc", self.cfuncptr)
     self.check_args(space, __args__, 2)
     ctx = space.fromcache(State).ctx
     w_self = __args__.arguments_w[0]
     w_idx = __args__.arguments_w[1]
     idx = sq_getindex(space, w_self, w_idx)
     with handles.using(space, w_self) as h_self:
         result = func(ctx, h_self, idx, llapi.HPy_NULL)
         if widen(result) == -1:
             raise NotImplementedError('write a test')
         return space.w_None
Exemplo n.º 11
0
 def call(self, space, __args__):
     func = llapi.cts.cast("HPyFunc_inquiry", self.cfuncptr)
     self.check_args(space, __args__, 1)
     ctx = space.fromcache(State).ctx
     w_self = __args__.arguments_w[0]
     with handles.using(space, w_self) as h_self:
         res = func(ctx, h_self)
         res = rffi.cast(lltype.Signed, res)
         if res == -1:
             raise NotImplementedError('write a test')
             #space.fromcache(State).check_and_raise_exception(always=True)
         return space.newbool(bool(res))
Exemplo n.º 12
0
 def call(self, space, __args__):
     # Literaly quote of the corresponding CPython comment:
     #     Note: This wrapper only works for __pow__()
     #
     func = llapi.cts.cast("HPyFunc_ternaryfunc", self.cfuncptr)
     self.check_argsv(space, __args__, 2, 3)
     n = len(__args__.arguments_w)
     ctx = space.fromcache(State).ctx
     w_self = __args__.arguments_w[0]
     w1 = __args__.arguments_w[1]
     if n == 2:
         w2 = space.w_None
     else:
         w2 = __args__.arguments_w[2]
     with handles.using(space, w_self, w1, w2) as (h_self, h1, h2):
         h_result = func(ctx, h_self, h1, h2)
         return handles.consume(space, h_result)
Exemplo n.º 13
0
 def descr_call(self, space, __args__):
     # XXX: basically a copy of cpyext's W_PyCMethodObject.descr_call()
     if len(__args__.arguments_w) == 0:
         w_objclass = self.w_objclass
         assert isinstance(w_objclass, W_TypeObject)
         raise oefmt(space.w_TypeError,
                     "descriptor '%8' of '%s' object needs an argument",
                     self.name, self.w_objclass.getname(space))
     w_instance = __args__.arguments_w[0]
     # XXX: needs a stricter test
     if not space.isinstance_w(w_instance, self.w_objclass):
         w_objclass = self.w_objclass
         assert isinstance(w_objclass, W_TypeObject)
         raise oefmt(
             space.w_TypeError,
             "descriptor '%8' requires a '%s' object but received a '%T'",
             self.name, w_objclass.name, w_instance)
     #
     with handles.using(space, w_instance) as h_instance:
         return self.call(space, h_instance, __args__, skip_args=1)
Exemplo n.º 14
0
 def descr_call(self, space, __args__):
     with handles.using(space, self.w_self) as h_self:
         return self.call(space, h_self, __args__)