Esempio n. 1
0
 def test_rand(self):
     eci = ExternalCompilationInfo(includes=['stdlib.h'])
     rand = rffi.llexternal('rand', [], rffi.INT, compilation_info=eci)
     srand = rffi.llexternal('srand', [rffi.UINT],
                             lltype.Void,
                             compilation_info=eci)
     srand(rffi.r_uint(123))
     res1 = rand()
     res2 = rand()
     res3 = rand()
     srand(rffi.r_uint(123))
     res1b = rand()
     res2b = rand()
     res3b = rand()
     assert res1 == res1b
     assert res2 == res2b
     assert res3 == res3b
     assert not ALLOCATED  # detects memory leaks in the test
Esempio n. 2
0
 def test_rand(self):
     eci = ExternalCompilationInfo(includes=['stdlib.h'])
     rand = rffi.llexternal('rand', [], rffi.INT,
                            compilation_info=eci)
     srand = rffi.llexternal('srand', [rffi.UINT], lltype.Void,
                             compilation_info=eci)
     srand(rffi.r_uint(123))
     res1 = rand()
     res2 = rand()
     res3 = rand()
     srand(rffi.r_uint(123))
     res1b = rand()
     res2b = rand()
     res3b = rand()
     assert res1 == res1b
     assert res2 == res2b
     assert res3 == res3b
     assert not ALLOCATED     # detects memory leaks in the test
Esempio n. 3
0
 def do_send_string(self, space, buffer, offset, size):
     # Since str2charp copies the buffer 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:
         rffi.cast(rffi.UINTP, message)[0] = rffi.r_uint(size) # XXX htonl!
         i = size - 1
         while i >= 0:
             message[4 + i] = buffer[offset + i]
             i -= 1
         self._sendall(space, message, size + 4)
     finally:
         lltype.free(message, flavor='raw')
Esempio n. 4
0
 def do_send_string(self, space, buffer, offset, size):
     # Since str2charp copies the buffer 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] = buffer[offset + i]
             i -= 1
         self._sendall(space, message, size + 4)
     finally:
         lltype.free(message, flavor='raw')
Esempio n. 5
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
Esempio n. 6
0
def test_call_stubs_single_float():
    from pypy.rlib.longlong2float import uint2singlefloat, singlefloat2uint
    from pypy.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(rffi.cast(lltype.Signed, fnptr),
                           [a, b, c], [], [])
    assert float(uint2singlefloat(rffi.r_uint(res))) == -11.5
Esempio n. 7
0
def test_call_stubs_single_float():
    from pypy.rlib.longlong2float import uint2singlefloat, singlefloat2uint
    from pypy.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
Esempio n. 8
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
Esempio n. 9
0
def int2singlefloat(x):
    x = rffi.r_uint(x)
    return longlong2float.uint2singlefloat(x)
Esempio n. 10
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
Esempio n. 11
0
def int2singlefloat(x):
    x = rffi.r_uint(x)
    return longlong2float.uint2singlefloat(x)