Exemplo n.º 1
0
    def descr_poll(self, space, timeout=-1.0, maxevents=-1):
        self.check_closed(space)
        if timeout < 0:
            timeout = -1.0
        else:
            timeout *= 1000.0

        if maxevents == -1:
            maxevents = FD_SETSIZE - 1
        elif maxevents < 1:
            raise oefmt(space.w_ValueError,
                        "maxevents must be greater than 0, not %d", maxevents)

        with lltype.scoped_alloc(rffi.CArray(rffi.UINT), maxevents) as fids:
            with lltype.scoped_alloc(rffi.CArray(rffi.INT),
                                     maxevents) as events:
                nfds = pypy_epoll_wait(self.epfd, fids, events, maxevents,
                                       int(timeout))
                if nfds < 0:
                    raise exception_from_saved_errno(space, space.w_IOError)

                elist_w = [None] * nfds
                for i in xrange(nfds):
                    elist_w[i] = space.newtuple(
                        [space.newint(fids[i]),
                         space.newint(events[i])])
                return space.newlist(elist_w)
Exemplo n.º 2
0
 def fake_call_impl_any(cif_description, func_addr, exchange_buffer):
     ofs = 16
     for avalue in unroll_avalues:
         TYPE = rffi.CArray(lltype.typeOf(avalue))
         data = rffi.ptradd(exchange_buffer, ofs)
         got = rffi.cast(lltype.Ptr(TYPE), data)[0]
         if lltype.typeOf(avalue) is lltype.SingleFloat:
             got = float(got)
             avalue = float(avalue)
         elif (lltype.typeOf(avalue) is rffi.SIGNEDCHAR or
               lltype.typeOf(avalue) is rffi.UCHAR):
             got = intmask(got)
             avalue = intmask(avalue)
         assert got == avalue
         ofs += 16
     write_to_ofs = 0
     if rvalue is not None:
         write_rvalue = rvalue
         if BIG_ENDIAN:
             if (lltype.typeOf(write_rvalue) is rffi.SIGNEDCHAR or
                 lltype.typeOf(write_rvalue) is rffi.UCHAR):
                 # 'write_rvalue' is an int type smaller than Signed
                 write_to_ofs = rffi.sizeof(rffi.LONG) - 1
     else:
         write_rvalue = 12923  # ignored
     TYPE = rffi.CArray(lltype.typeOf(write_rvalue))
     data = rffi.ptradd(exchange_buffer, ofs)
     rffi.cast(lltype.Ptr(TYPE), data)[write_to_ofs] = write_rvalue
Exemplo n.º 3
0
 def __init__(self, arena_size, page_size, small_request_threshold):
     # 'small_request_threshold' is the largest size that we
     # can ask with self.malloc().
     self.arena_size = arena_size
     self.page_size = page_size
     self.small_request_threshold = small_request_threshold
     self.arenas_count = 0
     #
     # 'pageaddr_for_size': for each size N between WORD and
     # small_request_threshold (included), contains either NULL or
     # a pointer to a page that has room for at least one more
     # allocation of the given size.
     length = small_request_threshold / WORD + 1
     self.page_for_size = self._new_page_ptr_list(length)
     self.full_page_for_size = self._new_page_ptr_list(length)
     self.old_page_for_size = self._new_page_ptr_list(length)
     self.old_full_page_for_size = self._new_page_ptr_list(length)
     self.nblocks_for_size = lltype.malloc(rffi.CArray(lltype.Signed),
                                           length,
                                           flavor='raw',
                                           immortal=True)
     self.hdrsize = llmemory.raw_malloc_usage(llmemory.sizeof(PAGE_HEADER))
     assert page_size > self.hdrsize
     self.nblocks_for_size[0] = 0  # unused
     for i in range(1, length):
         self.nblocks_for_size[i] = (page_size - self.hdrsize) // (WORD * i)
     #
     self.max_pages_per_arena = arena_size // page_size
     self.arenas_lists = lltype.malloc(rffi.CArray(ARENA_PTR),
                                       self.max_pages_per_arena,
                                       flavor='raw',
                                       zero=True,
                                       immortal=True)
     # this is used in mass_free() only
     self.old_arenas_lists = lltype.malloc(rffi.CArray(ARENA_PTR),
                                           self.max_pages_per_arena,
                                           flavor='raw',
                                           zero=True,
                                           immortal=True)
     #
     # the arena currently consumed; it must have at least one page
     # available, or be NULL.  The arena object that we point to is
     # not in any 'arenas_lists'.  We will consume all its pages before
     # we choose a next arena, even if there is a major collection
     # in-between.
     self.current_arena = ARENA_NULL
     #
     # guarantee that 'arenas_lists[1:min_empty_nfreepages]' are all empty
     self.min_empty_nfreepages = self.max_pages_per_arena
     #
     # part of current_arena might still contain uninitialized pages
     self.num_uninitialized_pages = 0
     #
     # the total memory used, counting every block in use, without
     # the additional bookkeeping stuff.
     self.total_memory_used = r_uint(0)
     self.peak_memory_used = r_uint(0)
     self.total_memory_alloced = r_uint(0)
     self.peak_memory_alloced = r_uint(0)
Exemplo n.º 4
0
def setup2(n):
    lst = rand_list_of(n)
    arr = lltype.malloc(rffi.CArray(rffi.LONGLONG), n, flavor='raw')
    for i, k in enumerate(lst):
        arr[i] = k

    lst2 = rand_list_of(n)
    arr2 = lltype.malloc(rffi.CArray(rffi.LONGLONG), n, flavor='raw')
    for i, k in enumerate(lst2):
        arr2[i] = k
    return arr, arr2, 0, n - 1
Exemplo n.º 5
0
def test_array_varsized_struct():
    dirent = rffi_platform.getstruct(
        "struct dirent", """
           struct dirent  /* for this example only, not the exact dirent */
           {
               int d_off;
               char d_name[1];
           };
                                       """,
        [("d_name", rffi.CArray(rffi.CHAR))])
    assert rffi.offsetof(dirent, 'c_d_name') == 4
    assert dirent.c_d_name == rffi.CArray(rffi.CHAR)
Exemplo n.º 6
0
def unpack_traceback(addr):
    codemap_raw = find_codemap_at_addr(
        addr, lltype.nullptr(rffi.CArray(lltype.Signed)))
    if not codemap_raw:
        return []  # no codemap for that position
    storage = lltype.malloc(rffi.CArray(lltype.Signed), 1, flavor='raw')
    storage[0] = 0
    res = []
    while True:
        item = yield_bytecode_at_addr(codemap_raw, addr, storage)
        if item == -1:
            break
        res.append(item)
    lltype.free(storage, flavor='raw')
    return res
Exemplo n.º 7
0
 def _do_call(self, funcsym, ll_args, RESULT):
     # XXX: check len(args)?
     ll_result = lltype.nullptr(rffi.CCHARP.TO)
     if self.restype != types.void:
         ll_result = lltype.malloc(rffi.CCHARP.TO,
                                   intmask(self.restype.c_size),
                                   flavor='raw')
     ffires = c_ffi_call(self.ll_cif,
                         self.funcsym,
                         rffi.cast(rffi.VOIDP, ll_result),
                         rffi.cast(rffi.VOIDPP, ll_args))
     if RESULT is not lltype.Void:
         TP = lltype.Ptr(rffi.CArray(RESULT))
         buf = rffi.cast(TP, ll_result)
         if types.is_struct(self.restype):
             assert RESULT == rffi.SIGNED
             # for structs, we directly return the buffer and transfer the
             # ownership
             res = rffi.cast(RESULT, buf)
         else:
             res = buf[0]
     else:
         res = None
     self._free_buffers(ll_result, ll_args)
     clibffi.check_fficall_result(ffires, self.flags)
     return res
Exemplo n.º 8
0
def spawn(loop, process, file, args, env, streams):
    """
    The file descriptor list should be a list of streams to wire up to FDs in
    the child. A None stream is mapped to UV_IGNORE.
    """

    with rffi.scoped_str2charp(file) as rawFile:
        rawArgs = rffi.liststr2charpp(args)
        rawEnv = rffi.liststr2charpp(env)
        with rffi.scoped_str2charp(".") as rawCWD:
            options = rffi.make(cConfig["process_options_t"], c_file=rawFile,
                                c_args=rawArgs, c_env=rawEnv, c_cwd=rawCWD)
            with lltype.scoped_alloc(rffi.CArray(stdio_container_t),
                                     len(streams)) as rawStreams:
                for i, stream in enumerate(streams):
                    if stream == lltype.nullptr(stream_t):
                        flags = UV_IGNORE
                    else:
                        flags = UV_CREATE_PIPE
                        if i == 0:
                            flags |= UV_READABLE_PIPE
                        elif i in (1, 2):
                            flags |= UV_WRITABLE_PIPE
                        set_stdio_stream(rawStreams[i], stream)
                    rffi.setintfield(rawStreams[i], "c_flags", flags)
                options.c_stdio = rawStreams
                rffi.setintfield(options, "c_stdio_count", len(streams))
                add_exit_cb(options, processDiscard)
                rffi.setintfield(options, "c_flags", UV_PROCESS_WINDOWS_HIDE)
                rv = uv_spawn(loop, process, options)
                free(options)
        rffi.free_charpp(rawEnv)
        rffi.free_charpp(rawArgs)

    check("spawn", rv)
Exemplo n.º 9
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.º 10
0
 def _do_call(self, funcsym, ll_args, RESULT):
     # XXX: check len(args)?
     ll_result = lltype.nullptr(rffi.VOIDP.TO)
     if self.restype != types.void:
         size = adjust_return_size(intmask(self.restype.c_size))
         ll_result = lltype.malloc(rffi.VOIDP.TO, size,
                                   flavor='raw')
     ffires = c_ffi_call(self.ll_cif,
                         self.funcsym,
                         rffi.cast(rffi.VOIDP, ll_result),
                         rffi.cast(rffi.VOIDPP, ll_args))
     if RESULT is not lltype.Void:
         TP = lltype.Ptr(rffi.CArray(RESULT))
         if types.is_struct(self.restype):
             assert RESULT == rffi.SIGNED
             # for structs, we directly return the buffer and transfer the
             # ownership
             buf = rffi.cast(TP, ll_result)
             res = rffi.cast(RESULT, buf)
         else:
             if _BIG_ENDIAN and types.getkind(self.restype) in ('i','u'):
                 ptr = ll_result
                 n = rffi.sizeof(lltype.Signed) - self.restype.c_size
                 ptr = rffi.ptradd(ptr, n)
                 res = rffi.cast(TP, ptr)[0]
             else:
                 res = rffi.cast(TP, ll_result)[0]
     else:
         res = None
     self._free_buffers(ll_result, ll_args)
     clibffi.check_fficall_result(ffires, self.flags)
     return res
Exemplo n.º 11
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)
Exemplo n.º 12
0
 def init_urandom():
     """NOT_RPYTHON
     Return an array of one HCRYPTPROV, initialized to NULL.
     It is filled automatically the first time urandom() is called.
     """
     return lltype.malloc(rffi.CArray(HCRYPTPROV), 1,
                          immortal=True, zero=True)
Exemplo n.º 13
0
    def test_byval_result(self):
        """
            RPY_EXPORTED
            struct Point make_point(Signed x, Signed y) {
                struct Point p;
                p.x = x;
                p.y = y;
                return p;
            }
        """
        libfoo = CDLL(self.libfoo_name)
        ffi_point_struct = make_struct_ffitype_e(
            rffi.sizeof(rffi.SIGNED) * 2, 0, [types.signed, types.signed])
        ffi_point = ffi_point_struct.ffistruct

        libfoo = CDLL(self.libfoo_name)
        make_point = (libfoo, 'make_point', [types.signed,
                                             types.signed], ffi_point)
        #
        PTR = lltype.Ptr(rffi.CArray(rffi.SIGNED))
        p = self.call(make_point, [12, 34],
                      PTR,
                      is_struct=True,
                      jitif=["byval"])
        assert p[0] == 12
        assert p[1] == 34
        lltype.free(p, flavor='raw')
        lltype.free(ffi_point_struct, flavor='raw')
Exemplo n.º 14
0
 def test_array_fields(self):
     POINT = lltype.Struct(
         "POINT",
         ("x", lltype.Float),
         ("y", lltype.Float),
     )
     points = lltype.malloc(rffi.CArray(POINT), 2, flavor="raw")
     points[0].x = 1.0
     points[0].y = 2.0
     points[1].x = 3.0
     points[1].y = 4.0
     points = rffi.cast(rffi.CArrayPtr(lltype.Char), points)
     assert array_getitem(types.double, 16, points, 0, 0) == 1.0
     assert array_getitem(types.double, 16, points, 0, 8) == 2.0
     assert array_getitem(types.double, 16, points, 1, 0) == 3.0
     assert array_getitem(types.double, 16, points, 1, 8) == 4.0
     #
     array_setitem(types.double, 16, points, 0, 0, 10.0)
     array_setitem(types.double, 16, points, 0, 8, 20.0)
     array_setitem(types.double, 16, points, 1, 0, 30.0)
     array_setitem(types.double, 16, points, 1, 8, 40.0)
     #
     assert array_getitem(types.double, 16, points, 0, 0) == 10.0
     assert array_getitem(types.double, 16, points, 0, 8) == 20.0
     assert array_getitem(types.double, 16, points, 1, 0) == 30.0
     assert array_getitem(types.double, 16, points, 1, 8) == 40.0
     #
     lltype.free(points, flavor="raw")
Exemplo n.º 15
0
    def test_as_ucs4(self, space):
        w_x = space.wrap(u"ab\u0660")
        count1 = space.int_w(space.len(w_x))
        x_chunk = PyUnicode_AsUCS4Copy(space, w_x)
        assert x_chunk[0] == ord('a')
        assert x_chunk[1] == ord('b')
        assert x_chunk[2] == 0x0660
        assert x_chunk[3] == 0
        Py_UCS4 = lltype.typeOf(x_chunk).TO.OF
        lltype.free(x_chunk, flavor='raw', track_allocation=False)

        target_chunk = lltype.malloc(rffi.CArray(Py_UCS4), 4, flavor='raw')
        target_chunk[3] = rffi.cast(Py_UCS4, 99999)
        x_chunk = PyUnicode_AsUCS4(space, w_x, target_chunk, 3, 0)
        assert x_chunk == target_chunk
        assert x_chunk[0] == ord('a')
        assert x_chunk[1] == ord('b')
        assert x_chunk[2] == 0x0660
        assert x_chunk[3] == 99999

        x_chunk[2] = rffi.cast(Py_UCS4, 77777)
        x_chunk = PyUnicode_AsUCS4(space, w_x, target_chunk, 4, 1)
        assert x_chunk == target_chunk
        assert x_chunk[0] == ord('a')
        assert x_chunk[1] == ord('b')
        assert x_chunk[2] == 0x0660
        assert x_chunk[3] == 0
        lltype.free(target_chunk, flavor='raw')
Exemplo n.º 16
0
    def test_byval_argument(self):
        """
            struct Point {
                Signed x;
                Signed y;
            };

            RPY_EXPORTED
            Signed sum_point(struct Point p) {
                return p.x + p.y;
            }
        """
        libfoo = CDLL(self.libfoo_name)
        ffi_point_struct = make_struct_ffitype_e(0, 0,
                                                 [types.signed, types.signed])
        ffi_point = ffi_point_struct.ffistruct
        sum_point = (libfoo, 'sum_point', [ffi_point], types.signed)
        #
        ARRAY = rffi.CArray(rffi.SIGNED)
        buf = lltype.malloc(ARRAY, 2, flavor='raw')
        buf[0] = 30
        buf[1] = 12
        adr = rffi.cast(rffi.VOIDP, buf)
        res = self.call(sum_point, [('arg_raw', adr)],
                        rffi.SIGNED,
                        jitif=["byval"])
        assert res == 42
        # check that we still have the ownership on the buffer
        assert buf[0] == 30
        assert buf[1] == 12
        lltype.free(buf, flavor='raw')
        lltype.free(ffi_point_struct, flavor='raw')
Exemplo n.º 17
0
    def __init__(self):
        GcCache.__init__(self, False, None)
        self._generated_functions = []
        self.gcrootmap = MockShadowStackRootMap()
        self.write_barrier_descr = WriteBarrierDescr(self)
        self.nursery_ptrs = lltype.malloc(rffi.CArray(lltype.Signed), 2,
                                          flavor='raw')
        self._initialize_for_tests()
        self.frames = []

        def malloc_slowpath(size):
            self._collect()
            res = self.nursery_ptrs[0]
            self.nursery_ptrs[0] += size
            return res

        self.malloc_slowpath_fnptr = llhelper_args(malloc_slowpath,
                                                   [lltype.Signed],
                                                   lltype.Signed)

        def malloc_array(itemsize, tid, num_elem):
            import pdb
            pdb.set_trace()

        self.malloc_slowpath_array_fnptr = llhelper_args(malloc_array,
                                                         [lltype.Signed] * 3,
                                                         lltype.Signed)

        self.all_nurseries = []
Exemplo n.º 18
0
    def __init__(self, space, environment, context, retrieveError):
        self.context = context
        if retrieveError:
            if environment.errorHandle:
                handle = environment.errorHandle
                handleType = roci.OCI_HTYPE_ERROR
            else:
                handle = environment.handle
                handleType = roci.OCI_HTYPE_ENV

            codeptr = lltype.malloc(rffi.CArray(roci.sb4), 1, flavor='raw')
            BUFSIZE = 1024
            textbuf, text = rffi.alloc_buffer(BUFSIZE)

            try:
                status = roci.OCIErrorGet(
                    handle, 1, lltype.nullptr(roci.oratext.TO), codeptr,
                    textbuf, BUFSIZE, handleType)
                if status != roci.OCI_SUCCESS:
                    raise OperationError(
                        get(space).w_InternalError,
                        space.wrap("No Oracle error?"))

                self.code = rffi.cast(lltype.Signed, codeptr[0])
                self.w_message = config.w_string(space, textbuf)
            finally:
                lltype.free(codeptr, flavor='raw')
                rffi.keep_buffer_alive_until_here(textbuf, text)

            if config.WITH_UNICODE:
                # XXX remove double zeros at the end
                pass
Exemplo n.º 19
0
Arquivo: llmodel.py Projeto: Mu-L/pypy
    def _setup_exception_handling_untranslated(self):
        # for running un-translated only, all exceptions occurring in the
        # llinterpreter are stored in '_exception_emulator', which is then
        # read back by the machine code reading at the address given by
        # pos_exception() and pos_exc_value().
        _exception_emulator = lltype.malloc(rffi.CArray(lltype.Signed), 2,
                                            zero=True, flavor='raw',
                                            immortal=True)
        self._exception_emulator = _exception_emulator

        def _store_exception(lle):
            self._last_exception = lle       # keepalive
            tp_i = rffi.cast(lltype.Signed, lle.args[0])
            v_i = rffi.cast(lltype.Signed, lle.args[1])
            _exception_emulator[0] = tp_i
            _exception_emulator[1] = v_i

        self.debug_ll_interpreter = LLInterpreter(self.rtyper)
        self.debug_ll_interpreter._store_exception = _store_exception

        def pos_exception():
            return rffi.cast(lltype.Signed, _exception_emulator)

        def pos_exc_value():
            return (rffi.cast(lltype.Signed, _exception_emulator) +
                    rffi.sizeof(lltype.Signed))

        self.pos_exception = pos_exception
        self.pos_exc_value = pos_exc_value
        self.insert_stack_check = lambda: (0, 0, 0)
Exemplo n.º 20
0
 def __init__(self, space, w_class, size, depth, display):
     W_AbstractObjectWithClassReference.__init__(self, space, w_class)
     self._real_depth_buffer = lltype.malloc(rffi.CArray(rffi.UINT), size, flavor='raw')
     self.pixelbuffer = display.get_pixelbuffer()
     self._realsize = size
     self.display = display
     self._depth = depth
Exemplo n.º 21
0
 def init_urandom():
     """NOT_RPYTHON
     Return an array of one int, initialized to 0.
     It is filled automatically the first time urandom() is called.
     """
     return lltype.malloc(rffi.CArray(lltype.Signed), 1,
                          immortal=True, zero=True)
Exemplo n.º 22
0
Arquivo: clibffi.py Projeto: Mu-L/pypy
def push_arg_as_ffiptr(ffitp, arg, ll_buf):
    # This is for primitive types.  Note that the exact type of 'arg' may be
    # different from the expected 'c_size'.  To cope with that, we fall back
    # to a byte-by-byte copy.
    TP = lltype.typeOf(arg)
    TP_P = lltype.Ptr(rffi.CArray(TP))
    TP_size = rffi.sizeof(TP)
    c_size = intmask(ffitp.c_size)
    # if both types have the same size, we can directly write the
    # value to the buffer
    if c_size == TP_size:
        buf = rffi.cast(TP_P, ll_buf)
        buf[0] = arg
    else:
        # needs byte-by-byte copying.  Make sure 'arg' is an integer type.
        # Note that this won't work for rffi.FLOAT/rffi.DOUBLE.
        assert TP is not rffi.FLOAT and TP is not rffi.DOUBLE
        if TP_size <= rffi.sizeof(lltype.Signed):
            arg = rffi.cast(lltype.Unsigned, arg)
        else:
            arg = rffi.cast(lltype.UnsignedLongLong, arg)
        if _LITTLE_ENDIAN:
            for i in range(c_size):
                ll_buf[i] = chr(arg & 0xFF)
                arg >>= 8
        elif _BIG_ENDIAN:
            for i in range(c_size - 1, -1, -1):
                ll_buf[i] = chr(arg & 0xFF)
                arg >>= 8
        else:
            raise AssertionError
Exemplo n.º 23
0
    def __init__(self,
                 rtyper,
                 stats,
                 opts,
                 translate_support_code=False,
                 gcdescr=None):
        assert type(opts) is not bool
        self.opts = opts

        from rpython.jit.backend.llsupport.gc import get_ll_description
        AbstractCPU.__init__(self)
        self.rtyper = rtyper
        self.stats = stats
        self.translate_support_code = translate_support_code
        if translate_support_code and rtyper is not None:
            translator = rtyper.annotator.translator
            self.remove_gctypeptr = translator.config.translation.gcremovetypeptr
        else:
            translator = None
        self.gc_ll_descr = get_ll_description(gcdescr, translator, rtyper)
        # support_guard_gc_type indicates if a gc type of an object can be read.
        # In some states (boehm or x86 untranslated) the type is not known just yet,
        # because there are cases where it is not guarded. The precise place where it's not
        # is while inlining short preamble.
        self.supports_guard_gc_type = self.gc_ll_descr.supports_guard_gc_type
        if translator and translator.config.translation.gcremovetypeptr:
            self.vtable_offset = None
        else:
            self.vtable_offset, _ = symbolic.get_field_token(
                rclass.OBJECT, 'typeptr', translate_support_code)
        self.subclassrange_min_offset, _ = symbolic.get_field_token(
            rclass.OBJECT_VTABLE, 'subclassrange_min', translate_support_code)
        if translate_support_code:
            self._setup_exception_handling_translated()
        else:
            self._setup_exception_handling_untranslated()
        self.asmmemmgr = asmmemmgr.AsmMemoryManager()
        if self.HAS_CODEMAP:
            self.codemap = codemap.CodemapStorage()
        self._setup_frame_realloc(translate_support_code)
        ad = self.gc_ll_descr.getframedescrs(self).arraydescr
        self.signedarraydescr = ad
        # the same as normal JITFRAME, however with an array of pointers
        self.refarraydescr = ArrayDescr(ad.basesize, ad.itemsize, ad.lendescr,
                                        FLAG_POINTER)
        if WORD == 4:
            self.floatarraydescr = ArrayDescr(ad.basesize, ad.itemsize * 2,
                                              ad.lendescr, FLAG_FLOAT)
        else:
            self.floatarraydescr = ArrayDescr(ad.basesize, ad.itemsize,
                                              ad.lendescr, FLAG_FLOAT)
        self.setup()
        self._debug_tls_errno_container = lltype.malloc(rffi.CArray(
            lltype.Signed),
                                                        7,
                                                        flavor='raw',
                                                        zero=True,
                                                        track_allocation=False)
        self._debug_tls_errno_container[1] = 1234  # dummy thread ident
Exemplo n.º 24
0
 def test_copy_list_to_raw_array(self):
     ARRAY = rffi.CArray(lltype.Signed)
     buf = lltype.malloc(ARRAY, 4, flavor='raw')
     lst = [1, 2, 3, 4]
     copy_list_to_raw_array(lst, buf)
     for i in range(4):
         assert buf[i] == i + 1
     lltype.free(buf, flavor='raw')
Exemplo n.º 25
0
def _struct_setfield(TYPE, addr, offset, value):
    """
    Write the field of type TYPE at addr+offset.
    addr is of type rffi.VOIDP, offset is an int.
    """
    addr = rffi.ptradd(addr, offset)
    PTR_FIELD = lltype.Ptr(rffi.CArray(TYPE))
    rffi.cast(PTR_FIELD, addr)[0] = value
Exemplo n.º 26
0
def _struct_getfield(TYPE, addr, offset):
    """
    Read the field of type TYPE at addr+offset.
    addr is of type rffi.VOIDP, offset is an int.
    """
    addr = rffi.ptradd(addr, offset)
    PTR_FIELD = lltype.Ptr(rffi.CArray(TYPE))
    return rffi.cast(PTR_FIELD, addr)[0]
Exemplo n.º 27
0
 def fake_call_impl_any(cif_description, func_addr, exchange_buffer):
     ofs = 16
     for avalue in unroll_avalues:
         TYPE = rffi.CArray(lltype.typeOf(avalue))
         data = rffi.ptradd(exchange_buffer, ofs)
         got = rffi.cast(lltype.Ptr(TYPE), data)[0]
         if lltype.typeOf(avalue) is lltype.SingleFloat:
             got = float(got)
             avalue = float(avalue)
         assert got == avalue
         ofs += 16
     if rvalue is not None:
         write_rvalue = rvalue
     else:
         write_rvalue = 12923  # ignored
     TYPE = rffi.CArray(lltype.typeOf(write_rvalue))
     data = rffi.ptradd(exchange_buffer, ofs)
     rffi.cast(lltype.Ptr(TYPE), data)[0] = write_rvalue
Exemplo n.º 28
0
 def __init__(self, space, size, depth):
     W_AbstractObjectWithIdentityHash.__init__(self)
     self._squeak_pixel_buffer = lltype.malloc(rffi.CArray(rffi.UINT),
                                               size,
                                               flavor='raw')
     self._realsize = size
     self._depth = depth
     self._display = space.display()
     self.relinquish_display()
Exemplo n.º 29
0
 def __init__(self, space, w_class, size, depth):
     model.W_AbstractObjectWithClassReference.__init__(self, space, w_class)
     self._real_depth_buffer = lltype.malloc(rffi.CArray(rffi.UINT),
                                             size,
                                             flavor='raw')
     self._realsize = size
     self._depth = depth
     self.display = space.display()
     self.relinquish_display()
Exemplo n.º 30
0
def win_perf_counter():
    with lltype.scoped_alloc(rffi.CArray(rffi.lltype.SignedLongLong), 1) as a:
        if state.divisor == 0.0:
            QueryPerformanceCounter(a)
            state.counter_start = a[0]
            QueryPerformanceFrequency(a)
            state.divisor = float(a[0])
        QueryPerformanceCounter(a)
        diff = a[0] - state.counter_start
    return float(diff) / state.divisor