[pypy-commit] pypy armhf-singlefloat: document and close about to be merged branch

2013-11-19 Thread bivab
Author: David Schneider david.schnei...@picle.org
Branch: armhf-singlefloat
Changeset: r68235:83952b768a05
Date: 2013-11-19 09:30 +0100
http://bitbucket.org/pypy/pypy/changeset/83952b768a05/

Log:document and close about to be merged 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
@@ -13,3 +13,5 @@
 .. branch: windows-packaging
 Package tk/tcl runtime with win32
 
+.. branch: armhf-singlefloat
+JIT support for singlefloats on ARM using the hardfloat ABI
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: merge armhf-singlefloat

2013-11-19 Thread bivab
Author: David Schneider david.schnei...@picle.org
Branch: 
Changeset: r68236:cc499f0c7d91
Date: 2013-11-19 09:30 +0100
http://bitbucket.org/pypy/pypy/changeset/cc499f0c7d91/

Log:merge armhf-singlefloat

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
@@ -13,3 +13,5 @@
 .. branch: windows-packaging
 Package tk/tcl runtime with win32
 
+.. branch: armhf-singlefloat
+JIT support for singlefloats on ARM using the hardfloat ABI
diff --git a/rpython/jit/backend/arm/callbuilder.py 
b/rpython/jit/backend/arm/callbuilder.py
--- a/rpython/jit/backend/arm/callbuilder.py
+++ b/rpython/jit/backend/arm/callbuilder.py
@@ -227,20 +227,81 @@
 
 class HardFloatCallBuilder(ARMCallbuilder):
 
+next_arg_vfp = 0
+next_arg_svfp = 0
+
+def get_next_vfp(self, tp):
+assert tp in 'fS'
+if self.next_arg_vfp == -1:
+return None
+if tp == 'S':
+i = self.next_arg_svfp
+next_vfp = (i  1) + 1
+if not (i + 1)  1: # i is even
+self.next_arg_vfp = max(self.next_arg_vfp, next_vfp)
+self.next_arg_svfp = self.next_arg_vfp  1
+else:
+self.next_arg_svfp += 1
+self.next_arg_vfp = next_vfp
+lst = r.svfp_argument_regs
+else: # 64bit double
+i = self.next_arg_vfp
+self.next_arg_vfp += 1
+if self.next_arg_svfp  1 == i:
+self.next_arg_svfp = self.next_arg_vfp  1
+lst = r.vfp_argument_regs
+try:
+return lst[i]
+except IndexError:
+self.next_arg_vfp = self.next_arg_svfp = -1
+return None
+
 def prepare_arguments(self):
 non_float_locs = []
 non_float_regs = []
 float_locs = []
 float_regs = []
 stack_args = []
+singlefloats = None
 
 arglocs = self.arglocs
 argtypes = self.argtypes
 
 count = 0  # stack alignment counter
 on_stack = 0
-for arg in arglocs:
-if arg.type != FLOAT:
+for i in range(len(arglocs)):
+argtype = INT
+if i  len(argtypes) and argtypes[i] == 'S':
+argtype = argtypes[i]
+arg = arglocs[i]
+if arg.is_float():
+argtype = FLOAT
+reg = self.get_next_vfp(argtype)
+if reg:
+assert len(float_regs)  len(r.vfp_argument_regs)
+float_locs.append(arg)
+assert reg not in float_regs
+float_regs.append(reg)
+else:  # float argument that needs to go on the stack
+if count % 2 != 0:
+stack_args.append(None)
+count = 0
+on_stack += 1
+stack_args.append(arg)
+on_stack += 2
+elif argtype == 'S':
+# Singlefloat argument
+if singlefloats is None:
+singlefloats = []
+tgt = self.get_next_vfp(argtype)
+if tgt:
+singlefloats.append((arg, tgt))
+else:  # Singlefloat argument that needs to go on the stack
+   # treated the same as a regular core register argument
+count += 1
+on_stack += 1
+stack_args.append(arg)
+else:
 if len(non_float_regs)  len(r.argument_regs):
 reg = r.argument_regs[len(non_float_regs)]
 non_float_locs.append(arg)
@@ -249,18 +310,6 @@
 count += 1
 on_stack += 1
 stack_args.append(arg)
-else:
-if len(float_regs)  len(r.vfp_argument_regs):
-reg = r.vfp_argument_regs[len(float_regs)]
-float_locs.append(arg)
-float_regs.append(reg)
-else:  # float argument that needs to go on the stack
-if count % 2 != 0:
-stack_args.append(None)
-count = 0
-on_stack += 1
-stack_args.append(arg)
-on_stack += 2
 # align the stack
 if count % 2 != 0:
 stack_args.append(None)
@@ -275,13 +324,28 @@
 non_float_locs.append(self.fnloc)
 non_float_regs.append(r.r4)
 self.fnloc = r.r4
+# remap values stored in vfp registers
+remap_frame_layout(self.asm, float_locs, float_regs, r.vfp_ip)
+if singlefloats:
+for src, dest in singlefloats:
+if src.is_float():
+assert 0, 'unsupported case'
+if src.is_stack():
+   

[pypy-commit] pypy default: deactivate test_multiprocessing until #1644 is resolved - buildslave hangs

2013-11-19 Thread oberstet
Author: Tobias Oberstein tobias.oberst...@tavendo.de
Branch: 
Changeset: r68237:4cb276ba3e4a
Date: 2013-11-18 21:54 +0100
http://bitbucket.org/pypy/pypy/changeset/4cb276ba3e4a/

Log:deactivate test_multiprocessing until #1644 is resolved - buildslave
hangs

diff --git a/lib-python/2.7/test/test_multiprocessing.py 
b/lib-python/2.7/test/test_multiprocessing.py
--- a/lib-python/2.7/test/test_multiprocessing.py
+++ b/lib-python/2.7/test/test_multiprocessing.py
@@ -1,5 +1,10 @@
 #!/usr/bin/env python
 
+## FIXME: remove when https://bugs.pypy.org/issue1644 is resolved
+import sys
+if sys.platform.startswith('freebsd'):
+raise Exception(This test hangs on FreeBSD. Test deactivated for now 
until https://bugs.pypy.org/issue1644 get resolved)
+
 #
 # Unit tests for the multiprocessing package
 #
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Merged in oberstet/pypy (pull request #200)

2013-11-19 Thread arigo
Author: Armin Rigo armin.r...@gmail.com
Branch: 
Changeset: r68238:4369d6c2378e
Date: 2013-11-19 09:56 +0100
http://bitbucket.org/pypy/pypy/changeset/4369d6c2378e/

Log:Merged in oberstet/pypy (pull request #200)

deactivate test_multiprocessing until #1644 is resolved - buildslave
hangs

diff --git a/lib-python/2.7/test/test_multiprocessing.py 
b/lib-python/2.7/test/test_multiprocessing.py
--- a/lib-python/2.7/test/test_multiprocessing.py
+++ b/lib-python/2.7/test/test_multiprocessing.py
@@ -1,5 +1,10 @@
 #!/usr/bin/env python
 
+## FIXME: remove when https://bugs.pypy.org/issue1644 is resolved
+import sys
+if sys.platform.startswith('freebsd'):
+raise Exception(This test hangs on FreeBSD. Test deactivated for now 
until https://bugs.pypy.org/issue1644 get resolved)
+
 #
 # Unit tests for the multiprocessing package
 #
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy ndarray-buffer: add a new implementation of arrays which keeps alive the original buffer

2013-11-19 Thread antocuni
Author: Antonio Cuni anto.c...@gmail.com
Branch: ndarray-buffer
Changeset: r68241:193128b62e58
Date: 2013-11-19 14:50 +0100
http://bitbucket.org/pypy/pypy/changeset/193128b62e58/

Log:add a new implementation of arrays which keeps alive the original
buffer

diff --git a/pypy/module/micronumpy/arrayimpl/concrete.py 
b/pypy/module/micronumpy/arrayimpl/concrete.py
--- a/pypy/module/micronumpy/arrayimpl/concrete.py
+++ b/pypy/module/micronumpy/arrayimpl/concrete.py
@@ -392,7 +392,15 @@
 def __del__(self):
 free_raw_storage(self.storage, track_allocation=False)
 
+class ConcreteArrayWithBase(ConcreteArrayNotOwning):
+def __init__(self, shape, dtype, order, strides, backstrides, storage, 
orig_base):
+ConcreteArrayNotOwning.__init__(self, shape, dtype, order,
+strides, backstrides, storage)
+self.orig_base = orig_base
 
+def base(self):
+return self.orig_base
+
 class NonWritableArray(ConcreteArray):
 def descr_setitem(self, space, orig_array, w_index, w_value):
 raise OperationError(space.w_ValueError, space.wrap(
diff --git a/pypy/module/micronumpy/base.py b/pypy/module/micronumpy/base.py
--- a/pypy/module/micronumpy/base.py
+++ b/pypy/module/micronumpy/base.py
@@ -49,11 +49,18 @@
 return W_NDimArray(impl)
 
 @staticmethod
-def from_shape_and_storage(space, shape, storage, dtype, order='C', 
owning=False, w_subtype=None):
+def from_shape_and_storage(space, shape, storage, dtype, order='C', 
owning=False,
+   w_subtype=None, w_base=None):
 from pypy.module.micronumpy.arrayimpl import concrete
 assert shape
 strides, backstrides = calc_strides(shape, dtype, order)
-if owning:
+if w_base is not None:
+if owning:
+raise OperationError(space.w_ValueError, 
+space.wrap(Cannot have owning=True when specifying a 
buffer))
+impl = concrete.ConcreteArrayWithBase(shape, dtype, order, strides,
+  backstrides, storage, w_base)
+elif owning:
 # Will free storage when GCd
 impl = concrete.ConcreteArray(shape, dtype, order, strides,
 backstrides, storage=storage)
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
@@ -1086,7 +1086,8 @@
 raise OperationError(space.w_TypeError, space.wrap(
 numpy scalars from buffers not supported yet))
 storage = rffi.cast(RAW_STORAGE_PTR, raw_ptr)
-return W_NDimArray.from_shape_and_storage(space, shape, storage, dtype)
+return W_NDimArray.from_shape_and_storage(space, shape, storage, dtype,
+  w_base=w_buffer)
 
 if not shape:
 return W_NDimArray.new_scalar(space, dtype)
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
@@ -2096,7 +2096,8 @@
 a[1] = ord('a')
 a[2] = ord('r')
 assert list(buf) == ['b', '\x00', 'a', '\x00', 'r', '\x00']
-
+assert a.base is buf
+
 
 class AppTestMultiDim(BaseNumpyAppTest):
 def test_init(self):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy ndarray-buffer: first passing test: only buffers which implement get_raw_address are supported of course, because the others can be movable

2013-11-19 Thread antocuni
Author: Antonio Cuni anto.c...@gmail.com
Branch: ndarray-buffer
Changeset: r68240:b9d813cc6c0a
Date: 2013-11-19 12:21 +0100
http://bitbucket.org/pypy/pypy/changeset/b9d813cc6c0a/

Log:first passing test: only buffers which implement get_raw_address are
supported of course, because the others can be movable

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
@@ -1,3 +1,5 @@
+from rpython.rtyper.lltypesystem import rffi
+from rpython.rlib.rawstorage import RAW_STORAGE_PTR
 from pypy.interpreter.error import operationerrfmt, OperationError
 from pypy.interpreter.typedef import TypeDef, GetSetProperty, 
make_weakref_descr
 from pypy.interpreter.gateway import interp2app, unwrap_spec, applevel, \
@@ -1065,13 +1067,27 @@
 offset=0, w_strides=None, order='C'):
 from pypy.module.micronumpy.arrayimpl.concrete import ConcreteArray
 from pypy.module.micronumpy.support import calc_strides
-if (offset != 0 or not space.is_none(w_strides) or
-not space.is_none(w_buffer)):
+if (offset != 0 or not space.is_none(w_strides)):
 raise OperationError(space.w_NotImplementedError,
  space.wrap(unsupported param))
+
 dtype = space.interp_w(interp_dtype.W_Dtype,
   space.call_function(space.gettypefor(interp_dtype.W_Dtype), w_dtype))
 shape = _find_shape(space, w_shape, dtype)
+
+if not space.is_none(w_buffer):
+buf = space.buffer_w(w_buffer)
+try:
+raw_ptr = buf.get_raw_address()
+except ValueError:
+raise OperationError(space.w_TypeError, space.wrap(
+Only raw buffers are supported))
+if not shape:
+raise OperationError(space.w_TypeError, space.wrap(
+numpy scalars from buffers not supported yet))
+storage = rffi.cast(RAW_STORAGE_PTR, raw_ptr)
+return W_NDimArray.from_shape_and_storage(space, shape, storage, dtype)
+
 if not shape:
 return W_NDimArray.new_scalar(space, dtype)
 if space.is_w(w_subtype, space.gettypefor(W_NDimArray)):
@@ -1091,8 +1107,6 @@
 Create an array from an existing buffer, given its address as int.
 PyPy-only implementation detail.
 
-from rpython.rtyper.lltypesystem import rffi
-from rpython.rlib.rawstorage import RAW_STORAGE_PTR
 storage = rffi.cast(RAW_STORAGE_PTR, addr)
 dtype = space.interp_w(interp_dtype.W_Dtype,
  
space.call_function(space.gettypefor(interp_dtype.W_Dtype),
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
@@ -218,7 +218,7 @@
 assert get(1, 1) == 3
 
 class AppTestNumArray(BaseNumpyAppTest):
-spaceconfig = dict(usemodules=[micronumpy, struct, binascii])
+spaceconfig = dict(usemodules=[micronumpy, struct, binascii, 
array])
 def w_CustomIndexObject(self, index):
 class CustomIndexObject(object):
 def __init__(self, index):
@@ -2087,6 +2087,17 @@
 a = np.ndarray([1], dtype=bool)
 assert a[0] == True
 
+def test_ndarray_from_buffer(self):
+import numpypy as np
+import array
+buf = array.array('c', ['\x00']*2*3)
+a = np.ndarray((3,), buffer=buf, dtype='i2')
+a[0] = ord('b')
+a[1] = ord('a')
+a[2] = ord('r')
+assert list(buf) == ['b', '\x00', 'a', '\x00', 'r', '\x00']
+
+
 class AppTestMultiDim(BaseNumpyAppTest):
 def test_init(self):
 import numpypy
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy ndarray-buffer: a branch where to support the buffer argument to ndarray()

2013-11-19 Thread antocuni
Author: Antonio Cuni anto.c...@gmail.com
Branch: ndarray-buffer
Changeset: r68239:c1f8cadec802
Date: 2013-11-19 11:39 +0100
http://bitbucket.org/pypy/pypy/changeset/c1f8cadec802/

Log:a branch where to support the buffer argument to ndarray()

___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy ndarray-buffer: implement the offset param

2013-11-19 Thread antocuni
Author: Antonio Cuni anto.c...@gmail.com
Branch: ndarray-buffer
Changeset: r68242:2187c37bb8b0
Date: 2013-11-19 15:17 +0100
http://bitbucket.org/pypy/pypy/changeset/2187c37bb8b0/

Log:implement the offset param

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
@@ -1067,15 +1067,15 @@
 offset=0, w_strides=None, order='C'):
 from pypy.module.micronumpy.arrayimpl.concrete import ConcreteArray
 from pypy.module.micronumpy.support import calc_strides
-if (offset != 0 or not space.is_none(w_strides)):
-raise OperationError(space.w_NotImplementedError,
- space.wrap(unsupported param))
-
 dtype = space.interp_w(interp_dtype.W_Dtype,
   space.call_function(space.gettypefor(interp_dtype.W_Dtype), w_dtype))
 shape = _find_shape(space, w_shape, dtype)
 
 if not space.is_none(w_buffer):
+if (not space.is_none(w_strides)):
+raise OperationError(space.w_NotImplementedError,
+ space.wrap(unsupported param))
+
 buf = space.buffer_w(w_buffer)
 try:
 raw_ptr = buf.get_raw_address()
@@ -1086,6 +1086,7 @@
 raise OperationError(space.w_TypeError, space.wrap(
 numpy scalars from buffers not supported yet))
 storage = rffi.cast(RAW_STORAGE_PTR, raw_ptr)
+storage = rffi.ptradd(storage, offset)
 return W_NDimArray.from_shape_and_storage(space, shape, storage, dtype,
   w_base=w_buffer)
 
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
@@ -2098,6 +2098,17 @@
 assert list(buf) == ['b', '\x00', 'a', '\x00', 'r', '\x00']
 assert a.base is buf
 
+def test_ndarray_from_buffer_and_offset(self):
+import numpypy as np
+import array
+buf = array.array('c', ['\x00']*7)
+buf[0] = 'X'
+a = np.ndarray((3,), buffer=buf, offset=1, dtype='i2')
+a[0] = ord('b')
+a[1] = ord('a')
+a[2] = ord('r')
+assert list(buf) == ['X', 'b', '\x00', 'a', '\x00', 'r', '\x00']
+
 
 class AppTestMultiDim(BaseNumpyAppTest):
 def test_init(self):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy ndarray-buffer: check the size of the buffer

2013-11-19 Thread antocuni
Author: Antonio Cuni anto.c...@gmail.com
Branch: ndarray-buffer
Changeset: r68243:8d2b54062cfc
Date: 2013-11-19 15:33 +0100
http://bitbucket.org/pypy/pypy/changeset/8d2b54062cfc/

Log:check the size of the buffer

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
@@ -22,6 +22,7 @@
 from rpython.rlib.rstring import StringBuilder
 from pypy.module.micronumpy.arrayimpl.base import BaseArrayImplementation
 from pypy.module.micronumpy.conversion_utils import order_converter, 
multi_axis_converter
+from pypy.module.micronumpy import support
 from pypy.module.micronumpy.constants import *
 
 def _find_shape(space, w_size, dtype):
@@ -1085,6 +1086,10 @@
 if not shape:
 raise OperationError(space.w_TypeError, space.wrap(
 numpy scalars from buffers not supported yet))
+totalsize = support.product(shape) * dtype.get_size()
+if totalsize+offset  buf.getlength():
+raise OperationError(space.w_TypeError, space.wrap(
+buffer is too small for requested array))
 storage = rffi.cast(RAW_STORAGE_PTR, raw_ptr)
 storage = rffi.ptradd(storage, offset)
 return W_NDimArray.from_shape_and_storage(space, shape, storage, dtype,
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
@@ -2109,6 +2109,16 @@
 a[2] = ord('r')
 assert list(buf) == ['X', 'b', '\x00', 'a', '\x00', 'r', '\x00']
 
+def test_ndarray_from_buffer_out_of_bounds(self):
+import numpypy as np
+import array
+buf = array.array('c', ['\x00']*2*10) # 20 bytes
+info = raises(TypeError, np.ndarray((11,), buffer=buf, dtype='i2'))
+assert str(info.value).startswith('buffer is too small')
+info = raises(TypeError, np.ndarray((5,), buffer=buf, offset=15, 
dtype='i2'))
+assert str(info.value).startswith('buffer is too small')
+
+
 
 class AppTestMultiDim(BaseNumpyAppTest):
 def test_init(self):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy ndarray-buffer: test and fix

2013-11-19 Thread antocuni
Author: Antonio Cuni anto.c...@gmail.com
Branch: ndarray-buffer
Changeset: r68244:8593deb29c94
Date: 2013-11-19 16:32 +0100
http://bitbucket.org/pypy/pypy/changeset/8593deb29c94/

Log:test and fix

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
@@ -1093,6 +1093,7 @@
 storage = rffi.cast(RAW_STORAGE_PTR, raw_ptr)
 storage = rffi.ptradd(storage, offset)
 return W_NDimArray.from_shape_and_storage(space, shape, storage, dtype,
+  w_subtype=w_subtype,
   w_base=w_buffer)
 
 if not shape:
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
@@ -2098,6 +2098,15 @@
 assert list(buf) == ['b', '\x00', 'a', '\x00', 'r', '\x00']
 assert a.base is buf
 
+def test_ndarray_subclass_from_buffer(self):
+import numpypy as np
+import array
+buf = array.array('c', ['\x00']*2*3)
+class X(np.ndarray):
+pass
+a = X((3,), buffer=buf, dtype='i2')
+assert type(a) is X
+
 def test_ndarray_from_buffer_and_offset(self):
 import numpypy as np
 import array
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] stmgc default: document the real reason why we can't use just any h_original and

2013-11-19 Thread Raemi
Author: Remi Meier remi.me...@gmail.com
Branch: 
Changeset: r549:b89b61f0df98
Date: 2013-11-19 17:15 +0100
http://bitbucket.org/pypy/stmgc/changeset/b89b61f0df98/

Log:document the real reason why we can't use just any h_original and
prevent things like stub-stub-stub on public addresses.

diff --git a/c4/doc-objects.txt b/c4/doc-objects.txt
--- a/c4/doc-objects.txt
+++ b/c4/doc-objects.txt
@@ -62,6 +62,7 @@
 - prebuilt object, never modified  1
 - other public object, never modified GT
 - outdated ptr to a more recent public copy
+- stolen protected, made publicsome PRN
 
 Public stubs (have also a ref to one thread):
 - from stealingptr (maybe to priv/prot) | 2
@@ -353,3 +354,6 @@
 it is a predefined HASH value for this object. This is used by
 `stm_hash` which otherwise returns a hashed version of the ID of
 the object.
+
+DONT ASSUME THE H_ORIGINAL TO BE INITIALIZED. IT MAY HAVE E.G.
+H_REVISION SET TO AN OLD, FREED OBJECT.
diff --git a/c4/et.c b/c4/et.c
--- a/c4/et.c
+++ b/c4/et.c
@@ -183,7 +183,8 @@
   if (v  2)
 goto follow_stub;
 
-  /* we update P_prev-h_revision as a shortcut */
+  /* we update P_prev-h_revision as a shortcut
+ P_prev-P-v  =  P_prev-v */
   /* XXX check if this really gives a worse performance than only
  doing this write occasionally based on a counter in d */
   P_prev-h_revision = v;
@@ -576,6 +577,7 @@
   B = stmgc_duplicate_old(P);
   B-h_tid |= GCFLAG_BACKUP_COPY;
   B-h_tid = ~GCFLAG_HAS_ID;
+
   if (!(P-h_original)  (P-h_tid  GCFLAG_OLD)) {
 /* if P is old, it must be the original
if P is young, it will create a shadow original later
diff --git a/c4/extra.c b/c4/extra.c
--- a/c4/extra.c
+++ b/c4/extra.c
@@ -89,21 +89,30 @@
 }
 assert(obj-h_tid  GCFLAG_OLD);
 
+if (stm_is_registered(obj)) {
+/* prevents stub-stub-stub-... */
+/* only increment refcount: */
+stm_register_integer_address((intptr_t)obj);
+return (intptr_t)obj;
+}
+
 spinlock_acquire(d-public_descriptor-collection_lock, 'P');
 
 /* it must have a h_original */
 gcptr orig;
-if (obj-h_original == 0 || obj-h_tid  GCFLAG_PREBUILT_ORIGINAL) {
+if ((!obj-h_original) || (obj-h_tid  GCFLAG_PREBUILT_ORIGINAL)) {
 orig = obj;
 } else {
 orig = (gcptr)obj-h_original;
 }
 
-if ((orig-h_tid  (GCFLAG_PUBLIC | GCFLAG_PREBUILT_ORIGINAL))
-== (GCFLAG_PUBLIC | GCFLAG_PREBUILT_ORIGINAL)) {
-/* public is not enough as public stubs may get replaced
-   by the protected object they point to, if they are in the 
-   same thread (I think...) */
+if ((orig-h_tid  GCFLAG_PUBLIC) 
+ (obj-h_tid  GCFLAG_PREBUILT_ORIGINAL)) {
+/* we can't just use *any* public original because their
+   h_revision is not kept up-to-date during major collections.
+   Meaning it can point to some long gone object.
+   Prebuilt originals, however, always get visited in major
+   collections. */
 result = (intptr_t)orig;
 }
 else {
@@ -233,10 +242,11 @@
 /* must create shadow original object XXX: or use
backup, if exists */
 gcptr O = (gcptr)stmgcpage_malloc(stmgc_size(p));
-memcpy(O, p, stmgc_size(p)); /* at least major collections
-  depend on some content of id_copy.
-  remove after fixing that XXX */
+memcpy(O, p, sizeof(struct stm_object_s));
+
 O-h_tid |= GCFLAG_OLD;
+assert(O-h_original == 0);
+assert(O-h_revision = -1); /* debugging */
 
 p-h_original = (revision_t)O;
 p-h_tid |= GCFLAG_HAS_ID;
@@ -245,6 +255,7 @@
 gcptr B = (gcptr)p-h_revision;
 /* not stolen already: */
 assert(!(B-h_tid  GCFLAG_PUBLIC));
+assert(!B-h_original);
 B-h_original = (revision_t)O;
 }
 
diff --git a/c4/gcpage.c b/c4/gcpage.c
--- a/c4/gcpage.c
+++ b/c4/gcpage.c
@@ -37,6 +37,13 @@
 }
 }
 
+static void check_consistent(gcptr obj) {
+if ((obj-h_revision  3) == 2)
+assert(stm_pointer_equal(obj, (gcptr)(obj-h_revision-2)));
+else if ((obj-h_revision  1) == 0)
+assert(stm_pointer_equal(obj, (gcptr)(obj-h_revision)));
+}
+
 
 /* Support code */
 
@@ -217,6 +224,22 @@
 
 /* registering of small stubs as integer addresses */
 
+_Bool stm_is_registered(gcptr obj)
+{
+wlog_t *found;
+_Bool res = 0;
+
+stmgcpage_acquire_global_lock();
+/* find and increment refcount; or insert */
+G2L_FIND(registered_objs, obj, found, goto finish);
+found-val = (gcptr)(((revision_t)found-val) + 1);
+goto finish;
+res = 1;
+ finish:
+

[pypy-commit] pypy stmgc-c4: import stmgc

2013-11-19 Thread Raemi
Author: Remi Meier remi.me...@gmail.com
Branch: stmgc-c4
Changeset: r68245:6c38f0067571
Date: 2013-11-19 17:16 +0100
http://bitbucket.org/pypy/pypy/changeset/6c38f0067571/

Log:import stmgc

diff --git a/rpython/translator/stm/src_stm/et.c 
b/rpython/translator/stm/src_stm/et.c
--- a/rpython/translator/stm/src_stm/et.c
+++ b/rpython/translator/stm/src_stm/et.c
@@ -184,7 +184,8 @@
   if (v  2)
 goto follow_stub;
 
-  /* we update P_prev-h_revision as a shortcut */
+  /* we update P_prev-h_revision as a shortcut
+ P_prev-P-v  =  P_prev-v */
   /* XXX check if this really gives a worse performance than only
  doing this write occasionally based on a counter in d */
   P_prev-h_revision = v;
@@ -577,6 +578,7 @@
   B = stmgc_duplicate_old(P);
   B-h_tid |= GCFLAG_BACKUP_COPY;
   B-h_tid = ~GCFLAG_HAS_ID;
+
   if (!(P-h_original)  (P-h_tid  GCFLAG_OLD)) {
 /* if P is old, it must be the original
if P is young, it will create a shadow original later
diff --git a/rpython/translator/stm/src_stm/extra.c 
b/rpython/translator/stm/src_stm/extra.c
--- a/rpython/translator/stm/src_stm/extra.c
+++ b/rpython/translator/stm/src_stm/extra.c
@@ -90,21 +90,30 @@
 }
 assert(obj-h_tid  GCFLAG_OLD);
 
+if (stm_is_registered(obj)) {
+/* prevents stub-stub-stub-... */
+/* only increment refcount: */
+stm_register_integer_address((intptr_t)obj);
+return (intptr_t)obj;
+}
+
 spinlock_acquire(d-public_descriptor-collection_lock, 'P');
 
 /* it must have a h_original */
 gcptr orig;
-if (obj-h_original == 0 || obj-h_tid  GCFLAG_PREBUILT_ORIGINAL) {
+if ((!obj-h_original) || (obj-h_tid  GCFLAG_PREBUILT_ORIGINAL)) {
 orig = obj;
 } else {
 orig = (gcptr)obj-h_original;
 }
 
-if ((orig-h_tid  (GCFLAG_PUBLIC | GCFLAG_PREBUILT_ORIGINAL))
-== (GCFLAG_PUBLIC | GCFLAG_PREBUILT_ORIGINAL)) {
-/* public is not enough as public stubs may get replaced
-   by the protected object they point to, if they are in the 
-   same thread (I think...) */
+if ((orig-h_tid  GCFLAG_PUBLIC) 
+ (obj-h_tid  GCFLAG_PREBUILT_ORIGINAL)) {
+/* we can't just use *any* public original because their
+   h_revision is not kept up-to-date during major collections.
+   Meaning it can point to some long gone object.
+   Prebuilt originals, however, always get visited in major
+   collections. */
 result = (intptr_t)orig;
 }
 else {
@@ -234,10 +243,11 @@
 /* must create shadow original object XXX: or use
backup, if exists */
 gcptr O = (gcptr)stmgcpage_malloc(stmgc_size(p));
-memcpy(O, p, stmgc_size(p)); /* at least major collections
-  depend on some content of id_copy.
-  remove after fixing that XXX */
+memcpy(O, p, sizeof(struct stm_object_s));
+
 O-h_tid |= GCFLAG_OLD;
+assert(O-h_original == 0);
+assert(O-h_revision = -1); /* debugging */
 
 p-h_original = (revision_t)O;
 p-h_tid |= GCFLAG_HAS_ID;
@@ -246,6 +256,7 @@
 gcptr B = (gcptr)p-h_revision;
 /* not stolen already: */
 assert(!(B-h_tid  GCFLAG_PUBLIC));
+assert(!B-h_original);
 B-h_original = (revision_t)O;
 }
 
diff --git a/rpython/translator/stm/src_stm/gcpage.c 
b/rpython/translator/stm/src_stm/gcpage.c
--- a/rpython/translator/stm/src_stm/gcpage.c
+++ b/rpython/translator/stm/src_stm/gcpage.c
@@ -38,6 +38,13 @@
 }
 }
 
+static void check_consistent(gcptr obj) {
+if ((obj-h_revision  3) == 2)
+assert(stm_pointer_equal(obj, (gcptr)(obj-h_revision-2)));
+else if ((obj-h_revision  1) == 0)
+assert(stm_pointer_equal(obj, (gcptr)(obj-h_revision)));
+}
+
 
 /* Support code */
 
@@ -218,6 +225,22 @@
 
 /* registering of small stubs as integer addresses */
 
+_Bool stm_is_registered(gcptr obj)
+{
+wlog_t *found;
+_Bool res = 0;
+
+stmgcpage_acquire_global_lock();
+/* find and increment refcount; or insert */
+G2L_FIND(registered_objs, obj, found, goto finish);
+found-val = (gcptr)(((revision_t)found-val) + 1);
+goto finish;
+res = 1;
+ finish:
+stmgcpage_release_global_lock();
+return res;
+}
+
 void stm_register_integer_address(intptr_t adr)
 {   /* needs to be inevitable! */
 wlog_t *found;
@@ -254,6 +277,7 @@
 /* become inevitable because we would have to re-register them
on abort, but make sure only to re-register if not registered
in the same aborted transaction (XXX) */
+/* (obj will not move) */
 stm_become_inevitable(stm_unregister_integer_address());
 
 stmgcpage_acquire_global_lock();
@@ -280,6 +304,10 @@
 
 

[pypy-commit] pypy numpypy-array_prepare_-array_wrap: Forgot to solve this merge conflict

2013-11-19 Thread rguillebert
Author: Romain Guillebert romain...@gmail.com
Branch: numpypy-array_prepare_-array_wrap
Changeset: r68247:0559ff165dad
Date: 2013-11-19 20:10 +0100
http://bitbucket.org/pypy/pypy/changeset/0559ff165dad/

Log:Forgot to solve this merge conflict

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
@@ -313,9 +313,6 @@
 self.w_flags = W_FlagsObject(self)
 return self.w_flags
 
-def descr_dtype(self, space):
-return self._get_dtype(space)
-
 class W_BoolBox(W_GenericBox, PrimitiveBox):
 descr__new__, _get_dtype, descr_reduce = new_dtype_getter(bool)
 
@@ -567,9 +564,6 @@
 conjugate = interp2app(W_GenericBox.descr_conjugate),
 astype = interp2app(W_GenericBox.descr_astype),
 view = interp2app(W_GenericBox.descr_view),
- local
-dtype = GetSetProperty(W_GenericBox.descr_dtype)
-===
 squeeze = interp2app(W_GenericBox.descr_self),
 copy = interp2app(W_GenericBox.descr_copy),
 
@@ -582,7 +576,6 @@
 ndim = GetSetProperty(W_GenericBox.descr_get_ndim),
 T = GetSetProperty(W_GenericBox.descr_self),
 flags = GetSetProperty(W_GenericBox.descr_get_flags),
- other
 )
 
 W_BoolBox.typedef = TypeDef(bool_, W_GenericBox.typedef,
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy numpypy-array_prepare_-array_wrap: sum doesn't exist in numpypy

2013-11-19 Thread rguillebert
Author: Romain Guillebert romain...@gmail.com
Branch: numpypy-array_prepare_-array_wrap
Changeset: r68248:b5c80215f7e5
Date: 2013-11-19 21:08 +0100
http://bitbucket.org/pypy/pypy/changeset/b5c80215f7e5/

Log:sum doesn't exist in numpypy

diff --git a/pypy/module/micronumpy/test/test_subtype.py 
b/pypy/module/micronumpy/test/test_subtype.py
--- a/pypy/module/micronumpy/test/test_subtype.py
+++ b/pypy/module/micronumpy/test/test_subtype.py
@@ -374,7 +374,7 @@
 raises(TypeError, log, a, out=c)
 
 def test___array_prepare__reduce(self):
-from numpypy import ndarray, array, sum, ones, add
+from numpypy import ndarray, array, ones, add
 class with_prepare(ndarray):
 def __array_prepare__(self, arr, context):
 x = array(arr).view(type=with_prepare)
@@ -382,7 +382,7 @@
 print 'called_prepare',arr
 return x
 a = ones(2).view(type=with_prepare)
-x = sum(a)
+x = a.sum()
 assert type(x) == with_prepare
 assert x.shape == ()
 # reduce functions do not call prepare, is this a numpy 'feature'?
@@ -391,6 +391,6 @@
 assert type(x) == with_prepare
 assert not getattr(x, 'called_prepare',False)
 a = ones((2,3)).view(type=with_prepare)
-x = sum(a, axis=0)
+x = a.sum(axis=0)
 assert type(x) == with_prepare
 assert not getattr(x, 'called_prepare',False)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: backout afb227c, breaks everything else and doesn't fix freebsd

2013-11-19 Thread bdkearns
Author: Brian Kearns bdkea...@gmail.com
Branch: 
Changeset: r68249:55b6a37713d9
Date: 2013-11-19 19:46 -0500
http://bitbucket.org/pypy/pypy/changeset/55b6a37713d9/

Log:backout afb227c, breaks everything else and doesn't fix freebsd

diff --git a/rpython/rlib/rdynload.py b/rpython/rlib/rdynload.py
--- a/rpython/rlib/rdynload.py
+++ b/rpython/rlib/rdynload.py
@@ -4,7 +4,6 @@
 from rpython.rtyper.tool import rffi_platform
 from rpython.rtyper.lltypesystem import rffi
 from rpython.rlib.rarithmetic import r_uint
-from rpython.rlib.objectmodel import we_are_translated
 from rpython.translator.tool.cbuild import ExternalCompilationInfo
 from rpython.translator.platform import platform
 
@@ -80,38 +79,6 @@
 RTLD_NOW = cConfig.RTLD_NOW
 RTLD_LAZY = cConfig.RTLD_LAZY
 
-_t_opened = {}
-
-def t_dlopen(name):
-# for direct execution: can't use the regular way on FreeBSD :-(
-# 
http://factor-language.blogspot.de/2009/02/note-about-libdl-functions-on-netbsd.html
-import ctypes
-if name:
-name = rffi.charp2str(name)
-else:
-name = None
-try:
-res = ctypes.cdll.LoadLibrary(name)
-except OSError, e:
-raise DLOpenError(str(e))
-h = rffi.cast(rffi.VOIDP, res._handle)
-_t_opened[rffi.cast(rffi.LONG, h)] = res
-return h
-
-def t_dlclose(handle):
-_t_opened.pop(rffi.cast(rffi.LONG, handle))
-return rffi.cast(rffi.INT, 0)
-
-def t_dldym(handle, name):
-import ctypes
-lib = _t_opened[rffi.cast(rffi.LONG, handle)]
-try:
-symbol = lib[name]
-except AttributeError:
-raise KeyError(name)
-res = ctypes.cast(symbol, ctypes.c_void_p)
-return rffi.cast(rffi.VOIDP, res.value or 0)
-
 def dlerror():
 # XXX this would never work on top of ll2ctypes, because
 # ctypes are calling dlerror itself, unsure if I can do much in this
@@ -124,8 +91,6 @@
 def dlopen(name, mode=-1):
  Wrapper around C-level dlopen
 
-if not we_are_translated():
-return t_dlopen(name)
 if mode == -1:
 if RTLD_LOCAL is not None:
 mode = RTLD_LOCAL
@@ -139,16 +104,11 @@
 raise DLOpenError(err)
 return res
 
-def dlclose(handle):
-if not we_are_translated():
-return t_dlclose(handle)
-return c_dlclose(handle)
+dlclose = c_dlclose
 
 def dlsym(libhandle, name):
  Wrapper around C-level dlsym
 
-if not we_are_translated():
-return t_dldym(libhandle, name)
 res = c_dlsym(libhandle, name)
 if not res:
 raise KeyError(name)
diff --git a/rpython/rlib/test/test_rdynload.py 
b/rpython/rlib/test/test_rdynload.py
--- a/rpython/rlib/test/test_rdynload.py
+++ b/rpython/rlib/test/test_rdynload.py
@@ -21,4 +21,3 @@
lltype.Signed)), dlsym(lib, 'abs'))
 assert 1 == handle(1)
 assert 1 == handle(-1)
-dlclose(lib)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy llvm-translation-backend: The operation bare_raw_store() should emit the same code as raw_store().

2013-11-19 Thread Manuel Jacob
Author: Manuel Jacob
Branch: llvm-translation-backend
Changeset: r68252:083d15984f7a
Date: 2013-11-20 02:04 +0100
http://bitbucket.org/pypy/pypy/changeset/083d15984f7a/

Log:The operation bare_raw_store() should emit the same code as
raw_store().

diff --git a/rpython/translator/llvm/genllvm.py 
b/rpython/translator/llvm/genllvm.py
--- a/rpython/translator/llvm/genllvm.py
+++ b/rpython/translator/llvm/genllvm.py
@@ -1343,6 +1343,7 @@
 def op_raw_store(self, result, addr, offset, value):
 addr = self._get_addr(value.type_, addr, offset)
 self.w('store {value.TV}, {addr.TV}'.format(**locals()))
+op_bare_raw_store = op_raw_store
 
 def op_raw_memclear(self, result, ptr, size):
 self.op_direct_call(result, get_repr(llvm_memset), ptr, null_char,
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: revert part of ed5309c80fdf and adapt its test to this branch: py3k doesn't

2013-11-19 Thread pjenvey
Author: Philip Jenvey pjen...@underboss.org
Branch: py3k
Changeset: r68253:a95599228f5a
Date: 2013-11-19 17:26 -0800
http://bitbucket.org/pypy/pypy/changeset/a95599228f5a/

Log:revert part of ed5309c80fdf and adapt its test to this branch: py3k
doesn't need these workarounds

diff --git a/pypy/module/sys/app.py b/pypy/module/sys/app.py
--- a/pypy/module/sys/app.py
+++ b/pypy/module/sys/app.py
@@ -20,13 +20,8 @@
 pass
 
 try:
-encoding = sys.stderr.encoding
-except:
-encoding = None
-
-try:
 from traceback import print_exception
-print_exception(exctype, value, traceback, _encoding=encoding)
+print_exception(exctype, value, traceback)
 except:
 if not excepthook_failsafe(exctype, value):
 raise
diff --git a/pypy/module/sys/test/test_sysmodule.py 
b/pypy/module/sys/test/test_sysmodule.py
--- a/pypy/module/sys/test/test_sysmodule.py
+++ b/pypy/module/sys/test/test_sysmodule.py
@@ -283,8 +283,7 @@
 def getvalue(self):
 return ''.join(self.output)
 
-for input, expectedoutput in [(u\u013a, \xe5),
-  (u\u, \\u)]:
+for input in (\u013a, \u):
 err = MyStringIO()
 err.encoding = 'iso-8859-2'
 sys.stderr = err
@@ -292,12 +291,12 @@
 eh = sys.__excepthook__
 try:
 raise ValueError(input)
-except ValueError, exc:
+except ValueError as exc:
 eh(*sys.exc_info())
 
 sys.stderr = savestderr
-print repr(err.getvalue())
-assert err.getvalue().endswith(ValueError: %s\n % expectedoutput)
+print(ascii(err.getvalue()))
+assert err.getvalue().endswith(ValueError: %s\n % input)
 
 # FIXME: testing the code for a lost or replaced excepthook in
 # Python/pythonrun.c::PyErr_PrintEx() is tricky.
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: 2to3

2013-11-19 Thread pjenvey
Author: Philip Jenvey pjen...@underboss.org
Branch: py3k
Changeset: r68254:422a28c0490d
Date: 2013-11-19 17:44 -0800
http://bitbucket.org/pypy/pypy/changeset/422a28c0490d/

Log:2to3

diff --git a/pypy/module/cpyext/test/test_getargs.py 
b/pypy/module/cpyext/test/test_getargs.py
--- a/pypy/module/cpyext/test/test_getargs.py
+++ b/pypy/module/cpyext/test/test_getargs.py
@@ -174,7 +174,7 @@
 if (!PyArg_ParseTuple(args, s#, buf, y)) {
 return NULL;
 }
-return PyInt_FromSsize_t(y);
+return PyLong_FromSsize_t(y);
 ''')
 if sys.maxsize  2**32:
 expected = 5
@@ -182,7 +182,7 @@
 expected = -0xfffb
 else:
 expected = 0x5
-assert charbuf('12345') == expected
+assert charbuf(b'12345') == expected
 
 def test_pyarg_parse_with_py_ssize_t(self):
 charbuf = self.import_parser(
@@ -192,6 +192,6 @@
 if (!PyArg_ParseTuple(args, s#, buf, y)) {
 return NULL;
 }
-return PyInt_FromSsize_t(y);
+return PyLong_FromSsize_t(y);
 ''', PY_SSIZE_T_CLEAN=True)
-assert charbuf('12345') == 5
+assert charbuf(b'12345') == 5
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: merge default

2013-11-19 Thread pjenvey
Author: Philip Jenvey pjen...@underboss.org
Branch: py3k
Changeset: r68255:6331cf185f84
Date: 2013-11-19 17:44 -0800
http://bitbucket.org/pypy/pypy/changeset/6331cf185f84/

Log:merge default

diff --git a/lib-python/2.7/test/test_multiprocessing.py 
b/lib-python/2.7/test/test_multiprocessing.py
--- a/lib-python/2.7/test/test_multiprocessing.py
+++ b/lib-python/2.7/test/test_multiprocessing.py
@@ -1,5 +1,10 @@
 #!/usr/bin/env python
 
+## FIXME: remove when https://bugs.pypy.org/issue1644 is resolved
+import sys
+if sys.platform.startswith('freebsd'):
+raise Exception(This test hangs on FreeBSD. Test deactivated for now 
until https://bugs.pypy.org/issue1644 get resolved)
+
 #
 # Unit tests for the multiprocessing package
 #
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
@@ -10,6 +10,8 @@
 .. branch: numpy-newbyteorder
 Clean up numpy types, add newbyteorder functionality
 
-.. branch windows-packaging
+.. branch: windows-packaging
 Package tk/tcl runtime with win32
 
+.. branch: armhf-singlefloat
+JIT support for singlefloats on ARM using the hardfloat ABI
diff --git a/pypy/module/micronumpy/interp_dtype.py 
b/pypy/module/micronumpy/interp_dtype.py
--- a/pypy/module/micronumpy/interp_dtype.py
+++ b/pypy/module/micronumpy/interp_dtype.py
@@ -151,6 +151,14 @@
 endian = NPY_NATBYTE
 return space.wrap(%s%s%s % (endian, basic, size))
 
+def descr_get_descr(self, space):
+if not self.is_record_type():
+return space.newlist([space.newtuple([space.wrap(),
+  self.descr_get_str(space)])])
+else:
+raise OperationError(space.w_NotImplementedError, space.wrap(
+descr not implemented for record types))
+
 def descr_get_base(self, space):
 return space.wrap(self.base)
 
@@ -448,6 +456,7 @@
 fields = GetSetProperty(W_Dtype.descr_get_fields),
 names = GetSetProperty(W_Dtype.descr_get_names),
 hasobject = GetSetProperty(W_Dtype.descr_get_hasobject),
+descr = GetSetProperty(W_Dtype.descr_get_descr),
 )
 W_Dtype.typedef.acceptable_as_base_class = False
 
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
@@ -93,7 +93,11 @@
 def descr_fill(self, space, w_value):
 self.fill(self.get_dtype().coerce(space, w_value))
 
-def descr_tostring(self, space):
+def descr_tostring(self, space, w_order=None):
+order = order_converter(space, w_order, NPY_CORDER)
+if order == NPY_FORTRANORDER:
+raise OperationError(space.w_NotImplementedError, space.wrap(
+unsupported value for order))
 return space.wrap(loop.tostring(space, self))
 
 def getitem_filter(self, space, arr):
diff --git a/pypy/module/micronumpy/test/test_dtypes.py 
b/pypy/module/micronumpy/test/test_dtypes.py
--- a/pypy/module/micronumpy/test/test_dtypes.py
+++ b/pypy/module/micronumpy/test/test_dtypes.py
@@ -831,6 +831,17 @@
 assert x.dtype == int8
 assert (x == array(42)).all()
 
+def test_descr(self):
+import numpy as np
+assert np.dtype('i8').descr == [('', 'i8')]
+assert np.dtype('|S4').descr == [('', '|S4')]
+d = [('test', 'i8'), ('blah', 'i2', (2, 3))]
+import sys
+if '__pypy__' in sys.builtin_module_names:
+raises(NotImplementedError, np.dtype(d).descr)
+else:
+assert np.dtype(d).descr == d
+
 class AppTestStrUnicodeDtypes(BaseNumpyAppTest):
 def test_mro(self):
 from numpypy import str_, unicode_, character, flexible, generic
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
@@ -68,7 +68,8 @@
 assert s.start == 1
 assert s.strides == [2, 10, 50]
 assert s.backstrides == [6, 40, 100]
-s = create_slice(self.space, a, [Chunk(1, 5, 3, 2), Chunk(1, 2, 1, 1), 
Chunk(1, 0, 0, 1)])
+s = create_slice(self.space, a, [Chunk(1, 5, 3, 2), Chunk(1, 2, 1, 1),
+ Chunk(1, 0, 0, 1)])
 assert s.shape == [2, 1]
 assert s.strides == [3, 10]
 assert s.backstrides == [3, 0]
@@ -2043,7 +2044,8 @@
 a = array([1, 2], dtype=int64)
 data = a.__reduce__()
 
-assert data[2][4] == 
'\x01\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00'
+assert data[2][4] == '\x01\x00\x00\x00\x00\x00\x00\x00' \
+ '\x02\x00\x00\x00\x00\x00\x00\x00'
 
 pickled_data = dumps(a)
 assert (loads(pickled_data) == a).all()
@@ -2791,9 +2793,11 @@
 assert k[0] == dtype('float16').type(5.)