Пример #1
0
def ll_int2oct(i, addPrefix):
    from pypy.rpython.lltypesystem.rstr import mallocstr
    if i == 0:
        result = mallocstr(1)
        result.hash = 0
        result.chars[0] = '0'
        return result
    temp = malloc(CHAR_ARRAY, 25)
    len = 0
    sign = 0
    if i < 0:
        sign = 1
        i = r_uint(-i)
    else:
        i = r_uint(i)
    while i:
        temp[len] = hex_chars[i & 0x7]
        i >>= 3
        len += 1
    len += sign
    if addPrefix:
        len += 1
    result = mallocstr(len)
    result.hash = 0
    j = 0
    if sign:
        result.chars[0] = '-'
        j = 1
    if addPrefix:
        result.chars[j] = '0'
        j += 1
    while j < len:
        result.chars[j] = temp[len-j-1]
        j += 1
    return result
Пример #2
0
 def ll_os_read(cls, fd, count):
     from pypy.rpython.lltypesystem.rstr import mallocstr
     if count < 0:
         raise OSError(errno.EINVAL, None)
     buffer = mallocstr(count)
     n = cls.ll_read_into(fd, buffer)
     if n != count:
         s = mallocstr(n)
         ll_strcpy(s, buffer, n)
         buffer = s
     return buffer
Пример #3
0
def test_hash_equal_whatever_lltype():
    s1 = rstr.mallocstr(2)
    s2 = rstr.mallocstr(2)
    s1.chars[0] = 'x'; s1.chars[1] = 'y'
    s2.chars[0] = 'x'; s2.chars[1] = 'y'
    def fn(x):
        assert hash_whatever(lltype.typeOf(x), x) == 42
        assert (hash_whatever(lltype.typeOf(s1), s1) ==
                hash_whatever(lltype.typeOf(s2), s2))
        assert equal_whatever(lltype.typeOf(s1), s1, s2)
    fn(42)
    interpret(fn, [42], type_system='lltype')
Пример #4
0
 def ll_os_readlink(cls, path):
     from pypy.rpython.lltypesystem.rstr import mallocstr
     bufsize = 1023
     while 1:
         buffer = mallocstr(bufsize)
         n = cls.ll_readlink_into(cls, path, buffer)
         if n < bufsize:
             break
         bufsize *= 4     # overflow, try again with a bigger buffer
     s = mallocstr(n)
     ll_strcpy(s, buffer, n)
     return s
Пример #5
0
def test_hash_equal_whatever_lltype():
    s1 = rstr.mallocstr(2)
    s2 = rstr.mallocstr(2)
    s1.chars[0] = "x"
    s1.chars[1] = "y"
    s2.chars[0] = "x"
    s2.chars[1] = "y"

    def fn(x):
        assert hash_whatever(lltype.typeOf(x), x) == 42
        assert hash_whatever(lltype.typeOf(s1), s1) == hash_whatever(lltype.typeOf(s2), s2)
        assert equal_whatever(lltype.typeOf(s1), s1, s2)

    fn(42)
    interpret(fn, [42], type_system="lltype")
Пример #6
0
def ll_int2hex(i, addPrefix):
    from pypy.rpython.lltypesystem.rstr import mallocstr
    temp = malloc(CHAR_ARRAY, 20)
    len = 0
    sign = 0
    if i < 0:
        sign = 1
        i = r_uint(-i)
    else:
        i = r_uint(i)
    if i == 0:
        len = 1
        temp[0] = '0'
    else:
        while i:
            temp[len] = hex_chars[i & 0xf]
            i >>= 4
            len += 1
    len += sign
    if addPrefix:
        len += 2
    result = mallocstr(len)
    result.hash = 0
    j = 0
    if sign:
        result.chars[0] = '-'
        j = 1
    if addPrefix:
        result.chars[j] = '0'
        result.chars[j+1] = 'x'
        j += 2
    while j < len:
        result.chars[j] = temp[len-j-1]
        j += 1
    return result
Пример #7
0
def ll_int2dec(val):
    from pypy.rpython.lltypesystem.rstr import mallocstr

    sign = int(val < 0)
    if sign:
        val = ll_unsigned(-val)
    else:
        val = ll_unsigned(val)
    len = 0
    i = val
    while i:
        len += 1
        i //= 10

    total_len = sign + len + int(val == 0)
    result = mallocstr(total_len)
    if sign:
        result.chars[0] = '-'
    elif val == 0:
        result.chars[0] = '0'

    j = 0
    while j < len:
        result.chars[total_len - j - 1] = chr(val % 10 + ord('0'))
        val //= 10
        j += 1
    return result
Пример #8
0
def ll_int2dec(i):
    from pypy.rpython.lltypesystem.rstr import mallocstr
    temp = malloc(CHAR_ARRAY, 20)
    len = 0
    sign = 0
    if i < 0:
        sign = 1
        i = r_uint(-i)
    else:
        i = r_uint(i)
    if i == 0:
        len = 1
        temp[0] = '0'
    else:
        while i:
            temp[len] = chr(i%10+ord('0'))
            i //= 10
            len += 1
    len += sign
    result = mallocstr(len)
    result.hash = 0
    if sign:
        result.chars[0] = '-'
        j = 1
    else:
        j = 0
    while j < len:
        result.chars[j] = temp[len-j-1]
        j += 1
    return result
Пример #9
0
def test_hash_equal_whatever_lltype():
    s1 = rstr.mallocstr(2)
    s2 = rstr.mallocstr(2)
    s1.chars[0] = 'x'
    s1.chars[1] = 'y'
    s2.chars[0] = 'x'
    s2.chars[1] = 'y'

    def fn(x):
        assert hash_whatever(lltype.typeOf(x), x) == 42
        assert (hash_whatever(lltype.typeOf(s1),
                              s1) == hash_whatever(lltype.typeOf(s2), s2))
        assert equal_whatever(lltype.typeOf(s1), s1, s2)

    fn(42)
    interpret(fn, [42], type_system='lltype')
Пример #10
0
def llstr(s):
    from pypy.rpython.lltypesystem.rstr import mallocstr
    # XXX not sure what to do with ootypesystem
    ll_s = mallocstr(len(s))
    for i, c in enumerate(s):
        ll_s.chars[i] = c
    return ll_s
Пример #11
0
 def to_rstr(s):
     from pypy.rpython.lltypesystem.rstr import STR, mallocstr
     if s is None:
         return lltype.nullptr(STR)
     p = mallocstr(len(s))
     for i in range(len(s)):
         p.chars[i] = s[i]
     return p
Пример #12
0
 def to_rstr(s):
     from pypy.rpython.lltypesystem.rstr import STR, mallocstr
     if s is None:
         return lltype.nullptr(STR)
     p = mallocstr(len(s))
     for i in range(len(s)):
         p.chars[i] = s[i]
     return p
Пример #13
0
 def test_strsetitem(self):
     ops = '''
     [p0, i]
     strsetitem(p0, 1, i)
     finish()
     '''
     llstr  = rstr.mallocstr(10)
     self.interpret(ops, [llstr, ord('a')])
     assert llstr.chars[1] == 'a'
Пример #14
0
 def llstr(s):
     from pypy.rpython.lltypesystem.rstr import mallocstr, mallocunicode
     if strtype is str:
         ll_s = mallocstr(len(s))
     else:
         ll_s = mallocunicode(len(s))
     for i, c in enumerate(s):
         ll_s.chars[i] = c
     return ll_s
Пример #15
0
 def llstr(s):
     from pypy.rpython.lltypesystem.rstr import mallocstr, mallocunicode
     if strtype is str:
         ll_s = mallocstr(len(s))
     else:
         ll_s = mallocunicode(len(s))
     for i, c in enumerate(s):
         ll_s.chars[i] = c
     return ll_s
Пример #16
0
 def llstr(s):
     from pypy.rpython.lltypesystem.rstr import mallocstr, mallocunicode
     from pypy.rpython.lltypesystem.rstr import STR, UNICODE
     if strtype is str:
         if s is None:
             return lltype.nullptr(STR)
         ll_s = mallocstr(len(s))
     else:
         if s is None:
             return lltype.nullptr(UNICODE)
         ll_s = mallocunicode(len(s))
     for i, c in enumerate(s):
         ll_s.chars[i] = c
     return ll_s
Пример #17
0
 def llstr(s):
     from pypy.rpython.lltypesystem.rstr import mallocstr, mallocunicode
     from pypy.rpython.lltypesystem.rstr import STR, UNICODE
     if strtype is str:
         if s is None:
             return lltype.nullptr(STR)
         ll_s = mallocstr(len(s))
     else:
         if s is None:
             return lltype.nullptr(UNICODE)
         ll_s = mallocunicode(len(s))
     for i, c in enumerate(s):
         ll_s.chars[i] = c
     return ll_s
Пример #18
0
 def ll_str(self, i): # doesn't work for non-gc classes!
     from pypy.rpython.lltypesystem import rstr
     from pypy.rpython.lltypesystem.ll_str import ll_int2hex
     from pypy.rlib.rarithmetic import r_uint
     if not i:
         return rstr.null_str
     instance = cast_pointer(OBJECTPTR, i)
     uid = r_uint(cast_ptr_to_int(i))
     nameLen = len(instance.typeptr.name)
     nameString = rstr.mallocstr(nameLen-1)
     i = 0
     while i < nameLen - 1:
         nameString.chars[i] = instance.typeptr.name[i]
         i += 1
     res =                        rstr.instance_str_prefix
     res = rstr.ll_strconcat(res, nameString)
     res = rstr.ll_strconcat(res, rstr.instance_str_infix)
     res = rstr.ll_strconcat(res, ll_int2hex(uid, False))
     res = rstr.ll_strconcat(res, rstr.instance_str_suffix)
     return res
Пример #19
0
 def ll_str(self, i):  # doesn't work for non-gc classes!
     from pypy.rpython.lltypesystem import rstr
     from pypy.rpython.lltypesystem.ll_str import ll_int2hex
     from pypy.rlib.rarithmetic import r_uint
     if not i:
         return rstr.null_str
     instance = cast_pointer(OBJECTPTR, i)
     uid = r_uint(cast_ptr_to_int(i))
     nameLen = len(instance.typeptr.name)
     nameString = rstr.mallocstr(nameLen - 1)
     i = 0
     while i < nameLen - 1:
         nameString.chars[i] = instance.typeptr.name[i]
         i += 1
     res = rstr.instance_str_prefix
     res = rstr.ll_strconcat(res, nameString)
     res = rstr.ll_strconcat(res, rstr.instance_str_infix)
     res = rstr.ll_strconcat(res, ll_int2hex(uid, False))
     res = rstr.ll_strconcat(res, rstr.instance_str_suffix)
     return res
Пример #20
0
 def RPyString_New(length=lltype.Signed):
     return mallocstr(length)
Пример #21
0
 def lowlevelhash(value):
     p = rstr.mallocstr(len(value))
     for i in range(len(value)):
         p.chars[i] = value[i]
     return rstr.LLHelpers.ll_strhash(p)
 def test_hlstr(self):
     s = mallocstr(3)
     s.chars[0] = "a"
     s.chars[1] = "b"
     s.chars[2] = "c"
     assert hlstr(s) == "abc"
Пример #23
0
 def lowlevelhash(value): 
     p = rstr.mallocstr(len(value))
     for i in range(len(value)):
         p.chars[i] = value[i]
     return rstr.LLHelpers.ll_strhash(p) 
Пример #24
0
 def test_hlstr(self):
     s = mallocstr(3)
     s.chars[0] = "a"
     s.chars[1] = "b"
     s.chars[2] = "c"
     assert hlstr(s) == "abc"
Пример #25
0
 def RPyString_New(length=lltype.Signed):
     return mallocstr(length)