[pypy-commit] pypy stdlib-2.7.5: Finish fixing rsre in this branch according to 7b0cafed5689.

2014-01-24 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: stdlib-2.7.5
Changeset: r68897:bfa0306f27f6
Date: 2014-01-24 09:40 +0100
http://bitbucket.org/pypy/pypy/changeset/bfa0306f27f6/

Log:Finish fixing rsre in this branch according to 7b0cafed5689.

diff --git a/rpython/rlib/rsre/rpy/__init__.py 
b/rpython/rlib/rsre/rpy/__init__.py
--- a/rpython/rlib/rsre/rpy/__init__.py
+++ b/rpython/rlib/rsre/rpy/__init__.py
@@ -1,1 +1,1 @@
-from ._sre import get_code
+from ._sre import get_code, VERSION
diff --git a/rpython/rlib/rsre/rpy/_sre.py b/rpython/rlib/rsre/rpy/_sre.py
--- a/rpython/rlib/rsre/rpy/_sre.py
+++ b/rpython/rlib/rsre/rpy/_sre.py
@@ -1,9 +1,10 @@
-
+import sys
 from rpython.rlib.rsre import rsre_char
 from rpython.rlib.rarithmetic import intmask
 
-
+VERSION = 2.7.5
 MAGIC = 20031017
+MAXREPEAT = rsre_char.MAXREPEAT
 CODESIZE = rsre_char.CODESIZE
 getlower = rsre_char.getlower
 
diff --git a/rpython/rlib/rsre/rpy/sre_compile.py 
b/rpython/rlib/rsre/rpy/sre_compile.py
--- a/rpython/rlib/rsre/rpy/sre_compile.py
+++ b/rpython/rlib/rsre/rpy/sre_compile.py
@@ -8,12 +8,12 @@
 # See the sre.py file for information on usage and redistribution.
 #
 
-Internal support module for sre (copied from CPython 2.7.3)
+Internal support module for sre (copied from CPython 2.7.5)
 
 import sys
 from . import _sre, sre_parse
 from .sre_constants import *
-from _sre import MAXREPEAT
+from ._sre import MAXREPEAT
 
 assert _sre.MAGIC == MAGIC, SRE module mismatch
 
diff --git a/rpython/rlib/rsre/rpy/sre_constants.py 
b/rpython/rlib/rsre/rpy/sre_constants.py
--- a/rpython/rlib/rsre/rpy/sre_constants.py
+++ b/rpython/rlib/rsre/rpy/sre_constants.py
@@ -9,13 +9,13 @@
 # See the sre.py file for information on usage and redistribution.
 #
 
-Internal support module for sre (copied from CPython 2.7.3)
+Internal support module for sre (copied from CPython 2.7.5)
 
 # update when constants are added or removed
 
 MAGIC = 20031017
 
-from _sre import MAXREPEAT
+from ._sre import MAXREPEAT
 
 # SRE standard exception (access as sre.error)
 # (use the real re.error exception class)
diff --git a/rpython/rlib/rsre/rpy/sre_parse.py 
b/rpython/rlib/rsre/rpy/sre_parse.py
--- a/rpython/rlib/rsre/rpy/sre_parse.py
+++ b/rpython/rlib/rsre/rpy/sre_parse.py
@@ -8,14 +8,14 @@
 # See the sre.py file for information on usage and redistribution.
 #
 
-Internal support module for sre (copied from CPython 2.7.3)
+Internal support module for sre (copied from CPython 2.7.5)
 
 # XXX: show string offset and offending character for all errors
 
 import sys
 
 from .sre_constants import *
-from _sre import MAXREPEAT
+from ._sre import MAXREPEAT
 
 SPECIAL_CHARS = .\\[{()*+?^$|
 REPEAT_CHARS = *+?{
diff --git a/rpython/rlib/rsre/rsre_char.py b/rpython/rlib/rsre/rsre_char.py
--- a/rpython/rlib/rsre/rsre_char.py
+++ b/rpython/rlib/rsre/rsre_char.py
@@ -5,7 +5,7 @@
 from rpython.rlib.rlocale import tolower, isalnum
 from rpython.rlib.unroll import unrolling_iterable
 from rpython.rlib import jit
-from rpython.rlib.rarithmetic import int_between
+from rpython.rlib.rarithmetic import int_between, intmask
 
 # Note: the unicode parts of this module require you to call
 # rsre_char.set_unicode_db() first, to select one of the modules
@@ -26,7 +26,10 @@
 # Identifying as _sre from Python 2.3 and onwards (at least up to 2.7)
 MAGIC = 20031017
 
-MAXREPEAT = 65535
+if sys.maxint  2**32:
+MAXREPEAT = intmask(2**32 - 1)
+else:
+MAXREPEAT = intmask(2**31 - 1)
 
 # In _sre.c this is bytesize of the code word type of the C implementation.
 # There it's 2 for normal Python builds and more for wide unicode builds 
(large 
diff --git a/rpython/rlib/rsre/rsre_core.py b/rpython/rlib/rsre/rsre_core.py
--- a/rpython/rlib/rsre/rsre_core.py
+++ b/rpython/rlib/rsre/rsre_core.py
@@ -95,6 +95,10 @@
 self.match_start = match_start
 self.end = end
 self.flags = flags
+# check we don't get the old value of MAXREPEAT
+# during the untranslated tests
+if not we_are_translated():
+assert 65535 not in pattern
 
 def reset(self, start):
 self.match_start = start
diff --git a/rpython/rlib/rsre/test/targetrsre.py 
b/rpython/rlib/rsre/test/targetrsre.py
--- a/rpython/rlib/rsre/test/targetrsre.py
+++ b/rpython/rlib/rsre/test/targetrsre.py
@@ -1,14 +1,15 @@
 #!/usr/bin/env python
 from rpython.rlib.rarithmetic import intmask
 from rpython.rlib.rsre import rsre_core
+from rpython.rlib.rsre.rsre_char import MAXREPEAT
 import os, time
 
 
 # item\s*title(.*?)/title
 r_code1 = [17, 18, 1, 21, 131091, 6, 6, 60, 105, 116, 101, 109, 62, 0,
 0, 0, 0, 0, 0, 19, 60, 19, 105, 19, 116, 19, 101, 19, 109, 19, 62, 29,
-9, 0, 65535, 15, 4, 9, 2, 0, 1, 19, 60, 19, 116, 19, 105, 19, 116, 19,
-108, 19, 101, 19, 62, 21, 0, 31, 5, 0, 65535, 2, 1, 21, 1, 19, 60, 19,
+9, 0, MAXREPEAT, 15, 4, 9, 2, 0, 1, 19, 60, 19, 116, 19, 105, 19, 116, 19,
+108, 19, 101, 19, 62, 21, 0, 31, 5, 0, MAXREPEAT, 2, 1, 21, 1, 19, 60, 19,
 47, 19, 116, 19, 105, 19, 116, 

[pypy-commit] pypy default: Import directly _rawffi.alt from here

2014-01-24 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r68898:2f6abb55cbfd
Date: 2014-01-24 10:17 +0100
http://bitbucket.org/pypy/pypy/changeset/2f6abb55cbfd/

Log:Import directly _rawffi.alt from here

diff --git a/pypy/module/pypyjit/test_pypy_c/test_ffi.py 
b/pypy/module/pypyjit/test_pypy_c/test_ffi.py
--- a/pypy/module/pypyjit/test_pypy_c/test_ffi.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_ffi.py
@@ -7,9 +7,9 @@
 from rpython.rlib.test.test_clibffi import get_libm_name
 def main(libm_name):
 try:
-from _ffi import CDLL, types
+from _rawffi.alt import CDLL, types
 except ImportError:
-sys.stderr.write('SKIP: cannot import _ffi\n')
+sys.stderr.write('SKIP: cannot import _rawffi.alt\n')
 return 0
 
 libm = CDLL(libm_name)
@@ -45,9 +45,9 @@
 from rpython.rlib.test.test_clibffi import get_libm_name
 def main(libm_name):
 try:
-from _ffi import CDLL, types
+from _rawffi.alt import CDLL, types
 except ImportError:
-sys.stderr.write('SKIP: cannot import _ffi\n')
+sys.stderr.write('SKIP: cannot import _rawffi.alt\n')
 return 0
 
 libm = CDLL(libm_name)
@@ -82,12 +82,12 @@
 from threading import Thread
 #
 if os.name == 'nt':
-from _ffi import WinDLL, types
+from _rawffi.alt import WinDLL, types
 libc = WinDLL('Kernel32.dll')
 sleep = libc.getfunc('Sleep', [types.uint], types.uint)
 delays = [0]*n + [1000]
 else:
-from _ffi import CDLL, types
+from _rawffi.alt import CDLL, types
 libc = CDLL(libc_name)
 sleep = libc.getfunc('sleep', [types.uint], types.uint)
 delays = [0]*n + [1]
@@ -144,7 +144,7 @@
 
 def test__ffi_struct(self):
 def main():
-from _ffi import _StructDescr, Field, types
+from _rawffi.alt import _StructDescr, Field, types
 fields = [
 Field('x', types.slong),
 ]
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy detect-immutable-fields: disambiguate the 6 different uses of index

2014-01-24 Thread cfbolz
Author: Carl Friedrich Bolz cfb...@gmx.de
Branch: detect-immutable-fields
Changeset: r68899:18f97d79777a
Date: 2014-01-24 11:43 +0100
http://bitbucket.org/pypy/pypy/changeset/18f97d79777a/

Log:disambiguate the 6 different uses of index

many of them were not an index at all any more after Alex' change

diff --git a/pypy/module/__pypy__/interp_magic.py 
b/pypy/module/__pypy__/interp_magic.py
--- a/pypy/module/__pypy__/interp_magic.py
+++ b/pypy/module/__pypy__/interp_magic.py
@@ -3,7 +3,7 @@
 from rpython.rlib.objectmodel import we_are_translated
 from pypy.objspace.std.listobject import W_ListObject
 from pypy.objspace.std.typeobject import MethodCache
-from pypy.objspace.std.mapdict import IndexCache
+from pypy.objspace.std.mapdict import MapAttrCache
 from rpython.rlib import rposix, rgc
 
 
@@ -35,7 +35,7 @@
 cache.misses = {}
 cache.hits = {}
 if space.config.objspace.std.withmapdict:
-cache = space.fromcache(IndexCache)
+cache = space.fromcache(MapAttrCache)
 cache.misses = {}
 cache.hits = {}
 
@@ -45,7 +45,7 @@
 in the mapdict cache with the given attribute name.
 assert space.config.objspace.std.withmethodcachecounter
 assert space.config.objspace.std.withmapdict
-cache = space.fromcache(IndexCache)
+cache = space.fromcache(MapAttrCache)
 return space.newtuple([space.newint(cache.hits.get(name, 0)),
space.newint(cache.misses.get(name, 0))])
 
diff --git a/pypy/module/gc/interp_gc.py b/pypy/module/gc/interp_gc.py
--- a/pypy/module/gc/interp_gc.py
+++ b/pypy/module/gc/interp_gc.py
@@ -12,8 +12,8 @@
 cache = space.fromcache(MethodCache)
 cache.clear()
 if space.config.objspace.std.withmapdict:
-from pypy.objspace.std.mapdict import IndexCache
-cache = space.fromcache(IndexCache)
+from pypy.objspace.std.mapdict import MapAttrCache
+cache = space.fromcache(MapAttrCache)
 cache.clear()
 rgc.collect()
 return space.wrap(0)
diff --git a/pypy/objspace/std/mapdict.py b/pypy/objspace/std/mapdict.py
--- a/pypy/objspace/std/mapdict.py
+++ b/pypy/objspace/std/mapdict.py
@@ -31,46 +31,46 @@
 self.ever_mutated = False
 
 def read(self, obj, selector):
-index = self.index(selector)
-if index is None:
+attr = self.find_map_attr(selector)
+if attr is None:
 return self.terminator._read_terminator(obj, selector)
-return obj._mapdict_read_storage(index.position, pure=not 
self.ever_mutated)
+return obj._mapdict_read_storage(attr.storageindex, pure=not 
self.ever_mutated)
 
 def write(self, obj, selector, w_value):
-index = self.index(selector)
-if index is None:
+attr = self.find_map_attr(selector)
+if attr is None:
 return self.terminator._write_terminator(obj, selector, w_value)
-obj._mapdict_write_storage(index.position, w_value)
-if not index.ever_mutated:
-index.ever_mutated = True
+obj._mapdict_write_storage(attr.storageindex, w_value)
+if not attr.ever_mutated:
+attr.ever_mutated = True
 return True
 
 def delete(self, obj, selector):
 return None
 
-def index(self, selector):
+def find_map_attr(self, selector):
 if jit.we_are_jitted():
 # hack for the jit:
-# the _index method is pure too, but its argument is never
+# the _find_map_attr method is pure too, but its argument is never
 # constant, because it is always a new tuple
-return self._index_jit_pure(selector[0], selector[1])
+return self._find_map_attr_jit_pure(selector[0], selector[1])
 else:
-return self._index_indirection(selector)
+return self._find_map_attr_indirection(selector)
 
 @jit.elidable
-def _index_jit_pure(self, name, index):
-return self._index_indirection((name, index))
+def _find_map_attr_jit_pure(self, name, index):
+return self._find_map_attr_indirection((name, index))
 
 @jit.dont_look_inside
-def _index_indirection(self, selector):
+def _find_map_attr_indirection(self, selector):
 if (self.space.config.objspace.std.withmethodcache):
-return self._index_cache(selector)
-return self._index(selector)
+return self._find_map_attr_cache(selector)
+return self._find_map_attr(selector)
 
 @jit.dont_look_inside
-def _index_cache(self, selector):
+def _find_map_attr_cache(self, selector):
 space = self.space
-cache = space.fromcache(IndexCache)
+cache = space.fromcache(MapAttrCache)
 SHIFT2 = r_uint.BITS - space.config.objspace.std.methodcachesizeexp
 SHIFT1 = SHIFT2 - 5
 attrs_as_int = objectmodel.current_object_addr_as_int(self)
@@ -78,27 +78,27 @@
 # 

[pypy-commit] pypy detect-immutable-fields: The check for immutability was done on the wrong attribute, leading to

2014-01-24 Thread cfbolz
Author: Carl Friedrich Bolz cfb...@gmx.de
Branch: detect-immutable-fields
Changeset: r68900:2d7e3e3b5a02
Date: 2014-01-24 12:11 +0100
http://bitbucket.org/pypy/pypy/changeset/2d7e3e3b5a02/

Log:The check for immutability was done on the wrong attribute, leading
to completely bogus immutability assumptions.

tests are important!

diff --git a/pypy/objspace/std/mapdict.py b/pypy/objspace/std/mapdict.py
--- a/pypy/objspace/std/mapdict.py
+++ b/pypy/objspace/std/mapdict.py
@@ -34,7 +34,7 @@
 attr = self.find_map_attr(selector)
 if attr is None:
 return self.terminator._read_terminator(obj, selector)
-return obj._mapdict_read_storage(attr.storageindex, pure=not 
self.ever_mutated)
+return obj._mapdict_read_storage(attr.storageindex, pure=not 
attr.ever_mutated)
 
 def write(self, obj, selector, w_value):
 attr = self.find_map_attr(selector)
diff --git a/pypy/objspace/std/test/test_mapdict.py 
b/pypy/objspace/std/test/test_mapdict.py
--- a/pypy/objspace/std/test/test_mapdict.py
+++ b/pypy/objspace/std/test/test_mapdict.py
@@ -107,6 +107,43 @@
 assert obj2.getdictvalue(space, b) == 60
 assert obj2.map is obj.map
 
+def test_attr_immutability():
+cls = Class()
+obj = cls.instantiate()
+obj.setdictvalue(space, a, 10)
+obj.setdictvalue(space, b, 20)
+obj.setdictvalue(space, b, 30)
+assert obj.storage == [10, 30]
+assert obj.map.ever_mutated == True
+assert obj.map.back.ever_mutated == False
+
+def _mapdict_read_storage(index, pure=False):
+assert index in (0, 1)
+if index == 0:
+assert pure == True
+else:
+assert pure == False
+return Object._mapdict_read_storage(obj, index, pure)
+
+obj._mapdict_read_storage = _mapdict_read_storage
+
+assert obj.getdictvalue(space, a) == 10
+assert obj.getdictvalue(space, b) == 30
+
+obj2 = cls.instantiate()
+obj2.setdictvalue(space, a, 15)
+obj2.setdictvalue(space, b, 25)
+assert obj2.map is obj.map
+assert obj2.map.ever_mutated == True
+assert obj2.map.back.ever_mutated == False
+
+# mutating obj2 changes the map
+obj2.setdictvalue(space, a, 50)
+assert obj2.map.back.ever_mutated == True
+assert obj2.map is obj.map
+
+
+
 def test_delete():
 for i, dattr in enumerate([a, b, c]):
 c = Class()
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy detect-immutable-fields: be consistent with adding an attribute: first change the map, then write to the

2014-01-24 Thread cfbolz
Author: Carl Friedrich Bolz cfb...@gmx.de
Branch: detect-immutable-fields
Changeset: r68901:78b5d4b49b56
Date: 2014-01-24 12:11 +0100
http://bitbucket.org/pypy/pypy/changeset/78b5d4b49b56/

Log:be consistent with adding an attribute: first change the map, then
write to the object.

diff --git a/pypy/objspace/std/mapdict.py b/pypy/objspace/std/mapdict.py
--- a/pypy/objspace/std/mapdict.py
+++ b/pypy/objspace/std/mapdict.py
@@ -40,9 +40,9 @@
 attr = self.find_map_attr(selector)
 if attr is None:
 return self.terminator._write_terminator(obj, selector, w_value)
-obj._mapdict_write_storage(attr.storageindex, w_value)
 if not attr.ever_mutated:
 attr.ever_mutated = True
+obj._mapdict_write_storage(attr.storageindex, w_value)
 return True
 
 def delete(self, obj, selector):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] stmgc c7: add largemalloc and fix its tests

2014-01-24 Thread Remi Meier
Author: Remi Meier
Branch: c7
Changeset: r672:5a8511bf2e9f
Date: 2014-01-24 14:22 +0100
http://bitbucket.org/pypy/stmgc/changeset/5a8511bf2e9f/

Log:add largemalloc and fix its tests

diff --git a/c7/core.c b/c7/core.c
--- a/c7/core.c
+++ b/c7/core.c
@@ -16,7 +16,7 @@
 #include nursery.h
 #include pages.h
 #include stmsync.h
-
+#include largemalloc.h
 
 
 char *object_pages;
@@ -196,6 +196,14 @@
 or should it be UNCOMMITTED??? 
*/
 
 num_threads_started = 0;
+
+assert(HEAP_PAGES  NB_PAGES - FIRST_AFTER_NURSERY_PAGE);
+assert(HEAP_PAGES  10);
+
+uintptr_t first_heap = stm_pages_reserve(HEAP_PAGES);
+char *heap = REAL_ADDRESS(get_thread_base(0), first_heap * 4096UL); 
+assert(memset(heap, 0xcd, HEAP_PAGES * 4096)); // testing
+stm_largemalloc_init(heap, HEAP_PAGES * 4096UL);
 }
 
 #define INVALID_GS_VALUE  0x6D6D6D6D
diff --git a/c7/core.h b/c7/core.h
--- a/c7/core.h
+++ b/c7/core.h
@@ -21,6 +21,8 @@
 #define READMARKER_START  ((FIRST_OBJECT_PAGE * 4096UL)  4)
 #define FIRST_READMARKER_PAGE (READMARKER_START / 4096UL)
 #define FIRST_AFTER_NURSERY_PAGE  (FIRST_OBJECT_PAGE + NB_NURSERY_PAGES)
+#define HEAP_PAGES(((NB_PAGES - FIRST_AFTER_NURSERY_PAGE) * 2) / 3)
+
 
 
 enum {
diff --git a/c7/largemalloc.c b/c7/largemalloc.c
new file mode 100644
--- /dev/null
+++ b/c7/largemalloc.c
@@ -0,0 +1,438 @@
+/* This contains a lot of inspiration from malloc() in the GNU C Library.
+   More precisely, this is (a subset of) the part that handles large
+   blocks, which in our case means at least 288 bytes.  It is actually
+   a general allocator, although it doesn't contain any of the small-
+   or medium-block support that are also present in the GNU C Library.
+*/
+
+#include stdio.h
+#include stddef.h
+#include assert.h
+#include largemalloc.h
+
+
+#define MMAP_LIMIT(1280*1024)
+
+#define largebin_index(sz)  \
+(((sz)  (48   6)) ?  ((sz)   6):  /*  0 - 47 */\
+ ((sz)  (24   9)) ? 42 + ((sz)   9):  /* 48 - 65 */\
+ ((sz)  (12  12)) ? 63 + ((sz)  12):  /* 66 - 74 */\
+ ((sz)  (6   15)) ? 74 + ((sz)  15):  /* 75 - 79 */\
+ ((sz)  (3   18)) ? 80 + ((sz)  18):  /* 80 - 82 */\
+   83)
+#define N_BINS 84
+#define LAST_BIN_INDEX(sz) ((sz) = (3  18))
+
+typedef struct dlist_s {
+struct dlist_s *next;   /* a doubly-linked list */
+struct dlist_s *prev;
+} dlist_t;
+
+typedef struct malloc_chunk {
+size_t prev_size; /* - if the previous chunk is free: size of its data
+ - otherwise, if this chunk is free: 1
+ - otherwise, 0. */
+size_t size;  /* size of the data in this chunk,
+ plus optionally the FLAG_SORTED */
+
+dlist_t d;/* if free: a doubly-linked list */
+  /* if not free: the user data starts here */
+
+/* The chunk has a total size of 'size'.  It is immediately followed
+   in memory by another chunk.  This list ends with the last chunk
+   being actually only one word long, 'size_t prev_size'.  Both this
+   last chunk and the theoretical chunk before the first one are
+   considered not free. */
+} mchunk_t;
+
+#define FLAG_SORTED  1
+#define THIS_CHUNK_FREE  1
+#define BOTH_CHUNKS_USED 0
+#define CHUNK_HEADER_SIZEoffsetof(struct malloc_chunk, d)
+#define END_MARKER   0xDEADBEEF
+
+#define chunk_at_offset(p, ofs)  ((mchunk_t *)(((char *)(p)) + (ofs)))
+#define data2chunk(p)chunk_at_offset(p, -CHUNK_HEADER_SIZE)
+
+static mchunk_t *next_chunk_s(mchunk_t *p)
+{
+assert(p-size  FLAG_SORTED);
+return chunk_at_offset(p, CHUNK_HEADER_SIZE + p-size - FLAG_SORTED);
+}
+static mchunk_t *next_chunk_u(mchunk_t *p)
+{
+assert(!(p-size  FLAG_SORTED));
+return chunk_at_offset(p, CHUNK_HEADER_SIZE + p-size);
+}
+
+
+/* The free chunks are stored in bins.  Each bin is a doubly-linked
+   list of chunks.  There are 84 bins, with largebin_index() giving the
+   correspondence between sizes are bin indices.
+
+   Each free chunk is preceeded in memory by a non-free chunk (or no
+   chunk at all).  Each free chunk is followed in memory by a non-free
+   chunk (or no chunk at all).  Chunks are consolidated with their
+   neighbors to ensure this.
+
+   In each bin's doubly-linked list, chunks are sorted by their size in
+   decreasing order (if you start from 'd.next').  At the end of this
+   list are some unsorted chunks.  All unsorted chunks are after all
+   sorted chunks.  The flag 'FLAG_SORTED' distinguishes them.
+
+   Note that if the user always calls stm_large_malloc() with a large
+   enough argument, then the few bins corresponding to smaller values
+   will never be sorted at all.  They are still populated with the
+   fragments of space between bigger allocations.
+*/
+
+static dlist_t 

[pypy-commit] pypy detect-immutable-fields: merged default in

2014-01-24 Thread alex_gaynor
Author: Alex Gaynor alex.gay...@gmail.com
Branch: detect-immutable-fields
Changeset: r68902:5a45c7f4d108
Date: 2014-01-24 07:43 -0600
http://bitbucket.org/pypy/pypy/changeset/5a45c7f4d108/

Log:merged default in

diff --git a/pypy/module/pypyjit/test_pypy_c/test_ffi.py 
b/pypy/module/pypyjit/test_pypy_c/test_ffi.py
--- a/pypy/module/pypyjit/test_pypy_c/test_ffi.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_ffi.py
@@ -7,9 +7,9 @@
 from rpython.rlib.test.test_clibffi import get_libm_name
 def main(libm_name):
 try:
-from _ffi import CDLL, types
+from _rawffi.alt import CDLL, types
 except ImportError:
-sys.stderr.write('SKIP: cannot import _ffi\n')
+sys.stderr.write('SKIP: cannot import _rawffi.alt\n')
 return 0
 
 libm = CDLL(libm_name)
@@ -45,9 +45,9 @@
 from rpython.rlib.test.test_clibffi import get_libm_name
 def main(libm_name):
 try:
-from _ffi import CDLL, types
+from _rawffi.alt import CDLL, types
 except ImportError:
-sys.stderr.write('SKIP: cannot import _ffi\n')
+sys.stderr.write('SKIP: cannot import _rawffi.alt\n')
 return 0
 
 libm = CDLL(libm_name)
@@ -82,12 +82,12 @@
 from threading import Thread
 #
 if os.name == 'nt':
-from _ffi import WinDLL, types
+from _rawffi.alt import WinDLL, types
 libc = WinDLL('Kernel32.dll')
 sleep = libc.getfunc('Sleep', [types.uint], types.uint)
 delays = [0]*n + [1000]
 else:
-from _ffi import CDLL, types
+from _rawffi.alt import CDLL, types
 libc = CDLL(libc_name)
 sleep = libc.getfunc('sleep', [types.uint], types.uint)
 delays = [0]*n + [1]
@@ -144,7 +144,7 @@
 
 def test__ffi_struct(self):
 def main():
-from _ffi import _StructDescr, Field, types
+from _rawffi.alt import _StructDescr, Field, types
 fields = [
 Field('x', types.slong),
 ]
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy detect-immutable-fields: Failing test, unsure how to make it pass

2014-01-24 Thread alex_gaynor
Author: Alex Gaynor alex.gay...@gmail.com
Branch: detect-immutable-fields
Changeset: r68903:9b7b906379c9
Date: 2014-01-24 08:59 -0600
http://bitbucket.org/pypy/pypy/changeset/9b7b906379c9/

Log:Failing test, unsure how to make it pass

diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -179,7 +179,7 @@
 return None
 def _set_mapdict_map(self, map):
 raise NotImplementedError
-def _mapdict_read_storage(self, index, pure=False):
+def _mapdict_read_storage(self, index, pure):
 raise NotImplementedError
 def _mapdict_write_storage(self, index, value):
 raise NotImplementedError
diff --git a/pypy/objspace/std/mapdict.py b/pypy/objspace/std/mapdict.py
--- a/pypy/objspace/std/mapdict.py
+++ b/pypy/objspace/std/mapdict.py
@@ -34,7 +34,18 @@
 attr = self.find_map_attr(selector)
 if attr is None:
 return self.terminator._read_terminator(obj, selector)
-return obj._mapdict_read_storage(attr.storageindex, pure=not 
attr.ever_mutated)
+if (
+not attr.ever_mutated and
+jit.isconstant(attr.storageindex) and
+jit.isconstant(obj)
+):
+return self._pure_mapdict_read_storage(obj, attr.storageindex)
+else:
+return obj._mapdict_read_storage(attr.storageindex)
+
+@jit.elidable
+def _pure_mapdict_read_storage(self, obj, storageindex):
+return obj._mapdict_read_storage(storageindex)
 
 def write(self, obj, selector, w_value):
 attr = self.find_map_attr(selector)
@@ -466,18 +477,13 @@
 self.map = map
 self.storage = make_sure_not_resized([None] * map.size_estimate())
 
-def _mapdict_read_storage(self, storageindex, pure=False):
+def _mapdict_read_storage(self, storageindex):
 assert storageindex = 0
-if pure and jit.isconstant(storageindex) and jit.isconstant(self):
-return self._pure_mapdict_read_storage(storageindex)
-return self.storage[storageindex]
-
-@jit.elidable
-def _pure_mapdict_read_storage(self, storageindex):
 return self.storage[storageindex]
 
 def _mapdict_write_storage(self, storageindex, value):
 self.storage[storageindex] = value
+
 def _mapdict_storage_length(self):
 return len(self.storage)
 def _set_mapdict_storage_and_map(self, storage, map):
@@ -543,17 +549,8 @@
 erased = getattr(self, _value%s % nmin1)
 return unerase_list(erased)
 
-def _mapdict_read_storage(self, storageindex, pure=False):
+def _mapdict_read_storage(self, storageindex):
 assert storageindex = 0
-if pure and jit.isconstant(storageindex) and jit.isconstant(self):
-return self._pure_mapdict_read_storage(storageindex)
-return self._indirection_mapdict_read_storage(storageindex)
-
-@jit.elidable
-def _pure_mapdict_read_storage(self, storageindex):
-return self._indirection_mapdict_read_storage(storageindex)
-
-def _indirection_mapdict_read_storage(self, storageindex):
 if storageindex  nmin1:
 for i in rangenmin1:
 if storageindex == i:
diff --git a/pypy/objspace/std/test/test_mapdict.py 
b/pypy/objspace/std/test/test_mapdict.py
--- a/pypy/objspace/std/test/test_mapdict.py
+++ b/pypy/objspace/std/test/test_mapdict.py
@@ -117,18 +117,19 @@
 assert obj.map.ever_mutated == True
 assert obj.map.back.ever_mutated == False
 
-def _mapdict_read_storage(index, pure=False):
-assert index in (0, 1)
-if index == 0:
-assert pure == True
-else:
-assert pure == False
-return Object._mapdict_read_storage(obj, index, pure)
+indices = []
 
-obj._mapdict_read_storage = _mapdict_read_storage
+def _pure_mapdict_read_storage(obj, index):
+assert index == 0
+indices.append(index)
+return obj._mapdict_read_storage(obj, index)
+
+obj.map._pure_mapdict_read_storage = _pure_mapdict_read_storage
 
 assert obj.getdictvalue(space, a) == 10
 assert obj.getdictvalue(space, b) == 30
+assert obj.getdictvalue(space, a) == 10
+assert indices == [0, 0]
 
 obj2 = cls.instantiate()
 obj2.setdictvalue(space, a, 15)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy detect-immutable-fields: Re-arrange to only read the field if the things are constants

2014-01-24 Thread alex_gaynor
Author: Alex Gaynor alex.gay...@gmail.com
Branch: detect-immutable-fields
Changeset: r68904:cadc0d2ebe59
Date: 2014-01-24 09:07 -0600
http://bitbucket.org/pypy/pypy/changeset/cadc0d2ebe59/

Log:Re-arrange to only read the field if the things are constants

diff --git a/pypy/objspace/std/mapdict.py b/pypy/objspace/std/mapdict.py
--- a/pypy/objspace/std/mapdict.py
+++ b/pypy/objspace/std/mapdict.py
@@ -35,9 +35,9 @@
 if attr is None:
 return self.terminator._read_terminator(obj, selector)
 if (
-not attr.ever_mutated and
 jit.isconstant(attr.storageindex) and
-jit.isconstant(obj)
+jit.isconstant(obj) and
+not attr.ever_mutated
 ):
 return self._pure_mapdict_read_storage(obj, attr.storageindex)
 else:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy detect-immutable-fields: This no longer appears

2014-01-24 Thread alex_gaynor
Author: Alex Gaynor alex.gay...@gmail.com
Branch: detect-immutable-fields
Changeset: r68907:65fb858e4798
Date: 2014-01-24 10:27 -0600
http://bitbucket.org/pypy/pypy/changeset/65fb858e4798/

Log:This no longer appears

diff --git a/pypy/module/pypyjit/test_pypy_c/test_thread.py 
b/pypy/module/pypyjit/test_pypy_c/test_thread.py
--- a/pypy/module/pypyjit/test_pypy_c/test_thread.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_thread.py
@@ -42,7 +42,6 @@
 assert loop.match(
 i53 = int_lt(i48, i27)
 guard_true(i53, descr=...)
-guard_not_invalidated(descr=...)
 i54 = int_add_ovf(i48, i47)
 guard_no_overflow(descr=...)
 --TICK--
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Document this branch

2014-01-24 Thread alex_gaynor
Author: Alex Gaynor alex.gay...@gmail.com
Branch: 
Changeset: r68910:73e7be19afcd
Date: 2014-01-24 10:50 -0600
http://bitbucket.org/pypy/pypy/changeset/73e7be19afcd/

Log:Document this branch

diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -52,3 +52,8 @@
 .. branch: annotator
 Remove FlowObjSpace.
 Improve cohesion between rpython.flowspace and rpython.annotator.
+
+.. branch: detect-immutable-fields
+mapdicts keep track of whether or not an attribute is every assigned to
+multiple times. If it's only assigned once then an elidable lookup is used when
+possible.
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: try to avoid at least some cases of interp2app identifer name clashes

2014-01-24 Thread pjenvey
Author: Philip Jenvey pjen...@underboss.org
Branch: 
Changeset: r68911:2f88f3eea121
Date: 2014-01-24 11:53 -0800
http://bitbucket.org/pypy/pypy/changeset/2f88f3eea121/

Log:try to avoid at least some cases of interp2app identifer name
clashes

diff --git a/rpython/rlib/objectmodel.py b/rpython/rlib/objectmodel.py
--- a/rpython/rlib/objectmodel.py
+++ b/rpython/rlib/objectmodel.py
@@ -750,6 +750,8 @@
 argument.
 
 flatten = {}
+caller = sys._getframe(1)
+caller_name = caller.f_globals.get('__name__')
 for base in inspect.getmro(M):
 if base is object:
 continue
@@ -764,13 +766,17 @@
 elif isinstance(value, staticmethod):
 func = value.__get__(42)
 func = func_with_new_name(func, func.__name__)
+if caller_name:
+# staticmethods lack a unique im_class so further
+# distinguish them from themselves
+func.__module__ = caller_name
 value = staticmethod(func)
 elif isinstance(value, classmethod):
 raise AssertionError(classmethods not supported 
  in 'import_from_mixin')
 flatten[key] = value
 #
-target = sys._getframe(1).f_locals
+target = caller.f_locals
 for key, value in flatten.items():
 if key in target:
 raise Exception(import_from_mixin: would overwrite the value 
diff --git a/rpython/rlib/test/test_objectmodel.py 
b/rpython/rlib/test/test_objectmodel.py
--- a/rpython/rlib/test/test_objectmodel.py
+++ b/rpython/rlib/test/test_objectmodel.py
@@ -621,3 +621,14 @@
 class B(A):
 import_from_mixin(M)
 assert B().foo == 42
+
+d = dict(__name__='foo')
+exec class M(object):
+@staticmethod
+def f(): pass
+ in d
+M = d['M']
+class A(object):
+import_from_mixin(M)
+assert A.f is not M.f
+assert A.f.__module__ != M.f.__module__
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: try to avoid at least some cases of interp2app identifer name clashes

2014-01-24 Thread pjenvey
Author: Philip Jenvey pjen...@underboss.org
Branch: py3k
Changeset: r68915:879dea160a95
Date: 2014-01-24 11:53 -0800
http://bitbucket.org/pypy/pypy/changeset/879dea160a95/

Log:try to avoid at least some cases of interp2app identifer name
clashes (grafted from 2f88f3eea121783eea13bf2d0d053eafc96e01a0)

diff --git a/rpython/rlib/objectmodel.py b/rpython/rlib/objectmodel.py
--- a/rpython/rlib/objectmodel.py
+++ b/rpython/rlib/objectmodel.py
@@ -750,6 +750,8 @@
 argument.
 
 flatten = {}
+caller = sys._getframe(1)
+caller_name = caller.f_globals.get('__name__')
 for base in inspect.getmro(M):
 if base is object:
 continue
@@ -764,13 +766,17 @@
 elif isinstance(value, staticmethod):
 func = value.__get__(42)
 func = func_with_new_name(func, func.__name__)
+if caller_name:
+# staticmethods lack a unique im_class so further
+# distinguish them from themselves
+func.__module__ = caller_name
 value = staticmethod(func)
 elif isinstance(value, classmethod):
 raise AssertionError(classmethods not supported 
  in 'import_from_mixin')
 flatten[key] = value
 #
-target = sys._getframe(1).f_locals
+target = caller.f_locals
 for key, value in flatten.items():
 if key in target:
 raise Exception(import_from_mixin: would overwrite the value 
diff --git a/rpython/rlib/test/test_objectmodel.py 
b/rpython/rlib/test/test_objectmodel.py
--- a/rpython/rlib/test/test_objectmodel.py
+++ b/rpython/rlib/test/test_objectmodel.py
@@ -621,3 +621,14 @@
 class B(A):
 import_from_mixin(M)
 assert B().foo == 42
+
+d = dict(__name__='foo')
+exec class M(object):
+@staticmethod
+def f(): pass
+ in d
+M = d['M']
+class A(object):
+import_from_mixin(M)
+assert A.f is not M.f
+assert A.f.__module__ != M.f.__module__
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k-refactor-str-types: fix imports

2014-01-24 Thread pjenvey
Author: Philip Jenvey pjen...@underboss.org
Branch: py3k-refactor-str-types
Changeset: r68913:2c5e0c0b4e71
Date: 2014-01-24 11:52 -0800
http://bitbucket.org/pypy/pypy/changeset/2c5e0c0b4e71/

Log:fix imports

diff --git a/pypy/module/__builtin__/operation.py 
b/pypy/module/__builtin__/operation.py
--- a/pypy/module/__builtin__/operation.py
+++ b/pypy/module/__builtin__/operation.py
@@ -19,7 +19,7 @@
 object, but escape the non-ASCII characters in the string returned by
 repr() using \\x, \\u or \\U escapes.  This generates a string similar
 to that returned by repr() in Python 2.
-from pypy.objspace.std.unicodetype import ascii_from_object
+from pypy.objspace.std.unicodeobject import ascii_from_object
 return ascii_from_object(space, w_obj)
 
 @unwrap_spec(code=int)
diff --git a/pypy/module/_codecs/interp_codecs.py 
b/pypy/module/_codecs/interp_codecs.py
--- a/pypy/module/_codecs/interp_codecs.py
+++ b/pypy/module/_codecs/interp_codecs.py
@@ -849,7 +849,7 @@
 
 @unwrap_spec(data=bufferstr, errors='str_or_None')
 def escape_encode(space, data, errors='strict'):
-from pypy.objspace.std.stringobject import string_escape_encode
+from pypy.objspace.std.bytesobject import string_escape_encode
 result = string_escape_encode(data, False)
 return space.newtuple([space.wrapbytes(result), space.wrap(len(data))])
 
diff --git a/pypy/module/_rawffi/interp_rawffi.py 
b/pypy/module/_rawffi/interp_rawffi.py
--- a/pypy/module/_rawffi/interp_rawffi.py
+++ b/pypy/module/_rawffi/interp_rawffi.py
@@ -2,7 +2,7 @@
 from pypy.interpreter.error import OperationError, wrap_oserror, 
operationerrfmt
 from pypy.interpreter.gateway import interp2app, unwrap_spec
 from pypy.interpreter.typedef import TypeDef, GetSetProperty
-from pypy.objspace.std.stringtype import getbytevalue
+from pypy.objspace.std.bytesobject import getbytevalue
 
 from rpython.rlib.clibffi import *
 from rpython.rlib.objectmodel import we_are_translated
diff --git a/pypy/module/cpyext/unicodeobject.py 
b/pypy/module/cpyext/unicodeobject.py
--- a/pypy/module/cpyext/unicodeobject.py
+++ b/pypy/module/cpyext/unicodeobject.py
@@ -230,7 +230,8 @@
 if not ref_unicode.c_utf8buffer:
 # Copy unicode buffer
 w_unicode = from_ref(space, ref)
-w_encoded = unicodetype.encode_object(space, w_unicode, utf-8, 
strict)
+w_encoded = unicodeobject.encode_object(space, w_unicode, utf-8,
+strict)
 s = space.bytes_w(w_encoded)
 ref_unicode.c_utf8buffer = rffi.str2charp(s)
 return ref_unicode.c_utf8buffer
diff --git a/pypy/module/imp/interp_imp.py b/pypy/module/imp/interp_imp.py
--- a/pypy/module/imp/interp_imp.py
+++ b/pypy/module/imp/interp_imp.py
@@ -5,7 +5,7 @@
 from pypy.interpreter.module import Module
 from pypy.interpreter.gateway import unwrap_spec
 from pypy.interpreter.pyparser import pyparse
-from pypy.objspace.std import unicodetype
+from pypy.objspace.std import unicodeobject
 from pypy.module._io.interp_iobase import W_IOBase
 from pypy.module._io import interp_io
 from pypy.interpreter.streamutil import wrap_streamerror
@@ -81,7 +81,7 @@
 stream.flush()
 encoding = pyparse._check_for_encoding(top)
 if encoding is None:
-encoding = unicodetype.getdefaultencoding(space)
+encoding = unicodeobject.getdefaultencoding(space)
 #
 # in python2, both CPython and PyPy pass the filename to
 # open(). However, CPython 3 just passes the fd, so the returned file
diff --git a/pypy/objspace/std/formatting.py b/pypy/objspace/std/formatting.py
--- a/pypy/objspace/std/formatting.py
+++ b/pypy/objspace/std/formatting.py
@@ -2,8 +2,6 @@
 String formatting routines.
 
 from pypy.interpreter.error import OperationError
-from pypy.objspace.std.unicodetype import (
-unicode_from_object, ascii_from_object)
 from rpython.rlib import jit
 from rpython.rlib.rarithmetic import ovfcheck
 from rpython.rlib.rfloat import formatd, DTSF_ALT, isnan, isinf
@@ -445,6 +443,7 @@
 self.std_wp(self.space.unicode_w(self.space.repr(w_value)))
 
 def fmt_a(self, w_value):
+from pypy.objspace.std.unicodeobject import ascii_from_object
 w_value = ascii_from_object(self.space, w_value)
 self.std_wp(self.space.unicode_w(w_value))
 
diff --git a/pypy/objspace/std/longtype.py b/pypy/objspace/std/longtype.py
--- a/pypy/objspace/std/longtype.py
+++ b/pypy/objspace/std/longtype.py
@@ -134,7 +134,7 @@
 
 @unwrap_spec(byteorder=str, signed=bool)
 def descr_from_bytes(space, w_cls, w_obj, byteorder, signed=False):
-from pypy.objspace.std.stringtype import makebytesdata_w
+from pypy.objspace.std.bytesobject import makebytesdata_w
 bytes = ''.join(makebytesdata_w(space, w_obj))
 try:
 bigint = rbigint.frombytes(bytes, byteorder=byteorder, signed=signed)
diff --git a/pypy/objspace/std/newformat.py 

[pypy-commit] pypy py3k-refactor-str-types: reintegrate our bytes/bytearray

2014-01-24 Thread pjenvey
Author: Philip Jenvey pjen...@underboss.org
Branch: py3k-refactor-str-types
Changeset: r68912:eeae6a72a1be
Date: 2014-01-24 11:49 -0800
http://bitbucket.org/pypy/pypy/changeset/eeae6a72a1be/

Log:reintegrate our bytes/bytearray

diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -233,9 +233,8 @@
 raise operationerrfmt(space.w_TypeError, msg, w_result)
 
 def ord(self, space):
-typename = space.type(self).getname(space)
-msg = ord() expected string of length 1, but %s found
-raise operationerrfmt(space.w_TypeError, msg, typename)
+msg = ord() expected string of length 1, but %T found
+raise operationerrfmt(space.w_TypeError, msg, self)
 
 def __spacebind__(self, space):
 return self
diff --git a/pypy/objspace/std/bytearrayobject.py 
b/pypy/objspace/std/bytearrayobject.py
--- a/pypy/objspace/std/bytearrayobject.py
+++ b/pypy/objspace/std/bytearrayobject.py
@@ -3,15 +3,14 @@
 from pypy.interpreter.baseobjspace import W_Root
 from pypy.interpreter.buffer import RWBuffer
 from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.objspace.std.bytearraytype import new_bytearray
-from pypy.objspace.std.stringtype import getbytevalue, makebytesdata_w
+from pypy.objspace.std.bytesobject import (
+getbytevalue, makebytesdata_w, newbytesdata_w)
 from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
-from pypy.interpreter.signature import Signature
 from pypy.objspace.std.sliceobject import W_SliceObject
 from pypy.objspace.std.stdtypedef import StdTypeDef
 from pypy.objspace.std.stringmethods import StringMethods
 from pypy.objspace.std.util import get_positive_index
-from rpython.rlib.objectmodel import newlist_hint, resizelist_hint, 
import_from_mixin
+from rpython.rlib.objectmodel import import_from_mixin
 from rpython.rlib.rstring import StringBuilder
 
 
@@ -101,10 +100,8 @@
 return False
 
 def _join_check_item(self, space, w_obj):
-if (space.isinstance_w(w_obj, space.w_str) or
-space.isinstance_w(w_obj, space.w_bytearray)):
-return 0
-return 1
+return not (space.isinstance_w(w_obj, space.w_bytes) or
+space.isinstance_w(w_obj, space.w_bytearray))
 
 def ord(self, space):
 if len(self.data) != 1:
@@ -134,74 +131,19 @@
 Create a bytearray object from a string of hexadecimal numbers.\n
 Spaces between two numbers are accepted.\n
 Example: bytearray.fromhex('B9 01EF') - 
bytearray(b'\\xb9\\x01\\xef').
-hexstring = space.str_w(w_hexstring)
-hexstring = hexstring.lower()
-data = []
-length = len(hexstring)
-i = -2
-while True:
-i += 2
-while i  length and hexstring[i] == ' ':
-i += 1
-if i = length:
-break
-if i+1 == length:
-raise OperationError(space.w_ValueError, space.wrap(
-non-hexadecimal number found in fromhex() arg at position 
%d % i))
-
-top = _hex_digit_to_int(hexstring[i])
-if top == -1:
-raise OperationError(space.w_ValueError, space.wrap(
-non-hexadecimal number found in fromhex() arg at position 
%d % i))
-bot = _hex_digit_to_int(hexstring[i+1])
-if bot == -1:
-raise OperationError(space.w_ValueError, space.wrap(
-non-hexadecimal number found in fromhex() arg at position 
%d % (i+1,)))
-data.append(chr(top*16 + bot))
-
+if not space.is_w(space.type(w_hexstring), space.w_unicode):
+raise operationerrfmt(space.w_TypeError, must be str, not %T,
+  w_hexstring)
+hexstring = space.unicode_w(w_hexstring)
+data = _hexstring_to_array(space, hexstring)
 # in CPython bytearray.fromhex is a staticmethod, so
 # we ignore w_type and always return a bytearray
 return new_bytearray(space, space.w_bytearray, data)
 
-def descr_init(self, space, __args__):
-# this is on the silly side
-w_source, w_encoding, w_errors = __args__.parse_obj(
-None, 'bytearray', init_signature, init_defaults)
-
-if w_source is None:
-w_source = space.wrap('')
-if w_encoding is None:
-w_encoding = space.w_None
-if w_errors is None:
-w_errors = space.w_None
-
-# Unicode argument
-if not space.is_w(w_encoding, space.w_None):
-from pypy.objspace.std.unicodeobject import (
-_get_encoding_and_errors, encode_object
-)
-encoding, errors = _get_encoding_and_errors(space, w_encoding, 
w_errors)
-
-# if w_source is an integer this correctly raises a TypeError
-  

[pypy-commit] pypy py3k-refactor-str-types: we follow the more consistent py33 behavior now

2014-01-24 Thread pjenvey
Author: Philip Jenvey pjen...@underboss.org
Branch: py3k-refactor-str-types
Changeset: r68914:20ec3039a327
Date: 2014-01-24 11:52 -0800
http://bitbucket.org/pypy/pypy/changeset/20ec3039a327/

Log:we follow the more consistent py33 behavior now

diff --git a/pypy/objspace/std/test/test_bytesobject.py 
b/pypy/objspace/std/test/test_bytesobject.py
--- a/pypy/objspace/std/test/test_bytesobject.py
+++ b/pypy/objspace/std/test/test_bytesobject.py
@@ -203,10 +203,10 @@
 assert b'abc'.rjust(5, b'*') == b'**abc' # Python 2.4
 assert b'abc'.rjust(0) == b'abc'
 assert b'abc'.rjust(-1) == b'abc'
+assert b'abc'.rjust(5, bytearray(b' ')) == b'  abc'
 raises(TypeError, b'abc'.rjust, 5.0)
 raises(TypeError, b'abc'.rjust, 5, '*')
 raises(TypeError, b'abc'.rjust, 5, b'xx')
-raises(TypeError, b'abc'.rjust, 5, bytearray(b' '))
 raises(TypeError, b'abc'.rjust, 5, 32)
 
 def test_ljust(self):
@@ -290,8 +290,8 @@
 assert b'abc'.center(5, b'*') == b'*abc*' # Python 2.4
 assert b'abc'.center(0) == b'abc'
 assert b'abc'.center(-1) == b'abc'
+assert b'abc'.center(5, bytearray(b' ')) == b' abc '
 raises(TypeError, b'abc'.center, 4, b'cba')
-raises(TypeError, b'abc'.center, 5, bytearray(b' '))
 assert b' abc'.center(7) == b'   abc '
 
 def test_count(self):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k-refactor-str-types: try to avoid at least some cases of interp2app identifer name clashes

2014-01-24 Thread pjenvey
Author: Philip Jenvey pjen...@underboss.org
Branch: py3k-refactor-str-types
Changeset: r68916:3e72e557a27b
Date: 2014-01-24 11:53 -0800
http://bitbucket.org/pypy/pypy/changeset/3e72e557a27b/

Log:try to avoid at least some cases of interp2app identifer name
clashes (grafted from 2f88f3eea121783eea13bf2d0d053eafc96e01a0)

diff --git a/rpython/rlib/objectmodel.py b/rpython/rlib/objectmodel.py
--- a/rpython/rlib/objectmodel.py
+++ b/rpython/rlib/objectmodel.py
@@ -750,6 +750,8 @@
 argument.
 
 flatten = {}
+caller = sys._getframe(1)
+caller_name = caller.f_globals.get('__name__')
 for base in inspect.getmro(M):
 if base is object:
 continue
@@ -764,13 +766,17 @@
 elif isinstance(value, staticmethod):
 func = value.__get__(42)
 func = func_with_new_name(func, func.__name__)
+if caller_name:
+# staticmethods lack a unique im_class so further
+# distinguish them from themselves
+func.__module__ = caller_name
 value = staticmethod(func)
 elif isinstance(value, classmethod):
 raise AssertionError(classmethods not supported 
  in 'import_from_mixin')
 flatten[key] = value
 #
-target = sys._getframe(1).f_locals
+target = caller.f_locals
 for key, value in flatten.items():
 if key in target:
 raise Exception(import_from_mixin: would overwrite the value 
diff --git a/rpython/rlib/test/test_objectmodel.py 
b/rpython/rlib/test/test_objectmodel.py
--- a/rpython/rlib/test/test_objectmodel.py
+++ b/rpython/rlib/test/test_objectmodel.py
@@ -621,3 +621,14 @@
 class B(A):
 import_from_mixin(M)
 assert B().foo == 42
+
+d = dict(__name__='foo')
+exec class M(object):
+@staticmethod
+def f(): pass
+ in d
+M = d['M']
+class A(object):
+import_from_mixin(M)
+assert A.f is not M.f
+assert A.f.__module__ != M.f.__module__
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: fix numpy.float64.as_integer_ratio

2014-01-24 Thread bdkearns
Author: Brian Kearns bdkea...@gmail.com
Branch: 
Changeset: r68917:455237237e4c
Date: 2014-01-24 15:24 -0500
http://bitbucket.org/pypy/pypy/changeset/455237237e4c/

Log:fix numpy.float64.as_integer_ratio

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
@@ -394,6 +394,9 @@
 class W_Float64Box(W_FloatingBox, PrimitiveBox):
 descr__new__, _get_dtype, descr_reduce = new_dtype_getter(float64)
 
+def descr_as_integer_ratio(self, space):
+return space.call_method(self.item(space), 'as_integer_ratio')
+
 class W_ComplexFloatingBox(W_InexactBox):
 def descr_get_real(self, space):
 dtype = self._COMPONENTS_BOX._get_dtype(space)
@@ -719,6 +722,7 @@
 __module__ = numpy,
 __new__ = interp2app(W_Float64Box.descr__new__.im_func),
 __reduce__ = interp2app(W_Float64Box.descr_reduce),
+as_integer_ratio = interp2app(W_Float64Box.descr_as_integer_ratio),
 )
 
 W_ComplexFloatingBox.typedef = TypeDef(complexfloating, W_InexactBox.typedef,
diff --git a/pypy/module/micronumpy/test/test_scalar.py 
b/pypy/module/micronumpy/test/test_scalar.py
--- a/pypy/module/micronumpy/test/test_scalar.py
+++ b/pypy/module/micronumpy/test/test_scalar.py
@@ -181,6 +181,11 @@
 s = np.dtype([('a', 'int64'), ('b', 'int64')]).type('a' * 16)
 assert s.view('S16') == 'a' * 16
 
+def test_as_integer_ratio(self):
+import numpy as np
+raises(AttributeError, 'np.float32(1.5).as_integer_ratio()')
+assert np.float64(1.5).as_integer_ratio() == (3, 2)
+
 def test_complex_scalar_complex_cast(self):
 import numpy as np
 for tp in [np.csingle, np.cdouble, np.clongdouble]:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Comment out (hopefully temporarily) this check again. (Note that it was never enabled before a few days ago.)

2014-01-24 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r68918:b58a2c01fd59
Date: 2014-01-24 21:56 +0100
http://bitbucket.org/pypy/pypy/changeset/b58a2c01fd59/

Log:Comment out (hopefully temporarily) this check again. (Note that it
was never enabled before a few days ago.)

diff --git a/rpython/jit/metainterp/pyjitpl.py 
b/rpython/jit/metainterp/pyjitpl.py
--- a/rpython/jit/metainterp/pyjitpl.py
+++ b/rpython/jit/metainterp/pyjitpl.py
@@ -594,9 +594,11 @@
 if tobox is not None:
 # sanity check: see whether the current struct value
 # corresponds to what the cache thinks the value is
-resbox = executor.execute(self.metainterp.cpu, self.metainterp,
-  rop.GETFIELD_GC, fielddescr, box)
-assert resbox.constbox().same_constant(tobox.constbox())
+# XXX pypy with the following check fails on micronumpy,
+# XXX investigate
+#resbox = executor.execute(self.metainterp.cpu, self.metainterp,
+#  rop.GETFIELD_GC, fielddescr, box)
+#assert resbox.constbox().same_constant(tobox.constbox())
 return tobox
 resbox = self.execute_with_descr(opnum, fielddescr, box)
 self.metainterp.heapcache.getfield_now_known(box, fielddescr, resbox)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k-refactor-str-types: close before merging

2014-01-24 Thread pjenvey
Author: Philip Jenvey pjen...@underboss.org
Branch: py3k-refactor-str-types
Changeset: r68920:74d93872d6bd
Date: 2014-01-24 13:50 -0800
http://bitbucket.org/pypy/pypy/changeset/74d93872d6bd/

Log:close before merging

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


[pypy-commit] pypy py3k: rpython forces 'utf8' now

2014-01-24 Thread pjenvey
Author: Philip Jenvey pjen...@underboss.org
Branch: py3k
Changeset: r68922:fbe8e328bbe8
Date: 2014-01-24 13:58 -0800
http://bitbucket.org/pypy/pypy/changeset/fbe8e328bbe8/

Log:rpython forces 'utf8' now

diff --git a/lib-python/3/test/test_pep3120.py 
b/lib-python/3/test/test_pep3120.py
--- a/lib-python/3/test/test_pep3120.py
+++ b/lib-python/3/test/test_pep3120.py
@@ -20,7 +20,7 @@
 import test.badsyntax_pep3120
 except SyntaxError as msg:
 msg = str(msg).lower()
-self.assertTrue('utf-8' in msg)
+self.assertTrue('utf8' in msg)
 else:
 self.fail(expected exception didn't occur)
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: add bytearray.__iter__

2014-01-24 Thread pjenvey
Author: Philip Jenvey pjen...@underboss.org
Branch: 
Changeset: r68924:263c41db4f9c
Date: 2014-01-24 16:18 -0800
http://bitbucket.org/pypy/pypy/changeset/263c41db4f9c/

Log:add bytearray.__iter__

diff --git a/pypy/objspace/std/bytearrayobject.py 
b/pypy/objspace/std/bytearrayobject.py
--- a/pypy/objspace/std/bytearrayobject.py
+++ b/pypy/objspace/std/bytearrayobject.py
@@ -285,6 +285,9 @@
 raise
 return space.newbool(res)
 
+def descr_iter(self, space):
+return space.newseqiter(self)
+
 def descr_buffer(self, space):
 return BytearrayBuffer(self.data)
 
@@ -893,6 +896,8 @@
 __ge__ = interp2app(W_BytearrayObject.descr_ge,
 doc=BytearrayDocstrings.__ge__.__doc__),
 
+__iter__ = interp2app(W_BytearrayObject.descr_iter,
+ doc=BytearrayDocstrings.__iter__.__doc__),
 __len__ = interp2app(W_BytearrayObject.descr_len,
  doc=BytearrayDocstrings.__len__.__doc__),
 __contains__ = interp2app(W_BytearrayObject.descr_contains,
diff --git a/pypy/objspace/std/test/test_bytearrayobject.py 
b/pypy/objspace/std/test/test_bytearrayobject.py
--- a/pypy/objspace/std/test/test_bytearrayobject.py
+++ b/pypy/objspace/std/test/test_bytearrayobject.py
@@ -134,6 +134,7 @@
 
 def test_iter(self):
 assert list(bytearray('hello')) == [104, 101, 108, 108, 111]
+assert list(bytearray('hello').__iter__()) == [104, 101, 108, 108, 111]
 
 def test_compare(self):
 assert bytearray('hello') == bytearray('hello')
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: kill

2014-01-24 Thread pjenvey
Author: Philip Jenvey pjen...@underboss.org
Branch: py3k
Changeset: r68929:6dded87497b9
Date: 2014-01-24 16:55 -0800
http://bitbucket.org/pypy/pypy/changeset/6dded87497b9/

Log:kill

diff --git a/pypy/objspace/std/unicodeobject.py 
b/pypy/objspace/std/unicodeobject.py
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -17,9 +17,8 @@
 from pypy.objspace.std.stdtypedef import StdTypeDef
 from pypy.objspace.std.stringmethods import StringMethods
 
-__all__ = ['W_UnicodeObject', 'wrapunicode', 'plain_str2unicode',
-   'encode_object', 'decode_object', 'unicode_from_object',
-   'unicode_to_decimal_w']
+__all__ = ['W_UnicodeObject', 'wrapunicode', 'encode_object', 'decode_object',
+   'unicode_from_object', 'unicode_to_decimal_w']
 
 
 class W_UnicodeObject(W_Root):
@@ -442,26 +441,11 @@
 descr_ljust = _fix_fillchar(StringMethods.descr_ljust)
 descr_rjust = _fix_fillchar(StringMethods.descr_rjust)
 
+
 def wrapunicode(space, uni):
 return W_UnicodeObject(uni)
 
 
-def plain_str2unicode(space, s):
-try:
-return unicode(s)
-except UnicodeDecodeError:
-for i in range(len(s)):
-if ord(s[i])  127:
-raise OperationError(
-space.w_UnicodeDecodeError,
-space.newtuple([
-space.wrap('ascii'),
-space.wrap(s),
-space.wrap(i),
-space.wrap(i+1),
-space.wrap(ordinal not in range(128))]))
-assert False, unreachable
-
 def _isidentifier(u):
 if not u:
 return False
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: pep8/cleanup

2014-01-24 Thread pjenvey
Author: Philip Jenvey pjen...@underboss.org
Branch: 
Changeset: r68923:2f70add7ec6d
Date: 2014-01-24 16:17 -0800
http://bitbucket.org/pypy/pypy/changeset/2f70add7ec6d/

Log:pep8/cleanup

diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -232,9 +232,8 @@
 raise operationerrfmt(space.w_TypeError, msg, w_result)
 
 def ord(self, space):
-typename = space.type(self).getname(space)
-msg = ord() expected string of length 1, but %s found
-raise operationerrfmt(space.w_TypeError, msg, typename)
+msg = ord() expected string of length 1, but %T found
+raise operationerrfmt(space.w_TypeError, msg, self)
 
 def __spacebind__(self, space):
 return self
diff --git a/pypy/objspace/std/bytearrayobject.py 
b/pypy/objspace/std/bytearrayobject.py
--- a/pypy/objspace/std/bytearrayobject.py
+++ b/pypy/objspace/std/bytearrayobject.py
@@ -1,20 +1,21 @@
 The builtin bytearray implementation
 
+from rpython.rlib.objectmodel import (
+import_from_mixin, newlist_hint, resizelist_hint)
+from rpython.rlib.rstring import StringBuilder
+
 from pypy.interpreter.baseobjspace import W_Root
 from pypy.interpreter.buffer import RWBuffer
 from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
+from pypy.interpreter.gateway import WrappedDefault, interp2app, unwrap_spec
 from pypy.interpreter.signature import Signature
 from pypy.objspace.std.sliceobject import W_SliceObject
 from pypy.objspace.std.stdtypedef import StdTypeDef
 from pypy.objspace.std.stringmethods import StringMethods
 from pypy.objspace.std.util import get_positive_index
-from rpython.rlib.objectmodel import newlist_hint, resizelist_hint, 
import_from_mixin
-from rpython.rlib.rstring import StringBuilder
 
+NON_HEX_MSG = non-hexadecimal number found in fromhex() arg at position %d
 
-def _make_data(s):
-return [s[i] for i in range(len(s))]
 
 class W_BytearrayObject(W_Root):
 import_from_mixin(StringMethods)
@@ -23,7 +24,7 @@
 w_self.data = data
 
 def __repr__(w_self):
- representation for debugging purposes 
+representation for debugging purposes
 return %s(%s) % (w_self.__class__.__name__, ''.join(w_self.data))
 
 def _new(self, value):
@@ -127,11 +128,6 @@
 
 @staticmethod
 def descr_fromhex(space, w_bytearraytype, w_hexstring):
-bytearray.fromhex(string) - bytearray\n
-\n
-Create a bytearray object from a string of hexadecimal numbers.\n
-Spaces between two numbers are accepted.\n
-Example: bytearray.fromhex('B9 01EF') - 
bytearray(b'\\xb9\\x01\\xef').
 hexstring = space.str_w(w_hexstring)
 hexstring = hexstring.lower()
 data = []
@@ -143,18 +139,15 @@
 i += 1
 if i = length:
 break
-if i+1 == length:
-raise OperationError(space.w_ValueError, space.wrap(
-non-hexadecimal number found in fromhex() arg at position 
%d % i))
+if i + 1 == length:
+raise operationerrfmt(space.w_ValueError, NON_HEX_MSG, i)
 
 top = _hex_digit_to_int(hexstring[i])
 if top == -1:
-raise OperationError(space.w_ValueError, space.wrap(
-non-hexadecimal number found in fromhex() arg at position 
%d % i))
+raise operationerrfmt(space.w_ValueError, NON_HEX_MSG, i)
 bot = _hex_digit_to_int(hexstring[i+1])
 if bot == -1:
-raise OperationError(space.w_ValueError, space.wrap(
-non-hexadecimal number found in fromhex() arg at position 
%d % (i+1,)))
+raise operationerrfmt(space.w_ValueError, NON_HEX_MSG, i + 1)
 data.append(chr(top*16 + bot))
 
 # in CPython bytearray.fromhex is a staticmethod, so
@@ -178,23 +171,25 @@
 from pypy.objspace.std.unicodeobject import (
 _get_encoding_and_errors, encode_object
 )
-encoding, errors = _get_encoding_and_errors(space, w_encoding, 
w_errors)
+encoding, errors = _get_encoding_and_errors(space, w_encoding,
+w_errors)
 
-# if w_source is an integer this correctly raises a TypeError
-# the CPython error message is: encoding or errors without a 
string argument
-# ours is: expected unicode, got int object
+# if w_source is an integer this correctly raises a
+# TypeError the CPython error message is: encoding or
+# errors without a string argument ours is: expected
+# unicode, got int object
 w_source = encode_object(space, w_source, encoding, errors)
 
 # Is it an int?
 

[pypy-commit] pypy py3k: merge default

2014-01-24 Thread pjenvey
Author: Philip Jenvey pjen...@underboss.org
Branch: py3k
Changeset: r68928:a27d22674995
Date: 2014-01-24 16:52 -0800
http://bitbucket.org/pypy/pypy/changeset/a27d22674995/

Log:merge default

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
@@ -389,6 +389,9 @@
 class W_Float64Box(W_FloatingBox, PrimitiveBox):
 descr__new__, _get_dtype, descr_reduce = new_dtype_getter(float64)
 
+def descr_as_integer_ratio(self, space):
+return space.call_method(self.item(space), 'as_integer_ratio')
+
 class W_ComplexFloatingBox(W_InexactBox):
 def descr_get_real(self, space):
 dtype = self._COMPONENTS_BOX._get_dtype(space)
@@ -715,6 +718,7 @@
 __module__ = numpy,
 __new__ = interp2app(W_Float64Box.descr__new__.im_func),
 __reduce__ = interp2app(W_Float64Box.descr_reduce),
+as_integer_ratio = interp2app(W_Float64Box.descr_as_integer_ratio),
 )
 
 W_ComplexFloatingBox.typedef = TypeDef(complexfloating, W_InexactBox.typedef,
diff --git a/pypy/module/micronumpy/test/test_scalar.py 
b/pypy/module/micronumpy/test/test_scalar.py
--- a/pypy/module/micronumpy/test/test_scalar.py
+++ b/pypy/module/micronumpy/test/test_scalar.py
@@ -181,6 +181,11 @@
 s = np.dtype([('a', 'int64'), ('b', 'int64')]).type('a' * 16)
 assert s.view('S16') == 'a' * 16
 
+def test_as_integer_ratio(self):
+import numpy as np
+raises(AttributeError, 'np.float32(1.5).as_integer_ratio()')
+assert np.float64(1.5).as_integer_ratio() == (3, 2)
+
 def test_complex_scalar_complex_cast(self):
 import numpy as np
 for tp in [np.csingle, np.cdouble, np.clongdouble]:
diff --git a/pypy/objspace/std/bytearrayobject.py 
b/pypy/objspace/std/bytearrayobject.py
--- a/pypy/objspace/std/bytearrayobject.py
+++ b/pypy/objspace/std/bytearrayobject.py
@@ -1,21 +1,22 @@
 The builtin bytearray implementation
 
+from rpython.rlib.objectmodel import (
+import_from_mixin, newlist_hint, resizelist_hint)
+from rpython.rlib.rstring import StringBuilder
+
 from pypy.interpreter.baseobjspace import W_Root
 from pypy.interpreter.buffer import RWBuffer
 from pypy.interpreter.error import OperationError, operationerrfmt
 from pypy.objspace.std.bytesobject import (
 getbytevalue, makebytesdata_w, newbytesdata_w)
-from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
+from pypy.interpreter.gateway import WrappedDefault, interp2app, unwrap_spec
 from pypy.objspace.std.sliceobject import W_SliceObject
 from pypy.objspace.std.stdtypedef import StdTypeDef
 from pypy.objspace.std.stringmethods import StringMethods
 from pypy.objspace.std.util import get_positive_index
-from rpython.rlib.objectmodel import import_from_mixin
-from rpython.rlib.rstring import StringBuilder
 
+NON_HEX_MSG = non-hexadecimal number found in fromhex() arg at position %d
 
-def _make_data(s):
-return [s[i] for i in range(len(s))]
 
 class W_BytearrayObject(W_Root):
 import_from_mixin(StringMethods)
@@ -24,7 +25,7 @@
 w_self.data = data
 
 def __repr__(w_self):
- representation for debugging purposes 
+representation for debugging purposes
 return %s(%s) % (w_self.__class__.__name__, ''.join(w_self.data))
 
 def _new(self, value):
@@ -126,11 +127,6 @@
 
 @staticmethod
 def descr_fromhex(space, w_bytearraytype, w_hexstring):
-bytearray.fromhex(string) - bytearray\n
-\n
-Create a bytearray object from a string of hexadecimal numbers.\n
-Spaces between two numbers are accepted.\n
-Example: bytearray.fromhex('B9 01EF') - 
bytearray(b'\\xb9\\x01\\xef').
 if not space.is_w(space.type(w_hexstring), space.w_unicode):
 raise operationerrfmt(space.w_TypeError, must be str, not %T,
   w_hexstring)
@@ -168,8 +164,8 @@
 elif not '\x20' = c  '\x7f':
 n = ord(c)
 buf.append('\\x')
-buf.append(0123456789abcdef[n4])
-buf.append(0123456789abcdef[n0xF])
+buf.append(0123456789abcdef[n  4])
+buf.append(0123456789abcdef[n  0xF])
 else:
 buf.append(c)
 
@@ -185,51 +181,60 @@
 
 def descr_eq(self, space, w_other):
 try:
-return space.newbool(self._val(space) == self._op_val(space, 
w_other))
-except OperationError, e:
+res = self._val(space) == self._op_val(space, w_other)
+except OperationError as e:
 if e.match(space, space.w_TypeError):
 return space.w_NotImplemented
 raise
+return space.newbool(res)
 
 def descr_ne(self, space, w_other):
 try:
-return space.newbool(self._val(space) != self._op_val(space, 
w_other))
-except OperationError, e:
+res 

[pypy-commit] pypy py3k: merge default

2014-01-24 Thread pjenvey
Author: Philip Jenvey pjen...@underboss.org
Branch: py3k
Changeset: r68931:021856169522
Date: 2014-01-24 17:20 -0800
http://bitbucket.org/pypy/pypy/changeset/021856169522/

Log:merge default

diff --git a/pypy/objspace/std/unicodeobject.py 
b/pypy/objspace/std/unicodeobject.py
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -362,9 +362,9 @@
 elif space.isinstance_w(w_newval, space.w_int):
 newval = space.int_w(w_newval)
 if newval  0 or newval  maxunicode:
-msg = (character mapping must be in range(0x%x) %
-   (maxunicode + 1,))
-raise operationerrfmt(space.w_TypeError, msg)
+raise operationerrfmt(space.w_TypeError,
+  character mapping must be in 
+  range(%s), hex(maxunicode + 1))
 result.append(unichr(newval))
 elif space.isinstance_w(w_newval, space.w_unicode):
 result.append(space.unicode_w(w_newval))
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: oops, give operationerrfmt a constant

2014-01-24 Thread pjenvey
Author: Philip Jenvey pjen...@underboss.org
Branch: 
Changeset: r68930:e3f4f801f664
Date: 2014-01-24 17:20 -0800
http://bitbucket.org/pypy/pypy/changeset/e3f4f801f664/

Log:oops, give operationerrfmt a constant

diff --git a/pypy/objspace/std/unicodeobject.py 
b/pypy/objspace/std/unicodeobject.py
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -300,9 +300,9 @@
 elif space.isinstance_w(w_newval, space.w_int):
 newval = space.int_w(w_newval)
 if newval  0 or newval  maxunicode:
-msg = (character mapping must be in range(0x%x) %
-   (maxunicode + 1,))
-raise operationerrfmt(space.w_TypeError, msg)
+raise operationerrfmt(space.w_TypeError,
+  character mapping must be in 
+  range(%s), hex(maxunicode + 1))
 result.append(unichr(newval))
 elif space.isinstance_w(w_newval, space.w_unicode):
 result.append(space.unicode_w(w_newval))
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: __iter__ all the things

2014-01-24 Thread pjenvey
Author: Philip Jenvey pjen...@underboss.org
Branch: py3k
Changeset: r68932:dbf9786cc7d8
Date: 2014-01-24 17:33 -0800
http://bitbucket.org/pypy/pypy/changeset/dbf9786cc7d8/

Log:__iter__ all the things

diff --git a/pypy/objspace/std/bytearrayobject.py 
b/pypy/objspace/std/bytearrayobject.py
--- a/pypy/objspace/std/bytearrayobject.py
+++ b/pypy/objspace/std/bytearrayobject.py
@@ -233,9 +233,6 @@
 raise
 return space.newbool(res)
 
-def descr_iter(self, space):
-return space.newseqiter(self)
-
 def descr_buffer(self, space):
 return BytearrayBuffer(self.data)
 
diff --git a/pypy/objspace/std/bytesobject.py b/pypy/objspace/std/bytesobject.py
--- a/pypy/objspace/std/bytesobject.py
+++ b/pypy/objspace/std/bytesobject.py
@@ -56,6 +56,9 @@
 def descr_hash(self, space):
 x.__hash__() == hash(x)
 
+def descr_iter(self, space):
+x.__iter__() == iter(x)
+
 def descr_le(self, space, w_other):
 x.__le__(y) == x=y
 
@@ -787,6 +790,7 @@
 __gt__ = interpindirect2app(W_AbstractBytesObject.descr_gt),
 __ge__ = interpindirect2app(W_AbstractBytesObject.descr_ge),
 
+__iter__ = interpindirect2app(W_AbstractBytesObject.descr_iter),
 __len__ = interpindirect2app(W_AbstractBytesObject.descr_len),
 __contains__ = interpindirect2app(W_AbstractBytesObject.descr_contains),
 
diff --git a/pypy/objspace/std/stringmethods.py 
b/pypy/objspace/std/stringmethods.py
--- a/pypy/objspace/std/stringmethods.py
+++ b/pypy/objspace/std/stringmethods.py
@@ -57,8 +57,8 @@
 def descr_len(self, space):
 return space.wrap(self._len())
 
-#def descr_iter(self, space):
-#pass
+def descr_iter(self, space):
+return space.newseqiter(self)
 
 def descr_contains(self, space, w_sub):
 value = self._val(space)
diff --git a/pypy/objspace/std/test/test_bytesobject.py 
b/pypy/objspace/std/test/test_bytesobject.py
--- a/pypy/objspace/std/test/test_bytesobject.py
+++ b/pypy/objspace/std/test/test_bytesobject.py
@@ -652,6 +652,7 @@
 for i in iter(b42):
 l.append(i)
 assert l == [52, 50]
+assert list(b42.__iter__()) == [52, 50]
 
 def test_repr(self):
 for f in str, repr:
diff --git a/pypy/objspace/std/unicodeobject.py 
b/pypy/objspace/std/unicodeobject.py
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -336,9 +336,6 @@
 return newformat.run_formatter(space, w_format_spec, format_string,
self)
 
-def descr_iter(self, space):
-return space.newseqiter(self)
-
 def descr_mod(self, space, w_values):
 return mod_format(space, self, w_values, do_unicode=True)
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit