当前位置: 首页>>代码示例>>Python>>正文


Python rffi.setintfield函数代码示例

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


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


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