diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py index c87ece75712..1d6e7c9c737 100644 --- a/pypy/objspace/std/listobject.py +++ b/pypy/objspace/std/listobject.py @@ -1648,6 +1648,7 @@ def _list_resize_hint_really(self, w_list, newsize, overallocate): else: new_allocated = newsize l = self.unerase(w_list.lstorage) + assert new_allocated >= 0 newitems = [self._none_value] * new_allocated before_len = w_list.length() if before_len: diff --git a/rpython/rtyper/rlist.py b/rpython/rtyper/rlist.py index 328072929dd..5ea5baf855a 100644 --- a/rpython/rtyper/rlist.py +++ b/rpython/rtyper/rlist.py @@ -485,8 +485,10 @@ def _ll_zero_or_null(item): return not check @specialize.memo() -def _null_of_type(T): - return T._defl() +def _is_array_of_gcref(T): + ITEM = T.ITEM + return isinstance(ITEM, Ptr) and ITEM.TO._gckind == 'gc' + def ll_alloc_and_set(LIST, count, item): count = int_force_ge_zero(count) @@ -519,14 +521,14 @@ def _ll_alloc_and_set_jit(LIST, count, item): @jit.oopspec("newlist_clear(count)") def _ll_alloc_and_clear(LIST, count): + from rpython.rlib.rgc import ll_arrayclear l = LIST.ll_newlist(count) - if malloc_zero_filled: + if malloc_zero_filled or _is_array_of_gcref(LIST): + # if it's an array of gcrefs, we don't need to clear it (the + # exceptiontransformer inserts clear calls, otherwise the GC would + # crash) return l - zeroitem = _null_of_type(LIST.ITEM) - i = 0 - while i < count: - l.ll_setitem_fast(i, zeroitem) - i += 1 + ll_arrayclear(l.ll_items()) return l @jit.look_inside_iff(lambda LIST, count, item: jit.isconstant(count) and count < 137)