Example #1
0
def _(obj):
    if isinstance(obj, space.Integer):
        return Uint8Array(lltype.malloc(rffi.UCHARP.TO, obj.value, flavor='raw'), obj.value)
    if isinstance(obj, space.List):
        length = len(obj.contents)
        array = Uint8Array(lltype.malloc(rffi.UCHARP.TO, length, flavor='raw'), length)
        for i in range(0, length):
            x = obj.contents[i]
            if isinstance(x, space.Integer):
                array.uint8data[i] = rffi.r_uchar(x.value)
            else:
                raise space.OldError(u"Value of incorrect type: " + x.repr())
        return array
    it = obj.iter()
    out = []
    try:
        while True:
            x = it.callattr(u"next", [])
            if isinstance(x, space.Integer):
                out.append(rffi.r_uchar(x.value))
            else:
                raise space.OldError(u"Value of incorrect type: " + x.repr())
    except StopIteration as stop:
        pass
    length = len(out)
    uint8data = lltype.malloc(rffi.UCHARP.TO, length, flavor='raw')
    for i in range(0, length):
        uint8data[i] = out[i]
    return Uint8Array(uint8data, length)
Example #2
0
def Uint8Array_init(obj):
    if isinstance(obj, space.Integer):
        return Uint8Array(
            lltype.malloc(rffi.UCHARP.TO, obj.value, flavor='raw'), obj.value)
    if isinstance(obj, space.List):
        length = len(obj.contents)
        array = Uint8Array(lltype.malloc(rffi.UCHARP.TO, length, flavor='raw'),
                           length)
        for i in range(0, length):
            x = obj.contents[i]
            if isinstance(x, space.Integer):
                array.uint8data[i] = rffi.r_uchar(x.value)
            else:
                raise space.OldError(u"Value of incorrect type: " + x.repr())
        return array
    it = obj.iter()
    out = []
    try:
        while True:
            x = it.callattr(u"next", [])
            if isinstance(x, space.Integer):
                out.append(rffi.r_uchar(x.value))
            else:
                raise space.OldError(u"Value of incorrect type: " + x.repr())
    except StopIteration as stop:
        pass
    length = len(out)
    uint8data = lltype.malloc(rffi.UCHARP.TO, length, flavor='raw')
    for i in range(0, length):
        uint8data[i] = out[i]
    return Uint8Array(uint8data, length)
Example #3
0
 def words_to_bytes(self, bytenum, words):
     bytes = lltype.malloc(RSDL.Uint8P.TO, bytenum, flavor="raw")
     if words:
         for pos in range(bytenum / 4):
             word = words[pos]
             bytes[pos * 4] = rffi.r_uchar((word >> 24) & 0xff)
             bytes[pos * 4 + 1] = rffi.r_uchar((word >> 16) & 0xff)
             bytes[pos * 4 + 2] = rffi.r_uchar((word >> 8) & 0xff)
             bytes[pos * 4 + 3] = rffi.r_uchar(word & 0xff)
     else:
         for idx in range(bytenum):
             bytes[idx] = rffi.r_uchar(0)
     return bytes
Example #4
0
 def words_to_bytes(self, bytenum, words):
     bytes = lltype.malloc(RSDL.Uint8P.TO, bytenum, flavor="raw")
     if words:
         for pos in range(bytenum / 4):
             word = words[pos]
             bytes[pos * 4] = rffi.r_uchar((word >> 24) & 0xff)
             bytes[pos * 4 + 1] = rffi.r_uchar((word >> 16) & 0xff)
             bytes[pos * 4 + 2] = rffi.r_uchar((word >> 8) & 0xff)
             bytes[pos * 4 + 3] = rffi.r_uchar(word & 0xff)
     else:
         for idx in range(bytenum):
             bytes[idx] = rffi.r_uchar(0)
     return bytes
Example #5
0
 def cursor_words_to_bytes(self, bytenum, words):
     """In Squeak, only the upper 16bits of the cursor form seem to count
     (I'm guessing because the code was ported over from 16-bit machines),
     so this ignores the lower 16-bits of each word."""
     bytes = lltype.malloc(RSDL.Uint8P.TO, bytenum, flavor='raw')
     if words:
         for idx, word in enumerate(words):
             bytes[idx * 2] = rffi.r_uchar((word >> 24) & 0xff)
             bytes[idx * 2 + 1] = rffi.r_uchar((word >> 16) & 0xff)
     else:
         for idx in range(bytenum):
             bytes[idx] = rffi.r_uchar(0)
     return bytes
Example #6
0
 def cursor_words_to_bytes(self, bytenum, words):
     """In Squeak, only the upper 16bits of the cursor form seem to count
     (I'm guessing because the code was ported over from 16-bit machines),
     so this ignores the lower 16-bits of each word."""
     bytes = lltype.malloc(RSDL.Uint8P.TO, bytenum, flavor='raw')
     if words:
         for idx, word in enumerate(words):
             bytes[idx * 2] = rffi.r_uchar((word >> 24) & 0xff)
             bytes[idx * 2 + 1] = rffi.r_uchar((word >> 16) & 0xff)
     else:
         for idx in range(bytenum):
             bytes[idx] = rffi.r_uchar(0)
     return bytes
Example #7
0
 def setitem(self, index, value):
     index = space.cast(index, numbers.Integer, u"index not an integer")
     if not 0 <= index.value < self.length:
         raise space.unwind(space.LKeyError(self, index))
     value = space.cast(value, numbers.Integer, u"value not an integer")
     self.uint8data[index.value] = rffi.r_uchar(value.value)
     return value
Example #8
0
 def setitem(self, index, value):
     index = space.cast(index, numbers.Integer, u"index not an integer")
     if not 0 <= index.value < self.length:
         raise space.unwind(space.LKeyError(self, index))
     value = space.cast(value, numbers.Integer, u"value not an integer")
     self.uint8data[index.value] = rffi.r_uchar(value.value)
     return value
Example #9
0
 def setitem(self, index, value):
     if not isinstance(index, numbers.Integer):
         raise space.OldError(u"index not an integer")
     if not 0 <= index.value < self.length:
         raise space.OldError(u"index out of range")
     if not isinstance(value, numbers.Integer):
         raise space.OldError(u"value of incorrect type")
     self.uint8data[index.value] = rffi.r_uchar(value.value)
     return value
Example #10
0
 def setitem(self, index, value):
     if not isinstance(index, numbers.Integer):
         raise space.OldError(u"index not an integer")
     if not 0 <= index.value < self.length:
         raise space.OldError(u"index out of range")
     if not isinstance(value, numbers.Integer):
         raise space.OldError(u"value of incorrect type")
     self.uint8data[index.value] = rffi.r_uchar(value.value)
     return value
Example #11
0
def tcsetattr(fd, when, attributes):
    with lltype.scoped_alloc(TERMIOSP.TO) as c_struct:
        rffi.setintfield(c_struct, "c_c_iflag", attributes[0])
        rffi.setintfield(c_struct, "c_c_oflag", attributes[1])
        rffi.setintfield(c_struct, "c_c_cflag", attributes[2])
        rffi.setintfield(c_struct, "c_c_lflag", attributes[3])
        ispeed = attributes[4]
        ospeed = attributes[5]
        cc = attributes[6]
        for i in range(NCCS):
            c_struct.c_c_cc[i] = rffi.r_uchar(ord(cc[i][0]))
        if c_cfsetispeed(c_struct, ispeed) < 0:
            raise OSError(rposix.get_saved_errno(), "tcsetattr failed")
        if c_cfsetospeed(c_struct, ospeed) < 0:
            raise OSError(rposix.get_saved_errno(), "tcsetattr failed")
        if c_tcsetattr(fd, when, c_struct) < 0:
            raise OSError(rposix.get_saved_errno(), "tcsetattr failed")
Example #12
0
def tcsetattr(fd, when, attributes):
    with lltype.scoped_alloc(TERMIOSP.TO) as c_struct:
        rffi.setintfield(c_struct, 'c_c_iflag', attributes[0])
        rffi.setintfield(c_struct, 'c_c_oflag', attributes[1])
        rffi.setintfield(c_struct, 'c_c_cflag', attributes[2])
        rffi.setintfield(c_struct, 'c_c_lflag', attributes[3])
        ispeed = attributes[4]
        ospeed = attributes[5]
        cc = attributes[6]
        for i in range(NCCS):
            c_struct.c_c_cc[i] = rffi.r_uchar(ord(cc[i][0]))
        if c_cfsetispeed(c_struct, ispeed) < 0:
            raise OSError(rposix.get_saved_errno(), 'tcsetattr failed')
        if c_cfsetospeed(c_struct, ospeed) < 0:
            raise OSError(rposix.get_saved_errno(), 'tcsetattr failed')
        if c_tcsetattr(fd, when, c_struct) < 0:
            raise OSError(rposix.get_saved_errno(), 'tcsetattr failed')
Example #13
0
def tcsetattr_llimpl(fd, when, attributes):
    c_struct = lltype.malloc(TERMIOSP.TO, flavor='raw')
    try:
        c_struct.c_c_iflag = r_uint(attributes[0])
        c_struct.c_c_oflag = r_uint(attributes[1])
        c_struct.c_c_cflag = r_uint(attributes[2])
        c_struct.c_c_lflag = r_uint(attributes[3])
        ispeed = r_uint(attributes[4])
        ospeed = r_uint(attributes[5])
        cc = attributes[6]
        for i in range(NCCS):
            c_struct.c_c_cc[i] = rffi.r_uchar(ord(cc[i][0]))
        if c_cfsetispeed(c_struct, ispeed) < 0:
            raise OSError(rposix.get_errno(), 'tcsetattr failed')
        if c_cfsetospeed(c_struct, ospeed) < 0:
            raise OSError(rposix.get_errno(), 'tcsetattr failed')
        if c_tcsetattr(fd, when, c_struct) < 0:
            raise OSError(rposix.get_errno(), 'tcsetattr failed')
    finally:
        lltype.free(c_struct, flavor='raw')
Example #14
0
def tcsetattr_llimpl(fd, when, attributes):
    c_struct = lltype.malloc(TERMIOSP.TO, flavor='raw')
    try:
        c_struct.c_c_iflag = r_uint(attributes[0])
        c_struct.c_c_oflag = r_uint(attributes[1])
        c_struct.c_c_cflag = r_uint(attributes[2])
        c_struct.c_c_lflag = r_uint(attributes[3])
        ispeed = r_uint(attributes[4])
        ospeed = r_uint(attributes[5])
        cc = attributes[6]
        for i in range(NCCS):
            c_struct.c_c_cc[i] = rffi.r_uchar(ord(cc[i][0]))
        if c_cfsetispeed(c_struct, ispeed) < 0:
            raise OSError(rposix.get_errno(), 'tcsetattr failed')
        if c_cfsetospeed(c_struct, ospeed) < 0:
            raise OSError(rposix.get_errno(), 'tcsetattr failed')
        if c_tcsetattr(fd, when, c_struct) < 0:
            raise OSError(rposix.get_errno(), 'tcsetattr failed')
    finally:
        lltype.free(c_struct, flavor='raw')
Example #15
0
 def set_squeak_colormap(self, surface):
     # TODO: fix this up from the image
     colors = lltype.malloc(rffi.CArray(RSDL.Color), 4, flavor='raw')
     colors[0].c_r = rffi.r_uchar(255)
     colors[0].c_g = rffi.r_uchar(255)
     colors[0].c_b = rffi.r_uchar(255)
     colors[0].c_a = rffi.r_uchar(255)
     colors[1].c_r = rffi.r_uchar(0)
     colors[1].c_g = rffi.r_uchar(0)
     colors[1].c_b = rffi.r_uchar(0)
     colors[1].c_a = rffi.r_uchar(255)
     colors[2].c_r = rffi.r_uchar(128)
     colors[2].c_g = rffi.r_uchar(128)
     colors[2].c_b = rffi.r_uchar(128)
     colors[2].c_a = rffi.r_uchar(255)
     colors[3].c_r = rffi.r_uchar(255)
     colors[3].c_g = rffi.r_uchar(255)
     colors[3].c_b = rffi.r_uchar(255)
     colors[3].c_a = rffi.r_uchar(255)
     RSDL.SetPaletteColors(surface.c_format.c_palette, rffi.cast(RSDL.ColorPtr, colors), 0, 4)
     lltype.free(colors, flavor='raw')
Example #16
0
 def set_squeak_colormap(self, screen):
     # TODO: fix this up from the image
     colors = lltype.malloc(rffi.CArray(RSDL.ColorPtr.TO), 4, flavor='raw')
     colors[0].c_r = rffi.r_uchar(255)
     colors[0].c_g = rffi.r_uchar(255)
     colors[0].c_b = rffi.r_uchar(255)
     colors[1].c_r = rffi.r_uchar(0)
     colors[1].c_g = rffi.r_uchar(0)
     colors[1].c_b = rffi.r_uchar(0)
     colors[2].c_r = rffi.r_uchar(128)
     colors[2].c_g = rffi.r_uchar(128)
     colors[2].c_b = rffi.r_uchar(128)
     colors[3].c_r = rffi.r_uchar(255)
     colors[3].c_g = rffi.r_uchar(255)
     colors[3].c_b = rffi.r_uchar(255)
     RSDL.SetColors(self.screen, rffi.cast(RSDL.ColorPtr, colors), 0, 4)
     lltype.free(colors, flavor='raw')
Example #17
0
 def set_squeak_colormap(self, screen):
     # TODO: fix this up from the image
     colors = lltype.malloc(rffi.CArray(RSDL.ColorPtr.TO), 4, flavor='raw')
     colors[0].c_r = rffi.r_uchar(255)
     colors[0].c_g = rffi.r_uchar(255)
     colors[0].c_b = rffi.r_uchar(255)
     colors[1].c_r = rffi.r_uchar(0)
     colors[1].c_g = rffi.r_uchar(0)
     colors[1].c_b = rffi.r_uchar(0)
     colors[2].c_r = rffi.r_uchar(128)
     colors[2].c_g = rffi.r_uchar(128)
     colors[2].c_b = rffi.r_uchar(128)
     colors[3].c_r = rffi.r_uchar(255)
     colors[3].c_g = rffi.r_uchar(255)
     colors[3].c_b = rffi.r_uchar(255)
     RSDL.SetColors(self.screen, rffi.cast(RSDL.ColorPtr, colors), 0, 4)
     lltype.free(colors, flavor='raw')