예제 #1
0
    def call_varargs_kw(self, space, h_self, __args__, skip_args,
                        has_keywords):
        # this function is more or less the equivalent of
        # ctx_CallRealFunctionFromTrampoline in cpython-universal
        n = len(__args__.arguments_w) - skip_args

        # XXX this looks inefficient: ideally, we would like the equivalent of
        # alloca(): do we have it in RPython? The alternative is to wrap
        # arguments_w in a tuple, convert to handle and pass it to a C
        # function whichs calls alloca() and the forwards everything to the
        # functpr
        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 + skip_args])
                i += 1

            if has_keywords:
                h_result = self.call_keywords(space, h_self, args_h, n,
                                              __args__)
            else:
                h_result = self.call_varargs(space, h_self, args_h, n)

            # XXX this should probably be in a try/finally. We should add a
            # test to check that we don't leak handles
            for i in range(n):
                handles.close(space, args_h[i])

        return handles.consume(space, h_result)
예제 #2
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)
예제 #3
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)
예제 #4
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)
예제 #5
0
    def call_keywords(self, space, h_self, args_h, n, __args__):
        state = space.fromcache(State)
        # XXX: if there are no keywords, should we pass HPy_NULL or an empty
        # dict?
        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_keywords', self.cfuncptr)
        try:
            return fptr(state.ctx, h_self, args_h, n, h_kw)
        finally:
            if h_kw:
                handles.consume(space, h_kw)
예제 #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)
예제 #7
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)
예제 #8
0
 def call_noargs(self, space, h_self):
     state = space.fromcache(State)
     func = llapi.cts.cast('HPyFunc_noargs', self.cfuncptr)
     h_result = func(state.ctx, h_self)
     # XXX check for exceptions
     return handles.consume(space, h_result)
예제 #9
0
def create_hpy_module(space, name, origin, lib, initfunc_ptr):
    state = space.fromcache(State)
    initfunc_ptr = rffi.cast(llapi.HPyInitFunc, initfunc_ptr)
    h_module = initfunc_ptr(state.ctx)
    return handles.consume(space, h_module)