Ejemplo n.º 1
0
    def decodeslice(self, space, w_slice):
        if not space.isinstance_w(w_slice, space.w_slice):
            raise OperationError(space.w_TypeError,
                                 space.wrap('index must be int or slice'))
        letter = self.shape.itemcode
        if letter != 'c':
            raise OperationError(space.w_TypeError,
                                 space.wrap("only 'c' arrays support slicing"))
        w_start = space.getattr(w_slice, space.wrap('start'))
        w_stop = space.getattr(w_slice, space.wrap('stop'))
        w_step = space.getattr(w_slice, space.wrap('step'))

        if space.is_w(w_start, space.w_None):
            start = 0
        else:
            start = space.int_w(w_start)
        if space.is_w(w_stop, space.w_None):
            stop = self.length
        else:
            stop = space.int_w(w_stop)
        if not space.is_w(w_step, space.w_None):
            step = space.int_w(w_step)
            if step != 1:
                raise OperationError(space.w_ValueError,
                                     space.wrap("no step support"))
        if not (0 <= start <= stop <= self.length):
            raise OperationError(space.w_ValueError,
                                 space.wrap("slice out of bounds"))
        if not self.ll_buffer:
            raise segfault_exception(space, "accessing a freed array")
        return start, stop
Ejemplo n.º 2
0
    def decodeslice(self, space, w_slice):
        if not space.isinstance_w(w_slice, space.w_slice):
            raise oefmt(space.w_TypeError, "index must be int or slice")
        letter = self.shape.itemcode
        if letter != 'c':
            raise oefmt(space.w_TypeError, "only 'c' arrays support slicing")
        w_start = space.getattr(w_slice, space.wrap('start'))
        w_stop = space.getattr(w_slice, space.wrap('stop'))
        w_step = space.getattr(w_slice, space.wrap('step'))

        if space.is_w(w_start, space.w_None):
            start = 0
        else:
            start = space.int_w(w_start)
        if space.is_w(w_stop, space.w_None):
            stop = self.length
        else:
            stop = space.int_w(w_stop)
        if not space.is_w(w_step, space.w_None):
            step = space.int_w(w_step)
            if step != 1:
                raise oefmt(space.w_ValueError, "no step support")
        if not (0 <= start <= stop <= self.length):
            raise oefmt(space.w_ValueError, "slice out of bounds")
        if not self.ll_buffer:
            raise segfault_exception(space, "accessing a freed array")
        return start, stop
Ejemplo n.º 3
0
 def setitem(self, space, num, w_value):
     if not self.ll_buffer:
         raise segfault_exception(space, "setting element of freed array")
     if num >= self.length or num < 0:
         raise OperationError(space.w_IndexError, space.w_None)
     unwrap_value(space, write_ptr, self.ll_buffer, num,
                  self.shape.itemcode, w_value)
Ejemplo n.º 4
0
 def getitem(self, space, num):
     if not self.ll_buffer:
         raise segfault_exception(space, "accessing elements of freed array")
     if num >= self.length or num < 0:
         raise OperationError(space.w_IndexError, space.w_None)
     return wrap_value(space, read_ptr, self.ll_buffer, num,
                       self.shape.itemcode)
Ejemplo n.º 5
0
 def setitem(self, space, num, w_value):
     if not self.ll_buffer:
         raise segfault_exception(space, "setting element of freed array")
     if num >= self.length or num < 0:
         raise OperationError(space.w_IndexError, space.w_None)
     unwrap_value(space, write_ptr, self.ll_buffer, num,
                  self.shape.itemcode, w_value)
Ejemplo n.º 6
0
 def getitem(self, space, num):
     if not self.ll_buffer:
         raise segfault_exception(space, "accessing elements of freed array")
     if num >= self.length or num < 0:
         raise OperationError(space.w_IndexError, space.w_None)
     return wrap_value(space, read_ptr, self.ll_buffer, num,
                       self.shape.itemcode)
Ejemplo n.º 7
0
    def decodeslice(self, space, w_slice):
        if not space.isinstance_w(w_slice, space.w_slice):
            raise oefmt(space.w_TypeError, "index must be int or slice")
        if self.fmt != 'c':
            raise oefmt(space.w_TypeError, "only 'c' arrays support slicing")
        w_start = space.getattr(w_slice, space.newtext('start'))
        w_stop = space.getattr(w_slice, space.newtext('stop'))
        w_step = space.getattr(w_slice, space.newtext('step'))

        if space.is_w(w_start, space.w_None):
            start = 0
        else:
            start = space.int_w(w_start)
        if space.is_w(w_stop, space.w_None):
            stop = self.length
        else:
            stop = space.int_w(w_stop)
        if not space.is_w(w_step, space.w_None):
            step = space.int_w(w_step)
            if step != 1:
                raise oefmt(space.w_ValueError, "no step support")
        if not (0 <= start <= stop <= self.length):
            raise oefmt(space.w_ValueError, "slice out of bounds")
        if not self.ll_buffer:
            raise segfault_exception(space, "accessing a freed array")
        return start, stop
Ejemplo n.º 8
0
 def getitem(self, space, idx):
     if not self.baseaddress:
         raise segfault_exception(space,
                                  "accessing elements of freed array")
     if idx >= self.length or idx < 0:
         raise OperationError(space.w_IndexError, space.w_None)
     itemaddress = rffi.cast(rffi.LONG,
                             self.baseaddress) + idx * self.clssize
     return self.converter.from_memory(space, space.w_None, itemaddress)
Ejemplo n.º 9
0
 def setattr(self, space, attr, w_value):
     if not self.ll_buffer:
         raise segfault_exception(space, "accessing NULL pointer")
     i = self.shape.getindex(space, attr)
     _, tp, _ = self.shape.fields[i]
     unwrap_value(space, push_field, self, i, tp.itemcode, w_value)
Ejemplo n.º 10
0
 def getattr(self, space, attr):
     if not self.ll_buffer:
         raise segfault_exception(space, "accessing NULL pointer")
     i = self.shape.getindex(space, attr)
     _, tp, _ = self.shape.fields[i]
     return wrap_value(space, cast_pos, self, i, tp.itemcode)
Ejemplo n.º 11
0
 def setattr(self, space, attr, w_value):
     if not self.ll_buffer:
         raise segfault_exception(space, "accessing NULL pointer")
     i = self.shape.getindex(space, attr)
     _, tp, _ = self.shape.fields[i]
     unwrap_value(space, push_field, self, i, tp.itemcode, w_value)
Ejemplo n.º 12
0
 def getattr(self, space, attr):
     if not self.ll_buffer:
         raise segfault_exception(space, "accessing NULL pointer")
     i = self.shape.getindex(space, attr)
     _, tp, _ = self.shape.fields[i]
     return wrap_value(space, cast_pos, self, i, tp.itemcode)