[pypy-commit] pypy array-overallocation-in-nursery: Use GcArray(overallocated=True) in rlist.py.

2013-11-03 Thread arigo
Author: Armin Rigo 
Branch: array-overallocation-in-nursery
Changeset: r67804:30af5046d2b3
Date: 2013-11-03 08:47 +0100
http://bitbucket.org/pypy/pypy/changeset/30af5046d2b3/

Log:Use GcArray(overallocated=True) in rlist.py.

diff --git a/rpython/rlib/rgc.py b/rpython/rlib/rgc.py
--- a/rpython/rlib/rgc.py
+++ b/rpython/rlib/rgc.py
@@ -200,13 +200,15 @@
 
 # supports non-overlapping copies only
 if not we_are_translated():
-if source == dest:
+if lltype.typeOf(source) == lltype.typeOf(dest) and source == dest:
 assert (source_start + length <= dest_start or
 dest_start + length <= source_start)
 
-TP = lltype.typeOf(source).TO
-assert TP == lltype.typeOf(dest).TO
-if _contains_gcptr(TP.OF):
+# supports copying between an overallocated GcArray and a regular GcArray
+TP_SRC = lltype.typeOf(source).TO
+TP_DST = lltype.typeOf(dest).TO
+assert TP_SRC.OF == TP_DST.OF
+if _contains_gcptr(TP_SRC.OF):
 # perform a write barrier that copies necessary flags from
 # source to dest
 if not llop.gc_writebarrier_before_copy(lltype.Bool, source, dest,
@@ -220,13 +222,13 @@
 return
 source_addr = llmemory.cast_ptr_to_adr(source)
 dest_addr   = llmemory.cast_ptr_to_adr(dest)
-cp_source_addr = (source_addr + llmemory.itemoffsetof(TP, 0) +
-  llmemory.sizeof(TP.OF) * source_start)
-cp_dest_addr = (dest_addr + llmemory.itemoffsetof(TP, 0) +
-llmemory.sizeof(TP.OF) * dest_start)
+cp_source_addr = (source_addr + llmemory.itemoffsetof(TP_SRC, 0) +
+  llmemory.sizeof(TP_SRC.OF) * source_start)
+cp_dest_addr = (dest_addr + llmemory.itemoffsetof(TP_DST, 0) +
+llmemory.sizeof(TP_DST.OF) * dest_start)
 
 llmemory.raw_memcopy(cp_source_addr, cp_dest_addr,
- llmemory.sizeof(TP.OF) * length)
+ llmemory.sizeof(TP_SRC.OF) * length)
 keepalive_until_here(source)
 keepalive_until_here(dest)
 
diff --git a/rpython/rtyper/lltypesystem/rlist.py 
b/rpython/rtyper/lltypesystem/rlist.py
--- a/rpython/rtyper/lltypesystem/rlist.py
+++ b/rpython/rtyper/lltypesystem/rlist.py
@@ -54,8 +54,11 @@
 else:
 raise NotImplementedError(variant)
 
-def get_itemarray_lowleveltype(self):
+def get_itemarray_lowleveltype(self, overallocated):
 ITEM = self.item_repr.lowleveltype
+hints = {}
+if overallocated:
+hints['overallocated'] = True
 ITEMARRAY = GcArray(ITEM,
 adtmeths = ADTIFixedList({
  "ll_newlist": ll_fixed_newlist,
@@ -65,7 +68,8 @@
  "ITEM": ITEM,
  "ll_getitem_fast": ll_fixed_getitem_fast,
  "ll_setitem_fast": ll_fixed_setitem_fast,
-}))
+}),
+hints = hints)
 return ITEMARRAY
 
 
@@ -86,10 +90,9 @@
 self.external_item_repr, self.item_repr = 
externalvsinternal(self.rtyper, self._item_repr_computer())
 if isinstance(self.LIST, GcForwardReference):
 ITEM = self.item_repr.lowleveltype
-ITEMARRAY = self.get_itemarray_lowleveltype()
+ITEMARRAY = self.get_itemarray_lowleveltype(True)
 # XXX we might think of turning length stuff into Unsigned
-self.LIST.become(GcStruct("list", ("length", Signed),
-  ("items", Ptr(ITEMARRAY)),
+self.LIST.become(GcStruct("list", ("items", Ptr(ITEMARRAY)),
   adtmeths = ADTIList({
   "ll_newlist": ll_newlist,
   "ll_newlist_hint": ll_newlist_hint,
@@ -112,8 +115,8 @@
 
 def prepare_const(self, n):
 result = malloc(self.LIST, immortal=True)
-result.length = n
 result.items = malloc(self.LIST.items.TO, n)
+result.items.used_length = n
 return result
 
 
@@ -123,7 +126,7 @@
 if 'item_repr' not in self.__dict__:
 self.external_item_repr, self.item_repr = 
externalvsinternal(self.rtyper, self._item_repr_computer())
 if isinstance(self.LIST, GcForwardReference):
-ITEMARRAY = self.get_itemarray_lowleveltype()
+ITEMARRAY = self.get_itemarray_lowleveltype(overallocated=False)
 self.LIST.become(ITEMARRAY)
 
 def compact_repr(self):
@@ -142,12 +145,14 @@
 
 # adapted C code
 
-@jit.look_inside_iff(lambda l, newsize, overallocate: 
jit.isconstant(len(l.items)) and jit.isconstant(newsize))
+@jit.look_inside_iff(lambda l, newsize, overallocate:
+ jit.isconstant(l.items.allocated_length) and
+ jit.isconstant(newsize))
 @signature(types.any(), type

[pypy-commit] pypy array-overallocation-in-nursery: One point of this refactoring is to allow list deletions to work without

2013-11-03 Thread arigo
Author: Armin Rigo 
Branch: array-overallocation-in-nursery
Changeset: r67805:c70e3a202baf
Date: 2013-11-03 09:15 +0100
http://bitbucket.org/pypy/pypy/changeset/c70e3a202baf/

Log:One point of this refactoring is to allow list deletions to work
without replacing the items with NULL.

diff --git a/rpython/rtyper/rlist.py b/rpython/rtyper/rlist.py
--- a/rpython/rtyper/rlist.py
+++ b/rpython/rtyper/rlist.py
@@ -8,7 +8,7 @@
 from rpython.rtyper.annlowlevel import ADTInterface
 from rpython.rtyper.error import TyperError
 from rpython.rtyper.lltypesystem.lltype import typeOf, Ptr, Void, Signed, Bool
-from rpython.rtyper.lltypesystem.lltype import nullptr, Char, UniChar, Number
+from rpython.rtyper.lltypesystem.lltype import Char, UniChar, Number
 from rpython.rtyper.rmodel import Repr, IteratorRepr, IntegerRepr
 from rpython.rtyper.rstr import AbstractStringRepr, AbstractCharRepr
 from rpython.tool.pairtype import pairtype, pair
@@ -495,15 +495,6 @@
 return LIST.ll_newlist(count)
 
 
-# return a nullptr() if lst is a list of pointers it, else None.
-def ll_null_item(lst):
-LIST = typeOf(lst)
-if isinstance(LIST, Ptr):
-ITEM = LIST.TO.ITEM
-if isinstance(ITEM, Ptr):
-return nullptr(ITEM.TO)
-return None
-
 def listItemType(lst):
 LIST = typeOf(lst)
 return LIST.TO.ITEM
@@ -603,9 +594,6 @@
 index = length - 1
 newlength = index
 res = l.ll_getitem_fast(index)
-null = ll_null_item(l)
-if null is not None:
-l.ll_setitem_fast(index, null)
 l._ll_resize_le(newlength)
 return res
 
@@ -622,9 +610,6 @@
 l.ll_setitem_fast(j, l.ll_getitem_fast(j1))
 j = j1
 j1 += 1
-null = ll_null_item(l)
-if null is not None:
-l.ll_setitem_fast(newlength, null)
 l._ll_resize_le(newlength)
 return res
 ll_pop_zero.oopspec = 'list.pop(l, 0)'
@@ -732,10 +717,6 @@
 l.ll_setitem_fast(j, l.ll_getitem_fast(j1))
 j = j1
 j1 += 1
-
-null = ll_null_item(l)
-if null is not None:
-l.ll_setitem_fast(newlength, null)
 l._ll_resize_le(newlength)
 ll_delitem_nonneg.oopspec = 'list.delitem(l, index)'
 
@@ -890,12 +871,6 @@
 ll_assert(start >= 0, "del l[start:] with unexpectedly negative start")
 ll_assert(start <= l.ll_length(), "del l[start:] with start > len(l)")
 newlength = start
-null = ll_null_item(l)
-if null is not None:
-j = l.ll_length() - 1
-while j >= newlength:
-l.ll_setitem_fast(j, null)
-j -= 1
 l._ll_resize_le(newlength)
 
 def ll_listdelslice_startstop(l, start, stop):
@@ -912,12 +887,6 @@
 l.ll_setitem_fast(j, l.ll_getitem_fast(i))
 i += 1
 j += 1
-null = ll_null_item(l)
-if null is not None:
-j = length - 1
-while j >= newlength:
-l.ll_setitem_fast(j, null)
-j -= 1
 l._ll_resize_le(newlength)
 ll_listdelslice_startstop.oopspec = 'list.delslice_startstop(l, start, stop)'
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy array-overallocation-in-nursery: Fix for refcounting. Deleted items are kept alive with refcounting, but too bad.

2013-11-03 Thread arigo
Author: Armin Rigo 
Branch: array-overallocation-in-nursery
Changeset: r67806:e5790b2e3315
Date: 2013-11-03 09:16 +0100
http://bitbucket.org/pypy/pypy/changeset/e5790b2e3315/

Log:Fix for refcounting. Deleted items are kept alive with refcounting,
but too bad.

diff --git a/rpython/memory/gctransform/support.py 
b/rpython/memory/gctransform/support.py
--- a/rpython/memory/gctransform/support.py
+++ b/rpython/memory/gctransform/support.py
@@ -34,8 +34,15 @@
 if isinstance(TYPE, lltype.Array):
 inner = list(_static_deallocator_body_for_type('v_%i'%depth, TYPE.OF, 
depth+1))
 if inner:
+# NB. in case of overallocated array, we still decref all items
+# rather than just the used ones.  This is because the unused
+# items still have a reference.  It's not really nice, but we
+# don't really care about the refcounting GC in the first place...
 yield ''*depth + 'i_%d = 0'%(depth,)
-yield ''*depth + 'l_%d = len(%s)'%(depth, v)
+if TYPE._is_overallocated_array():
+yield ''*depth + 'l_%d = %s.allocated_length'%(depth, v)
+else:
+yield ''*depth + 'l_%d = len(%s)'%(depth, v)
 yield ''*depth + 'while i_%d < l_%d:'%(depth, depth)
 yield ''*depth + 'v_%d = %s[i_%d]'%(depth, v, depth)
 for line in inner:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy array-overallocation-in-nursery: Be more eager in overallocating lists (but not extra eager in

2013-11-03 Thread arigo
Author: Armin Rigo 
Branch: array-overallocation-in-nursery
Changeset: r67807:c5de838f9d3b
Date: 2013-11-03 09:36 +0100
http://bitbucket.org/pypy/pypy/changeset/c5de838f9d3b/

Log:Be more eager in overallocating lists (but not extra eager in this
checkin; need to measure...)

diff --git a/rpython/rtyper/lltypesystem/rlist.py 
b/rpython/rtyper/lltypesystem/rlist.py
--- a/rpython/rtyper/lltypesystem/rlist.py
+++ b/rpython/rtyper/lltypesystem/rlist.py
@@ -156,22 +156,34 @@
 entry.
 """
 # This over-allocates proportional to the list size, making room
-# for additional growth.  The over-allocation is mild, but is
-# enough to give linear-time amortized behavior over a long
-# sequence of appends() in the presence of a poorly-performing
-# system malloc().
-# The growth pattern is:  0, 4, 8, 16, 25, 35, 46, 58, 72, 88, ...
+# for additional growth.  The over-allocation is eager for small
+# lists, and mild for large ones (but enough to give linear-time
+# amortized behavior over a long sequence of appends()).
+#
+# The idea is that small lists exist in the nursery; if they
+# survive, they will be copied out of it by the GC, which will
+# reduce their allocated_length down to their used_length.
+#
+# The growth pattern is:
+#  0, 8, 16, 32,  (doubling region, adding 'newsize')
+#  48, 72, 108,   (adding 'newsize >> 1')
+#  135, 168, 210, (adding 'newsize >> 2')
+#  236, ...   (adding 'newsize >> 3' from now on)
 if newsize <= 0:
 ll_assert(newsize == 0, "negative list length")
 l.items = _ll_new_empty_item_array(typeOf(l).TO)
 return
 elif overallocate:
-if newsize < 9:
-some = 3
+if newsize <= 4:
+new_allocated = 8
+elif newsize < 32:
+new_allocated = newsize + newsize
+elif newsize < 128:
+new_allocated = newsize + (newsize >> 1)
+elif newsize < 224:
+new_allocated = newsize + (newsize >> 2)
 else:
-some = 6
-some += newsize >> 3
-new_allocated = newsize + some
+new_allocated = newsize + (newsize >> 3)
 else:
 new_allocated = newsize
 # new_allocated is a bit more than newsize, enough to ensure an amortized
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy array-overallocation-in-nursery: Test and fix

2013-11-03 Thread arigo
Author: Armin Rigo 
Branch: array-overallocation-in-nursery
Changeset: r67808:2be7515d790c
Date: 2013-11-03 10:48 +0100
http://bitbucket.org/pypy/pypy/changeset/2be7515d790c/

Log:Test and fix

diff --git a/rpython/translator/simplify.py b/rpython/translator/simplify.py
--- a/rpython/translator/simplify.py
+++ b/rpython/translator/simplify.py
@@ -847,7 +847,7 @@
 self.fixed_list[p] = item
 else:
 self.fallback_list.append(item)
-append._always_inline_ = True
+append._always_inline_ = "force"
 
 def fence_exact(self):
 if self.optimize:
diff --git a/rpython/translator/test/test_simplify.py 
b/rpython/translator/test/test_simplify.py
--- a/rpython/translator/test/test_simplify.py
+++ b/rpython/translator/test/test_simplify.py
@@ -337,6 +337,18 @@
 res = interp.eval_graph(graph, [10])
 assert res == 5
 
+def test_simple_except(self):
+def main(n):
+try:
+lst = [chr(x) for x in range(n)]
+except:
+return -1
+lst[0] = "foobar"
+return ord(lst[5][0])
+interp, graph = self.specialize(main, [int])
+res = interp.eval_graph(graph, [10])
+assert res == 5
+
 def test_mutated_after_listcomp(self):
 def main(n):
 lst = [x*17 for x in range(n)]
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy array-overallocation-in-nursery: Comment

2013-11-03 Thread arigo
Author: Armin Rigo 
Branch: array-overallocation-in-nursery
Changeset: r67809:8ec658318fe2
Date: 2013-11-03 10:53 +0100
http://bitbucket.org/pypy/pypy/changeset/8ec658318fe2/

Log:Comment

diff --git a/rpython/translator/test/test_simplify.py 
b/rpython/translator/test/test_simplify.py
--- a/rpython/translator/test/test_simplify.py
+++ b/rpython/translator/test/test_simplify.py
@@ -340,6 +340,8 @@
 def test_simple_except(self):
 def main(n):
 try:
+# char -> string conversion inside the append() method,
+# forced because we later put a string inside lst
 lst = [chr(x) for x in range(n)]
 except:
 return -1
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy array-overallocation-in-nursery: Kill llmemory.gcarrayofptr_xxx. Found out that we can write the

2013-11-03 Thread arigo
Author: Armin Rigo 
Branch: array-overallocation-in-nursery
Changeset: r67810:e47b0be7335b
Date: 2013-11-03 12:30 +0100
http://bitbucket.org/pypy/pypy/changeset/e47b0be7335b/

Log:Kill llmemory.gcarrayofptr_xxx. Found out that we can write the
special case in gc/base.py without using them, but using only the
size of a GCREF as a special constant.

diff --git a/rpython/memory/gc/base.py b/rpython/memory/gc/base.py
--- a/rpython/memory/gc/base.py
+++ b/rpython/memory/gc/base.py
@@ -217,12 +217,13 @@
 # which we have a special case for performance, or we call
 # the slow path version.
 if self.is_gcarrayofgcptr(typeid):
-length = (obj + llmemory.gcarrayofptr_lengthoffset).signed[0]
-item = obj + llmemory.gcarrayofptr_itemsoffset
+item = obj + self.varsize_offset_to_variable_part(typeid)
+length_adr = (obj + self.varsize_offset_to_used_length(typeid))
+length = length_adr.signed[0]
 while length > 0:
 if self.points_to_valid_gc_object(item):
 callback(item, arg)
-item += llmemory.gcarrayofptr_singleitemoffset
+item += llmemory.size_of_gcref
 length -= 1
 return
 self._trace_slow_path(obj, callback, arg)
@@ -273,12 +274,12 @@
 typeid = self.get_type_id(obj)
 if self.is_gcarrayofgcptr(typeid):
 # a performance shortcut for GcArray(gcptr)
-item = obj + llmemory.gcarrayofptr_itemsoffset
-item += llmemory.gcarrayofptr_singleitemoffset * start
+item = obj + self.varsize_offset_to_variable_part(typeid)
+item += llmemory.size_of_gcref * start
 while length > 0:
 if self.points_to_valid_gc_object(item):
 callback(item, arg)
-item += llmemory.gcarrayofptr_singleitemoffset
+item += llmemory.size_of_gcref
 length -= 1
 return
 ll_assert(self.has_gcptr_in_varsize(typeid),
diff --git a/rpython/memory/gctypelayout.py b/rpython/memory/gctypelayout.py
--- a/rpython/memory/gctypelayout.py
+++ b/rpython/memory/gctypelayout.py
@@ -246,10 +246,10 @@
 else:
 assert isinstance(TYPE, lltype.GcArray)
 ARRAY = TYPE
+if (isinstance(ARRAY.OF, lltype.Ptr)
+and ARRAY.OF.TO._gckind == 'gc'):
+infobits |= T_IS_GCARRAY_OF_GCPTR
 if not ARRAY._is_overallocated_array():
-if (isinstance(ARRAY.OF, lltype.Ptr)
-and ARRAY.OF.TO._gckind == 'gc'):
-infobits |= T_IS_GCARRAY_OF_GCPTR
 varinfo.ofstolength = llmemory.ArrayLengthOffset(ARRAY)
 varinfo.ofstousedlength = varinfo.ofstolength
 else:
diff --git a/rpython/rtyper/lltypesystem/llmemory.py 
b/rpython/rtyper/lltypesystem/llmemory.py
--- a/rpython/rtyper/lltypesystem/llmemory.py
+++ b/rpython/rtyper/lltypesystem/llmemory.py
@@ -594,19 +594,11 @@
 # GCREF is similar to Address but it is GC-aware
 GCREF = lltype.Ptr(lltype.GcOpaqueType('GCREF'))
 
-# A placeholder for any type that is a GcArray of pointers.
-# This can be used in the symbolic offsets above to access such arrays
-# in a generic way.
-GCARRAY_OF_PTR = lltype.GcArray(GCREF, hints={'placeholder': True})
-gcarrayofptr_lengthoffset = ArrayLengthOffset(GCARRAY_OF_PTR)
-gcarrayofptr_itemsoffset = ArrayItemsOffset(GCARRAY_OF_PTR)
-gcarrayofptr_singleitemoffset = ItemOffset(GCARRAY_OF_PTR.OF)
+size_of_gcref = ItemOffset(GCREF)
+
 def array_type_match(A1, A2):
-return A1 == A2 or (A2 == GCARRAY_OF_PTR and
-isinstance(A1, lltype.GcArray) and
-isinstance(A1.OF, lltype.Ptr) and
-not A1._hints.get('nolength') and
-not A1._hints.get('overallocated'))
+return A1 == A2
+
 def array_item_type_match(T1, T2):
 return T1 == T2 or (T2 == GCREF and isinstance(T1, lltype.Ptr))
 
diff --git a/rpython/rtyper/lltypesystem/test/test_llmemory.py 
b/rpython/rtyper/lltypesystem/test/test_llmemory.py
--- a/rpython/rtyper/lltypesystem/test/test_llmemory.py
+++ b/rpython/rtyper/lltypesystem/test/test_llmemory.py
@@ -579,25 +579,6 @@
 assert weakref_deref(lltype.Ptr(S), w) == lltype.nullptr(S)
 assert weakref_deref(lltype.Ptr(S1), w) == lltype.nullptr(S1)
 
-def test_generic_gcarray_of_ptr():
-S1 = lltype.GcStruct('S1', ('x', lltype.Signed))
-A1 = lltype.GcArray(lltype.Ptr(S1))
-A2 = lltype.GcArray(lltype.Ptr(A1))
-a2 = lltype.malloc(A2, 3)
-a2[1] = lltype.malloc(A1, 4)
-a2[1][2] = lltype.malloc(S1)
-a2[1][2].x = -33
-
-adr = cast_ptr_to_adr(a2)
-assert (adr + gcarrayofptr_lengthoffset).signed[0] == 3
-adr += gcarrayofptr_itemsoffset
-adr += gcarrayofptr_singleitemoffset
- 

[pypy-commit] pypy array-overallocation-in-nursery: Test and fix

2013-11-03 Thread arigo
Author: Armin Rigo 
Branch: array-overallocation-in-nursery
Changeset: r67811:e83aae23c574
Date: 2013-11-03 12:57 +0100
http://bitbucket.org/pypy/pypy/changeset/e83aae23c574/

Log:Test and fix

diff --git a/rpython/memory/gc/incminimark.py b/rpython/memory/gc/incminimark.py
--- a/rpython/memory/gc/incminimark.py
+++ b/rpython/memory/gc/incminimark.py
@@ -1495,8 +1495,8 @@
 # Get the number of card marker bytes in the header.
 typeid = self.get_type_id(obj)
 offset_to_length = self.varsize_offset_to_length(typeid)
-length = (obj + offset_to_length).signed[0]
-bytes = self.card_marking_bytes_for_length(length)
+allocated_length = (obj + offset_to_length).signed[0]
+bytes = self.card_marking_bytes_for_length(allocated_length)
 p = llarena.getfakearenaaddress(obj - size_gc_header)
 #
 # If the object doesn't have GCFLAG_TRACK_YOUNG_PTRS, then it
@@ -1514,6 +1514,9 @@
 else:
 # Walk the bytes encoding the card marker bits, and for
 # each bit set, call trace_and_drag_out_of_nursery_partial().
+offset_to_used_length = self.varsize_offset_to_used_length(
+typeid)
+used_length = (obj + offset_to_used_length).signed[0]
 interval_start = 0
 while bytes > 0:
 p -= 1
@@ -1526,10 +1529,10 @@
 interval_stop = interval_start + self.card_page_indices
 #
 if cardbyte & 1:
-if interval_stop > length:
-interval_stop = length
-ll_assert(cardbyte <= 1 and bytes == 0,
-  "premature end of object")
+if interval_stop > used_length:
+interval_stop = used_length
+if interval_stop <= interval_start:
+break
 self.trace_and_drag_out_of_nursery_partial(
 obj, interval_start, interval_stop)
 #
diff --git a/rpython/memory/test/snippet.py b/rpython/memory/test/snippet.py
--- a/rpython/memory/test/snippet.py
+++ b/rpython/memory/test/snippet.py
@@ -161,6 +161,46 @@
 res = self.run('from_objwithfinalizer_to_youngobj')
 assert res == 1
 
+def define_overallocated_items_not_kept_alive(cls):
+from rpython.rtyper.annlowlevel import cast_instance_to_gcref
+from rpython.rtyper.lltypesystem import llmemory
+class B:
+count = 0
+class A:
+def __del__(self):
+self.b.count += 1
+ARRAY1 = lltype.GcArray(llmemory.GCREF, hints={'overallocated': True})
+#ARRAY2 = lltype.GcArray(('a', llmemory.GCREF), ('n', lltype.Signed),
+#hints={'overallocated': True})
+
+def make(b):
+a1 = lltype.malloc(ARRAY1, 10)
+#a2 = lltype.malloc(ARRAY2, 10)
+a1.used_length = 10
+#a2.used_length = 10
+i = 0
+while i < 10:
+a = A()
+a.b = b
+a1[i] = cast_instance_to_gcref(a)
+#a2[i].a = cast_instance_to_gcref(a)
+i += 1
+return a1
+
+def f():
+b = B()
+a1 = make(b)
+a1.used_length = 0
+#a2.used_length = 0
+llop.gc__collect(lltype.Void)
+return b.count
+return f
+
+def test_overallocated_items_not_kept_alive(self):
+res = self.run('overallocated_items_not_kept_alive')
+assert res == 10
+
+
 class SemiSpaceGCTests(SemiSpaceGCTestDefines):
 # xxx messy
 
@@ -172,5 +212,8 @@
 elif name == 'from_objwithfinalizer_to_youngobj':
 func = self.define_from_objwithfinalizer_to_youngobj()
 return self.interpret(func, [])
+elif name == 'overallocated_items_not_kept_alive':
+func = self.define_overallocated_items_not_kept_alive()
+return self.interpret(func, [])
 else:
 assert 0, "don't know what to do with that"
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy array-overallocation-in-nursery: Apply the diff of incminimark.py to minimark.py.

2013-11-03 Thread arigo
Author: Armin Rigo 
Branch: array-overallocation-in-nursery
Changeset: r67812:d0b26d48adbf
Date: 2013-11-03 13:24 +0100
http://bitbucket.org/pypy/pypy/changeset/d0b26d48adbf/

Log:Apply the diff of incminimark.py to minimark.py.

diff --git a/rpython/memory/gc/minimark.py b/rpython/memory/gc/minimark.py
--- a/rpython/memory/gc/minimark.py
+++ b/rpython/memory/gc/minimark.py
@@ -1355,8 +1355,8 @@
 # Get the number of card marker bytes in the header.
 typeid = self.get_type_id(obj)
 offset_to_length = self.varsize_offset_to_length(typeid)
-length = (obj + offset_to_length).signed[0]
-bytes = self.card_marking_bytes_for_length(length)
+allocated_length = (obj + offset_to_length).signed[0]
+bytes = self.card_marking_bytes_for_length(allocated_length)
 p = llarena.getfakearenaaddress(obj - size_gc_header)
 #
 # If the object doesn't have GCFLAG_TRACK_YOUNG_PTRS, then it
@@ -1374,6 +1374,9 @@
 else:
 # Walk the bytes encoding the card marker bits, and for
 # each bit set, call trace_and_drag_out_of_nursery_partial().
+offset_to_used_length = self.varsize_offset_to_used_length(
+typeid)
+used_length = (obj + offset_to_used_length).signed[0]
 interval_start = 0
 while bytes > 0:
 p -= 1
@@ -1386,10 +1389,10 @@
 interval_stop = interval_start + self.card_page_indices
 #
 if cardbyte & 1:
-if interval_stop > length:
-interval_stop = length
-ll_assert(cardbyte <= 1 and bytes == 0,
-  "premature end of object")
+if interval_stop > used_length:
+interval_stop = used_length
+if interval_stop <= interval_start:
+break
 self.trace_and_drag_out_of_nursery_partial(
 obj, interval_start, interval_stop)
 #
@@ -1463,7 +1466,7 @@
 # tid == -42, containing all flags), and it doesn't have the
 # HAS_SHADOW flag either.  We must move it out of the nursery,
 # into a new nonmovable location.
-totalsize = size_gc_header + self.get_size(obj)
+totalsize = size_gc_header + self.shrink_and_get_size(obj)
 newhdr = self._malloc_out_of_nursery(totalsize)
 #
 elif self.is_forwarded(obj):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Document this branch

2013-11-03 Thread alex_gaynor
Author: Alex Gaynor 
Branch: 
Changeset: r67813:27c463966e39
Date: 2013-11-03 10:25 -0800
http://bitbucket.org/pypy/pypy/changeset/27c463966e39/

Log:Document this branch

diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -130,3 +130,7 @@
 only every 32 minor collection is enough). Should avoid the "memory
 leaks" observed in long-running processes, actually created by the
 jit compiling more and more rarely executed paths.
+
+.. branch: fix-trace-jit
+Fixed the usage of sys.settrace() with the JIT. Also made it so using
+sys.settrace() doesn't cause the GIL to be released on every single iteration.
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Add a debug_flush() just before calling _exit(). Otherwise the

2013-11-03 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r67814:fb3b41cc383a
Date: 2013-11-03 19:50 +0100
http://bitbucket.org/pypy/pypy/changeset/fb3b41cc383a/

Log:Add a debug_flush() just before calling _exit(). Otherwise the log
file is left incomplete.

diff --git a/rpython/rtyper/module/ll_os.py b/rpython/rtyper/module/ll_os.py
--- a/rpython/rtyper/module/ll_os.py
+++ b/rpython/rtyper/module/ll_os.py
@@ -1641,9 +1641,11 @@
 
 @registering(os._exit)
 def register_os__exit(self):
+from rpython.rlib import debug
 os__exit = self.llexternal('_exit', [rffi.INT], lltype.Void)
 
 def _exit_llimpl(status):
+debug.debug_flush()
 os__exit(rffi.cast(rffi.INT, status))
 
 return extdef([int], s_None, llimpl=_exit_llimpl,
diff --git a/rpython/translator/c/test/test_standalone.py 
b/rpython/translator/c/test/test_standalone.py
--- a/rpython/translator/c/test/test_standalone.py
+++ b/rpython/translator/c/test/test_standalone.py
@@ -499,6 +499,21 @@
 assert 'foo}' in lines[2]
 assert len(lines) == 3
 
+def test_debug_flush_at_exit(self):
+def entry_point(argv):
+debug_start("mycat")
+os._exit(0)
+return 0
+
+t, cbuilder = self.compile(entry_point)
+path = udir.join('test_debug_flush_at_exit.log')
+cbuilder.cmdexec("", env={'PYPYLOG': ':%s' % path})
+#
+f = open(str(path), 'r')
+lines = f.readlines()
+f.close()
+assert lines[0].endswith('{mycat\n')
+
 def test_fatal_error(self):
 def g(x):
 if x == 1:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Add __pypy__.debug_flush() to request a debug_flush from app-level

2013-11-03 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r67815:69bc27908b13
Date: 2013-11-03 20:01 +0100
http://bitbucket.org/pypy/pypy/changeset/69bc27908b13/

Log:Add __pypy__.debug_flush() to request a debug_flush from app-level
explicitly.

diff --git a/pypy/module/__pypy__/__init__.py b/pypy/module/__pypy__/__init__.py
--- a/pypy/module/__pypy__/__init__.py
+++ b/pypy/module/__pypy__/__init__.py
@@ -69,6 +69,7 @@
 'debug_print'   : 'interp_debug.debug_print',
 'debug_stop': 'interp_debug.debug_stop',
 'debug_print_once'  : 'interp_debug.debug_print_once',
+'debug_flush'   : 'interp_debug.debug_flush',
 'builtinify': 'interp_magic.builtinify',
 'lookup_special': 'interp_magic.lookup_special',
 'do_what_I_mean': 'interp_magic.do_what_I_mean',
diff --git a/pypy/module/__pypy__/interp_debug.py 
b/pypy/module/__pypy__/interp_debug.py
--- a/pypy/module/__pypy__/interp_debug.py
+++ b/pypy/module/__pypy__/interp_debug.py
@@ -23,3 +23,8 @@
 debug_start(space, category)
 debug_print(space, args_w)
 debug_stop(space, category)
+
+
+@jit.dont_look_inside
+def debug_flush(space):
+debug.debug_flush()
diff --git a/pypy/module/__pypy__/test/test_debug.py 
b/pypy/module/__pypy__/test/test_debug.py
--- a/pypy/module/__pypy__/test/test_debug.py
+++ b/pypy/module/__pypy__/test/test_debug.py
@@ -43,3 +43,8 @@
 ('debug_print', 'hello world'),
 ])
 ])
+
+def test_debug_flush(self):
+from __pypy__ import debug_flush
+debug_flush()
+# assert did not crash
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: document this branch

2013-11-03 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r67816:d7f24445f817
Date: 2013-11-03 21:14 +0200
http://bitbucket.org/pypy/pypy/changeset/d7f24445f817/

Log:document this branch

diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -134,3 +134,6 @@
 .. branch: fix-trace-jit
 Fixed the usage of sys.settrace() with the JIT. Also made it so using
 sys.settrace() doesn't cause the GIL to be released on every single iteration.
+
+.. branch: rordereddict
+Implement OrderedDict in RPython
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] extradoc extradoc: This was done forever ago

2013-11-03 Thread alex_gaynor
Author: Alex Gaynor 
Branch: extradoc
Changeset: r5106:c2bd0a32f917
Date: 2013-11-03 12:29 -0800
http://bitbucket.org/pypy/extradoc/changeset/c2bd0a32f917/

Log:This was done forever ago

diff --git a/planning/jit.txt b/planning/jit.txt
--- a/planning/jit.txt
+++ b/planning/jit.txt
@@ -75,9 +75,6 @@
   still remains, even though it's obviously not necessary since x and None
   will have different known_classes.
 
-- optimize arraycopy also in the cases where one of the arrays is a virtual and
-  short. This is seen a lot in translate.py
-
 - calling string equality does not automatically promote the argument to
   a constant.
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: adjust this test now that numpypy is external

2013-11-03 Thread bdkearns
Author: Brian Kearns 
Branch: 
Changeset: r67817:cbfe08907bc1
Date: 2013-11-03 19:05 -0500
http://bitbucket.org/pypy/pypy/changeset/cbfe08907bc1/

Log:adjust this test now that numpypy is external

diff --git a/pypy/module/cpyext/test/test_typeobject.py 
b/pypy/module/cpyext/test/test_typeobject.py
--- a/pypy/module/cpyext/test/test_typeobject.py
+++ b/pypy/module/cpyext/test/test_typeobject.py
@@ -360,8 +360,8 @@
 
 def test_ndarray_ref(self, space, api):
 w_obj = space.appexec([], """():
-import numpypy as np
-return np.int64(2)""")
+import _numpypy
+return _numpypy.multiarray.dtype('int64').type(2)""")
 ref = make_ref(space, w_obj)
 api.Py_DecRef(ref)
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: add shape/ndim attributes to scalars

2013-11-03 Thread bdkearns
Author: Brian Kearns 
Branch: 
Changeset: r67818:923d5e1fe253
Date: 2013-11-03 20:10 -0500
http://bitbucket.org/pypy/pypy/changeset/923d5e1fe253/

Log:add shape/ndim attributes to scalars

diff --git a/pypy/module/micronumpy/interp_boxes.py 
b/pypy/module/micronumpy/interp_boxes.py
--- a/pypy/module/micronumpy/interp_boxes.py
+++ b/pypy/module/micronumpy/interp_boxes.py
@@ -265,6 +265,12 @@
 def descr_get_itemsize(self, space):
 return self.get_dtype(space).descr_get_itemsize(space)
 
+def descr_get_shape(self, space):
+return space.newtuple([])
+
+def descr_get_ndim(self, space):
+return space.wrap(0)
+
 class W_BoolBox(W_GenericBox, PrimitiveBox):
 descr__new__, _get_dtype, descr_reduce = new_dtype_getter("bool")
 
@@ -514,6 +520,8 @@
 
 dtype = GetSetProperty(W_GenericBox.descr_get_dtype),
 itemsize = GetSetProperty(W_GenericBox.descr_get_itemsize),
+shape = GetSetProperty(W_GenericBox.descr_get_shape),
+ndim = GetSetProperty(W_GenericBox.descr_get_ndim),
 )
 
 W_BoolBox.typedef = TypeDef("bool_", W_GenericBox.typedef,
diff --git a/pypy/module/micronumpy/test/test_scalar.py 
b/pypy/module/micronumpy/test/test_scalar.py
--- a/pypy/module/micronumpy/test/test_scalar.py
+++ b/pypy/module/micronumpy/test/test_scalar.py
@@ -61,3 +61,5 @@
 value = np.dtype('int64').type(12345)
 assert value.dtype == np.dtype('int64')
 assert value.itemsize == 8
+assert value.shape == ()
+assert value.ndim == 0
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: clean up order argument for reshape

2013-11-03 Thread bdkearns
Author: Brian Kearns 
Branch: 
Changeset: r67820:c649a2a354b0
Date: 2013-11-03 20:46 -0500
http://bitbucket.org/pypy/pypy/changeset/c649a2a354b0/

Log:clean up order argument for reshape

diff --git a/pypy/module/micronumpy/interp_numarray.py 
b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -345,17 +345,20 @@
 numpypy.reshape : equivalent function
 """
 args_w, kw_w = __args__.unpack()
-order = 'C'
+order = NPY_CORDER
 if kw_w:
 if "order" in kw_w:
-order = space.str_w(kw_w["order"])
+order = order_converter(space, kw_w["order"], order)
 del kw_w["order"]
 if kw_w:
 raise OperationError(space.w_TypeError, space.wrap(
 "reshape() got unexpected keyword argument(s)"))
-if order != 'C':
+if order == NPY_KEEPORDER:
+raise OperationError(space.w_ValueError, space.wrap(
+"order 'K' is not permitted for reshaping"))
+if order != NPY_CORDER and order != NPY_ANYORDER:
 raise OperationError(space.w_NotImplementedError, space.wrap(
-"order not implemented"))
+"unsupported value for order"))
 if len(args_w) == 1:
 w_shape = args_w[0]
 else:
diff --git a/pypy/module/micronumpy/test/test_numarray.py 
b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -715,7 +715,9 @@
 a = array()
 assert a.reshape((0,)).shape == (0,)
 assert a.reshape((0,), order='C').shape == (0,)
+assert a.reshape((0,), order='A').shape == (0,)
 raises(TypeError, a.reshape, (0,), badarg="C")
+raises(ValueError, a.reshape, (0,), order="K")
 import sys
 if '__pypy__' in sys.builtin_module_names:
 raises(NotImplementedError, a.reshape, (0,), order='F')
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: accept order argument for copy

2013-11-03 Thread bdkearns
Author: Brian Kearns 
Branch: 
Changeset: r67819:61d2ad085488
Date: 2013-11-03 20:38 -0500
http://bitbucket.org/pypy/pypy/changeset/61d2ad085488/

Log:accept order argument for copy

diff --git a/pypy/module/micronumpy/constants.py 
b/pypy/module/micronumpy/constants.py
--- a/pypy/module/micronumpy/constants.py
+++ b/pypy/module/micronumpy/constants.py
@@ -63,6 +63,11 @@
 NPY_FLOATINGLTR = 'f'
 NPY_COMPLEXLTR = 'c'
 
+NPY_ANYORDER = -1
+NPY_CORDER = 0
+NPY_FORTRANORDER = 1
+NPY_KEEPORDER = 2
+
 NPY_CLIP = 0
 NPY_WRAP = 1
 NPY_RAISE = 2
diff --git a/pypy/module/micronumpy/conversion_utils.py 
b/pypy/module/micronumpy/conversion_utils.py
--- a/pypy/module/micronumpy/conversion_utils.py
+++ b/pypy/module/micronumpy/conversion_utils.py
@@ -18,3 +18,25 @@
 return mode
 raise OperationError(space.w_TypeError,
  space.wrap("clipmode not understood"))
+
+def order_converter(space, w_order, default):
+if space.is_none(w_order):
+return default
+if not space.isinstance_w(w_order, space.w_str):
+if space.is_true(w_order):
+return NPY_FORTRANORDER
+else:
+return NPY_CORDER
+else:
+order = space.str_w(w_order)
+if order.startswith('C') or order.startswith('c'):
+return NPY_CORDER
+elif order.startswith('F') or order.startswith('f'):
+return NPY_FORTRANORDER
+elif order.startswith('A') or order.startswith('a'):
+return NPY_ANYORDER
+elif order.startswith('K') or order.startswith('k'):
+return NPY_KEEPORDER
+else:
+raise OperationError(space.w_TypeError, space.wrap(
+"order not understood"))
diff --git a/pypy/module/micronumpy/interp_numarray.py 
b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -18,6 +18,8 @@
 from rpython.rlib import jit
 from rpython.rlib.rstring import StringBuilder
 from pypy.module.micronumpy.arrayimpl.base import BaseArrayImplementation
+from pypy.module.micronumpy.conversion_utils import order_converter
+from pypy.module.micronumpy.constants import *
 
 def _find_shape(space, w_size, dtype):
 if space.is_none(w_size):
@@ -287,7 +289,11 @@
 def get_scalar_value(self):
 return self.implementation.get_scalar_value()
 
-def descr_copy(self, space):
+def descr_copy(self, space, w_order=None):
+order = order_converter(space, w_order, NPY_KEEPORDER)
+if order == NPY_FORTRANORDER:
+raise OperationError(space.w_NotImplementedError, space.wrap(
+"unsupported value for order"))
 copy = self.implementation.copy(space)
 w_subtype = space.type(self)
 return wrap_impl(space, w_subtype, self, copy)
diff --git a/pypy/module/micronumpy/test/test_numarray.py 
b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -411,6 +411,22 @@
 b = a.copy()
 assert b[0] == a[0]
 
+a = arange(8)
+b = a.copy(order=None)
+assert (b == a).all()
+b = a.copy(order=0)
+assert (b == a).all()
+b = a.copy(order='C')
+assert (b == a).all()
+b = a.copy(order='K')
+assert (b == a).all()
+b = a.copy(order='A')
+assert (b == a).all()
+import sys
+if '__pypy__' in sys.builtin_module_names:
+raises(NotImplementedError, a.copy, order='F')
+raises(NotImplementedError, a.copy, order=True)
+
 def test_iterator_init(self):
 from numpypy import array
 a = array(range(5))
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: this should be looking in numpy now

2013-11-03 Thread bdkearns
Author: Brian Kearns 
Branch: 
Changeset: r67823:8625b69babe3
Date: 2013-11-04 01:52 -0500
http://bitbucket.org/pypy/pypy/changeset/8625b69babe3/

Log:this should be looking in numpy now

diff --git a/pypy/module/micronumpy/tool/numready/main.py 
b/pypy/module/micronumpy/tool/numready/main.py
--- a/pypy/module/micronumpy/tool/numready/main.py
+++ b/pypy/module/micronumpy/tool/numready/main.py
@@ -97,7 +97,7 @@
 
 def main(argv):
 cpy_items = find_numpy_items("/usr/bin/python")
-pypy_items = find_numpy_items(argv[1], "numpypy")
+pypy_items = find_numpy_items(argv[1])
 ver = get_version_str(argv[1])
 all_items = []
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: fix complex cast on complex scalar

2013-11-03 Thread bdkearns
Author: Brian Kearns 
Branch: 
Changeset: r67821:07b43a29d735
Date: 2013-11-04 01:07 -0500
http://bitbucket.org/pypy/pypy/changeset/07b43a29d735/

Log:fix complex cast on complex scalar

diff --git a/pypy/module/micronumpy/interp_boxes.py 
b/pypy/module/micronumpy/interp_boxes.py
--- a/pypy/module/micronumpy/interp_boxes.py
+++ b/pypy/module/micronumpy/interp_boxes.py
@@ -339,6 +339,10 @@
 descr__new__, _get_dtype, descr_reduce = new_dtype_getter("float64")
 
 class W_ComplexFloatingBox(W_InexactBox):
+def descr_complex(self, space):
+assert isinstance(self, ComplexBox)
+return space.wrap(complex(self.real, self.imag))
+
 def descr_get_real(self, space):
 dtype = self._COMPONENTS_BOX._get_dtype(space)
 box = self.convert_real_to(dtype)
@@ -644,6 +648,7 @@
 __module__ = "numpypy",
 __new__ = interp2app(W_Complex64Box.descr__new__.im_func),
 __reduce__ = interp2app(W_Complex64Box.descr_reduce),
+__complex__ = interp2app(W_ComplexFloatingBox.descr_complex),
 real = GetSetProperty(W_ComplexFloatingBox.descr_get_real),
 imag = GetSetProperty(W_ComplexFloatingBox.descr_get_imag),
 )
@@ -652,6 +657,7 @@
 __module__ = "numpypy",
 __new__ = interp2app(W_Complex128Box.descr__new__.im_func),
 __reduce__ = interp2app(W_Complex128Box.descr_reduce),
+__complex__ = interp2app(W_ComplexFloatingBox.descr_complex),
 real = GetSetProperty(W_ComplexFloatingBox.descr_get_real),
 imag = GetSetProperty(W_ComplexFloatingBox.descr_get_imag),
 )
@@ -667,6 +673,7 @@
 __module__ = "numpypy",
 __new__ = interp2app(W_ComplexLongBox.descr__new__.im_func),
 __reduce__ = interp2app(W_ComplexLongBox.descr_reduce),
+__complex__ = interp2app(W_ComplexFloatingBox.descr_complex),
 real = GetSetProperty(W_ComplexFloatingBox.descr_get_real),
 imag = GetSetProperty(W_ComplexFloatingBox.descr_get_imag),
 )
diff --git a/pypy/module/micronumpy/test/dummy_module.py 
b/pypy/module/micronumpy/test/dummy_module.py
--- a/pypy/module/micronumpy/test/dummy_module.py
+++ b/pypy/module/micronumpy/test/dummy_module.py
@@ -5,7 +5,9 @@
 ufunc = type(sin)
 
 types = ['bool8', 'byte', 'ubyte', 'short', 'ushort', 'longlong', 'ulonglong',
- 'single', 'longfloat', 'longdouble', 'csingle', 'cfloat', 'void']
+ 'single', 'double', 'longfloat', 'longdouble',
+ 'csingle', 'cdouble', 'cfloat', 'clongdouble',
+ 'void']
 for t in ('int', 'uint'):
 for s in (8, 16, 32, 64, 'p'):
 types.append(t + str(s))
diff --git a/pypy/module/micronumpy/test/test_scalar.py 
b/pypy/module/micronumpy/test/test_scalar.py
--- a/pypy/module/micronumpy/test/test_scalar.py
+++ b/pypy/module/micronumpy/test/test_scalar.py
@@ -63,3 +63,9 @@
 assert value.itemsize == 8
 assert value.shape == ()
 assert value.ndim == 0
+
+def test_complex_scalar_complex_cast(self):
+import numpy as np
+for tp in [np.csingle, np.cdouble, np.clongdouble]:
+x = tp(1+2j)
+assert complex(x) == 1+2j
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: update __module__ for boxes

2013-11-03 Thread bdkearns
Author: Brian Kearns 
Branch: 
Changeset: r67822:02757994cd72
Date: 2013-11-04 01:52 -0500
http://bitbucket.org/pypy/pypy/changeset/02757994cd72/

Log:update __module__ for boxes

diff --git a/pypy/module/micronumpy/interp_boxes.py 
b/pypy/module/micronumpy/interp_boxes.py
--- a/pypy/module/micronumpy/interp_boxes.py
+++ b/pypy/module/micronumpy/interp_boxes.py
@@ -458,7 +458,7 @@
 return W_UnicodeBox(arr, 0, arr.dtype)
 
 W_GenericBox.typedef = TypeDef("generic",
-__module__ = "numpypy",
+__module__ = "numpy",
 
 __new__ = interp2app(W_GenericBox.descr__new__.im_func),
 
@@ -529,72 +529,72 @@
 )
 
 W_BoolBox.typedef = TypeDef("bool_", W_GenericBox.typedef,
-__module__ = "numpypy",
+__module__ = "numpy",
 __new__ = interp2app(W_BoolBox.descr__new__.im_func),
 __index__ = interp2app(W_BoolBox.descr_index),
 __reduce__ = interp2app(W_BoolBox.descr_reduce),
 )
 
 W_NumberBox.typedef = TypeDef("number", W_GenericBox.typedef,
-__module__ = "numpypy",
+__module__ = "numpy",
 )
 
 W_IntegerBox.typedef = TypeDef("integer", W_NumberBox.typedef,
-__module__ = "numpypy",
+__module__ = "numpy",
 )
 
 W_SignedIntegerBox.typedef = TypeDef("signedinteger", W_IntegerBox.typedef,
-__module__ = "numpypy",
+__module__ = "numpy",
 )
 
 W_UnsignedIntegerBox.typedef = TypeDef("unsignedinteger", W_IntegerBox.typedef,
-__module__ = "numpypy",
+__module__ = "numpy",
 )
 
 W_Int8Box.typedef = TypeDef("int8", W_SignedIntegerBox.typedef,
-__module__ = "numpypy",
+__module__ = "numpy",
 __new__ = interp2app(W_Int8Box.descr__new__.im_func),
 __index__ = interp2app(W_Int8Box.descr_index),
 __reduce__ = interp2app(W_Int8Box.descr_reduce),
 )
 
 W_UInt8Box.typedef = TypeDef("uint8", W_UnsignedIntegerBox.typedef,
-__module__ = "numpypy",
+__module__ = "numpy",
 __new__ = interp2app(W_UInt8Box.descr__new__.im_func),
 __index__ = interp2app(W_UInt8Box.descr_index),
 __reduce__ = interp2app(W_UInt8Box.descr_reduce),
 )
 
 W_Int16Box.typedef = TypeDef("int16", W_SignedIntegerBox.typedef,
-__module__ = "numpypy",
+__module__ = "numpy",
 __new__ = interp2app(W_Int16Box.descr__new__.im_func),
 __index__ = interp2app(W_Int16Box.descr_index),
 __reduce__ = interp2app(W_Int16Box.descr_reduce),
 )
 
 W_UInt16Box.typedef = TypeDef("uint16", W_UnsignedIntegerBox.typedef,
-__module__ = "numpypy",
+__module__ = "numpy",
 __new__ = interp2app(W_UInt16Box.descr__new__.im_func),
 __index__ = interp2app(W_UInt16Box.descr_index),
 __reduce__ = interp2app(W_UInt16Box.descr_reduce),
 )
 
 W_Int32Box.typedef = TypeDef("int32", (W_SignedIntegerBox.typedef,) + MIXIN_32,
-__module__ = "numpypy",
+__module__ = "numpy",
 __new__ = interp2app(W_Int32Box.descr__new__.im_func),
 __index__ = interp2app(W_Int32Box.descr_index),
 __reduce__ = interp2app(W_Int32Box.descr_reduce),
 )
 
 W_UInt32Box.typedef = TypeDef("uint32", W_UnsignedIntegerBox.typedef,
-__module__ = "numpypy",
+__module__ = "numpy",
 __new__ = interp2app(W_UInt32Box.descr__new__.im_func),
 __index__ = interp2app(W_UInt32Box.descr_index),
 __reduce__ = interp2app(W_UInt32Box.descr_reduce),
 )
 
 W_Int64Box.typedef = TypeDef("int64", (W_SignedIntegerBox.typedef,) + MIXIN_64,
-__module__ = "numpypy",
+__module__ = "numpy",
 __new__ = interp2app(W_Int64Box.descr__new__.im_func),
 __index__ = interp2app(W_Int64Box.descr_index),
 __reduce__ = interp2app(W_Int64Box.descr_reduce),
@@ -608,44 +608,44 @@
 W_ULongBox = W_UInt64Box
 
 W_UInt64Box.typedef = TypeDef("uint64", W_UnsignedIntegerBox.typedef,
-__module__ = "numpypy",
+__module__ = "numpy",
 __new__ = interp2app(W_UInt64Box.descr__new__.im_func),
 __index__ = interp2app(W_UInt64Box.descr_index),
 __reduce__ = interp2app(W_UInt64Box.descr_reduce),
 )
 
 W_InexactBox.typedef = TypeDef("inexact", W_NumberBox.typedef,
-__module__ = "numpypy",
+__module__ = "numpy",
 )
 
 W_FloatingBox.typedef = TypeDef("floating", W_InexactBox.typedef,
-__module__ = "numpypy",
+__module__ = "numpy",
 )
 
 W_Float16Box.typedef = TypeDef("float16", W_FloatingBox.typedef,
-__module__ = "numpypy",
+__module__ = "numpy",
 __new__ = interp2app(W_Float16Box.descr__new__.im_func),
 __reduce__ = interp2app(W_Float16Box.descr_reduce),
 )
 
 W_Float32Box.typedef = TypeDef("float32", W_FloatingBox.typedef,
-__module__ = "numpypy",
+__module__ = "numpy",
 __new__ = interp2app(W_Float32Box.descr__new__.im_func),
 __reduce__ = interp2app(W_Float32Box.descr_reduce),
 )
 
 W_Float64Box.typedef = TypeDef("float64", (W_FloatingBox.typedef, 
float_typedef),
-__module__ = "numpypy",
+__module__ = "numpy",
 __new__ = interp2app(W_Float64Box.descr__new__.im_func),
 __reduce__ = interp2app(W_Float64Box.descr_reduce),
 )
 
 W_ComplexFloatingBox.typedef = TypeDef("complexfloating", W_InexactBox.typedef,
-

[pypy-commit] pypy default: Make test_ztranslation fail on space.wrap(complex(...))

2013-11-03 Thread alex_gaynor
Author: Alex Gaynor 
Branch: 
Changeset: r67824:66bf553d6439
Date: 2013-11-03 22:59 -0800
http://bitbucket.org/pypy/pypy/changeset/66bf553d6439/

Log:Make test_ztranslation fail on space.wrap(complex(...))

diff --git a/pypy/objspace/fake/objspace.py b/pypy/objspace/fake/objspace.py
--- a/pypy/objspace/fake/objspace.py
+++ b/pypy/objspace/fake/objspace.py
@@ -176,7 +176,7 @@
 self._see_interp2app(x)
 if isinstance(x, GetSetProperty):
 self._see_getsetproperty(x)
-if isinstance(x, r_singlefloat):
+if isinstance(x, (r_singlefloat, complex)):
 self._wrap_not_rpython(x)
 if isinstance(x, list):
 if x == []: # special case: it is used e.g. in sys/__init__.py
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Revert, doesn't actually work

2013-11-03 Thread alex_gaynor
Author: Alex Gaynor 
Branch: 
Changeset: r67825:0d4f1f63b8a0
Date: 2013-11-03 23:00 -0800
http://bitbucket.org/pypy/pypy/changeset/0d4f1f63b8a0/

Log:Revert, doesn't actually work

diff --git a/pypy/objspace/fake/objspace.py b/pypy/objspace/fake/objspace.py
--- a/pypy/objspace/fake/objspace.py
+++ b/pypy/objspace/fake/objspace.py
@@ -176,7 +176,7 @@
 self._see_interp2app(x)
 if isinstance(x, GetSetProperty):
 self._see_getsetproperty(x)
-if isinstance(x, (r_singlefloat, complex)):
+if isinstance(x, r_singlefloat):
 self._wrap_not_rpython(x)
 if isinstance(x, list):
 if x == []: # special case: it is used e.g. in sys/__init__.py
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: The 'jitcounter' is another new object that is global, and that must be reset between tests in case they are

2013-11-03 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r67826:0ffd6995f846
Date: 2013-11-04 08:31 +0100
http://bitbucket.org/pypy/pypy/changeset/0ffd6995f846/

Log:The 'jitcounter' is another new object that is global, and that must
be reset between tests in case they are using the same piece of
compiled code.

diff --git a/pypy/module/micronumpy/test/test_zjit.py 
b/pypy/module/micronumpy/test/test_zjit.py
--- a/pypy/module/micronumpy/test/test_zjit.py
+++ b/pypy/module/micronumpy/test/test_zjit.py
@@ -6,7 +6,7 @@
 import py
 from rpython.jit.metainterp import pyjitpl
 from rpython.jit.metainterp.test.support import LLJitMixin
-from rpython.jit.metainterp.warmspot import reset_stats, get_stats
+from rpython.jit.metainterp.warmspot import reset_jit, get_stats
 from pypy.module.micronumpy import interp_boxes
 from pypy.module.micronumpy.compile import FakeSpace, Parser, InterpreterState
 from pypy.module.micronumpy.base import W_NDimArray
@@ -67,8 +67,7 @@
 
 def run(self, name):
 self.compile_graph()
-reset_stats()
-pyjitpl._warmrunnerdesc.memory_manager.alive_loops.clear()
+reset_jit()
 i = self.code_mapping[name]
 retval = self.interp.eval_graph(self.graph, [i])
 py.test.skip("don't run for now")
@@ -147,8 +146,7 @@
 
 def test_reduce_compile_only_once(self):
 self.compile_graph()
-reset_stats()
-pyjitpl._warmrunnerdesc.memory_manager.alive_loops.clear()
+reset_jit()
 i = self.code_mapping['reduce']
 # run it twice
 retval = self.interp.eval_graph(self.graph, [i])
@@ -158,8 +156,7 @@
 
 def test_reduce_axis_compile_only_once(self):
 self.compile_graph()
-reset_stats()
-pyjitpl._warmrunnerdesc.memory_manager.alive_loops.clear()
+reset_jit()
 i = self.code_mapping['axissum']
 # run it twice
 retval = self.interp.eval_graph(self.graph, [i])
diff --git a/rpython/jit/metainterp/counter.py 
b/rpython/jit/metainterp/counter.py
--- a/rpython/jit/metainterp/counter.py
+++ b/rpython/jit/metainterp/counter.py
@@ -151,3 +151,7 @@
 def decay_all_counters(self):
 "NOT_RPYTHON"
 pass
+
+def _clear_all(self):
+self.timetable.clear()
+self.celltable.clear()
diff --git a/rpython/jit/metainterp/test/support.py 
b/rpython/jit/metainterp/test/support.py
--- a/rpython/jit/metainterp/test/support.py
+++ b/rpython/jit/metainterp/test/support.py
@@ -3,6 +3,7 @@
 from rpython.rtyper.lltypesystem import lltype, llmemory
 from rpython.jit.backend.llgraph import runner
 from rpython.jit.metainterp.warmspot import ll_meta_interp, get_stats
+from rpython.jit.metainterp.warmspot import reset_stats
 from rpython.jit.metainterp.warmstate import unspecialize_value
 from rpython.jit.metainterp.optimizeopt import ALL_OPTS_DICT
 from rpython.jit.metainterp import pyjitpl, history, jitexc
diff --git a/rpython/jit/metainterp/warmspot.py 
b/rpython/jit/metainterp/warmspot.py
--- a/rpython/jit/metainterp/warmspot.py
+++ b/rpython/jit/metainterp/warmspot.py
@@ -164,6 +164,12 @@
 def reset_stats():
 pyjitpl._warmrunnerdesc.stats.clear()
 
+def reset_jit():
+"""Helper for some tests (see micronumpy/test/test_zjit.py)"""
+reset_stats()
+pyjitpl._warmrunnerdesc.memory_manager.alive_loops.clear()
+pyjitpl._warmrunnerdesc.jitcounter._clear_all()
+
 def get_translator():
 return pyjitpl._warmrunnerdesc.translator
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit