[pypy-commit] pypy python-numpy: merge with ndarray-attributes

mattip noreply at buildbot.pypy.org
Thu Aug 23 14:10:54 CEST 2012


Author: Matti Picus <matti.picus at gmail.com>
Branch: python-numpy
Changeset: r56816:52d972cfe57c
Date: 2012-08-22 09:48 +0300
http://bitbucket.org/pypy/pypy/changeset/52d972cfe57c/

Log:	merge with ndarray-attributes

diff --git a/pypy/annotation/description.py b/pypy/annotation/description.py
--- a/pypy/annotation/description.py
+++ b/pypy/annotation/description.py
@@ -450,6 +450,12 @@
                     attrs.update(self.basedesc.all_enforced_attrs)
                 self.all_enforced_attrs = attrs
 
+            if (self.is_builtin_exception_class() and
+                self.all_enforced_attrs is None):
+                from pypy.annotation import classdef
+                if self.pyobj not in classdef.FORCE_ATTRIBUTES_INTO_CLASSES:
+                    self.all_enforced_attrs = []    # no attribute allowed
+
     def add_source_attribute(self, name, value, mixin=False):
         if isinstance(value, types.FunctionType):
             # for debugging
diff --git a/pypy/annotation/test/test_annrpython.py b/pypy/annotation/test/test_annrpython.py
--- a/pypy/annotation/test/test_annrpython.py
+++ b/pypy/annotation/test/test_annrpython.py
@@ -3829,7 +3829,7 @@
 
             def next(self):
                 return 1
-        
+
         def fn():
             s = 0
             for x in A():
@@ -3841,6 +3841,24 @@
         assert len(a.translator.graphs) == 3 # fn, __iter__, next
         assert isinstance(s, annmodel.SomeInteger)
 
+    def test_next_function(self):
+        def fn(n):
+            x = [0, 1, n]
+            i = iter(x)
+            return next(i) + next(i)
+
+        a = self.RPythonAnnotator()
+        s = a.build_types(fn, [int])
+        assert isinstance(s, annmodel.SomeInteger)
+
+    def test_no_attr_on_common_exception_classes(self):
+        for cls in [ValueError, Exception]:
+            def fn():
+                e = cls()
+                e.foo = "bar"
+            a = self.RPythonAnnotator()
+            py.test.raises(Exception, a.build_types, fn, [])
+
 def g(n):
     return [0,1,2,n]
 
diff --git a/pypy/conftest.py b/pypy/conftest.py
--- a/pypy/conftest.py
+++ b/pypy/conftest.py
@@ -186,6 +186,9 @@
     def delslice(self, obj, *args):
         obj.__delslice__(*args)
 
+    def is_w(self, obj1, obj2):
+        return obj1 is obj2
+
 def translation_test_so_skip_if_appdirect():
     if option.runappdirect:
         py.test.skip("translation test, skipped for appdirect")
diff --git a/pypy/jit/backend/llsupport/ffisupport.py b/pypy/jit/backend/llsupport/ffisupport.py
--- a/pypy/jit/backend/llsupport/ffisupport.py
+++ b/pypy/jit/backend/llsupport/ffisupport.py
@@ -29,7 +29,7 @@
     if ((not cpu.supports_floats and kind == 'f') or
         (not cpu.supports_longlong and kind == 'L') or
         (not cpu.supports_singlefloats and kind == 'S') or
-        kind == '*'):
+        kind == '*' or kind == '?'):
         raise UnsupportedKind("Unsupported kind '%s'" % kind)
     if kind == 'u':
         kind = 'i'
diff --git a/pypy/jit/backend/x86/assembler.py b/pypy/jit/backend/x86/assembler.py
--- a/pypy/jit/backend/x86/assembler.py
+++ b/pypy/jit/backend/x86/assembler.py
@@ -2667,13 +2667,13 @@
     return AddressLoc(reg_or_imm1, reg_or_imm2, scale, offset)
 
 def addr_add_const(reg_or_imm1, offset):
-    return AddressLoc(reg_or_imm1, ImmedLoc(0), 0, offset)
+    return AddressLoc(reg_or_imm1, imm0, 0, offset)
 
 def mem(loc, offset):
-    return AddressLoc(loc, ImmedLoc(0), 0, offset)
+    return AddressLoc(loc, imm0, 0, offset)
 
 def heap(addr):
-    return AddressLoc(ImmedLoc(addr), ImmedLoc(0), 0, 0)
+    return AddressLoc(ImmedLoc(addr), imm0, 0, 0)
 
 def not_implemented(msg):
     os.write(2, '[x86/asm] %s\n' % msg)
diff --git a/pypy/module/_cffi_backend/ccallback.py b/pypy/module/_cffi_backend/ccallback.py
--- a/pypy/module/_cffi_backend/ccallback.py
+++ b/pypy/module/_cffi_backend/ccallback.py
@@ -93,7 +93,7 @@
 
     def print_error(self, operr):
         space = self.space
-        operr.write_unraisable(space, "in cffi callback", self.w_callable)
+        operr.write_unraisable(space, "cffi callback", self.w_callable)
 
     def write_error_return_value(self, ll_res):
         fresult = self.getfunctype().ctitem
diff --git a/pypy/module/_cffi_backend/ctypearray.py b/pypy/module/_cffi_backend/ctypearray.py
--- a/pypy/module/_cffi_backend/ctypearray.py
+++ b/pypy/module/_cffi_backend/ctypearray.py
@@ -79,6 +79,12 @@
         self.convert_array_from_object(cdata, w_ob)
 
     def convert_to_object(self, cdata):
+        if self.length < 0:
+            # we can't return a <cdata 'int[]'> here, because we don't
+            # know the length to give it.  As a compromize, returns
+            # <cdata 'int *'> in this case.
+            self = self.ctptr
+        #
         return cdataobj.W_CData(self.space, cdata, self)
 
     def add(self, cdata, i):
diff --git a/pypy/module/_cffi_backend/ctypeenum.py b/pypy/module/_cffi_backend/ctypeenum.py
--- a/pypy/module/_cffi_backend/ctypeenum.py
+++ b/pypy/module/_cffi_backend/ctypeenum.py
@@ -24,7 +24,7 @@
                                         name, len(name), align)
         self.enumerators2values = {}   # str -> int
         self.enumvalues2erators = {}   # int -> str
-        for i in range(len(enumerators)):
+        for i in range(len(enumerators)-1, -1, -1):
             self.enumerators2values[enumerators[i]] = enumvalues[i]
             self.enumvalues2erators[enumvalues[i]] = enumerators[i]
 
diff --git a/pypy/module/_cffi_backend/ctypeprim.py b/pypy/module/_cffi_backend/ctypeprim.py
--- a/pypy/module/_cffi_backend/ctypeprim.py
+++ b/pypy/module/_cffi_backend/ctypeprim.py
@@ -246,6 +246,8 @@
         #
         if space.isinstance_w(w_ob, space.w_str):
             value = self.cast_str(w_ob)
+        elif space.isinstance_w(w_ob, space.w_unicode):
+            value = self.cast_unicode(w_ob)
         else:
             value = space.float_w(w_ob)
         w_cdata = cdataobj.W_CDataMem(space, self.size, self)
diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py b/pypy/module/_cffi_backend/test/_backend_test_c.py
--- a/pypy/module/_cffi_backend/test/_backend_test_c.py
+++ b/pypy/module/_cffi_backend/test/_backend_test_c.py
@@ -1,5 +1,24 @@
 # ____________________________________________________________
 
+import sys
+if sys.version_info < (3,):
+    type_or_class = "type"
+    mandatory_b_prefix = ''
+    mandatory_u_prefix = 'u'
+    readbuf = str
+    bufchar = lambda x: x
+    bytechr = chr
+else:
+    type_or_class = "class"
+    long = int
+    unicode = str
+    unichr = chr
+    mandatory_b_prefix = 'b'
+    mandatory_u_prefix = ''
+    readbuf = lambda buf: buf.tobytes()
+    bufchar = ord
+    bytechr = lambda n: bytes([n])
+
 def size_of_int():
     BInt = new_primitive_type("int")
     return sizeof(BInt)
@@ -44,7 +63,7 @@
     p = new_primitive_type("signed char")
     x = cast(p, -65 + 17*256)
     assert repr(x) == "<cdata 'signed char' -65>"
-    assert repr(type(x)) == "<type '_cffi_backend.CData'>"
+    assert repr(type(x)) == "<%s '_cffi_backend.CData'>" % type_or_class
     assert int(x) == -65
     x = cast(p, -66 + (1<<199)*256)
     assert repr(x) == "<cdata 'signed char' -66>"
@@ -72,6 +91,8 @@
         assert int(cast(p, max + 1)) == min
         py.test.raises(TypeError, cast, p, None)
         assert long(cast(p, min - 1)) == max
+        assert int(cast(p, b'\x08')) == 8
+        assert int(cast(p, u'\x08')) == 8
     for name in ['char', 'short', 'int', 'long', 'long long']:
         p = new_primitive_type('unsigned ' + name)
         size = sizeof(p)
@@ -81,6 +102,8 @@
         assert int(cast(p, -1)) == max
         assert int(cast(p, max + 1)) == 0
         assert long(cast(p, -1)) == max
+        assert int(cast(p, b'\xFE')) == 254
+        assert int(cast(p, u'\xFE')) == 254
 
 def test_no_float_on_int_types():
     p = new_primitive_type('long')
@@ -96,7 +119,7 @@
         assert bool(cast(p, -INF))
         assert int(cast(p, -150)) == -150
         assert int(cast(p, 61.91)) == 61
-        assert long(cast(p, 61.91)) == 61L
+        assert long(cast(p, 61.91)) == 61
         assert type(int(cast(p, 61.91))) is int
         assert type(int(cast(p, 1E22))) is long
         assert type(long(cast(p, 61.91))) is long
@@ -112,7 +135,8 @@
 
         assert cast(p, -1.1) != cast(p, -1.1)
         assert repr(float(cast(p, -0.0))) == '-0.0'
-        assert float(cast(p, '\x09')) == 9.0
+        assert float(cast(p, b'\x09')) == 9.0
+        assert float(cast(p, u'\x09')) == 9.0
         assert float(cast(p, True)) == 1.0
         py.test.raises(TypeError, cast, p, None)
 
@@ -154,13 +178,13 @@
     assert bool(cast(p, '\x00'))
     assert cast(p, '\x00') != cast(p, -17*256)
     assert int(cast(p, 'A')) == 65
-    assert long(cast(p, 'A')) == 65L
+    assert long(cast(p, 'A')) == 65
     assert type(int(cast(p, 'A'))) is int
     assert type(long(cast(p, 'A'))) is long
     assert str(cast(p, 'A')) == repr(cast(p, 'A'))
-    assert repr(cast(p, 'A')) == "<cdata 'char' 'A'>"
-    assert repr(cast(p, 255)) == r"<cdata 'char' '\xff'>"
-    assert repr(cast(p, 0)) == r"<cdata 'char' '\x00'>"
+    assert repr(cast(p, 'A')) == "<cdata 'char' %s'A'>" % mandatory_b_prefix
+    assert repr(cast(p, 255)) == r"<cdata 'char' %s'\xff'>" % mandatory_b_prefix
+    assert repr(cast(p, 0)) == r"<cdata 'char' %s'\x00'>" % mandatory_b_prefix
 
 def test_pointer_type():
     p = new_primitive_type("int")
@@ -257,15 +281,17 @@
     py.test.raises(TypeError, newp, BChar, None)
     BPtr = new_pointer_type(BChar)
     p = newp(BPtr, None)
-    assert p[0] == '\x00'
-    p = newp(BPtr, 'A')
-    assert p[0] == 'A'
+    assert p[0] == b'\x00'
+    p = newp(BPtr, b'A')
+    assert p[0] == b'A'
     py.test.raises(TypeError, newp, BPtr, 65)
-    py.test.raises(TypeError, newp, BPtr, "foo")
-    c = cast(BChar, 'A')
+    py.test.raises(TypeError, newp, BPtr, b"foo")
+    py.test.raises(TypeError, newp, BPtr, u"foo")
+    c = cast(BChar, b'A')
     assert str(c) == repr(c)
-    assert int(c) == ord('A')
-    py.test.raises(TypeError, cast, BChar, 'foo')
+    assert int(c) == ord(b'A')
+    py.test.raises(TypeError, cast, BChar, b'foo')
+    py.test.raises(TypeError, cast, BChar, u'foo')
 
 def test_reading_pointer_to_pointer():
     BVoidP = new_pointer_type(new_void_type())
@@ -291,6 +317,9 @@
     assert p[0][0] == 43
 
 def test_load_standard_library():
+    if sys.platform == "win32":
+        py.test.raises(OSError, find_and_load_library, None)
+        return
     x = find_and_load_library(None)
     BVoidP = new_pointer_type(new_void_type())
     assert x.load_function(BVoidP, 'strcpy')
@@ -386,9 +415,9 @@
     assert repr(p2) == "<ctype 'int[][42]'>"
     #
     py.test.raises(OverflowError,
-                   new_array_type, new_pointer_type(p), sys.maxint+1)
+                   new_array_type, new_pointer_type(p), sys.maxsize+1)
     py.test.raises(OverflowError,
-                   new_array_type, new_pointer_type(p), sys.maxint // 3)
+                   new_array_type, new_pointer_type(p), sys.maxsize // 3)
 
 def test_array_instance():
     LENGTH = 1423
@@ -429,7 +458,7 @@
 def test_array_of_unknown_length_instance_with_initializer():
     p = new_primitive_type("int")
     p1 = new_array_type(new_pointer_type(p), None)
-    a = newp(p1, range(42))
+    a = newp(p1, list(range(42)))
     assert len(a) == 42
     a = newp(p1, tuple(range(142)))
     assert len(a) == 142
@@ -437,7 +466,7 @@
 def test_array_initializer():
     p = new_primitive_type("int")
     p1 = new_array_type(new_pointer_type(p), None)
-    a = newp(p1, range(100, 142))
+    a = newp(p1, list(range(100, 142)))
     for i in range(42):
         assert a[i] == 100 + i
     #
@@ -451,7 +480,7 @@
     p = new_primitive_type("int")
     p1 = new_array_type(new_pointer_type(p), 5)    # int[5]
     p2 = new_array_type(new_pointer_type(p1), 3)   # int[3][5]
-    a = newp(p2, [range(n, n+5) for n in [100, 200, 300]])
+    a = newp(p2, [list(range(n, n+5)) for n in [100, 200, 300]])
     assert repr(a) == "<cdata 'int[3][5]' owning %d bytes>" % (
         3*5*size_of_int(),)
     assert repr(a + 0).startswith("<cdata 'int(*)[5]' 0x")
@@ -521,7 +550,7 @@
     p = new_primitive_type("char")
     p1 = new_pointer_type(p)
     n = newp(p1, cast(p, "A"))
-    assert n[0] == "A"
+    assert n[0] == b"A"
 
 def test_cast_between_pointers():
     BIntP = new_pointer_type(new_primitive_type("int"))
@@ -626,7 +655,7 @@
     s.a2 = 123
     assert s.a1 == 0
     assert s.a2 == 123
-    py.test.raises(OverflowError, "s.a1 = sys.maxint+1")
+    py.test.raises(OverflowError, "s.a1 = sys.maxsize+1")
     assert s.a1 == 0
     py.test.raises(AttributeError, "p.foobar")
     py.test.raises(AttributeError, "s.foobar")
@@ -828,12 +857,12 @@
                                        ('a2', BShort, -1)])
     BFunc7 = new_function_type((BStruct,), BShort, False)
     f = cast(BFunc7, _testfunc(7))
-    res = f({'a1': 'A', 'a2': -4042})
-    assert res == -4042 + ord('A')
+    res = f({'a1': b'A', 'a2': -4042})
+    assert res == -4042 + ord(b'A')
     #
-    x = newp(BStructPtr, {'a1': 'A', 'a2': -4042})
+    x = newp(BStructPtr, {'a1': b'A', 'a2': -4042})
     res = f(x[0])
-    assert res == -4042 + ord('A')
+    assert res == -4042 + ord(b'A')
 
 def test_call_function_20():
     BChar = new_primitive_type("char")
@@ -844,11 +873,11 @@
                                        ('a2', BShort, -1)])
     BFunc18 = new_function_type((BStructPtr,), BShort, False)
     f = cast(BFunc18, _testfunc(20))
-    x = newp(BStructPtr, {'a1': 'A', 'a2': -4042})
+    x = newp(BStructPtr, {'a1': b'A', 'a2': -4042})
     # test the exception that allows us to pass a 'struct foo' where the
     # function really expects a 'struct foo *'.
     res = f(x[0])
-    assert res == -4042 + ord('A')
+    assert res == -4042 + ord(b'A')
     assert res == f(x)
 
 def test_call_function_9():
@@ -884,7 +913,7 @@
     BCharA = new_array_type(BCharP, None)
     x = newp(BCharA, 42)
     assert len(x) == 42
-    x = newp(BCharA, "foobar")
+    x = newp(BCharA, b"foobar")
     assert len(x) == 7
 
 def test_load_and_call_function():
@@ -894,10 +923,10 @@
     BFunc = new_function_type((BCharP,), BLong, False)
     ll = find_and_load_library('c')
     strlen = ll.load_function(BFunc, "strlen")
-    input = newp(new_array_type(BCharP, None), "foobar")
+    input = newp(new_array_type(BCharP, None), b"foobar")
     assert strlen(input) == 6
     #
-    assert strlen("foobarbaz") == 9
+    assert strlen(b"foobarbaz") == 9
     #
     BVoidP = new_pointer_type(new_void_type())
     strlenaddr = ll.load_function(BVoidP, "strlen")
@@ -911,6 +940,16 @@
     stderr = ll.read_variable(BVoidP, "stderr")
     assert stderr == cast(BVoidP, _testfunc(8))
 
+def test_read_variable_as_unknown_length_array():
+    if sys.platform == 'win32':
+        py.test.skip("untested")
+    BCharP = new_pointer_type(new_primitive_type("char"))
+    BArray = new_array_type(BCharP, None)
+    ll = find_and_load_library('c')
+    stderr = ll.read_variable(BArray, "stderr")
+    assert repr(stderr).startswith("<cdata 'char *' 0x")
+    # ^^ and not 'char[]', which is basically not allowed and would crash
+
 def test_write_variable():
     if sys.platform == 'win32':
         py.test.skip("untested")
@@ -933,7 +972,8 @@
     f = make_callback()
     assert f(-142) == -141
     assert repr(f).startswith(
-        "<cdata 'int(*)(int)' calling <function cb at 0x")
+        "<cdata 'int(*)(int)' calling <function ")
+    assert "cb at 0x" in repr(f)
     e = py.test.raises(TypeError, f)
     assert str(e.value) == "'int(*)(int)' expects 1 arguments, got 0"
 
@@ -1025,6 +1065,12 @@
     assert repr(cast(BEnum, '#-20')) == "<cdata 'enum foo' 'ab'>"
     assert repr(cast(BEnum, '#-21')) == "<cdata 'enum foo' '#-21'>"
 
+def test_enum_with_non_injective_mapping():
+    BEnum = new_enum_type("foo", ('ab', 'cd'), (7, 7))
+    e = cast(BEnum, 7)
+    assert repr(e) == "<cdata 'enum foo' 'ab'>"
+    assert string(e) == 'ab'
+
 def test_enum_in_struct():
     BEnum = new_enum_type("foo", ('def', 'c', 'ab'), (0, 1, -20))
     BStruct = new_struct_type("bar")
@@ -1053,26 +1099,33 @@
     BInt = new_primitive_type("int")
     BChar = new_primitive_type("char")
     def cb(n):
-        return chr(n)
+        return bytechr(n)
     BFunc = new_function_type((BInt,), BChar)
     f = callback(BFunc, cb)
-    assert f(0) == '\x00'
-    assert f(255) == '\xFF'
+    assert f(0) == b'\x00'
+    assert f(255) == b'\xFF'
+
+def _hacked_pypy_uni4():
+    pyuni4 = {1: True, 2: False}[len(u'\U00012345')]
+    return 'PY_DOT_PY' in globals() and not pyuni4
 
 def test_callback_returning_wchar_t():
     BInt = new_primitive_type("int")
     BWChar = new_primitive_type("wchar_t")
     def cb(n):
-        if n < 0:
+        if n == -1:
             return u'\U00012345'
+        if n == -2:
+            raise ValueError
         return unichr(n)
     BFunc = new_function_type((BInt,), BWChar)
     f = callback(BFunc, cb)
     assert f(0) == unichr(0)
     assert f(255) == unichr(255)
     assert f(0x1234) == u'\u1234'
-    if sizeof(BWChar) == 4:
+    if sizeof(BWChar) == 4 and not _hacked_pypy_uni4():
         assert f(-1) == u'\U00012345'
+    assert f(-2) == u'\x00'   # and an exception printed to stderr
 
 def test_struct_with_bitfields():
     BLong = new_primitive_type("long")
@@ -1170,14 +1223,14 @@
     BChar = new_primitive_type("char")
     BArray1 = new_array_type(new_pointer_type(BChar), 5)
     BArray2 = new_array_type(new_pointer_type(BArray1), 5)
-    a = newp(BArray2, ["abc", "de", "ghij"])
-    assert string(a[1]) == "de"
-    assert string(a[2]) == "ghij"
-    a[2] = "."
-    assert string(a[2]) == "."
-    a[2] = "12345"
-    assert string(a[2]) == "12345"
-    e = py.test.raises(IndexError, 'a[2] = "123456"')
+    a = newp(BArray2, [b"abc", b"de", b"ghij"])
+    assert string(a[1]) == b"de"
+    assert string(a[2]) == b"ghij"
+    a[2] = b"."
+    assert string(a[2]) == b"."
+    a[2] = b"12345"
+    assert string(a[2]) == b"12345"
+    e = py.test.raises(IndexError, 'a[2] = b"123456"')
     assert 'char[5]' in str(e.value)
     assert 'got 6 characters' in str(e.value)
 
@@ -1196,13 +1249,13 @@
 def test_too_many_items():
     BChar = new_primitive_type("char")
     BArray = new_array_type(new_pointer_type(BChar), 5)
-    py.test.raises(IndexError, newp, BArray, ('1', '2', '3', '4', '5', '6'))
-    py.test.raises(IndexError, newp, BArray, ['1', '2', '3', '4', '5', '6'])
-    py.test.raises(IndexError, newp, BArray, '123456')
+    py.test.raises(IndexError, newp, BArray, tuple(b'123456'))
+    py.test.raises(IndexError, newp, BArray, list(b'123456'))
+    py.test.raises(IndexError, newp, BArray, b'123456')
     BStruct = new_struct_type("foo")
     complete_struct_or_union(BStruct, [])
-    py.test.raises(TypeError, newp, new_pointer_type(BStruct), '')
-    py.test.raises(ValueError, newp, new_pointer_type(BStruct), ['1'])
+    py.test.raises(TypeError, newp, new_pointer_type(BStruct), b'')
+    py.test.raises(ValueError, newp, new_pointer_type(BStruct), [b'1'])
 
 def test_more_type_errors():
     BInt = new_primitive_type("int")
@@ -1233,7 +1286,7 @@
     #
     BChar = new_primitive_type("char")
     p = newp(new_pointer_type(BChar), cast(BChar, '!'))
-    assert p[0] == '!'
+    assert p[0] == b'!'
     #
     BFloat = new_primitive_type("float")
     p = newp(new_pointer_type(BFloat), cast(BFloat, 12.25))
@@ -1271,37 +1324,37 @@
 
 def test_string():
     BChar = new_primitive_type("char")
-    assert string(cast(BChar, 42)) == '*'
-    assert string(cast(BChar, 0)) == '\x00'
+    assert string(cast(BChar, 42)) == b'*'
+    assert string(cast(BChar, 0)) == b'\x00'
     BCharP = new_pointer_type(BChar)
     BArray = new_array_type(BCharP, 10)
-    a = newp(BArray, "hello")
+    a = newp(BArray, b"hello")
     assert len(a) == 10
-    assert string(a) == "hello"
+    assert string(a) == b"hello"
     p = a + 2
-    assert string(p) == "llo"
-    assert string(newp(new_array_type(BCharP, 4), "abcd")) == "abcd"
+    assert string(p) == b"llo"
+    assert string(newp(new_array_type(BCharP, 4), b"abcd")) == b"abcd"
     py.test.raises(RuntimeError, string, cast(BCharP, 0))
-    assert string(a, 4) == "hell"
-    assert string(a, 5) == "hello"
-    assert string(a, 6) == "hello"
+    assert string(a, 4) == b"hell"
+    assert string(a, 5) == b"hello"
+    assert string(a, 6) == b"hello"
 
 def test_string_byte():
     BByte = new_primitive_type("signed char")
-    assert string(cast(BByte, 42)) == '*'
-    assert string(cast(BByte, 0)) == '\x00'
+    assert string(cast(BByte, 42)) == b'*'
+    assert string(cast(BByte, 0)) == b'\x00'
     BArray = new_array_type(new_pointer_type(BByte), None)
     a = newp(BArray, [65, 66, 67])
-    assert type(string(a)) is str and string(a) == 'ABC'
+    assert type(string(a)) is bytes and string(a) == b'ABC'
     #
     BByte = new_primitive_type("unsigned char")
-    assert string(cast(BByte, 42)) == '*'
-    assert string(cast(BByte, 0)) == '\x00'
+    assert string(cast(BByte, 42)) == b'*'
+    assert string(cast(BByte, 0)) == b'\x00'
     BArray = new_array_type(new_pointer_type(BByte), None)
     a = newp(BArray, [65, 66, 67])
-    assert type(string(a)) is str and string(a) == 'ABC'
-    if 'PY_DOT_PY' not in globals():
-        assert string(a, 8).startswith('ABC')  # may contain additional garbage
+    assert type(string(a)) is bytes and string(a) == b'ABC'
+    if 'PY_DOT_PY' not in globals() and sys.version_info < (3,):
+        assert string(a, 8).startswith(b'ABC')  # may contain additional garbage
 
 def test_string_wchar():
     BWChar = new_primitive_type("wchar_t")
@@ -1311,7 +1364,7 @@
     BArray = new_array_type(new_pointer_type(BWChar), None)
     a = newp(BArray, [u'A', u'B', u'C'])
     assert type(string(a)) is unicode and string(a) == u'ABC'
-    if 'PY_DOT_PY' not in globals():
+    if 'PY_DOT_PY' not in globals() and sys.version_info < (3,):
         assert string(a, 8).startswith(u'ABC') # may contain additional garbage
 
 def test_string_typeerror():
@@ -1335,12 +1388,12 @@
     BStructPtr = new_pointer_type(BStruct)
     complete_struct_or_union(BStruct, [('a1', BCharArray10, -1)])
     p = newp(BStructPtr, None)
-    assert string(p.a1) == ''
-    p.a1 = 'foo'
-    assert string(p.a1) == 'foo'
-    assert list(p.a1) == ['f', 'o', 'o'] + ['\x00'] * 7
-    p.a1 = ['x', 'y']
-    assert string(p.a1) == 'xyo'
+    assert string(p.a1) == b''
+    p.a1 = b'foo'
+    assert string(p.a1) == b'foo'
+    assert list(p.a1) == [b'f', b'o', b'o'] + [b'\x00'] * 7
+    p.a1 = [b'x', b'y']
+    assert string(p.a1) == b'xyo'
 
 def test_invalid_function_result_types():
     BFunc = new_function_type((), new_void_type())
@@ -1366,7 +1419,7 @@
     f = cast(BFunc10, _testfunc(10))
     s = f(40)
     assert repr(s) == "<cdata 'struct foo_s' owning 4 bytes>"
-    assert s.a1 == chr(40)
+    assert s.a1 == bytechr(40)
     assert s.a2 == 40 * 40
     #
     BStruct11 = new_struct_type("test11")
@@ -1465,12 +1518,16 @@
     BInt = new_primitive_type("int")
     pyuni4 = {1: True, 2: False}[len(u'\U00012345')]
     wchar4 = {2: False, 4: True}[sizeof(BWChar)]
-    assert str(cast(BWChar, 0x45)) == "<cdata 'wchar_t' u'E'>"
-    assert str(cast(BWChar, 0x1234)) == "<cdata 'wchar_t' u'\u1234'>"
+    assert str(cast(BWChar, 0x45)) == "<cdata 'wchar_t' %s'E'>" % (
+        mandatory_u_prefix,)
+    assert str(cast(BWChar, 0x1234)) == "<cdata 'wchar_t' %s'\u1234'>" % (
+        mandatory_u_prefix,)
     if wchar4:
-        x = cast(BWChar, 0x12345)
-        assert str(x) == "<cdata 'wchar_t' u'\U00012345'>"
-        assert int(x) == 0x12345
+        if not _hacked_pypy_uni4():
+            x = cast(BWChar, 0x12345)
+            assert str(x) == "<cdata 'wchar_t' %s'\U00012345'>" % (
+                mandatory_u_prefix,)
+            assert int(x) == 0x12345
     else:
         assert not pyuni4
     #
@@ -1482,8 +1539,8 @@
     s = newp(BStructPtr)
     s.a1 = u'\x00'
     assert s.a1 == u'\x00'
-    py.test.raises(TypeError, "s.a1 = 'a'")
-    py.test.raises(TypeError, "s.a1 = '\xFF'")
+    py.test.raises(TypeError, "s.a1 = b'a'")
+    py.test.raises(TypeError, "s.a1 = bytechr(0xFF)")
     s.a1 = u'\u1234'
     assert s.a1 == u'\u1234'
     if pyuni4:
@@ -1491,10 +1548,11 @@
         s.a1 = u'\U00012345'
         assert s.a1 == u'\U00012345'
     elif wchar4:
-        s.a1 = cast(BWChar, 0x12345)
-        assert s.a1 == u'\ud808\udf45'
-        s.a1 = u'\ud807\udf44'
-        assert s.a1 == u'\U00011f44'
+        if not _hacked_pypy_uni4():
+            s.a1 = cast(BWChar, 0x12345)
+            assert s.a1 == u'\ud808\udf45'
+            s.a1 = u'\ud807\udf44'
+            assert s.a1 == u'\U00011f44'
     else:
         py.test.raises(TypeError, "s.a1 = u'\U00012345'")
     #
@@ -1510,7 +1568,7 @@
     assert string(a) == u'hello - world!'
     assert str(a) == repr(a)
     #
-    if wchar4:
+    if wchar4 and not _hacked_pypy_uni4():
         u = u'\U00012345\U00012346\U00012347'
         a = newp(BWCharArray, u)
         assert len(a) == 4
@@ -1523,25 +1581,26 @@
         py.test.raises(IndexError, 'a[4]')
     #
     w = cast(BWChar, 'a')
-    assert repr(w) == "<cdata 'wchar_t' u'a'>"
+    assert repr(w) == "<cdata 'wchar_t' %s'a'>" % mandatory_u_prefix
     assert str(w) == repr(w)
     assert string(w) == u'a'
     assert int(w) == ord('a')
     w = cast(BWChar, 0x1234)
-    assert repr(w) == "<cdata 'wchar_t' u'\u1234'>"
+    assert repr(w) == "<cdata 'wchar_t' %s'\u1234'>" % mandatory_u_prefix
     assert str(w) == repr(w)
     assert string(w) == u'\u1234'
     assert int(w) == 0x1234
     w = cast(BWChar, u'\u8234')
-    assert repr(w) == "<cdata 'wchar_t' u'\u8234'>"
+    assert repr(w) == "<cdata 'wchar_t' %s'\u8234'>" % mandatory_u_prefix
     assert str(w) == repr(w)
     assert string(w) == u'\u8234'
     assert int(w) == 0x8234
     w = cast(BInt, u'\u1234')
     assert repr(w) == "<cdata 'int' 4660>"
-    if wchar4:
+    if wchar4 and not _hacked_pypy_uni4():
         w = cast(BWChar, u'\U00012345')
-        assert repr(w) == "<cdata 'wchar_t' u'\U00012345'>"
+        assert repr(w) == "<cdata 'wchar_t' %s'\U00012345'>" % (
+            mandatory_u_prefix,)
         assert str(w) == repr(w)
         assert string(w) == u'\U00012345'
         assert int(w) == 0x12345
@@ -1574,7 +1633,7 @@
     f = callback(BFunc, cb, -42)
     assert f(u'a\u1234b') == 3
     #
-    if wchar4 and not pyuni4:
+    if wchar4 and not pyuni4 and not _hacked_pypy_uni4():
         # try out-of-range wchar_t values
         x = cast(BWChar, 1114112)
         py.test.raises(ValueError, string, x)
@@ -1676,27 +1735,31 @@
     s = newp(new_pointer_type(BShort), 100)
     assert sizeof(s) == size_of_ptr()
     assert sizeof(BShort) == 2
-    assert len(str(buffer(s))) == 2
+    assert len(readbuf(buffer(s))) == 2
     #
     BChar = new_primitive_type("char")
     BCharArray = new_array_type(new_pointer_type(BChar), None)
-    c = newp(BCharArray, "hi there")
+    c = newp(BCharArray, b"hi there")
     buf = buffer(c)
-    assert str(buf) == "hi there\x00"
-    assert len(buf) == len("hi there\x00")
-    assert buf[0] == 'h'
-    assert buf[2] == ' '
-    assert list(buf) == ['h', 'i', ' ', 't', 'h', 'e', 'r', 'e', '\x00']
-    buf[2] = '-'
-    assert c[2] == '-'
-    assert str(buf) == "hi-there\x00"
-    buf[:2] = 'HI'
-    assert string(c) == 'HI-there'
-    assert buf[:4:2] == 'H-'
+    assert readbuf(buf) == b"hi there\x00"
+    assert len(buf) == len(b"hi there\x00")
+    assert buf[0] == bufchar('h')
+    assert buf[2] == bufchar(' ')
+    assert list(buf) == list(map(bufchar, "hi there\x00"))
+    buf[2] = bufchar('-')
+    assert c[2] == b'-'
+    assert readbuf(buf) == b"hi-there\x00"
+    c[2] = b'!'
+    assert buf[2] == bufchar('!')
+    assert readbuf(buf) == b"hi!there\x00"
+    c[2] = b'-'
+    buf[:2] = b'HI'
+    assert string(c) == b'HI-there'
+    assert buf[:4:2] == b'H-'
     if '__pypy__' not in sys.builtin_module_names:
         # XXX pypy doesn't support the following assignment so far
-        buf[:4:2] = 'XY'
-        assert string(c) == 'XIYthere'
+        buf[:4:2] = b'XY'
+        assert string(c) == b'XIYthere'
 
 def test_getcname():
     BUChar = new_primitive_type("unsigned char")
diff --git a/pypy/module/_cffi_backend/test/_test_lib.c b/pypy/module/_cffi_backend/test/_test_lib.c
--- a/pypy/module/_cffi_backend/test/_test_lib.c
+++ b/pypy/module/_cffi_backend/test/_test_lib.c
@@ -2,6 +2,12 @@
 #include <stdarg.h>
 #include <errno.h>
 
+#ifdef _WIN32
+#define DLLEXPORT __declspec(dllexport)
+#else
+#define DLLEXPORT
+#endif
+
 static char _testfunc0(char a, char b)
 {
     return a + b;
@@ -140,7 +146,7 @@
     return ptr->a1 + ptr->a2;
 }
 
-void *gettestfunc(int num)
+DLLEXPORT void *gettestfunc(int num)
 {
     void *f;
     switch (num) {
diff --git a/pypy/module/_cffi_backend/test/test_c.py b/pypy/module/_cffi_backend/test/test_c.py
--- a/pypy/module/_cffi_backend/test/test_c.py
+++ b/pypy/module/_cffi_backend/test/test_c.py
@@ -4,6 +4,9 @@
 'test_c.py' from cffi/c/.
 """
 import py, sys, ctypes
+if sys.version_info < (2, 6):
+    py.test.skip("requires the b'' literal syntax")
+
 from pypy.tool.udir import udir
 from pypy.conftest import gettestobjspace, option
 from pypy.interpreter import gateway
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
@@ -432,6 +432,7 @@
 
 W_VoidBox.typedef = TypeDef("void", W_FlexibleBox.typedef,
     __module__ = "numpypy",
+    __new__ = interp2app(W_VoidBox.descr__new__.im_func),
     __getitem__ = interp2app(W_VoidBox.descr_getitem),
     __setitem__ = interp2app(W_VoidBox.descr_setitem),
 )
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
@@ -8,6 +8,7 @@
 from pypy.module.micronumpy import types, interp_boxes
 from pypy.rlib.objectmodel import specialize
 from pypy.rlib.rarithmetic import LONG_BIT, r_longlong, r_ulonglong
+from pypy.rpython.lltypesystem import rffi
 
 
 UNSIGNEDLTR = "u"
@@ -17,6 +18,8 @@
 VOIDLTR = 'V'
 STRINGLTR = 'S'
 UNICODELTR = 'U'
+INTPLTR = 'p'
+UINTPLTR = 'P'
 
 class W_Dtype(Wrappable):
     _immutable_fields_ = ["itemtype", "num", "kind"]
@@ -415,6 +418,35 @@
             #alternate_constructors=[space.w_buffer],
             # XXX no buffer in space
         )
+        ptr_size = rffi.sizeof(rffi.CCHARP)
+        if ptr_size == 4:
+            intp_box = interp_boxes.W_Int32Box
+            intp_type = types.Int32()
+            uintp_box = interp_boxes.W_UInt32Box
+            uintp_type = types.UInt32()
+        elif ptr_size == 8:
+            intp_box = interp_boxes.W_Int64Box
+            intp_type = types.Int64()
+            uintp_box = interp_boxes.W_UInt64Box
+            uintp_type = types.UInt64()
+        else:
+            raise ValueError('unknown point size %d' % ptr_size)
+        self.w_intpdtype = W_Dtype(
+            intp_type,
+            num=5,
+            kind=INTPLTR,
+            name='intp',
+            char=INTPLTR,
+            w_box_type = space.gettypefor(intp_box),
+        )    
+        self.w_uintpdtype = W_Dtype(
+            uintp_type,
+            num=6,
+            kind=UINTPLTR,
+            name='uintp',
+            char=UINTPLTR,
+            w_box_type = space.gettypefor(uintp_box),
+        )    
         self.builtin_dtypes = [
             self.w_booldtype, self.w_int8dtype, self.w_uint8dtype,
             self.w_int16dtype, self.w_uint16dtype, self.w_int32dtype,
@@ -422,7 +454,7 @@
             self.w_int64dtype, self.w_uint64dtype,
             self.w_float32dtype,
             self.w_float64dtype, self.w_stringdtype, self.w_unicodedtype,
-            self.w_voiddtype,
+            self.w_voiddtype, self.w_intpdtype, self.w_uintpdtype,
         ]
         self.float_dtypes_by_num_bytes = sorted(
             (dtype.itemtype.get_element_size(), dtype)
@@ -464,7 +496,8 @@
             #'CDOUBLE',
             #'DATETIME',
             'UINT': self.w_uint32dtype,
-            'INTP': self.w_longdtype,
+            'INTP': self.w_intpdtype,
+            'UINTP': self.w_uintpdtype,
             #'HALF',
             'BYTE': self.w_int8dtype,
             #'CFLOAT': ,
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
@@ -727,6 +727,149 @@
     def descr_repeat(self, space, repeats, w_axis=None):
         return repeat(space, self, repeats, w_axis)
 
+    def descr_argsort(self, space, w_axis=-1, w_kind='quicksort', w_order=None):
+        raise OperationError(space.w_NotImplementedError, space.wrap(
+            "argsort not implemented yet"))
+
+    def descr_astype(self, space, w_type):
+        raise OperationError(space.w_NotImplementedError, space.wrap(
+            "astype not implemented yet"))
+
+    def descr_base(self, space):
+        raise OperationError(space.w_NotImplementedError, space.wrap(
+            "base not implemented yet"))
+
+    def descr_byteswap(self, space, w_inplace=False):
+        raise OperationError(space.w_NotImplementedError, space.wrap(
+            "byteswap not implemented yet"))
+
+    def descr_choose(self, space, w_choices, w_out=None, w_mode='raise'):
+        raise OperationError(space.w_NotImplementedError, space.wrap(
+            "choose not implemented yet"))
+
+    def descr_clip(self, space, w_min, w_max, w_out=None):
+        raise OperationError(space.w_NotImplementedError, space.wrap(
+            "clip not implemented yet"))
+
+    def descr_conj(self, space):
+        raise OperationError(space.w_NotImplementedError, space.wrap(
+            "conj not implemented yet"))
+
+    def descr_ctypes(self, space):
+        raise OperationError(space.w_NotImplementedError, space.wrap(
+            "ctypes not implemented yet"))
+
+    def descr_cumprod(self, space, w_axis=None, w_dtype=None, w_out=None): 
+        raise OperationError(space.w_NotImplementedError, space.wrap(
+            "cumprod not implemented yet"))
+
+    def descr_cumsum(self, space, w_axis=None, w_dtype=None, w_out=None): 
+        raise OperationError(space.w_NotImplementedError, space.wrap(
+            "cumsum not implemented yet"))
+
+    def descr_data(self, space):
+        raise OperationError(space.w_NotImplementedError, space.wrap(
+            "data not implemented yet"))
+
+    def descr_diagonal(self, space, w_offset=0, w_axis1=0, w_axis2=1): 
+        raise OperationError(space.w_NotImplementedError, space.wrap(
+            "diagonal not implemented yet"))
+
+    def descr_dump(self, space, w_file):
+        raise OperationError(space.w_NotImplementedError, space.wrap(
+            "dump not implemented yet"))
+
+    def descr_dumps(self, space):
+        raise OperationError(space.w_NotImplementedError, space.wrap(
+            "dumps not implemented yet"))
+
+    def descr_get_flags(self, space):
+        raise OperationError(space.w_NotImplementedError, space.wrap(
+            "getting flags not implemented yet"))
+
+    def descr_set_flags(self, space, w_args):
+        raise OperationError(space.w_NotImplementedError, space.wrap(
+            "setting flags not implemented yet"))
+
+    @unwrap_spec(offset=int)    
+    def descr_getfield(self, space, w_dtype, offset):
+        raise OperationError(space.w_NotImplementedError, space.wrap(
+            "getfield not implemented yet"))
+
+    def descr_imag(self, space):
+        raise OperationError(space.w_NotImplementedError, space.wrap(
+            "imag not implemented yet"))
+
+    def descr_itemset(self, space, w_arg):
+        raise OperationError(space.w_NotImplementedError, space.wrap(
+            "itemset not implemented yet"))
+
+    @unwrap_spec(neworder=str)    
+    def descr_newbyteorder(self, space, neworder):
+        raise OperationError(space.w_NotImplementedError, space.wrap(
+            "newbyteorder not implemented yet"))
+
+    def descr_ptp(self, space, w_axis=None, w_out=None):
+        raise OperationError(space.w_NotImplementedError, space.wrap(
+            "ptp (peak to peak) not implemented yet"))
+
+    def descr_put(self, space, w_indices, w_values, w_mode='raise'):
+        raise OperationError(space.w_NotImplementedError, space.wrap(
+            "put not implemented yet"))
+
+    def descr_real(self, space):
+        raise OperationError(space.w_NotImplementedError, space.wrap(
+            "real not implemented yet"))
+
+    def descr_resize(self, space, w_new_shape, w_refcheck=True):
+        raise OperationError(space.w_NotImplementedError, space.wrap(
+            "resize not implemented yet"))
+
+    def descr_round(self, space, w_decimals=0, w_out=None):
+        raise OperationError(space.w_NotImplementedError, space.wrap(
+            "round not implemented yet"))
+
+    def descr_searchsorted(self, space, w_v, w_side='left'):
+        raise OperationError(space.w_NotImplementedError, space.wrap(
+            "searchsorted not implemented yet"))
+
+    def descr_setasflat(self, space, w_v):
+        raise OperationError(space.w_NotImplementedError, space.wrap(
+            "setasflat not implemented yet"))
+
+    def descr_setfield(self, space, w_val, w_dtype, w_offset=0):
+        raise OperationError(space.w_NotImplementedError, space.wrap(
+            "setfield not implemented yet"))
+
+    def descr_setflags(self, space, w_write=None, w_align=None, w_uic=None): 
+        raise OperationError(space.w_NotImplementedError, space.wrap(
+            "setflags not implemented yet"))
+
+    def descr_sort(self, space, w_axis=-1, w_kind='quicksort', w_order=None):
+        raise OperationError(space.w_NotImplementedError, space.wrap(
+            "sort not implemented yet"))
+
+    def descr_squeeze(self, space):
+        raise OperationError(space.w_NotImplementedError, space.wrap(
+            "squeeze not implemented yet"))
+
+    def descr_strides(self, space):
+        raise OperationError(space.w_NotImplementedError, space.wrap(
+            "strides not implemented yet"))
+
+    def descr_tofile(self, space, w_fid, w_sep="", w_format="%s"):
+        raise OperationError(space.w_NotImplementedError, space.wrap(
+            "tofile not implemented yet"))
+
+    def descr_trace(self, space, w_offset=0, w_axis1=0, w_axis2=1,
+                    w_dtype=None, w_out=None): 
+        raise OperationError(space.w_NotImplementedError, space.wrap(
+            "trace not implemented yet"))
+
+    def descr_view(self, space, w_dtype=None, w_type=None) :
+        raise OperationError(space.w_NotImplementedError, space.wrap(
+            "view not implemented yet"))
+
 def convert_to_array(space, w_obj):
     if isinstance(w_obj, BaseArray):
         return w_obj
@@ -1492,6 +1635,43 @@
     compress = interp2app(BaseArray.descr_compress),
     repeat = interp2app(BaseArray.descr_repeat),
     count_nonzero = interp2app(BaseArray.descr_count_nonzero),
+
+    argsort = interp2app(BaseArray.descr_argsort),
+    astype = interp2app(BaseArray.descr_astype),
+    base = GetSetProperty(BaseArray.descr_base),
+    byteswap = interp2app(BaseArray.descr_byteswap),
+    choose = interp2app(BaseArray.descr_choose),
+    clip = interp2app(BaseArray.descr_clip),
+    conj = interp2app(BaseArray.descr_conj),
+    conjugate = interp2app(BaseArray.descr_conj),
+    ctypes = GetSetProperty(BaseArray.descr_ctypes),
+    cumprod = interp2app(BaseArray.descr_cumprod),
+    cumsum = interp2app(BaseArray.descr_cumsum),
+    data = GetSetProperty(BaseArray.descr_data),
+    diagonal = interp2app(BaseArray.descr_diagonal),
+    dump = interp2app(BaseArray.descr_dump),
+    dumps = interp2app(BaseArray.descr_dumps),
+    flags = GetSetProperty(BaseArray.descr_get_flags,
+                           BaseArray.descr_set_flags),
+    getfield = interp2app(BaseArray.descr_getfield),
+    imag = GetSetProperty(BaseArray.descr_imag),
+    itemset = interp2app(BaseArray.descr_itemset),
+    newbyteorder = interp2app(BaseArray.descr_newbyteorder),
+    ptp = interp2app(BaseArray.descr_ptp),
+    put = interp2app(BaseArray.descr_put),
+    real = GetSetProperty(BaseArray.descr_real),
+    resize = interp2app(BaseArray.descr_resize),
+    round = interp2app(BaseArray.descr_round),
+    searchsorted = interp2app(BaseArray.descr_searchsorted),
+    setasflat = interp2app(BaseArray.descr_setasflat),
+    setfield = interp2app(BaseArray.descr_setfield),
+    setflags = interp2app(BaseArray.descr_setflags),
+    sort = interp2app(BaseArray.descr_sort),
+    squeeze = interp2app(BaseArray.descr_squeeze),
+    strides = GetSetProperty(BaseArray.descr_strides),
+    tofile = interp2app(BaseArray.descr_tofile),
+    trace = interp2app(BaseArray.descr_trace),
+    view = interp2app(BaseArray.descr_view),
 )
 
 
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
@@ -31,6 +31,8 @@
         from _numpypy import dtype
 
         assert dtype(bool).num == 0
+        assert dtype('intp').num == 5
+        assert dtype('uintp').num == 6
         assert dtype(int).num == 7
         assert dtype(long).num == 9
         assert dtype(float).num == 12
@@ -176,10 +178,15 @@
 
     def test_cant_subclass(self):
         from _numpypy import dtype
-
         # You can't subclass dtype
         raises(TypeError, type, "Foo", (dtype,), {})
 
+    def test_can_subclass(self):
+        import _numpypy
+        class xyz(_numpypy.void):
+            pass
+        assert True
+
     def test_aliases(self):
         from _numpypy import dtype
 
@@ -228,6 +235,17 @@
 
 
 class AppTestTypes(BaseNumpyAppTest):
+    def setup_class(cls):
+        BaseNumpyAppTest.setup_class.im_func(cls)
+        if option.runappdirect:
+            import platform
+            bits, linkage = platform.architecture()
+            ptr_size = int(bits[:-3]) // 8
+        else:
+            from pypy.rpython.lltypesystem import rffi
+            ptr_size = rffi.sizeof(rffi.CCHARP)
+        cls.w_ptr_size = cls.space.wrap(ptr_size)
+
     def test_abstract_types(self):
         import _numpypy as numpy
         raises(TypeError, numpy.generic, 0)
@@ -269,7 +287,9 @@
     def test_int8(self):
         import _numpypy as numpy
 
-        assert numpy.int8.mro() == [numpy.int8, numpy.signedinteger, numpy.integer, numpy.number, numpy.generic, object]
+        assert numpy.int8.mro() == [numpy.int8, numpy.signedinteger,
+                                    numpy.integer, numpy.number, 
+                                    numpy.generic, object]
 
         a = numpy.array([1, 2, 3], numpy.int8)
         assert type(a[1]) is numpy.int8
@@ -291,7 +311,9 @@
     def test_uint8(self):
         import _numpypy as numpy
 
-        assert numpy.uint8.mro() == [numpy.uint8, numpy.unsignedinteger, numpy.integer, numpy.number, numpy.generic, object]
+        assert numpy.uint8.mro() == [numpy.uint8, numpy.unsignedinteger, 
+                                     numpy.integer, numpy.number, 
+                                     numpy.generic, object]
 
         a = numpy.array([1, 2, 3], numpy.uint8)
         assert type(a[1]) is numpy.uint8
@@ -361,16 +383,22 @@
         import _numpypy as numpy
 
         assert numpy.int_ is numpy.dtype(int).type
-        assert numpy.int_.mro() == [numpy.int_, numpy.signedinteger, numpy.integer, numpy.number, numpy.generic, int, object]
+        assert numpy.int_.mro() == [numpy.int_, numpy.signedinteger, 
+                                    numpy.integer, numpy.number, 
+                                    numpy.generic, int, object]
 
     def test_int64(self):
         import sys
         import _numpypy as numpy
 
         if sys.maxint == 2 ** 63 -1:
-            assert numpy.int64.mro() == [numpy.int64, numpy.signedinteger, numpy.integer, numpy.number, numpy.generic, int, object]
+            assert numpy.int64.mro() == [numpy.int64, numpy.signedinteger, 
+                                         numpy.integer, numpy.number, 
+                                         numpy.generic, int, object]
         else:
-            assert numpy.int64.mro() == [numpy.int64, numpy.signedinteger, numpy.integer, numpy.number, numpy.generic, object]
+            assert numpy.int64.mro() == [numpy.int64, numpy.signedinteger, 
+                                         numpy.integer, numpy.number, 
+                                         numpy.generic, object]
 
         assert numpy.dtype(numpy.int64).type is numpy.int64
         assert numpy.int64(3) == 3
@@ -385,7 +413,9 @@
         import sys
         import _numpypy as numpy
 
-        assert numpy.uint64.mro() == [numpy.uint64, numpy.unsignedinteger, numpy.integer, numpy.number, numpy.generic, object]
+        assert numpy.uint64.mro() == [numpy.uint64, numpy.unsignedinteger, 
+                                      numpy.integer, numpy.number, 
+                                      numpy.generic, object]
 
         assert numpy.dtype(numpy.uint64).type is numpy.uint64
         skip("see comment")
@@ -400,7 +430,9 @@
     def test_float32(self):
         import _numpypy as numpy
 
-        assert numpy.float32.mro() == [numpy.float32, numpy.floating, numpy.inexact, numpy.number, numpy.generic, object]
+        assert numpy.float32.mro() == [numpy.float32, numpy.floating, 
+                                       numpy.inexact, numpy.number, 
+                                       numpy.generic, object]
 
         assert numpy.float32(12) == numpy.float64(12)
         assert numpy.float32('23.4') == numpy.float32(23.4)
@@ -409,7 +441,9 @@
     def test_float64(self):
         import _numpypy as numpy
 
-        assert numpy.float64.mro() == [numpy.float64, numpy.floating, numpy.inexact, numpy.number, numpy.generic, float, object]
+        assert numpy.float64.mro() == [numpy.float64, numpy.floating, 
+                                       numpy.inexact, numpy.number, 
+                                       numpy.generic, float, object]
 
         a = numpy.array([1, 2, 3], numpy.float64)
         assert type(a[1]) is numpy.float64
@@ -450,15 +484,16 @@
 
     def test_various_types(self):
         import _numpypy as numpy
-        import sys
 
         assert numpy.int16 is numpy.short
         assert numpy.int8 is numpy.byte
         assert numpy.bool_ is numpy.bool8
-        if sys.maxint == (1 << 63) - 1:
+        if self.ptr_size == 4:
+            assert numpy.intp is numpy.int32
+            assert numpy.uintp is numpy.uint32
+        elif self.ptr_size == 8:
             assert numpy.intp is numpy.int64
-        else:
-            assert numpy.intp is numpy.int32
+            assert numpy.uintp is numpy.uint64
 
     def test_mro(self):
         import _numpypy as numpy
@@ -504,6 +539,11 @@
         assert dtype('=i8').byteorder == '='
         assert dtype(byteorder + 'i8').byteorder == '='
 
+    def test_intp(self):
+        from _numpypy import dtype
+        assert dtype('p') == dtype('intp')
+        assert dtype('P') == dtype('uintp')
+
     def test_alignment(self):
         from _numpypy import dtype
         assert dtype('i4').alignment == 4
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
@@ -2261,4 +2261,17 @@
         assert arr[1]['y']['y'] == 3.5
         assert arr[1]['y']['x'] == 0.0
         assert arr[1]['x'] == 15
-        
+
+    def test_string_record(self):
+        from _numpypy import dtype, array
+        d = dtype([('x', str), ('y', 'int32')])
+        assert d.fields['x'] == (dtype(str), 0)
+        assert d.fields['y'] == (dtype('int32'), 1)
+        d = dtype([('x', 'S1'), ('y', 'int32')])
+        assert d.fields['x'] == (dtype(str), 0)
+        assert d.fields['y'] == (dtype('int32'), 1)
+        a = array([('a', 2), ('c', 1)], dtype=d)
+        assert a[0]['x'] == 'a'
+        assert a[1]['y'] == 1
+
+       
diff --git a/pypy/module/signal/interp_signal.py b/pypy/module/signal/interp_signal.py
--- a/pypy/module/signal/interp_signal.py
+++ b/pypy/module/signal/interp_signal.py
@@ -364,6 +364,15 @@
 @jit.dont_look_inside
 @unwrap_spec(which=int, first=float, interval=float)
 def setitimer(space, which, first, interval=0):
+    """setitimer(which, seconds[, interval])
+    
+    Sets given itimer (one of ITIMER_REAL, ITIMER_VIRTUAL
+    or ITIMER_PROF) to fire after value seconds and after
+    that every interval seconds.
+    The itimer can be cleared by setting seconds to zero.
+    
+    Returns old values as a tuple: (delay, interval).
+    """
     with lltype.scoped_alloc(itimervalP.TO, 1) as new:
 
         timeval_from_double(first, new[0].c_it_value)
@@ -381,6 +390,10 @@
 @jit.dont_look_inside
 @unwrap_spec(which=int)
 def getitimer(space, which):
+    """getitimer(which)
+    
+    Returns current value of given itimer.
+    """
     with lltype.scoped_alloc(itimervalP.TO, 1) as old:
 
         c_getitimer(which, old)
diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py
--- a/pypy/objspace/descroperation.py
+++ b/pypy/objspace/descroperation.py
@@ -229,13 +229,15 @@
         return space.get_and_call_function(w_descr, w_obj, w_name)
 
     def is_true(space, w_obj):
-        method = "__nonzero__"
-        w_descr = space.lookup(w_obj, method)
+        w_descr = space.lookup(w_obj, "__nonzero__")
         if w_descr is None:
-            method = "__len__"
-            w_descr = space.lookup(w_obj, method)
+            w_descr = space.lookup(w_obj, "__len__")
             if w_descr is None:
                 return True
+            # call __len__
+            w_res = space.get_and_call_function(w_descr, w_obj)
+            return space._check_len_result(w_res) != 0
+        # call __nonzero__
         w_res = space.get_and_call_function(w_descr, w_obj)
         # more shortcuts for common cases
         if space.is_w(w_res, space.w_False):
@@ -245,11 +247,10 @@
         w_restype = space.type(w_res)
         # Note there is no check for bool here because the only possible
         # instances of bool are w_False and w_True, which are checked above.
-        if (space.is_w(w_restype, space.w_int) or
-            space.is_w(w_restype, space.w_long)):
+        if space.is_w(w_restype, space.w_int):
             return space.int_w(w_res) != 0
         else:
-            msg = "%s should return bool or integer" % (method,)
+            msg = "__nonzero__ should return bool or integer"
             raise OperationError(space.w_TypeError, space.wrap(msg))
 
     def nonzero(space, w_obj):
diff --git a/pypy/objspace/flow/operation.py b/pypy/objspace/flow/operation.py
--- a/pypy/objspace/flow/operation.py
+++ b/pypy/objspace/flow/operation.py
@@ -236,6 +236,7 @@
         name = line[0]
         if hasattr(operator, name):
             Table.append((name, getattr(operator, name)))
+    Table.append(('next', __builtin__.next))
     # build the dictionaries
     for name, func in Table:
         if name not in FunctionByName:
diff --git a/pypy/objspace/test/test_descroperation.py b/pypy/objspace/test/test_descroperation.py
--- a/pypy/objspace/test/test_descroperation.py
+++ b/pypy/objspace/test/test_descroperation.py
@@ -658,7 +658,7 @@
         class X(object):
             def __len__(self): return 1L
             __nonzero__ = __len__
-        assert X()
+        raises(TypeError, bool, X())  # must return bool or int, not long
         del X.__nonzero__
         assert X()
 
@@ -668,6 +668,7 @@
             def __len__(self):
                 return sys.maxsize + 1
         raises(OverflowError, len, X())
+        raises(OverflowError, bool, X())
 
     def test_len_underflow(self):
         import sys
@@ -675,10 +676,12 @@
             def __len__(self):
                 return -1
         raises(ValueError, len, X())
+        raises(ValueError, bool, X())
         class Y(object):
             def __len__(self):
                 return -1L
         raises(ValueError, len, Y())
+        raises(ValueError, bool, Y())
 
     def test_len_custom__int__(self):
         class X(object):
@@ -691,8 +694,12 @@
 
         l = len(X(3.0))
         assert l == 3 and type(l) is int
+        assert X(3.0)
+        assert not X(0.0)
         l = len(X(X(2)))
         assert l == 2 and type(l) is int
+        assert X(X(2))
+        assert not X(X(0))
 
     def test_bool___contains__(self):
         class X(object):
diff --git a/pypy/rlib/jit_libffi.py b/pypy/rlib/jit_libffi.py
--- a/pypy/rlib/jit_libffi.py
+++ b/pypy/rlib/jit_libffi.py
@@ -108,7 +108,8 @@
     def getkind(ffi_type):
         """Returns 'v' for void, 'f' for float, 'i' for signed integer,
         'u' for unsigned integer, 'S' for singlefloat, 'L' for long long
-        integer (signed or unsigned), or '*' for struct.
+        integer (signed or unsigned), '*' for struct, or '?' for others
+        (e.g. long double).
         """
         if   ffi_type == types.void:    return 'v'
         elif ffi_type == types.double:  return 'f'
@@ -136,7 +137,7 @@
         elif ffi_type == types.uint64:  return 'L'
         #
         elif types.is_struct(ffi_type): return '*'
-        raise KeyError
+        return '?'
 
     @staticmethod
     @jit.elidable
diff --git a/pypy/rlib/libffi.py b/pypy/rlib/libffi.py
--- a/pypy/rlib/libffi.py
+++ b/pypy/rlib/libffi.py
@@ -1,3 +1,6 @@
+"""
+This whole file is DEPRECATED.  Use jit_libffi.py instead.
+"""
 from __future__ import with_statement
 
 from pypy.rpython.lltypesystem import rffi, lltype
diff --git a/pypy/rpython/rbuiltin.py b/pypy/rpython/rbuiltin.py
--- a/pypy/rpython/rbuiltin.py
+++ b/pypy/rpython/rbuiltin.py
@@ -273,10 +273,10 @@
     return i2
 
 def rtype_Exception__init__(hop):
-    pass
+    hop.exception_cannot_occur()
 
 def rtype_object__init__(hop):
-    pass
+    hop.exception_cannot_occur()
 
 def rtype_OSError__init__(hop):
     hop.exception_cannot_occur()
diff --git a/pypy/rpython/test/test_rbuiltin.py b/pypy/rpython/test/test_rbuiltin.py
--- a/pypy/rpython/test/test_rbuiltin.py
+++ b/pypy/rpython/test/test_rbuiltin.py
@@ -540,6 +540,26 @@
         res = self.interpret(llfn, [0x12345678])
         assert res == 0x5678
 
+    def test_builtin_next(self):
+        def f(n):
+            x = [1, n, 2]
+            s = iter(x)
+            return next(s) + next(s)
+        res = self.interpret(f, [10])
+        assert res == 11
+
+    def test_builtin_next_stop_iteration(self):
+        def f(n):
+            x = [n]
+            s = iter(x)
+            try:
+                return next(s) + next(s)
+            except StopIteration:
+                return n + 500
+
+        res = self.interpret(f, [12])
+        assert res == 512
+
 
 class TestLLtype(BaseTestRbuiltin, LLRtypeMixin):
 
diff --git a/pypy/rpython/test/test_rclass.py b/pypy/rpython/test/test_rclass.py
--- a/pypy/rpython/test/test_rclass.py
+++ b/pypy/rpython/test/test_rclass.py
@@ -958,6 +958,16 @@
                 found.append(op.args[1].value)
         assert found == ['mutate_c']
 
+    def test_calling_object_init(self):
+        class A(object):
+            pass
+        class B(A):
+            def __init__(self):
+                A.__init__(self)
+        def f():
+            B()
+        self.gengraph(f, [])
+
 
 class TestLLtype(BaseTestRclass, LLRtypeMixin):
 
diff --git a/pypy/rpython/test/test_rdict.py b/pypy/rpython/test/test_rdict.py
--- a/pypy/rpython/test/test_rdict.py
+++ b/pypy/rpython/test/test_rdict.py
@@ -111,6 +111,16 @@
         assert self.interpret(func, [42, 0]) == False
         assert self.interpret(func, [42, 42]) == True
 
+    def test_contains_2(self):
+        d = {'5': None, '7': None}
+        def func(x):
+            return chr(x) in d
+        #assert self.interpret(func, [ord('5')]) == True
+        #assert self.interpret(func, [ord('6')]) == False
+
+        def func(n):
+            return str(n) in d
+        assert self.interpret(func, [512]) == False
 
     def test_dict_iteration(self):
         def func(i, j):
diff --git a/pypy/rpython/test/test_rlist.py b/pypy/rpython/test/test_rlist.py
--- a/pypy/rpython/test/test_rlist.py
+++ b/pypy/rpython/test/test_rlist.py
@@ -686,12 +686,52 @@
                 res = self.interpret(fn, [i, case])
                 assert res is fn(i, case)
 
+    def test_constant_list_contains(self):
+        # a 'contains' operation on list containing only annotation-time
+        # constants should be optimized into the equivalent code of
+        # 'in prebuilt-dictionary'.  Hard to test directly...
+        def g():
+            return 16
+        def f(i):
+            return i in [1, 2, 4, 8, g()]
+        res = self.interpret(f, [2])
+        assert res is True
+        res = self.interpret(f, [15])
+        assert res is False
+        res = self.interpret(f, [16])
+        assert res is True
 
-    def test_not_a_char_list_after_all(self):
+    def test_nonconstant_list_contains(self):
+        def f(i):
+            return i in [1, -i, 2, 4, 8]
+        res = self.interpret(f, [2])
+        assert res is True
+        res = self.interpret(f, [15])
+        assert res is False
+        res = self.interpret(f, [0])
+        assert res is True
+
+
+    def test_not_a_char_list_after_all_1(self):
+        def fn(n):
+            l = ['h', 'e', 'l', 'l', '0']
+            return str(n) in l     # turns into: str(n) in {'h','e','l','0'}
+        res = self.interpret(fn, [5])
+        assert res is False
+        res = self.interpret(fn, [0])
+        assert res is True
+
         def fn():
-            l = ['h', 'e', 'l', 'l', 'o']
+            l = ['h', 'e', 'l', 'l', '0']
+            return 'hi' in l     # turns into: 'hi' in {'h','e','l','0'}
+        res = self.interpret(fn, [])
+        assert res is False
+
+    def test_not_a_char_list_after_all_2(self):
+        def fn(n):
+            l = ['h', 'e', 'l', 'l', 'o', chr(n)]
             return 'world' in l
-        res = self.interpret(fn, [])
+        res = self.interpret(fn, [0])
         assert res is False
 
     def test_list_index(self):
diff --git a/pypy/translator/c/funcgen.py b/pypy/translator/c/funcgen.py
--- a/pypy/translator/c/funcgen.py
+++ b/pypy/translator/c/funcgen.py
@@ -704,8 +704,9 @@
         value = self.expr(op.args[2])
         TYPE = op.args[2].concretetype
         typename = cdecl(self.db.gettype(TYPE).replace('@', '*@'), '')
-        return ('((%(typename)s) (%(addr)s + %(offset)s))[0] = %(value)s;' %
-                locals())
+        return (
+           '((%(typename)s) (((char *)%(addr)s) + %(offset)s))[0] = %(value)s;'
+           % locals())
 
     def OP_RAW_LOAD(self, op):
         addr = self.expr(op.args[0])
@@ -713,8 +714,9 @@
         result = self.expr(op.result)
         TYPE = op.result.concretetype
         typename = cdecl(self.db.gettype(TYPE).replace('@', '*@'), '')
-        return ("%(result)s = ((%(typename)s) (%(addr)s + %(offset)s))[0];" %
-                locals())
+        return (
+          "%(result)s = ((%(typename)s) (((char *)%(addr)s) + %(offset)s))[0];"
+          % locals())
 
     def OP_CAST_PRIMITIVE(self, op):
         TYPE = self.lltypemap(op.result)
diff --git a/pypy/translator/transform.py b/pypy/translator/transform.py
--- a/pypy/translator/transform.py
+++ b/pypy/translator/transform.py
@@ -109,6 +109,34 @@
                                         op.result)
                 block.operations[i] = new_op
 
+# x in [2, 3]
+# -->
+# b = newlist(2, 3)
+# c = contains(b, x)
+# -->
+# c = contains(Constant((2, 3)), x)
+
+def transform_list_contains(self, block_subset):
+    """Transforms x in [2, 3]"""
+    for block in block_subset:
+        newlist_sources = {}    # maps b to [2, 3] in the above notation
+        for i in range(len(block.operations)):
+            op = block.operations[i]
+            if op.opname == 'newlist':
+                newlist_sources[op.result] = op.args
+            elif op.opname == 'contains' and op.args[0] in newlist_sources:
+                items = {}
+                for v in newlist_sources[op.args[0]]:
+                    s = self.binding(v)
+                    if not s.is_immutable_constant():
+                        break
+                    items[s.const] = None
+                else:
+                    # all arguments of the newlist are annotation constants
+                    op.args[0] = Constant(items)
+                    s_dict = self.binding(op.args[0])
+                    s_dict.dictdef.generalize_key(self.binding(op.args[1]))
+
 
 def transform_dead_op_vars(self, block_subset):
     # we redo the same simplification from simplify.py,
@@ -221,6 +249,7 @@
     transform_allocate,
     transform_extend_with_str_slice,
     transform_extend_with_char_count,
+    transform_list_contains,
     ]
 
 def transform_graph(ann, extra_passes=None, block_subset=None):


More information about the pypy-commit mailing list