Exemple #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])
Exemple #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])
Exemple #3
0
 def get_index(self, length, r):
     if length == 0:
         raise test_random.CannotProduceOperation
     v_index = r.choice(self.intvars)
     if not (0 <= getint(v_index) < length):
         v_index = ConstInt(r.random_integer() % length)
     return v_index
Exemple #4
0
 def get_index(self, length, r):
     if length == 0:
         raise test_random.CannotProduceOperation
     v_index = r.choice(self.intvars)
     if not (0 <= getint(v_index) < length):
         v_index = ConstInt(r.random_integer() % length)
     return v_index
Exemple #5
0
 def produce_into(self, builder, r):
     v_length = builder.get_index(10, r)
     v_ptr = builder.do(self.opnum, [v_length])
     getattr(builder, self.builder_cache).append(v_ptr)
     # Initialize the string. Is there a better way to do this?
     for i in range(getint(v_length)):
         v_index = ConstInt(i)
         v_char = ConstInt(r.random_integer() % self.max)
         builder.do(self.set_char, [v_ptr, v_index, v_char])
Exemple #6
0
 def produce_into(self, builder, r):
     v_length = builder.get_index(10, r)
     v_ptr = builder.do(self.opnum, [v_length])
     getattr(builder, self.builder_cache).append(v_ptr)
     # Initialize the string. Is there a better way to do this?
     for i in range(getint(v_length)):
         v_index = ConstInt(i)
         v_char = ConstInt(r.random_integer() % self.max)
         builder.do(self.set_char, [v_ptr, v_index, v_char])
Exemple #7
0
 def produce_into(self, builder, r):
     v, A, v_index, descr = self.field_descr(builder, r)
     while True:
         if r.random() < 0.3:
             w = ConstInt(r.random_integer())
         else:
             w = r.choice(builder.intvars)
         value = getint(w)
         if rffi.cast(lltype.Signed, rffi.cast(A.OF, value)) == value:
             break
     builder.do(self.opnum, [v, v_index, w], descr)
Exemple #8
0
 def produce_into(self, builder, r):
     v, A, v_index, descr = self.field_descr(builder, r)
     while True:
         if r.random() < 0.3:
             w = ConstInt(r.random_integer())
         else:
             w = r.choice(builder.intvars)
         value = getint(w)
         if rffi.cast(lltype.Signed, rffi.cast(A.OF, value)) == value:
             break
     builder.do(self.opnum, [v, v_index, w], descr)
Exemple #9
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
Exemple #10
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