• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python rffi.setintfield函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pypy.rpython.lltypesystem.rffi.setintfield函数的典型用法代码示例。如果您正苦于以下问题:Python setintfield函数的具体用法?Python setintfield怎么用?Python setintfield使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了setintfield函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: poll

    def poll(fddict, timeout=-1):
        """'fddict' maps file descriptors to interesting events.
        'timeout' is an integer in milliseconds, and NOT a float
        number of seconds, but it's the same in CPython.  Use -1 for infinite.
        Returns a list [(fd, events)].
        """
        numfd = len(fddict)
        pollfds = lltype.malloc(_c.pollfdarray, numfd, flavor='raw')
        try:
            i = 0
            for fd, events in fddict.iteritems():
                rffi.setintfield(pollfds[i], 'c_fd', fd)
                rffi.setintfield(pollfds[i], 'c_events', events)
                i += 1
            assert i == numfd

            ret = _c.poll(pollfds, numfd, timeout)

            if ret < 0:
                raise PollError(_c.geterrno())

            retval = []
            for i in range(numfd):
                pollfd = pollfds[i]
                fd      = rffi.cast(lltype.Signed, pollfd.c_fd)
                revents = rffi.cast(lltype.Signed, pollfd.c_revents)
                if revents:
                    retval.append((fd, revents))
        finally:
            lltype.free(pollfds, flavor='raw')
        return retval
开发者ID:alkorzt,项目名称:pypy,代码行数:31,代码来源:rpoll.py


示例2: frame_attach

def frame_attach(space, py_obj, w_obj):
    "Fills a newly allocated PyFrameObject with a frame object"
    frame = space.interp_w(PyFrame, w_obj)
    py_frame = rffi.cast(PyFrameObject, py_obj)
    py_frame.c_f_code = rffi.cast(PyCodeObject, make_ref(space, frame.pycode))
    py_frame.c_f_globals = make_ref(space, frame.w_globals)
    rffi.setintfield(py_frame, 'c_f_lineno', frame.f_lineno)
开发者ID:gorakhargosh,项目名称:pypy,代码行数:7,代码来源:frameobject.py


示例3: buffer_attach

def buffer_attach(space, py_obj, w_obj):
    """
    Fills a newly allocated PyBufferObject with the given (str) buffer object.
    """
    py_buf = rffi.cast(PyBufferObject, py_obj)
    py_buf.c_b_offset = 0
    rffi.setintfield(py_buf, 'c_b_readonly', 1)
    rffi.setintfield(py_buf, 'c_b_hash', -1)

    if isinstance(w_obj, SubBuffer):
        py_buf.c_b_offset = w_obj.offset
        w_obj = w_obj.buffer

    # If w_obj already allocated a fixed buffer, use it, and keep a
    # reference to w_obj.
    # Otherwise, b_base stays NULL, and we own the b_ptr.

    if isinstance(w_obj, StringBuffer):
        py_buf.c_b_base = lltype.nullptr(PyObject.TO)
        py_buf.c_b_ptr = rffi.cast(rffi.VOIDP, rffi.str2charp(w_obj.value))
        py_buf.c_b_size = w_obj.getlength()
    elif isinstance(w_obj, ArrayBuffer):
        w_base = w_obj.array
        py_buf.c_b_base = make_ref(space, w_base)
        py_buf.c_b_ptr = rffi.cast(rffi.VOIDP, w_obj.array._charbuf_start())
        py_buf.c_b_size = w_obj.getlength()
    else:
        raise OperationError(space.w_NotImplementedError, space.wrap(
            "buffer flavor not supported"))
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:29,代码来源:bufferobject.py


示例4: fill_from_object

 def fill_from_object(self, space, w_address):
     # XXX a bit of code duplication
     _, w_port = space.unpackiterable(w_address, 2)
     port = space.int_w(w_port)
     a = self.lock(_c.sockaddr_in)
     rffi.setintfield(a, 'c_sin_port', htons(port))
     self.unlock()
开发者ID:alkorzt,项目名称:pypy,代码行数:7,代码来源:rsocket.py


示例5: get_addr

def get_addr(hostname, socktype, protocol, port, address_to_fill):
    hostent = _c.gethostbyname(hostname)

    if not hostent:
        raise GAIError(EAI_FAIL)

    hname, aliases, address_list = gethost_common("", hostent)
        
    result = []

    for address in address_list:
        if address.family == _c.AF_INET:
            a = address.lock(_c.sockaddr_in)
            rffi.setintfield(a, 'c_sin_port', r_uint(port) & 0xffff)
            address.unlock()
        a = address.lock()
        addr = make_address(a, address.addrlen, address_to_fill)
        address.unlock()
        result.append((address.family,
                       socktype,
                       protocol,
                       "", # XXX canonname?
                       addr))

    return result
开发者ID:alkorzt,项目名称:pypy,代码行数:25,代码来源:getaddrinfo.py


示例6: decompress

def decompress(stream, data, flush=Z_SYNC_FLUSH, max_length=sys.maxint):
    """
    Feed more data into an inflate stream.  Returns a tuple (string,
    finished, unused_data_length).  The string contains (a part of) the
    decompressed data.  If flush != Z_NO_FLUSH, this also flushes the
    output data; see zlib.h or the documentation of the zlib module for
    the possible values of 'flush'.

    The 'string' is never longer than 'max_length'.  The
    'unused_data_length' is the number of unprocessed input characters,
    either because they are after the end of the compressed stream or
    because processing it would cause the 'max_length' to be exceeded.
    """
    # Warning, reentrant calls to the zlib with a given stream can cause it
    # to crash.  The caller of pypy.rlib.rzlib should use locks if needed.

    # _operate() does not support the Z_FINISH method of decompressing.
    # We can use Z_SYNC_FLUSH instead and manually check that we got to
    # the end of the data.
    if flush == Z_FINISH:
        flush = Z_SYNC_FLUSH
        should_finish = True
    else:
        should_finish = False
    while_doing = "while decompressing data"
    data, err, avail_in = _operate(stream, data, flush, max_length, _inflate,
                                   while_doing)
    if should_finish:
        # detect incomplete input
        rffi.setintfield(stream, 'c_avail_in', 0)
        err = _inflate(stream, Z_FINISH)
        if err < 0:
            raise RZlibError.fromstream(stream, err, while_doing)
    finished = (err == Z_STREAM_END)
    return data, finished, avail_in
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:35,代码来源:rzlib.py


示例7: _select

 def _select(self, for_writing):
     """Returns 0 when reading/writing is possible,
     1 when timing out and -1 on error."""
     timeout = self.timeout
     if timeout <= 0.0 or self.fd == _c.INVALID_SOCKET:
         # blocking I/O or no socket.
         return 0
     tv = rffi.make(_c.timeval)
     rffi.setintfield(tv, 'c_tv_sec', int(timeout))
     rffi.setintfield(tv, 'c_tv_usec', int((timeout-int(timeout))
                                           * 1000000))
     fds = lltype.malloc(_c.fd_set.TO, flavor='raw')
     _c.FD_ZERO(fds)
     _c.FD_SET(self.fd, fds)
     null = lltype.nullptr(_c.fd_set.TO)
     if for_writing:
         n = _c.select(self.fd + 1, null, fds, null, tv)
     else:
         n = _c.select(self.fd + 1, fds, null, null, tv)
     lltype.free(fds, flavor='raw')
     lltype.free(tv, flavor='raw')
     if n < 0:
         return -1
     if n == 0:
         return 1
     return 0
开发者ID:alkorzt,项目名称:pypy,代码行数:26,代码来源:rsocket.py


示例8: _operate

def _operate(stream, data, flush, max_length, cfunc, while_doing):
    """Common code for compress() and decompress().
    """
    # Prepare the input buffer for the stream
    with lltype.scoped_alloc(rffi.CCHARP.TO, len(data)) as inbuf:
        for i in xrange(len(data)):
            inbuf[i] = data[i]
        stream.c_next_in = rffi.cast(Bytefp, inbuf)
        rffi.setintfield(stream, 'c_avail_in', len(data))

        # Prepare the output buffer
        with lltype.scoped_alloc(rffi.CCHARP.TO, OUTPUT_BUFFER_SIZE) as outbuf:
            # Strategy: we call deflate() to get as much output data as fits in
            # the buffer, then accumulate all output into a StringBuffer
            # 'result'.
            result = StringBuilder()

            while True:
                stream.c_next_out = rffi.cast(Bytefp, outbuf)
                bufsize = OUTPUT_BUFFER_SIZE
                if max_length < bufsize:
                    if max_length <= 0:
                        err = Z_OK
                        break
                    bufsize = max_length
                max_length -= bufsize
                rffi.setintfield(stream, 'c_avail_out', bufsize)
                err = cfunc(stream, flush)
                if err == Z_OK or err == Z_STREAM_END:
                    # accumulate data into 'result'
                    avail_out = rffi.cast(lltype.Signed, stream.c_avail_out)
                    result.append_charpsize(outbuf, bufsize - avail_out)
                    # if the output buffer is full, there might be more data
                    # so we need to try again.  Otherwise, we're done.
                    if avail_out > 0:
                        break
                    # We're also done if we got a Z_STREAM_END (which should
                    # only occur when flush == Z_FINISH).
                    if err == Z_STREAM_END:
                        break
                    else:
                        continue
                elif err == Z_BUF_ERROR:
                    avail_out = rffi.cast(lltype.Signed, stream.c_avail_out)
                    # When compressing, we will only get Z_BUF_ERROR if
                    # the output buffer was full but there wasn't more
                    # output when we tried again, so it is not an error
                    # condition.
                    if avail_out == bufsize:
                        break

                # fallback case: report this error
                raise RZlibError.fromstream(stream, err, while_doing)

    # When decompressing, if the compressed stream of data was truncated,
    # then the zlib simply returns Z_OK and waits for more.  If it is
    # complete it returns Z_STREAM_END.
    return (result.build(),
            err,
            rffi.cast(lltype.Signed, stream.c_avail_in))
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:60,代码来源:rzlib.py


示例9: draw_pixel

 def draw_pixel(self, x, y, color):
     color = self.colors[color]
     start_x = x * self.scale
     start_y = y * self.scale
     dstrect = self.blit_rect
     rffi.setintfield(dstrect, 'c_x',  start_x)
     rffi.setintfield(dstrect, 'c_y',  start_y)
     RSDL.FillRect(self.screen, dstrect, color)
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:8,代码来源:gameboy_implementation.py


示例10: fakeimpl

 def fakeimpl(arg):
     st = getattr(os, name)(arg)
     fields = [TYPE for fieldname, TYPE in LL_STAT_FIELDS]
     TP = TUPLE_TYPE(fields)
     ll_tup = lltype.malloc(TP.TO)
     for i, (fieldname, TYPE) in enumerate(LL_STAT_FIELDS):
         val = getattr(st, fieldname)
         rffi.setintfield(ll_tup, 'item%d' % i, int(val))
     return ll_tup
开发者ID:antoine1fr,项目名称:pygirl,代码行数:9,代码来源:ll_os_stat.py


示例11: from_in6_addr

 def from_in6_addr(in6_addr):
     result = instantiate(INET6Address)
     # store the malloc'ed data into 'result' as soon as possible
     # to avoid leaks if an exception occurs inbetween
     sin = lltype.malloc(_c.sockaddr_in6, flavor='raw', zero=True)
     result.setdata(sin, sizeof(_c.sockaddr_in6))
     rffi.setintfield(sin, 'c_sin6_family', AF_INET)
     rffi.structcopy(sin.c_sin6_addr, in6_addr)
     return result
开发者ID:alkorzt,项目名称:pypy,代码行数:9,代码来源:rsocket.py


示例12: select

def select(inl, outl, excl, timeout=-1.0):
    nfds = 0
    if inl: 
        ll_inl = lltype.malloc(_c.fd_set.TO, flavor='raw')
        _c.FD_ZERO(ll_inl)
        for i in inl:
            _c.FD_SET(i, ll_inl)
            if i > nfds:
                nfds = i
    else:
        ll_inl = lltype.nullptr(_c.fd_set.TO)
    if outl: 
        ll_outl = lltype.malloc(_c.fd_set.TO, flavor='raw')
        _c.FD_ZERO(ll_outl)
        for i in outl:
            _c.FD_SET(i, ll_outl)
            if i > nfds:
                nfds = i
    else:
        ll_outl = lltype.nullptr(_c.fd_set.TO)
    if excl: 
        ll_excl = lltype.malloc(_c.fd_set.TO, flavor='raw')
        _c.FD_ZERO(ll_excl)
        for i in excl:
            _c.FD_SET(i, ll_excl)
            if i > nfds:
                nfds = i
    else:
        ll_excl = lltype.nullptr(_c.fd_set.TO)
    if timeout != -1.0:
        ll_timeval = rffi.make(_c.timeval)
        rffi.setintfield(ll_timeval, 'c_tv_sec', int(timeout))
        rffi.setintfield(ll_timeval, 'c_tv_usec', int((timeout-int(timeout))
                                                  * 1000000))
    else:
        ll_timeval = lltype.nullptr(_c.timeval)
    try:
        res = _c.select(nfds + 1, ll_inl, ll_outl, ll_excl, ll_timeval)
        if res == -1:
            raise SelectError(_c.geterrno())
        if res == 0:
            return ([], [], [])
        else:
            return (
                [i for i in inl if _c.FD_ISSET(i, ll_inl)],
                [i for i in outl if _c.FD_ISSET(i, ll_outl)],
                [i for i in excl if _c.FD_ISSET(i, ll_excl)])
    finally:
        if ll_inl:
            lltype.free(ll_inl, flavor='raw')
        if ll_outl:
            lltype.free(ll_outl, flavor='raw')
        if ll_excl:
            lltype.free(ll_excl, flavor='raw')
        if ll_timeval:
            lltype.free(ll_timeval, flavor='raw')
开发者ID:alkorzt,项目名称:pypy,代码行数:56,代码来源:rpoll.py


示例13: descr__init__

    def descr__init__(self, space, w_ident, filter=KQ_FILTER_READ, flags=KQ_EV_ADD, fflags=0, data=0, udata=0):
        ident = space.c_filedescriptor_w(w_ident)

        self.event = lltype.malloc(kevent, flavor="raw")
        rffi.setintfield(self.event, "c_ident", ident)
        rffi.setintfield(self.event, "c_filter", filter)
        rffi.setintfield(self.event, "c_flags", flags)
        rffi.setintfield(self.event, "c_fflags", fflags)
        rffi.setintfield(self.event, "c_data", data)
        self.event.c_udata = rffi.cast(rffi.VOIDP, udata)
开发者ID:are-prabhu,项目名称:pypy,代码行数:10,代码来源:interp_kqueue.py


示例14: makeipv4addr

def makeipv4addr(s_addr, result=None):
    if result is None:
        result = instantiate(INETAddress)
    elif result.family != AF_INET:
        raise RSocketError("address family mismatched")
    sin = lltype.malloc(_c.sockaddr_in, flavor='raw', zero=True)
    result.setdata(sin, sizeof(_c.sockaddr_in))
    rffi.setintfield(sin, 'c_sin_family', AF_INET)   # PLAT sin_len
    rffi.setintfield(sin.c_sin_addr, 'c_s_addr', s_addr)
    return result
开发者ID:alkorzt,项目名称:pypy,代码行数:10,代码来源:rsocket.py


示例15: test_unknown_addr_as_object

def test_unknown_addr_as_object():    
    c_addr = lltype.malloc(rsocket._c.sockaddr, flavor='raw')
    c_addr.c_sa_data[0] = 'c'
    rffi.setintfield(c_addr, 'c_sa_family', 15)
    # XXX what size to pass here? for the purpose of this test it has
    #     to be short enough so we have some data, 1 sounds good enough
    #     + sizeof USHORT
    w_obj = rsocket.Address(c_addr, 1 + 2).as_object(-1, space)
    assert space.is_true(space.isinstance(w_obj, space.w_tuple))
    assert space.int_w(space.getitem(w_obj, space.wrap(0))) == 15
    assert space.str_w(space.getitem(w_obj, space.wrap(1))) == 'c'
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:11,代码来源:test_sock_app.py


示例16: mallocrect

def mallocrect(x, y, w, h):
    p = lltype.malloc(RSDL.Rect, flavor='raw')
    rffi.setintfield(p, 'c_x', x)
    rffi.setintfield(p, 'c_y', y)
    rffi.setintfield(p, 'c_w', w)
    rffi.setintfield(p, 'c_h', h)
    return p
开发者ID:ParitoshThapliyal59,项目名称:pypy,代码行数:7,代码来源:RSDL_helper.py


示例17: test_blit_rect

    def test_blit_rect(self):
        surface = RSDL.CreateRGBSurface(0, 150, 50, 32,
                                        r_uint(0x000000FF),
                                        r_uint(0x0000FF00),
                                        r_uint(0x00FF0000),
                                        r_uint(0xFF000000))
        fmt = surface.c_format
        color = RSDL.MapRGB(fmt, 255, 0, 0)
        RSDL.FillRect(surface, lltype.nullptr(RSDL.Rect), color)
        
        paintrect = RSDL_helper.mallocrect(75, 0, 150, 50)
        dstrect = lltype.malloc(RSDL.Rect, flavor='raw')
        try:
            color = RSDL.MapRGB(fmt, 255, 128, 0)
            RSDL.FillRect(surface, paintrect, color)

            rffi.setintfield(dstrect, 'c_x',  10)
            rffi.setintfield(dstrect, 'c_y',  10)
            rffi.setintfield(dstrect, 'c_w', 150)
            rffi.setintfield(dstrect, 'c_h',  50)
            RSDL.BlitSurface(surface, lltype.nullptr(RSDL.Rect), self.screen, dstrect)
            RSDL.Flip(self.screen)
        finally:
            lltype.free(dstrect, flavor='raw')
            lltype.free(paintrect, flavor='raw')
        RSDL.FreeSurface(surface)
        self.check("Half Red/Orange rectangle(150px * 50px) at the top left, 10 pixels from the border")
开发者ID:ParitoshThapliyal59,项目名称:pypy,代码行数:27,代码来源:test_video.py


示例18: time_sleep_llimpl

            def time_sleep_llimpl(secs):
                void = lltype.nullptr(rffi.VOIDP.TO)
                t = lltype.malloc(self.TIMEVAL, flavor='raw')
                try:
                    frac = math.fmod(secs, 1.0)
                    rffi.setintfield(t, 'c_tv_sec', int(secs))
                    rffi.setintfield(t, 'c_tv_usec', int(frac*1000000.0))

                    if rffi.cast(rffi.LONG, c_select(0, void, void, void, t)) != 0:
                        errno = rposix.get_errno()
                        if errno != EINTR:
                            raise OSError(rposix.get_errno(), "Select failed")
                finally:
                    lltype.free(t, flavor='raw')
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:14,代码来源:ll_time.py


示例19: posix_fakeimpl

 def posix_fakeimpl(arg):
     st = getattr(os, name)(arg)
     fields = [TYPE for fieldname, TYPE in STAT_FIELDS]
     TP = TUPLE_TYPE(fields)
     ll_tup = lltype.malloc(TP.TO)
     for i, (fieldname, TYPE) in enumerate(STAT_FIELDS):
         val = getattr(st, fieldname)
         if isinstance(TYPE, lltype.Number):
             rffi.setintfield(ll_tup, 'item%d' % i, int(val))
         elif TYPE is lltype.Float:
             setattr(ll_tup, 'item%d' % i, float(val))
         else:
             setattr(ll_tup, 'item%d' % i, val)
     return ll_tup
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:14,代码来源:ll_os_stat.py


示例20: flush

    def flush(self):
        if not self.running:
            raise OperationError(self.space.w_ValueError,
                self.space.wrap("this object was already flushed"))
        self.running = False
        
        out_bufsize = SMALLCHUNK
        out_buf = lltype.malloc(rffi.CCHARP.TO, out_bufsize, flavor='raw',
                                zero=True)

        try:
    
            self.bzs.c_next_out = out_buf
            rffi.setintfield(self.bzs, 'c_avail_out', out_bufsize)
        
            total_out = _bzs_total_out(self.bzs)
            
            temp = []
            while True:
                bzerror = BZ2_bzCompress(self.bzs, BZ_FINISH)
                if bzerror == BZ_STREAM_END:
                    break
                elif bzerror != BZ_FINISH_OK:
                    _catch_bz2_error(self.space, bzerror)
                
                if rffi.getintfield(self.bzs, 'c_avail_out') == 0:
                    data = "".join([out_buf[i] for i in range(_bzs_total_out(self.bzs))])
                    temp.append(data)
                    
                    out_bufsize = _new_buffer_size(out_bufsize)
                    out_buf = lltype.malloc(rffi.CCHARP.TO, out_bufsize,
                                            flavor='raw', zero=True)
                    self.bzs.c_next_out = out_buf
                    rffi.setintfield(self.bzs, 'c_avail_out', out_bufsize)
        

            if rffi.getintfield(self.bzs, 'c_avail_out'):
                size = _bzs_total_out(self.bzs) - total_out
                res = "".join([out_buf[i] for i in range(size)])
            else:
                total_out = _bzs_total_out(self.bzs)
                res = "".join([out_buf[i] for i in range(total_out)])
            if not temp:
                return self.space.wrap(res)
            else:
                temp.append(res)
                return self.space.wrap("".join(temp))
        finally:
            lltype.free(out_buf, flavor='raw')
开发者ID:alkorzt,项目名称:pypy,代码行数:49,代码来源:interp_bz2.py



注:本文中的pypy.rpython.lltypesystem.rffi.setintfield函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python rffi.sizeof函数代码示例发布时间:2022-05-27
下一篇:
Python rffi.ptradd函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap