Ejemplo n.º 1
0
 def produce_into(self, builder, r):
     v_srcstring = self.get_string(builder, r)
     v_dststring = self.get_string(builder, r)
     src = getref(self.ptr, v_srcstring)
     dst = getref(self.ptr, v_dststring)
     if src == dst:                                # because it's not a
         raise test_random.CannotProduceOperation  # memmove(), but memcpy()
     srclen = len(src.chars)
     dstlen = len(dst.chars)
     v_length = builder.get_index(min(srclen, dstlen), r)
     v_srcstart = builder.get_index(srclen - getint(v_length) + 1, r)
     v_dststart = builder.get_index(dstlen - getint(v_length) + 1, r)
     builder.do(self.opnum, [v_srcstring, v_dststring,
                             v_srcstart, v_dststart, v_length])
Ejemplo n.º 2
0
 def produce_into(self, builder, r):
     v_srcstring = self.get_string(builder, r)
     v_dststring = self.get_string(builder, r)
     src = getref(self.ptr, v_srcstring)
     dst = getref(self.ptr, v_dststring)
     if src == dst:  # because it's not a
         raise test_random.CannotProduceOperation  # memmove(), but memcpy()
     srclen = len(src.chars)
     dstlen = len(dst.chars)
     v_length = builder.get_index(min(srclen, dstlen), r)
     v_srcstart = builder.get_index(srclen - getint(v_length) + 1, r)
     v_dststart = builder.get_index(dstlen - getint(v_length) + 1, r)
     builder.do(
         self.opnum,
         [v_srcstring, v_dststring, v_srcstart, v_dststart, v_length])
Ejemplo n.º 3
0
 def produce_into(self, builder, r):
     v_string = self.get_string(builder, r)
     if isinstance(v_string, ConstPtr):
         raise test_random.CannotProduceOperation  # setitem(Const, ...)
     v_index = builder.get_index(len(getref(self.ptr, v_string).chars), r)
     v_target = ConstInt(r.random_integer() % self.max)
     builder.do(self.opnum, [v_string, v_index, v_target])
Ejemplo n.º 4
0
 def produce_into(self, builder, r):
     v_string = self.get_string(builder, r)
     if isinstance(v_string, ConstPtr):
         raise test_random.CannotProduceOperation  # setitem(Const, ...)
     v_index = builder.get_index(len(getref(self.ptr, v_string).chars), r)
     v_target = ConstInt(r.random_integer() % self.max)
     builder.do(self.opnum, [v_string, v_index, v_target])
Ejemplo n.º 5
0
 def get_string(self, builder, r):
     current = getattr(builder, self.builder_cache)
     if current and r.random() < .8:
         v_string = r.choice(current)
         string = getref(self.ptr, v_string)
     else:
         string = self.alloc(getint(builder.get_index(500, r)))
         v_string = ConstPtr(lltype.cast_opaque_ptr(llmemory.GCREF, string))
         current.append(v_string)
     for i in range(len(string.chars)):
         char = r.random_integer() % self.max
         string.chars[i] = lltype.cast_primitive(self.primitive, char)
     return v_string
Ejemplo n.º 6
0
 def get_string(self, builder, r):
     current = getattr(builder, self.builder_cache)
     if current and r.random() < .8:
         v_string = r.choice(current)
         string = getref(self.ptr, v_string)
     else:
         string = self.alloc(getint(builder.get_index(500, r)))
         v_string = ConstPtr(lltype.cast_opaque_ptr(llmemory.GCREF, string))
         current.append(v_string)
     for i in range(len(string.chars)):
         char = r.random_integer() % self.max
         string.chars[i] = lltype.cast_primitive(self.primitive, char)
     return v_string
Ejemplo n.º 7
0
 def field_descr(self, builder, r):
     v, A = builder.get_structptr_var(r, type=lltype.Array,
                                      array_of_structs=True)
     array = getref(lltype.Ptr(A), v)
     v_index = builder.get_index(len(array), r)
     choice = []
     for name in A.OF._names:
         FIELD = getattr(A.OF, name)
         if not isinstance(FIELD, lltype.Ptr):
             choice.append(name)
     if not choice:
         raise test_random.CannotProduceOperation
     name = r.choice(choice)
     descr = builder.cpu.interiorfielddescrof(A, name)
     descr._random_info = 'cpu.interiorfielddescrof(..., %r)' % (name,)
     descr._random_type = A
     TYPE = getattr(A.OF, name)
     return v, v_index, descr, TYPE
Ejemplo n.º 8
0
 def field_descr(self, builder, r):
     v, A = builder.get_structptr_var(r,
                                      type=lltype.Array,
                                      array_of_structs=True)
     array = getref(lltype.Ptr(A), v)
     v_index = builder.get_index(len(array), r)
     choice = []
     for name in A.OF._names:
         FIELD = getattr(A.OF, name)
         if not isinstance(FIELD, lltype.Ptr):
             choice.append(name)
     if not choice:
         raise test_random.CannotProduceOperation
     name = r.choice(choice)
     descr = builder.cpu.interiorfielddescrof(A, name)
     descr._random_info = 'cpu.interiorfielddescrof(..., %r)' % (name, )
     descr._random_type = A
     TYPE = getattr(A.OF, name)
     return v, v_index, descr, TYPE
Ejemplo n.º 9
0
 def produce_into(self, builder, r):
     v_string = self.get_string(builder, r)
     v_index = builder.get_index(len(getref(self.ptr, v_string).chars), r)
     builder.do(self.opnum, [v_string, v_index])
Ejemplo n.º 10
0
 def field_descr(self, builder, r):
     v, A = builder.get_arrayptr_var(r)
     array = getref(lltype.Ptr(A), v)
     v_index = builder.get_index(len(array), r)
     descr = self.array_descr(builder, A)
     return v, A, v_index, descr
Ejemplo n.º 11
0
 def produce_into(self, builder, r):
     v_string = self.get_string(builder, r)
     v_index = builder.get_index(len(getref(self.ptr, v_string).chars), r)
     builder.do(self.opnum, [v_string, v_index])
Ejemplo n.º 12
0
 def field_descr(self, builder, r):
     v, A = builder.get_arrayptr_var(r)
     array = getref(lltype.Ptr(A), v)
     v_index = builder.get_index(len(array), r)
     descr = self.array_descr(builder, A)
     return v, A, v_index, descr