示例#1
0
文件: zlib.py 项目: gordol/lever
def Compress_compress_beta(self, inp, out):
    stream = self.stream
    i_data = cast(inp.getattr(u"data"), Uint8Data, u"inp.data")
    i_start = cast(inp.getattr(u"start"), Integer, u"inp.start").value
    i_stop = cast(inp.getattr(u"stop"), Integer, u"inp.stop").value
    if not (0 <= i_start <= i_stop <= i_data.length):
        raise unwind(LTypeError(u"inp.start/stop invalid"))

    o_data = cast(out.getattr(u"data"), Uint8Data, u"out.data")
    o_start = cast(out.getattr(u"start"), Integer, u"out.start").value
    o_stop = cast(out.getattr(u"stop"), Integer, u"out.stop").value
    if not (0 <= o_start <= o_stop <= o_data.length):
        raise unwind(LTypeError(u"out.start/stop invalid"))

    stream.c_next_in = rffi.ptradd(i_data.uint8data, i_start)
    stream.c_avail_in = rffi.r_uint(i_stop - i_start)
    stream.c_next_out = rffi.ptradd(o_data.uint8data, o_stop)
    stream.c_avail_out = rffi.r_uint(o_data.length - o_stop)
    if i_start == i_stop:
        err = rzlib._deflate(stream, rzlib.Z_FINISH)
    else:
        err = rzlib._deflate(stream, 0)

    if err == rzlib.Z_NEED_DICT:
        raise unwind(LError(u"Z_NEED_DICT"))
    if err == rzlib.Z_BUF_ERROR:
        raise unwind(LError(u"Z_BUF_ERROR"))
    if err == rzlib.Z_OK or err == rzlib.Z_STREAM_END:
        inp.setattr(u"start", Integer(i_stop - rffi.r_long(stream.c_avail_in)))
        out.setattr(u"stop", Integer(rffi.r_long(stream.c_avail_out) + o_stop))
    return null
示例#2
0
文件: kernel.py 项目: sn6uv/rmathics
    def msg_recv(socket):
        result = []
        morep = rffi.lltype.malloc(rffi.INTP.TO, 1, flavor='raw')
        morep[0] = rffi.r_int(1)

        more_sizep = rffi.lltype.malloc(rffi.UINTP.TO, 1, flavor='raw')
        more_sizep[0] = rffi.r_uint(rffi.sizeof(rffi.INT))

        while int(morep[0]):
            part = rffi.lltype.malloc(rzmq.msg_t.TO, flavor='raw')
            rc = rzmq.msg_init(part)
            assert rc == 0

            msg_size = rzmq.msg_recv(part, socket, 0)
            assert msg_size != -1

            result.append(rffi.charpsize2str(rzmq.msg_data(part), msg_size))

            rc = rzmq.getsockopt(socket, rzmq.RCVMORE, morep, more_sizep)
            assert rc == 0

            rc = rzmq.msg_close(part)
            assert rc == 0

        return result
示例#3
0
    def msg_recv(socket):
        result = []
        morep = rffi.lltype.malloc(rffi.INTP.TO, 1, flavor='raw')
        morep[0] = rffi.r_int(1)

        more_sizep = rffi.lltype.malloc(rffi.UINTP.TO, 1, flavor='raw')
        more_sizep[0] = rffi.r_uint(rffi.sizeof(rffi.INT))

        while int(morep[0]):
            part = rffi.lltype.malloc(rzmq.msg_t.TO, flavor='raw')
            rc = rzmq.msg_init(part)
            assert rc == 0

            msg_size = rzmq.msg_recv(part, socket, 0)
            assert msg_size != -1

            result.append(rffi.charpsize2str(rzmq.msg_data(part), msg_size))

            rc = rzmq.getsockopt(socket, rzmq.RCVMORE, morep, more_sizep)
            assert rc == 0

            rc = rzmq.msg_close(part)
            assert rc == 0

        return result
示例#4
0
def EnumKey(space, w_hkey, index):
    """string = EnumKey(key, index) - Enumerates subkeys of an open registry key.

key is an already open key, or any one of the predefined HKEY_* constants.
index is an integer that identifies the index of the key to retrieve.

The function retrieves the name of one subkey each time it is called.
It is typically called repeatedly until an EnvironmentError exception is
raised, indicating no more values are available."""
    hkey = hkey_w(w_hkey, space)
    null_dword = lltype.nullptr(rwin32.LPDWORD.TO)

    # The Windows docs claim that the max key name length is 255
    # characters, plus a terminating nul character.  However,
    # empirical testing demonstrates that it is possible to
    # create a 256 character key that is missing the terminating
    # nul.  RegEnumKeyEx requires a 257 character buffer to
    # retrieve such a key name.
    with lltype.scoped_alloc(rffi.CCHARP.TO, 257) as buf:
        with lltype.scoped_alloc(rwin32.LPDWORD.TO, 1) as retValueSize:
            retValueSize[0] = rffi.r_uint(257) # includes NULL terminator
            ret = rwinreg.RegEnumKeyExA(hkey, index, buf, retValueSize,
                                       null_dword, None, null_dword,
                                       lltype.nullptr(rwin32.PFILETIME.TO))
            if ret != 0:
                raiseWindowsError(space, ret, 'RegEnumKeyEx')
            return space.newtext(rffi.charp2str(buf))
示例#5
0
 def set_pixelbuffer_word(self, n, word):
     # Invert the byte-order.
     self.pixelbuffer()[n] = rffi.r_uint(
         (word >> 24) |
         ((word >> 8) & 0x0000ff00) |
         ((word << 8) & 0x00ff0000) |
         (word << 24)
     )
def test_fileplugin_filewrite_words(monkeypatch):
    def write(fd, data):
        assert len(data) == 4
        assert data == 'dcba'
        return 4
    monkeypatch.setattr(os, "write", write)

    content = model.W_WordsObject(space, space.w_String, 1)
    content.words = [rffi.r_uint(1633837924)]
    try:
        stack = [space.w(1), space.w(1), content, space.w(1), space.w(1)]
        w_c = external_call('FilePlugin', 'primitiveFileWrite', stack)
    finally:
        monkeypatch.undo()
def test_fileplugin_filewrite_bitmap(monkeypatch):
    def write(fd, data):
        assert len(data) == 4
        assert data == 'dcba'
        return 4
    monkeypatch.setattr(os, "write", write)

    content = model_display.W_DisplayBitmap(space, space.w_Bitmap, 1, 32)
    content._real_depth_buffer[0] = rffi.r_uint(1633837924)
    try:
        stack = [space.w(1), space.w(1), content, space.w(1), space.w(1)]
        w_c = external_call('FilePlugin', 'primitiveFileWrite', stack)
    finally:
        monkeypatch.undo()
示例#8
0
 def do_send_string(self, space, buf, offset, size):
     # Since str2charp copies the buf anyway, always combine the
     # "header" and the "body" of the message and send them at once.
     message = lltype.malloc(rffi.CCHARP.TO, size + 4, flavor='raw')
     try:
         length = rffi.r_uint(rsocket.htonl(
                 rffi.cast(lltype.Unsigned, size)))
         rffi.cast(rffi.UINTP, message)[0] = length
         i = size - 1
         while i >= 0:
             message[4 + i] = buf[offset + i]
             i -= 1
         self._sendall(space, message, size + 4)
     finally:
         lltype.free(message, flavor='raw')
示例#9
0
 def do_send_string(self, space, buf, offset, size):
     # Since str2charp copies the buf anyway, always combine the
     # "header" and the "body" of the message and send them at once.
     message = lltype.malloc(rffi.CCHARP.TO, size + 4, flavor='raw')
     try:
         length = rffi.r_uint(
             rsocket.htonl(rffi.cast(lltype.Unsigned, size)))
         rffi.cast(rffi.UINTP, message)[0] = length
         i = size - 1
         while i >= 0:
             message[4 + i] = buf[offset + i]
             i -= 1
         self._sendall(space, message, size + 4)
     finally:
         lltype.free(message, flavor='raw')
示例#10
0
def test_fileplugin_filewrite_bitmap(monkeypatch):
    def write(fd, data):
        assert len(data) == 4
        assert data == 'dcba'
        return 4
    monkeypatch.setattr(os, "write", write)

    content = W_DisplayBitmap(space, 1, 32)
    content._squeak_pixel_buffer[0] = rffi.r_uint(1633837924)
    try:
        stack = [space.w(1), space.w(1), content, space.w(1), space.w(1)]
        w_c = external_call(space,
            'FilePlugin',
            'primitiveFileWrite',
            stack)
    finally:
        monkeypatch.undo()
示例#11
0
def test_fileplugin_filewrite_words(monkeypatch):
    def write(fd, data):
        assert len(data) == 4
        assert data == 'dcba'
        return 4
    monkeypatch.setattr(os, "write", write)

    content = W_WordsObject(space, space.w_String, 1)
    content.words = [rffi.r_uint(1633837924)]
    try:
        stack = [space.w(1), space.w(1), content, space.w(1), space.w(1)]
        w_c = external_call(space,
            'FilePlugin',
            'primitiveFileWrite',
            stack)
    finally:
        monkeypatch.undo()
示例#12
0
def parse(vm):
    (xml_o, nodes_mod),_ = vm.decode_args("SM")
    assert isinstance(xml_o, Con_String)
    
    with lltype.scoped_alloc(xmlSAXHandler, zero=True) as h:
        h.c_initialized = rffi.r_uint(XML_SAX2_MAGIC)
        h.c_characters = llhelper(charactersSAXFuncP, _characters)
        h.c_startElementNs = llhelper(startElementNsSAX2FuncP, _start_element)
        h.c_endElementNs = llhelper(endElementNsSAX2FuncP, _end_element)
        docs_eo = Con_List(vm, [])
        _storage_hack.push(_Store(vm, [docs_eo], nodes_mod))
        r = xmlSAXUserParseMemory(h, lltype.nullptr(rffi.VOIDP.TO), xml_o.v, len(xml_o.v))
    if r < 0 or len(_storage_hack.peek().elems_stack) != 1:
        raise Exception("XXX")
    _storage_hack.pop()
    doc_o = vm.get_slot_apply(nodes_mod.get_defn(vm, "Doc"), "new", [docs_eo])
    
    return doc_o
示例#13
0
    def set_pixelbuffer_word(self, n, word):
        mask = 0b11111
        lsb = (r_uint(word) & r_uint(0xffff0000)) >> 16
        msb = (r_uint(word) & r_uint(0x0000ffff))

        if not system.IS_DARWIN:
            # Invert order of rgb-components
            lsb = (
                ((lsb >> 10) & mask) |
                (((lsb >> 5) & mask) << 6) |
                ((lsb & mask) << 11)
            )
            msb = (
                ((msb >> 10) & mask) |
                (((msb >> 5) & mask) << 6) |
                ((msb & mask) << 11)
            )
        self.pixelbuffer()[n] = rffi.r_uint(lsb | (msb << 16))
示例#14
0
def parse(vm):
    (xml_o, nodes_mod), _ = vm.decode_args("SM")
    assert isinstance(xml_o, Con_String)

    with lltype.scoped_alloc(xmlSAXHandler, zero=True) as h:
        h.c_initialized = rffi.r_uint(XML_SAX2_MAGIC)
        h.c_characters = llhelper(charactersSAXFuncP, _characters)
        h.c_startElementNs = llhelper(startElementNsSAX2FuncP, _start_element)
        h.c_endElementNs = llhelper(endElementNsSAX2FuncP, _end_element)
        docs_eo = Con_List(vm, [])
        _storage_hack.push(_Store(vm, [docs_eo], nodes_mod))
        r = xmlSAXUserParseMemory(h, lltype.nullptr(rffi.VOIDP.TO), xml_o.v,
                                  len(xml_o.v))
    if r < 0 or len(_storage_hack.peek().elems_stack) != 1:
        raise Exception("XXX")
    _storage_hack.pop()
    doc_o = vm.get_slot_apply(nodes_mod.get_defn(vm, "Doc"), "new", [docs_eo])

    return doc_o
示例#15
0
 def set_pixelbuffer_word(self, n, word):
     n = r_uint(n)
     if ((n + 1) % self.words_per_line) == 0 and self.bits_in_last_word > 0:
         # This is the last word on the line. A few bits may be cut off.
         bits = self.bits_in_last_word
     else:
         bits = constants.BITS_PER_WORD
     buf = self._sdl_pixel_buffer
     word = r_uint(word)
     depth = r_uint(self._depth)
     shift = constants.BITS_PER_WORD - depth
     display_words_per_word = BELOW_MINIMUM_DEPTH / depth
     pixelmask = ((r_uint(1) << depth) - 1) << shift
     table = PIXEL_LOOKUP_TABLE[depth - 1]
     assert table is not None
     for i in range(bits / depth):
         pixel = (word & pixelmask) >> (shift - i * depth)
         buf[n * display_words_per_word + i] = rffi.r_uint(table[pixel])
         pixelmask >>= depth
示例#16
0
def test_call_stubs_single_float():
    from rpython.rlib.longlong2float import uint2singlefloat, singlefloat2uint
    from rpython.rlib.rarithmetic import r_singlefloat, intmask
    #
    c0 = GcCache(False)
    ARGS = [lltype.SingleFloat, lltype.SingleFloat, lltype.SingleFloat]
    RES = lltype.SingleFloat

    def f(a, b, c):
        a = float(a)
        b = float(b)
        c = float(c)
        x = a - (b / c)
        return r_singlefloat(x)

    fnptr = llhelper(lltype.Ptr(lltype.FuncType(ARGS, RES)), f)
    descr2 = get_call_descr(c0, ARGS, RES)
    a = intmask(singlefloat2uint(r_singlefloat(-10.0)))
    b = intmask(singlefloat2uint(r_singlefloat(3.0)))
    c = intmask(singlefloat2uint(r_singlefloat(2.0)))
    res = descr2.call_stub_i(rffi.cast(lltype.Signed, fnptr),
                             [a, b, c], [], [])
    assert float(uint2singlefloat(rffi.r_uint(res))) == -11.5
示例#17
0
def test_call_stubs_single_float():
    from rpython.rlib.longlong2float import uint2singlefloat, singlefloat2uint
    from rpython.rlib.rarithmetic import r_singlefloat, intmask
    #
    c0 = GcCache(False)
    ARGS = [lltype.SingleFloat, lltype.SingleFloat, lltype.SingleFloat]
    RES = lltype.SingleFloat

    def f(a, b, c):
        a = float(a)
        b = float(b)
        c = float(c)
        x = a - (b / c)
        return r_singlefloat(x)

    fnptr = llhelper(lltype.Ptr(lltype.FuncType(ARGS, RES)), f)
    descr2 = get_call_descr(c0, ARGS, RES)
    a = intmask(singlefloat2uint(r_singlefloat(-10.0)))
    b = intmask(singlefloat2uint(r_singlefloat(3.0)))
    c = intmask(singlefloat2uint(r_singlefloat(2.0)))
    res = descr2.call_stub_i(rffi.cast(lltype.Signed, fnptr),
                             [a, b, c], [], [])
    assert float(uint2singlefloat(rffi.r_uint(res))) == -11.5
示例#18
0
def time_t_to_FILE_TIME(time, filetime):
    ft = rffi.r_longlong((time + secs_between_epochs) * 10000000)
    filetime.c_dwHighDateTime = rffi.r_uint(ft >> 32)
    filetime.c_dwLowDateTime = rffi.r_uint(ft)    # masking off high bits
示例#19
0
文件: longlong.py 项目: Darriall/pypy
def int2singlefloat(x):
    x = rffi.r_uint(x)
    return longlong2float.uint2singlefloat(x)
示例#20
0
 def setword(self, n, word):
     self._real_depth_buffer[n] = rffi.r_uint(word)
示例#21
0
def time_t_to_FILE_TIME(time, filetime):
    ft = rffi.r_longlong((time + secs_between_epochs) * 10000000)
    filetime.c_dwHighDateTime = rffi.r_uint(ft >> 32)
    filetime.c_dwLowDateTime = rffi.r_uint(ft)  # masking off high bits
示例#22
0
 def set_pixelbuffer_word(self, n, word):
     self.pixelbuffer()[n] = rffi.r_uint(word)
示例#23
0
def int2singlefloat(x):
    x = rffi.r_uint(x)
    return longlong2float.uint2singlefloat(x)
示例#24
0
 def setword(self, n, word):
     self._squeak_pixel_buffer[n] = rffi.r_uint(word)
示例#25
0
文件: zlib.py 项目: gordol/lever
def adler32(array, start):
    start = rzlib.ADLER32_DEFAULT_START if start is None else start.value
    string = array.to_str()
    checksum = rzlib.adler32(string, rffi.r_uint(start))
    return Integer(rffi.r_long(checksum))