1. Stian Andreassen
  2. pypy-improvebigint


Maciej Fijalkowski  committed 472a414

hack differently - disallow negative multiplication of array alltogether

  • Participants
  • Parent commits 1196e6e
  • Branches virtual-arguments

Comments (0)

Files changed (4)

File pypy/annotation/binaryop.py

View file
 class __extend__(pairtype(SomeList, SomeInteger)):
     def mul((lst1, int2)):
+        if not int2.nonneg:
+            raise TypeError("in [item] * times, times must be proven non-negative")
         return lst1.listdef.offspring()
     def getitem((lst1, int2)):

File pypy/jit/codewriter/jtransform.py

View file
     def do_fixed_newlist(self, op, args, arraydescr):
         v_length = self._get_initial_newlist_length(op, args)
-        if v_length.concretetype == lltype.Signed:
-            raise Exception("[item] * lgt must have lgt to be proven non-negative for the JIT")
         return SpaceOperation('new_array', [arraydescr, v_length], op.result)
     def do_fixed_list_len(self, op, args, arraydescr):

File pypy/jit/codewriter/test/test_codewriter.py

View file
     assert 'setarrayitem_raw_i' in s
     assert 'getarrayitem_raw_i' in s
     assert 'residual_call_ir_v $<* fn _ll_1_raw_free__arrayPtr>' in s
-def test_newlist_negativ():
-    def f(n):
-        l = [0] * n
-        return len(l)
-    rtyper = support.annotate(f, [-1])
-    jitdriver_sd = FakeJitDriverSD(rtyper.annotator.translator.graphs[0])
-    cw = CodeWriter(FakeCPU(rtyper), [jitdriver_sd])
-    cw.find_all_graphs(FakePolicy())
-    py.test.raises(Exception, "cw.make_jitcodes(verbose=True)")

File pypy/rpython/rlist.py

View file
     def rtype_mul((r_lst, r_int), hop):
         cRESLIST = hop.inputconst(Void, hop.r_result.LIST)
         v_lst, v_factor = hop.inputargs(r_lst, Signed)
+        if not hop.args_s[1].nonneg:
+            raise TypeError("in [item] * times, times must be proven non-negative")
         return hop.gendirectcall(ll_mul, cRESLIST, v_lst, v_factor)