[pypy-commit] pypy default: add a test for c17aa572ce36

2013-02-12 Thread bdkearns
Author: Brian Kearns bdkea...@gmail.com
Branch: 
Changeset: r61121:514fb4ea981d
Date: 2013-02-12 03:50 -0500
http://bitbucket.org/pypy/pypy/changeset/514fb4ea981d/

Log:add a test for c17aa572ce36

diff --git a/pypy/module/test_lib_pypy/pyrepl/test_bugs.py 
b/pypy/module/test_lib_pypy/pyrepl/test_bugs.py
--- a/pypy/module/test_lib_pypy/pyrepl/test_bugs.py
+++ b/pypy/module/test_lib_pypy/pyrepl/test_bugs.py
@@ -44,3 +44,24 @@
 ('accept', [''])
 ]
 read_spec(spec, HistoricalTestReader)
+
+def test_signal_failure(monkeypatch):
+import os
+import pty
+import signal
+from pyrepl.unix_console import UnixConsole
+
+def failing_signal(a, b):
+raise ValueError
+
+mfd, sfd = pty.openpty()
+try:
+c = UnixConsole(sfd, sfd)
+c.prepare()
+c.restore()
+monkeypatch.setattr(signal, 'signal', failing_signal)
+c.prepare()
+c.restore()
+finally:
+os.close(mfd)
+os.close(sfd)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: small addition to last test

2013-02-12 Thread bdkearns
Author: Brian Kearns bdkea...@gmail.com
Branch: 
Changeset: r61122:f81f586cea88
Date: 2013-02-12 04:04 -0500
http://bitbucket.org/pypy/pypy/changeset/f81f586cea88/

Log:small addition to last test

diff --git a/pypy/module/test_lib_pypy/pyrepl/test_bugs.py 
b/pypy/module/test_lib_pypy/pyrepl/test_bugs.py
--- a/pypy/module/test_lib_pypy/pyrepl/test_bugs.py
+++ b/pypy/module/test_lib_pypy/pyrepl/test_bugs.py
@@ -54,6 +54,9 @@
 def failing_signal(a, b):
 raise ValueError
 
+def really_failing_signal(a, b):
+raise AssertionError
+
 mfd, sfd = pty.openpty()
 try:
 c = UnixConsole(sfd, sfd)
@@ -61,6 +64,7 @@
 c.restore()
 monkeypatch.setattr(signal, 'signal', failing_signal)
 c.prepare()
+monkeypatch.setattr(signal, 'signal', really_failing_signal)
 c.restore()
 finally:
 os.close(mfd)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jitframe-on-heap: Kill another copy of the same (broken) logic

2013-02-12 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: jitframe-on-heap
Changeset: r61123:009a38d24d36
Date: 2013-02-12 12:47 +0200
http://bitbucket.org/pypy/pypy/changeset/009a38d24d36/

Log:Kill another copy of the same (broken) logic

diff --git a/rpython/jit/backend/llsupport/rewrite.py 
b/rpython/jit/backend/llsupport/rewrite.py
--- a/rpython/jit/backend/llsupport/rewrite.py
+++ b/rpython/jit/backend/llsupport/rewrite.py
@@ -175,21 +175,15 @@
None, descr=descrs.jf_frame_info)
 self.newops.append(op2)
 arglist = op.getarglist()
-index = self.cpu.getarryoffset_for_frame()
+index_list = loop_token.compiled_loop_token._ll_initial_locs
 for i, arg in enumerate(arglist):
 descr = self.cpu.getarraydescr_for_frame(arg.type)
-if WORD == 4 and arg.type == history.FLOAT:
-self.newops.append(ResOperation(rop.SETARRAYITEM_GC,
-[frame, ConstInt(index // 2),
- arg],
-None, descr))
-index += 2 
-else:
-self.newops.append(ResOperation(rop.SETARRAYITEM_GC,
-[frame, ConstInt(index),
- arg],
-None, descr))
-index += 1
+_, itemsize, _ = self.cpu.unpack_arraydescr_size(descr)
+index = index_list[i] // itemsize # index is in bytes
+self.newops.append(ResOperation(rop.SETARRAYITEM_GC,
+[frame, ConstInt(index),
+ arg],
+None, descr))
 descr = op.getdescr()
 assert isinstance(descr, JitCellToken)
 jd = descr.outermost_jitdriver_sd
diff --git a/rpython/jit/backend/llsupport/test/test_rewrite.py 
b/rpython/jit/backend/llsupport/test/test_rewrite.py
--- a/rpython/jit/backend/llsupport/test/test_rewrite.py
+++ b/rpython/jit/backend/llsupport/test/test_rewrite.py
@@ -72,6 +72,7 @@
 
 casmdescr = JitCellToken()
 clt = FakeLoopToken()
+clt._ll_initial_locs = [0, WORD]
 frame_info = lltype.malloc(jitframe.JITFRAMEINFO, flavor='raw')
 clt.frame_info = frame_info
 frame_info.jfi_frame_depth = 13
@@ -116,8 +117,8 @@
 return self.floatframedescr
 return self.signedframedescr
 
-def getarryoffset_for_frame(self):
-return 0
+def unpack_arraydescr_size(self, d):
+return 0, d.itemsize, 0
 
 def arraydescrof(self, ARRAY):
 try:
diff --git a/rpython/jit/backend/x86/regalloc.py 
b/rpython/jit/backend/x86/regalloc.py
--- a/rpython/jit/backend/x86/regalloc.py
+++ b/rpython/jit/backend/x86/regalloc.py
@@ -190,13 +190,14 @@
 
 def _set_initial_bindings(self, inputargs, looptoken):
 locs = []
+base_ofs = self.assembler.cpu.get_baseofs_of_frame_field()
 for box in inputargs:
 assert isinstance(box, Box)
 loc = self.fm.get_new_loc(box)
-locs.append(loc.value)
+locs.append(loc.value - base_ofs)
 if looptoken.compiled_loop_token is not None:
 # for tests
-looptoken.compiled_loop_token._x86_initial_locs = locs
+looptoken.compiled_loop_token._ll_initial_locs = locs
 
 def possibly_free_var(self, var):
 if var.type == FLOAT:
diff --git a/rpython/jit/backend/x86/runner.py 
b/rpython/jit/backend/x86/runner.py
--- a/rpython/jit/backend/x86/runner.py
+++ b/rpython/jit/backend/x86/runner.py
@@ -55,9 +55,6 @@
 else:
 return 1000
 
-def getarryoffset_for_frame(self):
-return JITFRAME_FIXED_SIZE
-
 def setup(self):
 self.assembler = Assembler386(self, self.translate_support_code)
 
@@ -119,9 +116,8 @@
 #llop.debug_print(lltype.Void,  Entering, addr)
 frame_info = clt.frame_info
 frame = self.gc_ll_descr.malloc_jitframe(frame_info)
-base_ofs = self.get_baseofs_of_frame_field()
 ll_frame = lltype.cast_opaque_ptr(llmemory.GCREF, frame)
-locs = executable_token.compiled_loop_token._x86_initial_locs
+locs = executable_token.compiled_loop_token._ll_initial_locs
 prev_interpreter = None   # help flow space
 if not self.translate_support_code:
 prev_interpreter = LLInterpreter.current_interpreter
@@ -129,7 +125,7 @@
 try:
 for i, kind in kinds:
 arg = args[i]
-num = locs[i] - base_ofs
+num = locs[i]
 if kind == history.INT:
 self.set_int_value(ll_frame, num, arg)
 elif kind == 

[pypy-commit] pypy urlparse-unquote-faster: fix quadratic slowness of unquote (caused by buliding string with inplace addition)

2013-02-12 Thread kostialopuhin
Author: Konstantin Lopuhin kostia.lopu...@gmail.com
Branch: urlparse-unquote-faster
Changeset: r61124:c7ea99e3b4db
Date: 2013-02-12 00:22 +0400
http://bitbucket.org/pypy/pypy/changeset/c7ea99e3b4db/

Log:fix quadratic slowness of unquote (caused by buliding string with
inplace addition)

diff --git a/lib-python/2.7/urllib.py b/lib-python/2.7/urllib.py
--- a/lib-python/2.7/urllib.py
+++ b/lib-python/2.7/urllib.py
@@ -1205,15 +1205,16 @@
 # fastpath
 if len(res) == 1:
 return s
-s = res[0]
+res_list = [res[0]]
 for item in res[1:]:
 try:
-s += _hextochr[item[:2]] + item[2:]
+x = _hextochr[item[:2]] + item[2:]
 except KeyError:
-s += '%' + item
+x = '%' + item
 except UnicodeDecodeError:
-s += unichr(int(item[:2], 16)) + item[2:]
-return s
+x = unichr(int(item[:2], 16)) + item[2:]
+res_list.append(x)
+return ''.join(res_list)
 
 def unquote_plus(s):
 unquote('%7e/abc+def') - '~/abc def'
diff --git a/lib-python/2.7/urlparse.py b/lib-python/2.7/urlparse.py
--- a/lib-python/2.7/urlparse.py
+++ b/lib-python/2.7/urlparse.py
@@ -321,15 +321,16 @@
 # fastpath
 if len(res) == 1:
 return s
-s = res[0]
+res_list = [res[0]]
 for item in res[1:]:
 try:
-s += _hextochr[item[:2]] + item[2:]
+x = _hextochr[item[:2]] + item[2:]
 except KeyError:
-s += '%' + item
+x = '%' + item
 except UnicodeDecodeError:
-s += unichr(int(item[:2], 16)) + item[2:]
-return s
+x = unichr(int(item[:2], 16)) + item[2:]
+res_list.append(x)
+return ''.join(res_list)
 
 def parse_qs(qs, keep_blank_values=0, strict_parsing=0):
 Parse a query given as a string argument.
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Merged in kostialopuhin/pypy/urlparse-unquote-faster (pull request #118)

2013-02-12 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: 
Changeset: r61125:dcc4f89c3872
Date: 2013-02-12 12:59 +0200
http://bitbucket.org/pypy/pypy/changeset/dcc4f89c3872/

Log:Merged in kostialopuhin/pypy/urlparse-unquote-faster (pull request
#118)

Make unquote from urllib and urlparse faster

diff --git a/pypy/doc/config/translation.lldebug.txt 
b//doc/config/translation.lldebug.txt
rename from pypy/doc/config/translation.lldebug.txt
rename to /doc/config/translation.lldebug.txt
diff --git a/pypy/goal/__init__.py b//goal/__init__.py
rename from pypy/goal/__init__.py
rename to /goal/__init__.py
diff --git a/pypy/module/cpyext/include/ceval.h b//module/cpyext/include/ceval.h
rename from pypy/module/cpyext/include/ceval.h
rename to /module/cpyext/include/ceval.h
diff --git a/pypy/module/micronumpy/arrayimpl/sort.py 
b//module/micronumpy/arrayimpl/sort.py
rename from pypy/module/micronumpy/arrayimpl/sort.py
rename to /module/micronumpy/arrayimpl/sort.py
diff --git a/pypy/module/micronumpy/constants.py 
b//module/micronumpy/constants.py
rename from pypy/module/micronumpy/constants.py
rename to /module/micronumpy/constants.py
diff --git a/pypy/module/test_lib_pypy/numpypy/core/test_shape_base.py 
b//module/test_lib_pypy/numpypy/core/test_shape_base.py
rename from pypy/module/test_lib_pypy/numpypy/core/test_shape_base.py
rename to /module/test_lib_pypy/numpypy/core/test_shape_base.py
diff --git a/pypy/module/test_lib_pypy/pyrepl/test_keymap.py 
b//module/test_lib_pypy/pyrepl/test_keymap.py
rename from pypy/module/test_lib_pypy/pyrepl/test_keymap.py
rename to /module/test_lib_pypy/pyrepl/test_keymap.py
diff --git a/pypy/module/test_lib_pypy/pyrepl/test_readline.py 
b//module/test_lib_pypy/pyrepl/test_readline.py
rename from pypy/module/test_lib_pypy/pyrepl/test_readline.py
rename to /module/test_lib_pypy/pyrepl/test_readline.py
diff --git a/pypy/sandbox/__init__.py b//sandbox/__init__.py
rename from pypy/sandbox/__init__.py
rename to /sandbox/__init__.py
diff --git a/lib-python/2.7/urllib.py b/lib-python/2.7/urllib.py
--- a/lib-python/2.7/urllib.py
+++ b/lib-python/2.7/urllib.py
@@ -1205,15 +1205,16 @@
 # fastpath
 if len(res) == 1:
 return s
-s = res[0]
+res_list = [res[0]]
 for item in res[1:]:
 try:
-s += _hextochr[item[:2]] + item[2:]
+x = _hextochr[item[:2]] + item[2:]
 except KeyError:
-s += '%' + item
+x = '%' + item
 except UnicodeDecodeError:
-s += unichr(int(item[:2], 16)) + item[2:]
-return s
+x = unichr(int(item[:2], 16)) + item[2:]
+res_list.append(x)
+return ''.join(res_list)
 
 def unquote_plus(s):
 unquote('%7e/abc+def') - '~/abc def'
diff --git a/lib-python/2.7/urlparse.py b/lib-python/2.7/urlparse.py
--- a/lib-python/2.7/urlparse.py
+++ b/lib-python/2.7/urlparse.py
@@ -321,15 +321,16 @@
 # fastpath
 if len(res) == 1:
 return s
-s = res[0]
+res_list = [res[0]]
 for item in res[1:]:
 try:
-s += _hextochr[item[:2]] + item[2:]
+x = _hextochr[item[:2]] + item[2:]
 except KeyError:
-s += '%' + item
+x = '%' + item
 except UnicodeDecodeError:
-s += unichr(int(item[:2], 16)) + item[2:]
-return s
+x = unichr(int(item[:2], 16)) + item[2:]
+res_list.append(x)
+return ''.join(res_list)
 
 def parse_qs(qs, keep_blank_values=0, strict_parsing=0):
 Parse a query given as a string argument.
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jitframe-on-heap: fixes for gc_integration

2013-02-12 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: jitframe-on-heap
Changeset: r61126:45ecdb12c70d
Date: 2013-02-12 13:05 +0200
http://bitbucket.org/pypy/pypy/changeset/45ecdb12c70d/

Log:fixes for gc_integration

diff --git a/rpython/jit/backend/x86/assembler.py 
b/rpython/jit/backend/x86/assembler.py
--- a/rpython/jit/backend/x86/assembler.py
+++ b/rpython/jit/backend/x86/assembler.py
@@ -322,14 +322,11 @@
 # have been used to pass arguments. Note that we pass only
 # one argument, that is the frame
 mc.PUSH_r(edi.value)
+mc.MOV_rr(edi.value, esp.value)
 #
 if IS_X86_32:
-xxx
-stack_size += 2*WORD
-mc.PUSH_r(eax.value)# alignment
+mc.SUB_ri(esp.value, 2*WORD) # alignment
 mc.PUSH_r(esp.value)
-elif IS_X86_64:
-mc.MOV_rr(edi.value, esp.value)
 #
 # esp is now aligned to a multiple of 16 again
 mc.CALL(imm(slowpathaddr))
@@ -340,9 +337,8 @@
 jnz_location = mc.get_relative_pos()
 #
 if IS_X86_32:
-
-mc.ADD_ri(esp.value, 2*WORD)# cancel the two PUSHes above
-elif IS_X86_64:
+mc.ADD_ri(esp.value, 3*WORD)# alignment
+else:
 # restore the edi
 mc.POP_r(edi.value)
 #
@@ -396,16 +392,18 @@
 mc.SUB_ri(esp.value, 2 * WORD)
 mc.MOV_rs(eax.value, 3 * WORD) # 2 + 1
 mc.MOV_sr(0, eax.value)
-elif IS_X86_64:
+else:
 mc.MOV_rs(edi.value, WORD)
 else:
 # we're possibly called from the slowpath of malloc, so we have
 # one extra CALL on the stack, but one less PUSH,
 # save to store stuff 2 locations away on the stack.
+mc.MOV_sr(3 * WORD, eax.value) # save for later
 if IS_X86_32:
-xxx
-mc.MOV_sr(3*WORD, eax.value)
-mc.MOV_rr(edi.value, ebp.value)
+mc.SUB_ri(esp.value, 2 * WORD) # align
+mc.MOV_sr(0, ebp.value)
+else:
+mc.MOV_rr(edi.value, ebp.value)
 
 mc.CALL(imm(func))
 #
@@ -429,8 +427,8 @@
 mc.RET16_i(WORD)
 else:
 if IS_X86_32:
-XXX
-mc.MOV_rs(eax.value, 3 * WORD)
+mc.LEA_rs(esp.value, 2 * WORD)
+mc.MOV_rs(eax.value, 3 * WORD) # restore
 mc.RET()
 
 rawstart = mc.materialize(self.cpu.asmmemmgr, [])
diff --git a/rpython/jit/backend/x86/test/test_gc_integration.py 
b/rpython/jit/backend/x86/test/test_gc_integration.py
--- a/rpython/jit/backend/x86/test/test_gc_integration.py
+++ b/rpython/jit/backend/x86/test/test_gc_integration.py
@@ -7,7 +7,7 @@
 from rpython.jit.backend.llsupport.gc import GcLLDescription, GcLLDescr_boehm,\
  GcLLDescr_framework, GcCache, JitFrameDescrs
 from rpython.jit.backend.detect_cpu import getcpuclass
-from rpython.jit.backend.x86.arch import WORD, JITFRAME_FIXED_SIZE
+from rpython.jit.backend.x86.arch import WORD, JITFRAME_FIXED_SIZE, IS_X86_64
 from rpython.jit.backend.llsupport import jitframe
 from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
 from rpython.rtyper.annlowlevel import llhelper, llhelper_args
@@ -71,10 +71,15 @@
 # the gcmap should contain three things, p0, p1 and p3
 # p3 stays in a register
 # while p0 and p1 are on the frame
-assert frame.jf_gcmap[0] == (1  11) | (1  12) | (1  31)
-assert frame.jf_frame[11]
-assert frame.jf_frame[12]
-assert frame.jf_frame[31]
+if IS_X86_64:
+nos = [11, 12, 31]
+else:
+nos = [4, 5, 25]
+assert frame.jf_gcmap[0] == ((1  nos[0]) | (1  nos[1]) |
+ (1  nos[2]))
+assert frame.jf_frame[nos[0]]
+assert frame.jf_frame[nos[1]]
+assert frame.jf_frame[nos[2]]
 
 def test_rewrite_constptr(self):
 ops = '''
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jitframe-on-heap: more 32bit fixes

2013-02-12 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: jitframe-on-heap
Changeset: r61128:99028fa539f2
Date: 2013-02-12 13:19 +0200
http://bitbucket.org/pypy/pypy/changeset/99028fa539f2/

Log:more 32bit fixes

diff --git a/rpython/jit/backend/x86/assembler.py 
b/rpython/jit/backend/x86/assembler.py
--- a/rpython/jit/backend/x86/assembler.py
+++ b/rpython/jit/backend/x86/assembler.py
@@ -248,12 +248,15 @@
 # XXX investigate if we need to save callee-saved registers
 # on the frame
 mc.SUB_rr(edi.value, eax.value)   # compute the size we want
-assert not IS_X86_32
 # the arg is already in edi
-if hasattr(self.cpu.gc_ll_descr, 'passes_frame'):
+mc.SUB_ri(esp.value, 16 - WORD)
+if IS_X86_32:
+mc.MOV_sr(0, edi.value)
+if hasattr(self.cpu.gc_ll_descr, 'passes_frame'):
+mc.MOV_sr(WORD, ebp.value)
+elif hasattr(self.cpu.gc_ll_descr, 'passes_frame'):
 # for tests only
 mc.MOV_rr(esi.value, ebp.value)
-mc.SUB_ri(esp.value, 16 - WORD)
 mc.CALL(imm(addr))
 mc.ADD_ri(esp.value, 16 - WORD)
 mc.TEST_rr(eax.value, eax.value)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jitframe-on-heap: fix those tests

2013-02-12 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: jitframe-on-heap
Changeset: r61129:b0c9765f3558
Date: 2013-02-12 13:23 +0200
http://bitbucket.org/pypy/pypy/changeset/b0c9765f3558/

Log:fix those tests

diff --git a/rpython/jit/backend/x86/test/test_gc_integration.py 
b/rpython/jit/backend/x86/test/test_gc_integration.py
--- a/rpython/jit/backend/x86/test/test_gc_integration.py
+++ b/rpython/jit/backend/x86/test/test_gc_integration.py
@@ -233,7 +233,10 @@
 def test_malloc_slowpath(self):
 def check(frame):
 assert len(frame.jf_gcmap) == 1
-assert frame.jf_gcmap[0] == (129) | (1  30)
+if IS_X86_64:
+assert frame.jf_gcmap[0] == (129) | (1  30)
+else:
+assert frame.jf_gcmap[0] == (124) | (1  23)
 
 self.cpu = self.getcpu(check)
 ops = '''
@@ -260,9 +263,14 @@
 def test_save_regs_around_malloc(self):
 def check(frame):
 x = frame.jf_gcmap
-assert len(x) == 1
-assert (bin(x[0]).count('1') ==
-'0b111100'.count('1'))
+if IS_X86_64:
+assert len(x) == 1
+assert (bin(x[0]).count('1') ==
+'0b111100'.count('1'))
+else:
+assert len(x) == 2
+s = bin(x[0]).count('1') + bin(x[1]).count('1')
+assert s == 16
 # all but two registers + some stuff on stack
 
 self.cpu = self.getcpu(check)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: actually backout dcc4f89c3872

2013-02-12 Thread bdkearns
Author: Brian Kearns bdkea...@gmail.com
Branch: 
Changeset: r61130:935bd2f2584b
Date: 2013-02-12 06:29 -0500
http://bitbucket.org/pypy/pypy/changeset/935bd2f2584b/

Log:actually backout dcc4f89c3872

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


[pypy-commit] pypy jitframe-on-heap: We now keep the frame in ebp, easy

2013-02-12 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: jitframe-on-heap
Changeset: r61131:7db4696a951c
Date: 2013-02-12 13:41 +0200
http://bitbucket.org/pypy/pypy/changeset/7db4696a951c/

Log:We now keep the frame in ebp, easy

diff --git a/rpython/jit/backend/x86/assembler.py 
b/rpython/jit/backend/x86/assembler.py
--- a/rpython/jit/backend/x86/assembler.py
+++ b/rpython/jit/backend/x86/assembler.py
@@ -877,7 +877,7 @@
 # to provide a place where we can read the frame from, in case
 # we need to reload it after a collection
 rst = self._load_shadowstack_top_in_ebx(self.mc, gcrootmap)
-self.mc.MOV_mr((ebx.value, 0), edi.value)  # MOV [ebx], edi
+self.mc.MOV_mr((ebx.value, 0), ebp.value)  # MOV [ebx], ebp
 self.mc.ADD_ri(ebx.value, WORD)
 if rx86.fits_in_32bits(rst):
 self.mc.MOV_jr(rst, ebx.value)# MOV [rootstacktop], ebx
diff --git a/rpython/jit/backend/x86/test/test_gc_integration.py 
b/rpython/jit/backend/x86/test/test_gc_integration.py
--- a/rpython/jit/backend/x86/test/test_gc_integration.py
+++ b/rpython/jit/backend/x86/test/test_gc_integration.py
@@ -548,7 +548,7 @@
 
 loop = self.parse(
 [p0, p1, p2]
-pf = force_token() # this is a bit below the frame
+pf = force_token() # this is the frame
 call(ConstClass(check_adr), pf, descr=checkdescr) # this can collect
 p3 = getfield_gc(p0, descr=fielddescr)
 pf2 = force_token()
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jitframe-on-heap: fix the last gc_integration test

2013-02-12 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: jitframe-on-heap
Changeset: r61132:094a1cda58d3
Date: 2013-02-12 13:43 +0200
http://bitbucket.org/pypy/pypy/changeset/094a1cda58d3/

Log:fix the last gc_integration test

diff --git a/rpython/jit/backend/x86/test/test_gc_integration.py 
b/rpython/jit/backend/x86/test/test_gc_integration.py
--- a/rpython/jit/backend/x86/test/test_gc_integration.py
+++ b/rpython/jit/backend/x86/test/test_gc_integration.py
@@ -527,7 +527,10 @@
 frames.append(frame)
 new_frame = JITFRAME.allocate(frame.jf_frame_info)
 gcmap = unpack_gcmap(frame)
-assert gcmap == [28, 29, 30]
+if IS_X86_64:
+assert gcmap == [28, 29, 30]
+else:
+assert gcmap == [22, 23, 24]
 for item, s in zip(gcmap, new_items):
 new_frame.jf_frame[item] = rffi.cast(lltype.Signed, s)
 assert cpu.gc_ll_descr.gcrootmap.stack[0] == 
rffi.cast(lltype.Signed, frame)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy unquote-faster: fix quadratic slowness of unquote (caused by buliding string with inplace addition)

2013-02-12 Thread kostialopuhin
Author: Konstantin Lopuhin kostia.lopu...@gmail.com
Branch: unquote-faster
Changeset: r61133:f505dfc8c778
Date: 2013-02-12 16:09 +0400
http://bitbucket.org/pypy/pypy/changeset/f505dfc8c778/

Log:fix quadratic slowness of unquote (caused by buliding string with
inplace addition)

diff --git a/lib-python/2.7/urllib.py b/lib-python/2.7/urllib.py
--- a/lib-python/2.7/urllib.py
+++ b/lib-python/2.7/urllib.py
@@ -1205,15 +1205,16 @@
 # fastpath
 if len(res) == 1:
 return s
-s = res[0]
+res_list = [res[0]]
 for item in res[1:]:
 try:
-s += _hextochr[item[:2]] + item[2:]
+x = _hextochr[item[:2]] + item[2:]
 except KeyError:
-s += '%' + item
+x = '%' + item
 except UnicodeDecodeError:
-s += unichr(int(item[:2], 16)) + item[2:]
-return s
+x = unichr(int(item[:2], 16)) + item[2:]
+res_list.append(x)
+return ''.join(res_list)
 
 def unquote_plus(s):
 unquote('%7e/abc+def') - '~/abc def'
diff --git a/lib-python/2.7/urlparse.py b/lib-python/2.7/urlparse.py
--- a/lib-python/2.7/urlparse.py
+++ b/lib-python/2.7/urlparse.py
@@ -321,15 +321,16 @@
 # fastpath
 if len(res) == 1:
 return s
-s = res[0]
+res_list = [res[0]]
 for item in res[1:]:
 try:
-s += _hextochr[item[:2]] + item[2:]
+x = _hextochr[item[:2]] + item[2:]
 except KeyError:
-s += '%' + item
+x = '%' + item
 except UnicodeDecodeError:
-s += unichr(int(item[:2], 16)) + item[2:]
-return s
+x = unichr(int(item[:2], 16)) + item[2:]
+res_list.append(x)
+return ''.join(res_list)
 
 def parse_qs(qs, keep_blank_values=0, strict_parsing=0):
 Parse a query given as a string argument.
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy unquote-faster: avoid extra copy

2013-02-12 Thread kostialopuhin
Author: Konstantin Lopuhin kostia.lopu...@gmail.com
Branch: unquote-faster
Changeset: r61134:134dddef38b4
Date: 2013-02-12 17:01 +0400
http://bitbucket.org/pypy/pypy/changeset/134dddef38b4/

Log:avoid extra copy

diff --git a/lib-python/2.7/urllib.py b/lib-python/2.7/urllib.py
--- a/lib-python/2.7/urllib.py
+++ b/lib-python/2.7/urllib.py
@@ -1206,7 +1206,8 @@
 if len(res) == 1:
 return s
 res_list = [res[0]]
-for item in res[1:]:
+for j in xrange(1, len(res)):
+item = res[j]
 try:
 x = _hextochr[item[:2]] + item[2:]
 except KeyError:
diff --git a/lib-python/2.7/urlparse.py b/lib-python/2.7/urlparse.py
--- a/lib-python/2.7/urlparse.py
+++ b/lib-python/2.7/urlparse.py
@@ -322,7 +322,8 @@
 if len(res) == 1:
 return s
 res_list = [res[0]]
-for item in res[1:]:
+for j in xrange(1, len(res)):
+item = res[j]
 try:
 x = _hextochr[item[:2]] + item[2:]
 except KeyError:
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Merged in kostialopuhin/pypy/unquote-faster (pull request #119)

2013-02-12 Thread bdkearns
Author: Brian Kearns bdkea...@gmail.com
Branch: 
Changeset: r61135:46fb234140b9
Date: 2013-02-12 05:07 -0800
http://bitbucket.org/pypy/pypy/changeset/46fb234140b9/

Log:Merged in kostialopuhin/pypy/unquote-faster (pull request #119)

Make unquote from urllib and urlparse faster

diff --git a/lib-python/2.7/urllib.py b/lib-python/2.7/urllib.py
--- a/lib-python/2.7/urllib.py
+++ b/lib-python/2.7/urllib.py
@@ -1205,15 +1205,17 @@
 # fastpath
 if len(res) == 1:
 return s
-s = res[0]
-for item in res[1:]:
+res_list = [res[0]]
+for j in xrange(1, len(res)):
+item = res[j]
 try:
-s += _hextochr[item[:2]] + item[2:]
+x = _hextochr[item[:2]] + item[2:]
 except KeyError:
-s += '%' + item
+x = '%' + item
 except UnicodeDecodeError:
-s += unichr(int(item[:2], 16)) + item[2:]
-return s
+x = unichr(int(item[:2], 16)) + item[2:]
+res_list.append(x)
+return ''.join(res_list)
 
 def unquote_plus(s):
 unquote('%7e/abc+def') - '~/abc def'
diff --git a/lib-python/2.7/urlparse.py b/lib-python/2.7/urlparse.py
--- a/lib-python/2.7/urlparse.py
+++ b/lib-python/2.7/urlparse.py
@@ -321,15 +321,17 @@
 # fastpath
 if len(res) == 1:
 return s
-s = res[0]
-for item in res[1:]:
+res_list = [res[0]]
+for j in xrange(1, len(res)):
+item = res[j]
 try:
-s += _hextochr[item[:2]] + item[2:]
+x = _hextochr[item[:2]] + item[2:]
 except KeyError:
-s += '%' + item
+x = '%' + item
 except UnicodeDecodeError:
-s += unichr(int(item[:2], 16)) + item[2:]
-return s
+x = unichr(int(item[:2], 16)) + item[2:]
+res_list.append(x)
+return ''.join(res_list)
 
 def parse_qs(qs, keep_blank_values=0, strict_parsing=0):
 Parse a query given as a string argument.
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: test, fix missing dtype in coerce

2013-02-12 Thread mattip
Author: mattip
Branch: 
Changeset: r61136:78737ede9909
Date: 2013-02-12 17:09 +0200
http://bitbucket.org/pypy/pypy/changeset/78737ede9909/

Log:test, fix missing dtype in coerce

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
@@ -1666,6 +1666,9 @@
 a = arange(6, dtype='f4').reshape(2,3)
 b = a.astype('i4')
 
+a = array('x').astype('S3').dtype
+assert a.itemsize == 3
+
 def test_base(self):
 from _numpypy import array
 assert array(1).base is None
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -1603,7 +1603,7 @@
 arr = interp_boxes.VoidBoxStorage(len(arg), new_string_dtype(space, 
len(arg)))
 for i in range(len(arg)):
 arr.storage[i] = arg[i]
-return interp_boxes.W_StringBox(arr,  0, None)
+return interp_boxes.W_StringBox(arr,  0, arg.dtype)
 
 @jit.unroll_safe
 def store(self, arr, i, offset, box):
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: typo

2013-02-12 Thread mattip
Author: mattip
Branch: 
Changeset: r61137:24d0ce574830
Date: 2013-02-12 17:25 +0200
http://bitbucket.org/pypy/pypy/changeset/24d0ce574830/

Log:typo

diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -1603,7 +1603,7 @@
 arr = interp_boxes.VoidBoxStorage(len(arg), new_string_dtype(space, 
len(arg)))
 for i in range(len(arg)):
 arr.storage[i] = arg[i]
-return interp_boxes.W_StringBox(arr,  0, arg.dtype)
+return interp_boxes.W_StringBox(arr,  0, arr.dtype)
 
 @jit.unroll_safe
 def store(self, arr, i, offset, box):
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jitframe-on-heap: er, I'm a moron

2013-02-12 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: jitframe-on-heap
Changeset: r61138:ad46b2046728
Date: 2013-02-12 17:38 +0200
http://bitbucket.org/pypy/pypy/changeset/ad46b2046728/

Log:er, I'm a moron

diff --git a/rpython/jit/backend/llsupport/jitframe.py 
b/rpython/jit/backend/llsupport/jitframe.py
--- a/rpython/jit/backend/llsupport/jitframe.py
+++ b/rpython/jit/backend/llsupport/jitframe.py
@@ -5,7 +5,7 @@
 from rpython.rlib.objectmodel import enforceargs
 
 SIZEOFSIGNED = rffi.sizeof(lltype.Signed)
-IS_32BIT = (SIZEOFSIGNED == 2 ** 31 - 1)
+IS_32BIT = (SIZEOFSIGNED == 4)
 
 # this is an info that only depends on the assembler executed, copied from
 # compiled loop token (in fact we could use this as a compiled loop token
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jitframe-on-heap: missing import

2013-02-12 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: jitframe-on-heap
Changeset: r61139:af14ec8e43fc
Date: 2013-02-12 17:48 +0200
http://bitbucket.org/pypy/pypy/changeset/af14ec8e43fc/

Log:missing import

diff --git a/rpython/jit/backend/x86/test/test_zrpy_gc_boehm.py 
b/rpython/jit/backend/x86/test/test_zrpy_gc_boehm.py
--- a/rpython/jit/backend/x86/test/test_zrpy_gc_boehm.py
+++ b/rpython/jit/backend/x86/test/test_zrpy_gc_boehm.py
@@ -1,7 +1,7 @@
 
 import weakref
 from rpython.rlib.jit import JitDriver, dont_look_inside
-from rpython.jit.backend.x86.test.test_zrpy_gc import run, get_entry
+from rpython.jit.backend.x86.test.test_zrpy_gc import run, get_entry, compile
 
 class X(object):
 def __init__(self, x=0):
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jitframe-on-heap: oops

2013-02-12 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: jitframe-on-heap
Changeset: r61141:e11d4dff507d
Date: 2013-02-12 18:11 +0200
http://bitbucket.org/pypy/pypy/changeset/e11d4dff507d/

Log:oops

diff --git a/rpython/jit/backend/arm/test/test_runner.py 
b/rpython/jit/backend/arm/test/test_runner.py
--- a/rpython/jit/backend/arm/test/test_runner.py
+++ b/rpython/jit/backend/arm/test/test_runner.py
@@ -57,7 +57,7 @@
 ResOperation(rop.GUARD_FALSE, [inp[1]], None, 
descr=BasicFailDescr(1)),
 ResOperation(rop.FINISH, [inp[1]], None, descr=BasicFinalDescr(1)),
 ]
-operations[-1].setfailargs(out)
+operations[-2].setfailargs(out)
 cpu.compile_loop(inp, operations, looptoken)
 args = [i for i in range(1, 15)]
 deadframe = self.cpu.execute_token(looptoken, *args)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jitframe-on-heap: a historical commit - start sharing code between arm and x86

2013-02-12 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: jitframe-on-heap
Changeset: r61143:3c7de3e490d1
Date: 2013-02-12 18:30 +0200
http://bitbucket.org/pypy/pypy/changeset/3c7de3e490d1/

Log:a historical commit - start sharing code between arm and x86

diff --git a/rpython/jit/backend/arm/regalloc.py 
b/rpython/jit/backend/arm/regalloc.py
--- a/rpython/jit/backend/arm/regalloc.py
+++ b/rpython/jit/backend/arm/regalloc.py
@@ -1,8 +1,8 @@
-from rpython.rtyper.annlowlevel import llhelper, cast_instance_to_gcref
+from rpython.rtyper.annlowlevel import cast_instance_to_gcref
 from rpython.rlib import rgc
 from rpython.rlib.debug import debug_print, debug_start, debug_stop
 from rpython.jit.backend.llsupport.regalloc import FrameManager, \
-RegisterManager, TempBox, compute_vars_longevity
+RegisterManager, TempBox, compute_vars_longevity, BaseRegalloc
 from rpython.jit.backend.arm import registers as r
 from rpython.jit.backend.arm import locations
 from rpython.jit.backend.arm.locations import imm, get_fp_offset
@@ -16,7 +16,7 @@
 )
 from rpython.jit.backend.arm.jump import remap_frame_layout_mixed
 from rpython.jit.backend.arm.arch import MY_COPY_OF_REGS
-from rpython.jit.backend.arm.arch import WORD, DOUBLE_WORD, JITFRAME_FIXED_SIZE
+from rpython.jit.backend.arm.arch import WORD, JITFRAME_FIXED_SIZE
 from rpython.jit.codewriter import longlong
 from rpython.jit.metainterp.history import (Const, ConstInt, ConstFloat, 
ConstPtr,
 Box, BoxPtr,
@@ -32,7 +32,6 @@
 from rpython.jit.backend.llsupport.descr import unpack_arraydescr
 from rpython.jit.backend.llsupport.descr import unpack_fielddescr
 from rpython.jit.backend.llsupport.descr import unpack_interiorfielddescr
-from rpython.rlib.objectmodel import we_are_translated
 
 
 # xxx hack: set a default value for TargetToken._arm_loop_code.  If 0, we know
@@ -179,7 +178,7 @@
 return reg
 
 
-class Regalloc(object):
+class Regalloc(BaseRegalloc):
 
 def __init__(self, assembler=None):
 self.cpu = assembler.cpu
@@ -316,12 +315,6 @@
 def get_final_frame_depth(self):
 return self.frame_manager.get_frame_depth()
 
-def _set_initial_bindings(self, inputargs):
-# the input args are passed in the jitframe
-for box in inputargs:
-assert isinstance(box, Box)
-self.fm.get_new_loc(box)
-
 def _update_bindings(self, locs, inputargs):
 used = {}
 i = 0
diff --git a/rpython/jit/backend/llsupport/regalloc.py 
b/rpython/jit/backend/llsupport/regalloc.py
--- a/rpython/jit/backend/llsupport/regalloc.py
+++ b/rpython/jit/backend/llsupport/regalloc.py
@@ -627,6 +627,22 @@
  Platform specific - Allocates a temporary register 
 raise NotImplementedError(Abstract)
 
+class BaseRegalloc(object):
+ Base class on which all the backend regallocs should be based
+
+def _set_initial_bindings(self, inputargs, looptoken):
+ Set the bindings at the start of the loop
+
+locs = []
+base_ofs = self.assembler.cpu.get_baseofs_of_frame_field()
+for box in inputargs:
+assert isinstance(box, Box)
+loc = self.fm.get_new_loc(box)
+locs.append(loc.value - base_ofs)
+if looptoken.compiled_loop_token is not None:
+# for tests
+looptoken.compiled_loop_token._ll_initial_locs = locs
+
 
 def compute_vars_longevity(inputargs, operations):
 # compute a dictionary that maps variables to index in
diff --git a/rpython/jit/backend/x86/regalloc.py 
b/rpython/jit/backend/x86/regalloc.py
--- a/rpython/jit/backend/x86/regalloc.py
+++ b/rpython/jit/backend/x86/regalloc.py
@@ -23,7 +23,7 @@
 from rpython.jit.backend.llsupport.descr import unpack_fielddescr
 from rpython.jit.backend.llsupport.descr import unpack_interiorfielddescr
 from rpython.jit.backend.llsupport.gcmap import allocate_gcmap
-from rpython.jit.backend.llsupport.regalloc import FrameManager,\
+from rpython.jit.backend.llsupport.regalloc import FrameManager, BaseRegalloc,\
  RegisterManager, TempBox, compute_vars_longevity, is_comparison_or_ovf_op
 from rpython.jit.backend.x86.arch import WORD, JITFRAME_FIXED_SIZE
 from rpython.jit.backend.x86.arch import IS_X86_32, IS_X86_64
@@ -133,7 +133,7 @@
 for _i, _reg in enumerate(gpr_reg_mgr_cls.all_regs):
 gpr_reg_mgr_cls.all_reg_indexes[_reg.value] = _i
 
-class RegAlloc(object):
+class RegAlloc(BaseRegalloc):
 
 def __init__(self, assembler, translate_support_code=False):
 assert isinstance(translate_support_code, bool)
@@ -188,17 +188,6 @@
 def get_final_frame_depth(self):
 return self.fm.get_frame_depth()
 
-def _set_initial_bindings(self, inputargs, looptoken):
-locs = []
-base_ofs = self.assembler.cpu.get_baseofs_of_frame_field()
-for box in inputargs:
-assert isinstance(box, Box)
-loc = 

[pypy-commit] pypy jitframe-on-heap: rewrite this test

2013-02-12 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: jitframe-on-heap
Changeset: r61140:8c534cd20ab5
Date: 2013-02-12 18:10 +0200
http://bitbucket.org/pypy/pypy/changeset/8c534cd20ab5/

Log:rewrite this test

diff --git a/rpython/jit/backend/arm/test/test_runner.py 
b/rpython/jit/backend/arm/test/test_runner.py
--- a/rpython/jit/backend/arm/test/test_runner.py
+++ b/rpython/jit/backend/arm/test/test_runner.py
@@ -1,12 +1,9 @@
 import py
 from rpython.jit.backend.detect_cpu import getcpuclass
-from rpython.jit.backend.arm.arch import WORD
-from rpython.jit.backend.test.runner_test import LLtypeBackendTest, \
-boxfloat, \
-constfloat
-from rpython.jit.metainterp.history import (BasicFailDescr,
- BoxInt,
- ConstInt)
+from rpython.jit.backend.test.runner_test import LLtypeBackendTest,\
+ boxfloat, constfloat
+from rpython.jit.metainterp.history import (BasicFailDescr, BasicFinalDescr,
+BoxInt)
 from rpython.jit.metainterp.resoperation import ResOperation, rop
 from rpython.jit.tool.oparser import parse
 from rpython.rtyper.lltypesystem import lltype, llmemory, rclass
@@ -57,8 +54,10 @@
 ResOperation(rop.INT_ADD, [inp[8], inp[9]], out[11]),
 ResOperation(rop.INT_ADD, [inp[10], inp[11]], out[12]),
 ResOperation(rop.INT_ADD, [inp[12], inp[13]], out[13]),
-ResOperation(rop.FINISH, out, None, descr=BasicFailDescr(1)),
+ResOperation(rop.GUARD_FALSE, [inp[1]], None, 
descr=BasicFailDescr(1)),
+ResOperation(rop.FINISH, [inp[1]], None, descr=BasicFinalDescr(1)),
 ]
+operations[-1].setfailargs(out)
 cpu.compile_loop(inp, operations, looptoken)
 args = [i for i in range(1, 15)]
 deadframe = self.cpu.execute_token(looptoken, *args)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jitframe-on-heap: finish fixing this test

2013-02-12 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: jitframe-on-heap
Changeset: r61142:932cb78d444f
Date: 2013-02-12 18:14 +0200
http://bitbucket.org/pypy/pypy/changeset/932cb78d444f/

Log:finish fixing this test

diff --git a/rpython/jit/backend/arm/test/test_runner.py 
b/rpython/jit/backend/arm/test/test_runner.py
--- a/rpython/jit/backend/arm/test/test_runner.py
+++ b/rpython/jit/backend/arm/test/test_runner.py
@@ -61,7 +61,7 @@
 cpu.compile_loop(inp, operations, looptoken)
 args = [i for i in range(1, 15)]
 deadframe = self.cpu.execute_token(looptoken, *args)
-output = [self.cpu.get_latest_value_int(deadframe, i - 1) for i in 
range(1, 15)]
+output = [self.cpu.get_int_value(deadframe, i - 1) for i in range(1, 
15)]
 expected = [3, 7, 11, 15, 19, 23, 27, 3, 7, 11, 15, 19, 23, 27]
 assert output == expected
 
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi auto-types: An extra test for 'bool'.

2013-02-12 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: auto-types
Changeset: r1146:c1ea20ec5783
Date: 2013-02-12 16:41 +0100
http://bitbucket.org/cffi/cffi/changeset/c1ea20ec5783/

Log:An extra test for 'bool'.

diff --git a/testing/test_verify.py b/testing/test_verify.py
--- a/testing/test_verify.py
+++ b/testing/test_verify.py
@@ -1249,6 +1249,7 @@
 for sign in ['signed', 'unsigned']:
 type = '%s %s' % (sign, basetype)
 assert int(ffi.cast(_Bool, ffi.cast(type, 42))) == 1
+assert int(ffi.cast(bool, ffi.cast(type, 42))) == 1
 assert int(ffi.cast(_Bool, ffi.cast(type, 0))) == 0
 
 def test_addressof():
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi enum-as-int: Fix enums to use the same rule as gcc: they are actually not always

2013-02-12 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: enum-as-int
Changeset: r1147:c0fb2acdd6f7
Date: 2013-02-12 18:14 +0100
http://bitbucket.org/cffi/cffi/changeset/c0fb2acdd6f7/

Log:Fix enums to use the same rule as gcc: they are actually not always
'int', but the first of the following types that fits: 'unsigned
int', 'int', 'unsigned long', 'long'.

diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -823,32 +823,6 @@
 return (PyObject *)cd;
 }
 
-static PyObject *convert_cdata_to_enum_string(CDataObject *cd, int both)
-{
-int value;
-PyObject *d_key, *d_value;
-CTypeDescrObject *ct = cd-c_type;
-
-assert(ct-ct_flags  CT_IS_ENUM);
-value = (int)read_raw_signed_data(cd-c_data, ct-ct_size);
-d_key = PyInt_FromLong(value);
-if (d_key == NULL)
-return NULL;
-
-d_value = PyDict_GetItem(PyTuple_GET_ITEM(ct-ct_stuff, 1), d_key);
-if (d_value != NULL) {
-if (both)
-d_value = PyText_FromFormat(%d: %s, value,
-PyText_AS_UTF8(d_value));
-else
-Py_INCREF(d_value);
-}
-else
-d_value = PyObject_Str(d_key);
-Py_DECREF(d_key);
-return d_value;
-}
-
 static CDataObject *_new_casted_primitive(CTypeDescrObject *ct);  /*forward*/
 
 static PyObject *
@@ -1432,6 +1406,38 @@
 
 static PyObject *cdata_float(CDataObject *cd);  /*forward*/
 
+static PyObject *convert_cdata_to_enum_string(CDataObject *cd, int both)
+{
+PyObject *d_key, *d_value;
+CTypeDescrObject *ct = cd-c_type;
+
+assert(ct-ct_flags  CT_IS_ENUM);
+d_key = convert_to_object(cd-c_data, ct);
+if (d_key == NULL)
+return NULL;
+
+d_value = PyDict_GetItem(PyTuple_GET_ITEM(ct-ct_stuff, 1), d_key);
+if (d_value != NULL) {
+if (both) {
+PyObject *o = PyObject_Str(d_key);
+if (o == NULL)
+d_value = NULL;
+else {
+d_value = PyText_FromFormat(%s: %s,
+PyText_AS_UTF8(o),
+PyText_AS_UTF8(d_value));
+Py_DECREF(o);
+}
+}
+else
+Py_INCREF(d_value);
+}
+else
+d_value = PyObject_Str(d_key);
+Py_DECREF(d_key);
+return d_value;
+}
+
 static PyObject *cdata_repr(CDataObject *cd)
 {
 char *extra;
@@ -3866,8 +3872,7 @@
 return -1;
 }
 }
-if ((ctype-ct_flags  (CT_PRIMITIVE_SIGNED | CT_IS_ENUM))
-== CT_PRIMITIVE_SIGNED) {
+if (ctype-ct_flags  CT_PRIMITIVE_SIGNED) {
 PY_LONG_LONG value;
 /* It's probably fine to always zero-extend, but you never
know: maybe some code somewhere expects a negative
@@ -4086,6 +4091,10 @@
 CTypeDescrObject *td;
 Py_ssize_t i, n;
 struct aligncheck_int { char x; int y; };
+struct aligncheck_long { char x; long y; };
+long smallest_item = 0;
+unsigned long largest_item = 0;
+int size, flags;
 
 if (!PyArg_ParseTuple(args, sO!O!:new_enum_type,
   ename,
@@ -4109,6 +4118,7 @@
 
 for (i=n; --i = 0; ) {
 long lvalue;
+unsigned long ulvalue;
 PyObject *value = PyTuple_GET_ITEM(enumvalues, i);
 tmpkey = PyTuple_GET_ITEM(enumerators, i);
 Py_INCREF(tmpkey);
@@ -4132,11 +4142,29 @@
 }
 }
 lvalue = PyLong_AsLong(value);
-if ((lvalue == -1  PyErr_Occurred()) || lvalue != (int)lvalue) {
-PyErr_Format(PyExc_OverflowError,
- enum '%s' declaration for '%s' does not fit an int,
- ename, PyText_AS_UTF8(tmpkey));
-goto error;
+if (PyErr_Occurred()) {
+PyErr_Clear();
+ulvalue = PyLong_AsUnsignedLong(value);
+if (PyErr_Occurred()) {
+PyErr_Format(PyExc_OverflowError,
+ enum '%s' declaration for '%s' does not fit 
+ a long or unsigned long,
+ ename, PyText_AS_UTF8(tmpkey));
+goto error;
+}
+if (ulvalue  largest_item)
+largest_item = ulvalue;
+}
+else {
+if (lvalue  0) {
+if (lvalue  smallest_item)
+smallest_item = lvalue;
+}
+else {
+ulvalue = (unsigned long)lvalue;
+if (ulvalue  largest_item)
+largest_item = ulvalue;
+}
 }
 if (PyDict_SetItem(dict1, tmpkey, value)  0)
 goto error;
@@ -4146,6 +4174,32 @@
 tmpkey = NULL;
 }
 
+if (smallest_item  0) {
+flags = CT_PRIMITIVE_SIGNED | CT_PRIMITIVE_FITS_LONG | CT_IS_ENUM;
+if (smallest_item == (int)smallest_item 
+ 

[pypy-commit] cffi default: hg merge slicing

2013-02-12 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r1149:62db8ccc85d2
Date: 2013-02-12 18:19 +0100
http://bitbucket.org/cffi/cffi/changeset/62db8ccc85d2/

Log:hg merge slicing

diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -102,7 +102,8 @@
 PyObject *ct_stuff;/* structs: dict of the fields
   arrays: ctypedescr of the ptr type
   function: tuple(abi, ctres, ctargs..)
-  enum: pair {name:x},{x:name} */
+  enum: pair {name:x},{x:name}
+  ptrs: lazily, ctypedescr of array */
 void *ct_extra;/* structs: first field (not a ref!)
   function types: cif_description
   primitives: prebuilt cif object */
@@ -1490,6 +1491,9 @@
 s = PyText_FromString(buffer);
 }
 }
+else if ((cd-c_type-ct_flags  CT_ARRAY)  cd-c_type-ct_length  0) {
+s = PyText_FromFormat(sliced length %zd, get_array_length(cd));
+}
 else {
 if (cd-c_data != NULL) {
 s = PyText_FromFormat(%p, cd-c_data);
@@ -1717,9 +1721,155 @@
 }
 
 static PyObject *
+new_array_type(CTypeDescrObject *ctptr, PyObject *lengthobj);   /* forward */
+
+static CTypeDescrObject *
+_cdata_getslicearg(CDataObject *cd, PySliceObject *slice, Py_ssize_t bounds[])
+{
+Py_ssize_t start, stop;
+CTypeDescrObject *ct;
+
+start = PyInt_AsSsize_t(slice-start);
+if (start == -1  PyErr_Occurred()) {
+if (slice-start == Py_None)
+PyErr_SetString(PyExc_IndexError, slice start must be specified);
+return NULL;
+}
+stop = PyInt_AsSsize_t(slice-stop);
+if (stop == -1  PyErr_Occurred()) {
+if (slice-stop == Py_None)
+PyErr_SetString(PyExc_IndexError, slice stop must be specified);
+return NULL;
+}
+if (slice-step != Py_None) {
+PyErr_SetString(PyExc_IndexError, slice with step not supported);
+return NULL;
+}
+if (start  stop) {
+PyErr_SetString(PyExc_IndexError, slice start  stop);
+return NULL;
+}
+
+ct = cd-c_type;
+if (ct-ct_flags  CT_ARRAY) {
+if (start  0) {
+PyErr_SetString(PyExc_IndexError,
+negative index not supported);
+return NULL;
+}
+if (stop = get_array_length(cd)) {
+PyErr_Format(PyExc_IndexError,
+ index too large (expected %zd  %zd),
+ stop, get_array_length(cd));
+return NULL;
+}
+ct = (CTypeDescrObject *)ct-ct_stuff;
+}
+else if (!(ct-ct_flags  CT_POINTER)) {
+PyErr_Format(PyExc_TypeError, cdata of type '%s' cannot be indexed,
+ ct-ct_name);
+return NULL;
+}
+
+bounds[0] = start;
+bounds[1] = stop - start;
+return ct;
+}
+
+static PyObject *
+cdata_slice(CDataObject *cd, PySliceObject *slice)
+{
+Py_ssize_t bounds[2];
+CDataObject_own_length *scd;
+CTypeDescrObject *ct = _cdata_getslicearg(cd, slice, bounds);
+if (ct == NULL)
+return NULL;
+
+if (ct-ct_stuff == NULL) {
+ct-ct_stuff = new_array_type(ct, Py_None);
+if (ct-ct_stuff == NULL)
+return NULL;
+}
+ct = (CTypeDescrObject *)ct-ct_stuff;
+
+scd = (CDataObject_own_length *)PyObject_Malloc(
+  offsetof(CDataObject_own_length, alignment));
+if (PyObject_Init((PyObject *)scd, CData_Type) == NULL)
+return NULL;
+Py_INCREF(ct);
+scd-head.c_type = ct;
+scd-head.c_data = cd-c_data + ct-ct_itemdescr-ct_size * bounds[0];
+scd-head.c_weakreflist = NULL;
+scd-length = bounds[1];
+return (PyObject *)scd;
+}
+
+static int
+cdata_ass_slice(CDataObject *cd, PySliceObject *slice, PyObject *v)
+{
+Py_ssize_t bounds[2], i, length, itemsize;
+PyObject *it, *item;
+PyObject *(*iternext)(PyObject *);
+char *cdata;
+int err;
+CTypeDescrObject *ct = _cdata_getslicearg(cd, slice, bounds);
+if (ct == NULL)
+return -1;
+ct = ct-ct_itemdescr;
+itemsize = ct-ct_size;
+cdata = cd-c_data + itemsize * bounds[0];
+length = bounds[1];
+
+if (CData_Check(v)) {
+CTypeDescrObject *ctv = ((CDataObject *)v)-c_type;
+if ((ctv-ct_flags  CT_ARRAY)  (ctv-ct_itemdescr == ct) 
+(get_array_length((CDataObject *)v) == length)) {
+/* fast path: copying from exactly the correct type */
+memcpy(cdata, ((CDataObject *)v)-c_data, itemsize * length);
+return 0;
+}
+}
+
+it = PyObject_GetIter(v);
+if (it == NULL)
+return -1;
+iternext = *it-ob_type-tp_iternext;
+
+for (i = 0; i  length; i++) {
+  

[pypy-commit] cffi enum-as-int: More documentation

2013-02-12 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: enum-as-int
Changeset: r1150:ea9fec031def
Date: 2013-02-12 18:21 +0100
http://bitbucket.org/cffi/cffi/changeset/ea9fec031def/

Log:More documentation

diff --git a/doc/source/index.rst b/doc/source/index.rst
--- a/doc/source/index.rst
+++ b/doc/source/index.rst
@@ -1347,9 +1347,10 @@
functions like ``long double add(long double a, long double b);``.
 
 .. versionchanged:: 0.6
-   `(*)` Enums are now handled like ints.  In previous versions,
-   you would get the enum's value as a string.  Now we follow the C
-   convention and treat them as really equivalent to ints.  To compare
+   `(*)` Enums are now handled like ints (unsigned or signed, int or
+   long, like GCC; note that the first choice is unsigned).  In previous
+   versions, you would get the enum's value as a string.  Now we follow the C
+   convention and treat them as really equivalent to integers.  To compare
their value symbolically, use code like ``if x.field == lib.FOO``.
If you really want to get their value as a string, use
``ffi.string(ffi.cast(the_enum_type, x.field))``.
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi default: hg merge enum-as-int

2013-02-12 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r1151:4aed2f4e2bc1
Date: 2013-02-12 18:26 +0100
http://bitbucket.org/cffi/cffi/changeset/4aed2f4e2bc1/

Log:hg merge enum-as-int

diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -824,35 +824,6 @@
 return (PyObject *)cd;
 }
 
-static PyObject *convert_enum_string_to_int(CTypeDescrObject *ct, PyObject *ob)
-{
-PyObject *d_value;
-char *p = PyText_AsUTF8(ob);
-if (p == NULL)
-return NULL;
-
-if (p[0] == '#') {
-char *number = p + 1;   /* strip initial '#' */
-PyObject *ob2 = PyText_FromString(number);
-if (ob2 == NULL)
-return NULL;
-
-d_value = PyNumber_Long(ob2);
-Py_DECREF(ob2);
-}
-else {
-d_value = PyDict_GetItem(PyTuple_GET_ITEM(ct-ct_stuff, 0), ob);
-if (d_value == NULL) {
-PyErr_Format(PyExc_ValueError,
- '%s' is not an enumerator for %s,
- p, ct-ct_name);
-return NULL;
-}
-Py_INCREF(d_value);
-}
-return d_value;
-}
-
 static CDataObject *_new_casted_primitive(CTypeDescrObject *ct);  /*forward*/
 
 static PyObject *
@@ -887,21 +858,7 @@
 PY_LONG_LONG value;
 /*READ(data, ct-ct_size)*/
 value = read_raw_signed_data(data, ct-ct_size);
-
-if (ct-ct_flags  CT_IS_ENUM) {
-PyObject *d_value, *d_key = PyInt_FromLong((int)value);
-if (d_key == NULL)
-return NULL;
-
-d_value = PyDict_GetItem(PyTuple_GET_ITEM(ct-ct_stuff, 1), d_key);
-Py_DECREF(d_key);
-if (d_value != NULL)
-Py_INCREF(d_value);
-else
-d_value = PyText_FromFormat(#%d, (int)value);
-return d_value;
-}
-else if (ct-ct_flags  CT_PRIMITIVE_FITS_LONG)
+if (ct-ct_flags  CT_PRIMITIVE_FITS_LONG)
 return PyInt_FromLong((long)value);
 else
 return PyLong_FromLongLong(value);
@@ -1190,27 +1147,8 @@
 }
 if (ct-ct_flags  CT_PRIMITIVE_SIGNED) {
 PY_LONG_LONG value = _my_PyLong_AsLongLong(init);
-
-if (value == -1  PyErr_Occurred()) {
-if (!(ct-ct_flags  CT_IS_ENUM))
-return -1;
-else {
-PyObject *ob;
-PyErr_Clear();
-if (!PyTextAny_Check(init)) {
-expected = str or int;
-goto cannot_convert;
-}
-
-ob = convert_enum_string_to_int(ct, init);
-if (ob == NULL)
-return -1;
-value = PyLong_AsLongLong(ob);
-Py_DECREF(ob);
-if (value == -1  PyErr_Occurred())
-return -1;
-}
-}
+if (value == -1  PyErr_Occurred())
+return -1;
 write_raw_integer_data(buf, value, ct-ct_size);
 if (value != read_raw_signed_data(buf, ct-ct_size))
 goto overflow;
@@ -1469,20 +1407,48 @@
 
 static PyObject *cdata_float(CDataObject *cd);  /*forward*/
 
+static PyObject *convert_cdata_to_enum_string(CDataObject *cd, int both)
+{
+PyObject *d_key, *d_value;
+CTypeDescrObject *ct = cd-c_type;
+
+assert(ct-ct_flags  CT_IS_ENUM);
+d_key = convert_to_object(cd-c_data, ct);
+if (d_key == NULL)
+return NULL;
+
+d_value = PyDict_GetItem(PyTuple_GET_ITEM(ct-ct_stuff, 1), d_key);
+if (d_value != NULL) {
+if (both) {
+PyObject *o = PyObject_Str(d_key);
+if (o == NULL)
+d_value = NULL;
+else {
+d_value = PyText_FromFormat(%s: %s,
+PyText_AS_UTF8(o),
+PyText_AS_UTF8(d_value));
+Py_DECREF(o);
+}
+}
+else
+Py_INCREF(d_value);
+}
+else
+d_value = PyObject_Str(d_key);
+Py_DECREF(d_key);
+return d_value;
+}
+
 static PyObject *cdata_repr(CDataObject *cd)
 {
 char *extra;
 PyObject *result, *s;
 
 if (cd-c_type-ct_flags  CT_PRIMITIVE_ANY) {
-if (!(cd-c_type-ct_flags  CT_IS_LONGDOUBLE)) {
-PyObject *o = convert_to_object(cd-c_data, cd-c_type);
-if (o == NULL)
-return NULL;
-s = PyObject_Repr(o);
-Py_DECREF(o);
+if (cd-c_type-ct_flags  CT_IS_ENUM) {
+s = convert_cdata_to_enum_string(cd, 1);
 }
-else {
+else if (cd-c_type-ct_flags  CT_IS_LONGDOUBLE) {
 long double lvalue;
 char buffer[128];   /* big enough */
 /*READ(cd-c_data, sizeof(long double)*/
@@ -1490,6 +1456,13 @@
 sprintf(buffer, %LE, lvalue);
 s = PyText_FromString(buffer);
 }
+else {
+

[pypy-commit] cffi default: hg merge auto-types

2013-02-12 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r1152:a5e3e36914a5
Date: 2013-02-12 18:27 +0100
http://bitbucket.org/cffi/cffi/changeset/a5e3e36914a5/

Log:hg merge auto-types

diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -3346,7 +3346,7 @@
 return NULL;
 
 flag = CT_STRUCT;
-if (strcmp(name, _IO_FILE) == 0)
+if (strcmp(name, _IO_FILE) == 0 || strcmp(name, $FILE) == 0)
 flag |= CT_IS_FILE;
 return _b_struct_or_union_type(struct, name, flag);
 }
diff --git a/c/test_c.py b/c/test_c.py
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -2582,7 +2582,7 @@
 if sys.platform == win32:
 py.test.skip(testing FILE not implemented)
 #
-BFILE = new_struct_type(_IO_FILE)
+BFILE = new_struct_type($FILE)
 BFILEP = new_pointer_type(BFILE)
 BChar = new_primitive_type(char)
 BCharP = new_pointer_type(BChar)
diff --git a/cffi/api.py b/cffi/api.py
--- a/cffi/api.py
+++ b/cffi/api.py
@@ -71,7 +71,6 @@
 if name.startswith('RTLD_'):
 setattr(self, name, getattr(backend, name))
 #
-self._parser._declarations['typedef FILE'] = model.file_type
 BVoidP = self._get_cached_btype(model.voidp_type)
 if isinstance(backend, types.ModuleType):
 # _cffi_backend: attach these constants to the class
diff --git a/cffi/commontypes.py b/cffi/commontypes.py
new file mode 100644
--- /dev/null
+++ b/cffi/commontypes.py
@@ -0,0 +1,246 @@
+import sys
+from . import api, model
+
+
+COMMON_TYPES = {
+'FILE': model.unknown_type('FILE', '_IO_FILE'),
+'bool': '_Bool',
+}
+
+for _type in model.PrimitiveType.ALL_PRIMITIVE_TYPES:
+if _type.endswith('_t'):
+COMMON_TYPES[_type] = _type
+del _type
+
+_CACHE = {}
+
+def resolve_common_type(commontype):
+try:
+return _CACHE[commontype]
+except KeyError:
+result = COMMON_TYPES.get(commontype, commontype)
+if not isinstance(result, str):
+pass# result is already a BaseType
+elif result.endswith(' *'):
+if result.startswith('const '):
+result = model.ConstPointerType(
+resolve_common_type(result[6:-2]))
+else:
+result = model.PointerType(resolve_common_type(result[:-2]))
+elif result in model.PrimitiveType.ALL_PRIMITIVE_TYPES:
+result = model.PrimitiveType(result)
+else:
+assert commontype != result
+result = resolve_common_type(result)   # recursively
+assert isinstance(result, model.BaseTypeByIdentity)
+_CACHE[commontype] = result
+return result
+
+
+# 
+# Windows common types
+
+
+def win_common_types(maxsize):
+result = {}
+if maxsize  (132):
+result.update({  # Windows 32-bits
+'HALF_PTR': 'short',
+'INT_PTR': 'int',
+'LONG_PTR': 'long',
+'UHALF_PTR': 'unsigned short',
+'UINT_PTR': 'unsigned int',
+'ULONG_PTR': 'unsigned long',
+})
+else:
+result.update({  # Windows 64-bits
+'HALF_PTR': 'int',
+'INT_PTR': 'long long',
+'LONG_PTR': 'long long',
+'UHALF_PTR': 'unsigned int',
+'UINT_PTR': 'unsigned long long',
+'ULONG_PTR': 'unsigned long long',
+})
+result.update({
+BYTE: unsigned char,
+BOOL: int,
+CCHAR: char,
+CHAR: char,
+DWORD: unsigned long,
+DWORD32: unsigned int,
+DWORD64: unsigned long long,
+FLOAT: float,
+INT: int,
+INT8: signed char,
+INT16: short,
+INT32: int,
+INT64: long long,
+LONG: long,
+LONGLONG: long long,
+LONG32: int,
+LONG64: long long,
+WORD: unsigned short,
+PVOID: model.voidp_type,
+ULONGLONG: unsigned long long,
+WCHAR: wchar_t,
+SHORT: short,
+TBYTE: WCHAR,
+TCHAR: WCHAR,
+UCHAR: unsigned char,
+UINT: unsigned int,
+UINT8: unsigned char,
+UINT16: unsigned short,
+UINT32: unsigned int,
+UINT64: unsigned long long,
+ULONG: unsigned long,
+ULONG32: unsigned int,
+ULONG64: unsigned long long,
+USHORT: unsigned short,
+
+SIZE_T: ULONG_PTR,
+SSIZE_T: LONG_PTR,
+ATOM: WORD,
+BOOLEAN: BYTE,
+COLORREF: DWORD,
+
+HANDLE: PVOID,
+DWORDLONG: ULONGLONG,
+DWORD_PTR: ULONG_PTR,
+HACCEL: HANDLE,
+
+HBITMAP: HANDLE,
+HBRUSH: HANDLE,
+HCOLORSPACE: HANDLE,
+HCONV: HANDLE,
+HCONVLIST: HANDLE,
+HDC: HANDLE,
+HDDEDATA: HANDLE,
+HDESK: HANDLE,
+HDROP: HANDLE,
+HDWP: HANDLE,
+HENHMETAFILE: HANDLE,
+

[pypy-commit] pypy jitframe-on-heap: fix this test

2013-02-12 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: jitframe-on-heap
Changeset: r61144:a202d86f7287
Date: 2013-02-12 23:06 +0200
http://bitbucket.org/pypy/pypy/changeset/a202d86f7287/

Log:fix this test

diff --git a/rpython/jit/backend/llsupport/test/test_runner.py 
b/rpython/jit/backend/llsupport/test/test_runner.py
--- a/rpython/jit/backend/llsupport/test/test_runner.py
+++ b/rpython/jit/backend/llsupport/test/test_runner.py
@@ -22,6 +22,6 @@
 
 # for the individual tests see
 #  ../../test/runner_test.py
-
-def setup_class(cls):
-cls.cpu = MyLLCPU(rtyper=None, stats=FakeStats(), opts=None)
+
+def get_cpu(self):
+return MyLLCPU(rtyper=None, stats=FakeStats(), opts=None)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jitframe-on-heap: test_gc for 32bit

2013-02-12 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: jitframe-on-heap
Changeset: r61145:839be53e2b6c
Date: 2013-02-12 23:08 +0200
http://bitbucket.org/pypy/pypy/changeset/839be53e2b6c/

Log:test_gc for 32bit

diff --git a/rpython/jit/backend/llsupport/test/test_gc.py 
b/rpython/jit/backend/llsupport/test/test_gc.py
--- a/rpython/jit/backend/llsupport/test/test_gc.py
+++ b/rpython/jit/backend/llsupport/test/test_gc.py
@@ -299,9 +299,12 @@
 assert all_addrs[6] == indexof(3)
 assert all_addrs[7] == indexof(5)
 assert all_addrs[8] == indexof(7)
-assert all_addrs[9] == indexof(63)
-# XXX 32bit
-assert all_addrs[10] == indexof(65)
+if sys.maxint == 2**31 - 1:
+assert all_addrs[9] == indexof(31)
+assert all_addrs[10] == indexof(33)
+else:
+assert all_addrs[9] == indexof(63)
+assert all_addrs[10] == indexof(65)
 
 assert len(all_addrs) == 4 + 6 + 4
 # 4 static fields, 4 addresses from gcmap, 2 from gcpattern
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: test, add to_builtin_type for str

2013-02-12 Thread mattip
Author: mattip matti.pi...@gmail.com
Branch: 
Changeset: r61146:711464be0c98
Date: 2013-02-12 21:29 +0200
http://bitbucket.org/pypy/pypy/changeset/711464be0c98/

Log:test, add to_builtin_type for str

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
@@ -2195,6 +2195,8 @@
 assert (a + a).item(1) == 4
 raises(IndexError, array(5).item(1))
 assert array([1]).item() == 1
+a = array('x')
+assert a.item() == 'x'
 
 def test_int_array_index(self):
 from _numpypy import array
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -1593,6 +1593,9 @@
 def get_size(self):
 return self.size
 
+def to_builtin_type(self, space, box):
+return space.wrap(self.to_str(box))
+
 class StringType(BaseType, BaseStringType):
 T = lltype.Char
 
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jitframe-on-heap: floats come at even places, always

2013-02-12 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: jitframe-on-heap
Changeset: r61147:2b18ceeedd8f
Date: 2013-02-12 23:22 +0200
http://bitbucket.org/pypy/pypy/changeset/2b18ceeedd8f/

Log:floats come at even places, always

diff --git a/rpython/jit/backend/llsupport/test/test_rewrite.py 
b/rpython/jit/backend/llsupport/test/test_rewrite.py
--- a/rpython/jit/backend/llsupport/test/test_rewrite.py
+++ b/rpython/jit/backend/llsupport/test/test_rewrite.py
@@ -72,7 +72,7 @@
 
 casmdescr = JitCellToken()
 clt = FakeLoopToken()
-clt._ll_initial_locs = [0, WORD]
+clt._ll_initial_locs = [0, 8]
 frame_info = lltype.malloc(jitframe.JITFRAMEINFO, flavor='raw')
 clt.frame_info = frame_info
 frame_info.jfi_frame_depth = 13
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy missing-os-functions: A branch to expose all posix functions supported by the platform,

2013-02-12 Thread amauryfa
Author: Amaury Forgeot d'Arc amaur...@gmail.com
Branch: missing-os-functions
Changeset: r61149:6daaf21d82ff
Date: 2013-02-12 21:34 +0100
http://bitbucket.org/pypy/pypy/changeset/6daaf21d82ff/

Log:A branch to expose all posix functions supported by the platform,
even when the hosting Python does not have them.

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


[pypy-commit] pypy missing-os-functions: Use explicit names for posix functions and methods.

2013-02-12 Thread amauryfa
Author: Amaury Forgeot d'Arc amaur...@gmail.com
Branch: missing-os-functions
Changeset: r61150:0a0abe7ca7a4
Date: 2013-02-12 22:43 +0100
http://bitbucket.org/pypy/pypy/changeset/0a0abe7ca7a4/

Log:Use explicit names for posix functions and methods. It still relies
on host Python for configuration, though

diff --git a/pypy/module/posix/__init__.py b/pypy/module/posix/__init__.py
--- a/pypy/module/posix/__init__.py
+++ b/pypy/module/posix/__init__.py
@@ -33,13 +33,13 @@
 applevel_name = os.name
 
 appleveldefs = {
-'error'  : 'app_posix.error',
-'stat_result': 'app_posix.stat_result',
-'fdopen' : 'app_posix.fdopen',
-'tmpfile': 'app_posix.tmpfile',
-'popen'  : 'app_posix.popen',
-'tmpnam' : 'app_posix.tmpnam',
-'tempnam': 'app_posix.tempnam',
+'error'  : 'app_posix.error',
+'stat_result': 'app_posix.stat_result',
+'fdopen' : 'app_posix.fdopen',
+'tmpfile': 'app_posix.tmpfile',
+'popen'  : 'app_posix.popen',
+'tmpnam' : 'app_posix.tmpnam',
+'tempnam': 'app_posix.tempnam',
 }
 if os.name == 'nt':
 appleveldefs.update({
@@ -47,140 +47,92 @@
 'popen3' : 'app_posix.popen3',
 'popen4' : 'app_posix.popen4',
 })
-
-if hasattr(os, 'wait'):
+if hasattr(posix, 'wait'):
 appleveldefs['wait'] = 'app_posix.wait'
-if hasattr(os, 'wait3'):
+if hasattr(posix, 'wait3'):
 appleveldefs['wait3'] = 'app_posix.wait3'
-if hasattr(os, 'wait4'):
+if hasattr(posix, 'wait4'):
 appleveldefs['wait4'] = 'app_posix.wait4'
 
+# Functions implemented on all platforms
 interpleveldefs = {
-'open'  : 'interp_posix.open',
-'lseek' : 'interp_posix.lseek',
-'write' : 'interp_posix.write',
-'isatty': 'interp_posix.isatty',
-'read'  : 'interp_posix.read',
-'close' : 'interp_posix.close',
-'closerange': 'interp_posix.closerange',
-'fstat' : 'interp_posix.fstat',
-'stat'  : 'interp_posix.stat',
-'lstat' : 'interp_posix.lstat',
-'stat_float_times' : 'interp_posix.stat_float_times',
-'dup'   : 'interp_posix.dup',
-'dup2'  : 'interp_posix.dup2',
-'access': 'interp_posix.access',
-'times' : 'interp_posix.times',
-'system': 'interp_posix.system',
-'unlink': 'interp_posix.unlink',
-'remove': 'interp_posix.remove',
-'getcwd': 'interp_posix.getcwd',
-'getcwdu'   : 'interp_posix.getcwdu',
-'chdir' : 'interp_posix.chdir',
-'mkdir' : 'interp_posix.mkdir',
-'rmdir' : 'interp_posix.rmdir',
-'environ'   : 'interp_posix.get(space).w_environ',
-'listdir'   : 'interp_posix.listdir',
-'strerror'  : 'interp_posix.strerror',
-'pipe'  : 'interp_posix.pipe',
-'chmod' : 'interp_posix.chmod',
-'rename': 'interp_posix.rename',
-'umask' : 'interp_posix.umask',
-'_exit' : 'interp_posix._exit',
-'utime' : 'interp_posix.utime',
-'_statfields': 'interp_posix.getstatfields(space)',
-'kill'  : 'interp_posix.kill',
-'abort' : 'interp_posix.abort',
-'urandom'   : 'interp_posix.urandom',
-}
+'open'  : 'interp_posix.open',
+'lseek' : 'interp_posix.lseek',
+'write' : 'interp_posix.write',
+'isatty': 'interp_posix.isatty',
+'read'  : 'interp_posix.read',
+'close' : 'interp_posix.close',
+'closerange': 'interp_posix.closerange',
+'fstat' : 'interp_posix.fstat',
+'stat'  : 'interp_posix.stat',
+'lstat' : 'interp_posix.lstat',
+'stat_float_times' : 'interp_posix.stat_float_times',
+'dup'   : 'interp_posix.dup',
+'dup2'  : 'interp_posix.dup2',
+'access': 'interp_posix.access',
+'times' : 'interp_posix.times',
+'system': 'interp_posix.system',
+'unlink': 'interp_posix.unlink',
+'remove': 'interp_posix.remove',
+'getcwd': 'interp_posix.getcwd',
+'getcwdu'   : 'interp_posix.getcwdu',
+'chdir' : 'interp_posix.chdir',
+'mkdir' : 'interp_posix.mkdir',
+'rmdir' : 'interp_posix.rmdir',
+'environ'   : 'interp_posix.get(space).w_environ',
+'listdir'   : 'interp_posix.listdir',
+'strerror'  : 'interp_posix.strerror',
+'pipe'  : 'interp_posix.pipe',
+'chmod' : 'interp_posix.chmod',
+'rename': 'interp_posix.rename',
+'umask' : 'interp_posix.umask',
+'_exit' : 'interp_posix._exit',
+'utime' : 'interp_posix.utime',
+'_statfields': 'interp_posix.getstatfields(space)',
+'kill'  : 'interp_posix.kill',
+'abort' : 'interp_posix.abort',
+'urandom'   : 'interp_posix.urandom',
+}
 

[pypy-commit] pypy default: (fijal, agaynor) another try at presizing

2013-02-12 Thread bdkearns
Author: Brian Kearns bdkea...@gmail.com
Branch: 
Changeset: r61151:2924a59b74ba
Date: 2013-02-12 16:54 -0500
http://bitbucket.org/pypy/pypy/changeset/2924a59b74ba/

Log:(fijal, agaynor) another try at presizing

diff --git a/rpython/rlib/rstring.py b/rpython/rlib/rstring.py
--- a/rpython/rlib/rstring.py
+++ b/rpython/rlib/rstring.py
@@ -3,6 +3,7 @@
 
 from rpython.annotator.model import (SomeObject, SomeString, s_None, SomeChar,
 SomeInteger, SomeUnicodeCodePoint, SomeUnicodeString, SomePtr, SomePBC)
+from rpython.rlib.objectmodel import newlist_hint
 from rpython.rlib.rarithmetic import ovfcheck
 from rpython.rtyper.extregistry import ExtRegistryEntry
 from rpython.tool.pairtype import pairtype
@@ -14,7 +15,10 @@
 if bylen == 0:
 raise ValueError(empty separator)
 
-res = []
+if maxsplit  0:
+res = newlist_hint(min(maxsplit, len(value)))
+else:
+res = []
 start = 0
 while maxsplit != 0:
 next = value.find(by, start)
@@ -27,8 +31,12 @@
 res.append(value[start:len(value)])
 return res
 
+
 def rsplit(value, by, maxsplit=-1):
-res = []
+if maxsplit  0:
+res = newlist_hint(min(maxsplit, len(value)))
+else:
+res = []
 end = len(value)
 bylen = len(by)
 if bylen == 0:
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: kill!

2013-02-12 Thread pjenvey
Author: Philip Jenvey pjen...@underboss.org
Branch: py3k
Changeset: r61152:cff1d143164c
Date: 2013-02-12 14:06 -0800
http://bitbucket.org/pypy/pypy/changeset/cff1d143164c/

Log:kill!

diff --git a/pypy/objspace/std/dictmultiobject.py 
b/pypy/objspace/std/dictmultiobject.py
--- a/pypy/objspace/std/dictmultiobject.py
+++ b/pypy/objspace/std/dictmultiobject.py
@@ -862,49 +862,6 @@
 return space.w_False
 return space.w_True
 
-def characterize(space, w_a, w_b):
- (similar to CPython)
-returns the smallest key in acontent for which b's value is different or 
absent and this value 
-w_smallest_diff_a_key = None
-w_its_value = None
-iteratorimplementation = w_a.iteritems()
-while 1:
-w_key, w_val = iteratorimplementation.next_item()
-if w_key is None:
-break
-if w_smallest_diff_a_key is None or space.is_true(space.lt(w_key, 
w_smallest_diff_a_key)):
-w_bvalue = w_b.getitem(w_key)
-if w_bvalue is None:
-w_its_value = w_val
-w_smallest_diff_a_key = w_key
-else:
-if not space.eq_w(w_val, w_bvalue):
-w_its_value = w_val
-w_smallest_diff_a_key = w_key
-return w_smallest_diff_a_key, w_its_value
-
-def lt__DictMulti_DictMulti(space, w_left, w_right):
-# Different sizes, no problem
-if w_left.length()  w_right.length():
-return space.w_True
-if w_left.length()  w_right.length():
-return space.w_False
-
-# Same size
-w_leftdiff, w_leftval = characterize(space, w_left, w_right)
-if w_leftdiff is None:
-return space.w_False
-w_rightdiff, w_rightval = characterize(space, w_right, w_left)
-if w_rightdiff is None:
-# w_leftdiff is not None, w_rightdiff is None
-return space.w_True
-w_res = space.lt(w_leftdiff, w_rightdiff)
-if (not space.is_true(w_res) and
-space.eq_w(w_leftdiff, w_rightdiff) and
-w_rightval is not None):
-w_res = space.lt(w_leftval, w_rightval)
-return w_res
-
 def dict_copy__DictMulti(space, w_self):
 w_new = W_DictMultiObject.allocate_and_init_instance(space)
 update1_dict_dict(space, w_new, w_self)
diff --git a/pypy/objspace/std/test/test_dictmultiobject.py 
b/pypy/objspace/std/test/test_dictmultiobject.py
--- a/pypy/objspace/std/test/test_dictmultiobject.py
+++ b/pypy/objspace/std/test/test_dictmultiobject.py
@@ -387,27 +387,13 @@
 bool = d1 != d3
 assert bool == True
 
-def test_lt(self):
+def test_richcompare(self):
+import operator
 d1 = {1: 2, 3: 4}
-d2 = {1: 2, 3: 4}
-d3 = {1: 2, 3: 5}
-d4 = {1: 2}
-bool = d1  d2
-assert bool == False
-bool = d1  d3
-assert bool == True
-bool = d1  d4
-assert bool == False
-
-def test_lt2(self):
-assert {'a': 1 }  { 'a': 2 }
-assert not {'a': 1 }  { 'a': 2 }
-assert not {'a': 1, 'b': 0 }  { 'a': 2, 'b': 0 }
-assert {'a': 1, 'b': 0 }  { 'a': 2, 'b': 0 }
-assert {'a': 1, 'b': 0 }  { 'a': 1, 'b': 2 }
-assert not {'a': 1, 'b': 0 }  { 'a': 1, 'b': -2 }
-assert {'a': 1 }  { 'b': 1}
-assert {'a': 1, 'x': 2 }  { 'b': 1, 'x': 2}
+d2 = {1: 2, 3: 5}
+for op in 'lt', 'le', 'gt', 'ge':
+f = getattr(operator, op)
+raises(TypeError, f, d1, d2)
 
 def test_str_repr(self):
 assert '{}' == str({})
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: regrtest.replace_stdout carelessly changes stdout's name attrib, fix it to

2013-02-12 Thread pjenvey
Author: Philip Jenvey pjen...@underboss.org
Branch: py3k
Changeset: r61153:27dc4381e169
Date: 2013-02-12 14:10 -0800
http://bitbucket.org/pypy/pypy/changeset/27dc4381e169/

Log:regrtest.replace_stdout carelessly changes stdout's name attrib, fix
it to happen before import so its consistent w/ the test run

diff --git a/pypy/tool/pytest/run-script/regrverbose.py 
b/pypy/tool/pytest/run-script/regrverbose.py
--- a/pypy/tool/pytest/run-script/regrverbose.py
+++ b/pypy/tool/pytest/run-script/regrverbose.py
@@ -8,10 +8,10 @@
 modname = sys.argv[0]
 impname = 'test.' + modname
 try:
+regrtest.replace_stdout()
 mod = __import__(impname, globals(), locals(), [modname])
 indirect_test = getattr(mod, 'test_main', None)
 if indirect_test is not None:
-regrtest.replace_stdout()
 indirect_test()
 except unittest.SkipTest:
 sys.stderr.write(=*26 + skipped + =*26 + \n)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: (amaury) presize to maxsplit + 1 not maxsplit

2013-02-12 Thread bdkearns
Author: Brian Kearns bdkea...@gmail.com
Branch: 
Changeset: r61154:2db1e1e6b77e
Date: 2013-02-12 17:16 -0500
http://bitbucket.org/pypy/pypy/changeset/2db1e1e6b77e/

Log:(amaury) presize to maxsplit + 1 not maxsplit

diff --git a/rpython/rlib/rstring.py b/rpython/rlib/rstring.py
--- a/rpython/rlib/rstring.py
+++ b/rpython/rlib/rstring.py
@@ -16,7 +16,7 @@
 raise ValueError(empty separator)
 
 if maxsplit  0:
-res = newlist_hint(min(maxsplit, len(value)))
+res = newlist_hint(min(maxsplit + 1, len(value)))
 else:
 res = []
 start = 0
@@ -34,7 +34,7 @@
 
 def rsplit(value, by, maxsplit=-1):
 if maxsplit  0:
-res = newlist_hint(min(maxsplit, len(value)))
+res = newlist_hint(min(maxsplit + 1, len(value)))
 else:
 res = []
 end = len(value)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: test, implement to_builtin_type for StringType

2013-02-12 Thread mattip
Author: Matti Picus matti.pi...@gmail.com
Branch: 
Changeset: r61156:c99336a795d3
Date: 2013-02-13 00:25 +0200
http://bitbucket.org/pypy/pypy/changeset/c99336a795d3/

Log:test, implement to_builtin_type for StringType

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
@@ -2195,6 +2195,8 @@
 assert (a + a).item(1) == 4
 raises(IndexError, array(5).item(1))
 assert array([1]).item() == 1
+a = array('x')
+assert a.item() == 'x'
 
 def test_int_array_index(self):
 from _numpypy import array
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -1637,6 +1637,10 @@
 builder.append(')
 return builder.build()
 
+# XXX move to base class when UnicodeType is supported
+def to_builtin_type(self, space, box):
+return space.wrap(self.to_str(box))
+
 class VoidType(BaseType, BaseStringType):
 T = lltype.Char
 
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: fix whatsnew

2013-02-12 Thread bdkearns
Author: Brian Kearns bdkea...@gmail.com
Branch: 
Changeset: r61157:df3aa2beb60f
Date: 2013-02-12 19:40 -0500
http://bitbucket.org/pypy/pypy/changeset/df3aa2beb60f/

Log:fix whatsnew

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
@@ -58,3 +58,6 @@
 .. branch: cleanup-tests
 Consolidated the lib_pypy/pypy_test and pypy/module/test_lib_pypy tests into
 +one directory for reduced confusion and so they all run nightly.
+
+.. branch: unquote-faster
+.. branch: urlparse-unquote-faster
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: update rich comparisons

2013-02-12 Thread pjenvey
Author: Philip Jenvey pjen...@underboss.org
Branch: py3k
Changeset: r61158:46552d7beaa9
Date: 2013-02-12 18:14 -0800
http://bitbucket.org/pypy/pypy/changeset/46552d7beaa9/

Log:update rich comparisons

diff --git a/pypy/interpreter/astcompiler/test/test_compiler.py 
b/pypy/interpreter/astcompiler/test/test_compiler.py
--- a/pypy/interpreter/astcompiler/test/test_compiler.py
+++ b/pypy/interpreter/astcompiler/test/test_compiler.py
@@ -668,8 +668,8 @@
 #cmp
 self.assert_(p == p)
 self.assert_(d == d)
-self.assert_(p  d)
-self.assert_(d  p)
+self.failUnlessRaises(TypeError, lambda: p  d)
+self.failUnlessRaises(TypeError, lambda: d  p)
 #__non__zero__
 if p: self.fail(Empty mapping must compare to False)
 if not d: self.fail(Full mapping must compare to True)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: improve this test to also test failures on backwards seeks when no raw seek is available

2013-02-12 Thread bdkearns
Author: Brian Kearns bdkea...@gmail.com
Branch: 
Changeset: r61161:bca3a1371847
Date: 2013-02-13 00:41 -0500
http://bitbucket.org/pypy/pypy/changeset/bca3a1371847/

Log:improve this test to also test failures on backwards seeks when no
raw seek is available

diff --git a/rpython/rlib/test/test_streamio.py 
b/rpython/rlib/test/test_streamio.py
--- a/rpython/rlib/test/test_streamio.py
+++ b/rpython/rlib/test/test_streamio.py
@@ -390,7 +390,7 @@
 all = file.readall()
 end = len(all)
 cases = [(readto, seekto, whence) for readto in range(0, end+1)
-  for seekto in range(readto, end+1)
+  for seekto in range(0, end+1)
   for whence in [1, 2]]
 random.shuffle(cases)
 if isinstance(self, (LLRtypeMixin, OORtypeMixin)):
@@ -406,9 +406,19 @@
 offset = seekto - readto
 elif whence == 2:
 offset = seekto - end
-file.seek(offset, whence)
-rest = file.readall()
-assert rest == all[seekto:]
+if whence == 2 and seekto  file.tell() or seekto  
file.tell() - file.pos:
+try:
+file.seek(offset, whence)
+except streamio.MyNotImplementedError:
+assert whence == 1
+except streamio.StreamError:
+assert whence == 2
+else:
+assert False
+else:
+file.seek(offset, whence)
+rest = file.readall()
+assert rest == all[seekto:]
 return True
 res = self.interpret(f, [])
 assert res
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: prevent streamio SEEK_SET from trashing the buffers for in-buffer seeks, fixes issue1234

2013-02-12 Thread bdkearns
Author: Brian Kearns bdkea...@gmail.com
Branch: 
Changeset: r61162:66d1e56f69a4
Date: 2013-02-13 01:25 -0500
http://bitbucket.org/pypy/pypy/changeset/66d1e56f69a4/

Log:prevent streamio SEEK_SET from trashing the buffers for in-buffer
seeks, fixes issue1234

diff --git a/rpython/rlib/streamio.py b/rpython/rlib/streamio.py
--- a/rpython/rlib/streamio.py
+++ b/rpython/rlib/streamio.py
@@ -552,30 +552,26 @@
 # This may fail on the do_seek() or do_tell() call.
 # But it won't call either on a relative forward seek.
 # Nor on a seek to the very end.
-if whence == 0:
-self.do_seek(offset, 0)
-self.buf = 
-self.pos = 0
-return
-if whence == 1:
+if whence == 0 or whence == 1:
 currentsize = len(self.buf) - self.pos
-if offset  0:
-if self.pos + offset = 0:
-self.pos += offset
-else:
-self.do_seek(self.tell() + offset, 0)
-self.pos = 0
-self.buf = 
-return
-elif offset = currentsize:
-self.pos += offset
+if whence == 0:
+difpos = offset - self.tell()
+else:
+difpos = offset
+if -self.pos = difpos = currentsize:
+self.pos += difpos
 return
 self.buf = 
 self.pos = 0
-offset -= currentsize
+if whence == 1:
+offset -= currentsize
 try:
-self.do_seek(offset, 1)
+self.do_seek(offset, whence)
 except MyNotImplementedError:
+if difpos  0:
+raise
+if whence == 0:
+offset = difpos - currentsize
 intoffset = offset2int(offset)
 self.read(intoffset)
 return
diff --git a/rpython/rlib/test/test_streamio.py 
b/rpython/rlib/test/test_streamio.py
--- a/rpython/rlib/test/test_streamio.py
+++ b/rpython/rlib/test/test_streamio.py
@@ -391,7 +391,7 @@
 end = len(all)
 cases = [(readto, seekto, whence) for readto in range(0, end+1)
   for seekto in range(0, end+1)
-  for whence in [1, 2]]
+  for whence in [0, 1, 2]]
 random.shuffle(cases)
 if isinstance(self, (LLRtypeMixin, OORtypeMixin)):
 cases = cases[:7]  # pick some cases at random - too slow!
@@ -401,16 +401,17 @@
 file = streamio.BufferingInputStream(base)
 head = file.read(readto)
 assert head == all[:readto]
-offset = 42 # for the flow space
 if whence == 1:
 offset = seekto - readto
 elif whence == 2:
 offset = seekto - end
+else:
+offset = seekto
 if whence == 2 and seekto  file.tell() or seekto  
file.tell() - file.pos:
 try:
 file.seek(offset, whence)
 except streamio.MyNotImplementedError:
-assert whence == 1
+assert whence in (0, 1)
 except streamio.StreamError:
 assert whence == 2
 else:
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: test and fix for _io buffering: in buffer back seeks shouldn't trash the buffer

2013-02-12 Thread bdkearns
Author: Brian Kearns bdkea...@gmail.com
Branch: 
Changeset: r61159:fa3dd6e22b8c
Date: 2013-02-13 00:21 -0500
http://bitbucket.org/pypy/pypy/changeset/fa3dd6e22b8c/

Log:test and fix for _io buffering: in buffer back seeks shouldn't trash
the buffer just because we have no forward buffer

diff --git a/pypy/module/_io/interp_bufferedio.py 
b/pypy/module/_io/interp_bufferedio.py
--- a/pypy/module/_io/interp_bufferedio.py
+++ b/pypy/module/_io/interp_bufferedio.py
@@ -268,16 +268,15 @@
 self._raw_tell(space)
 current = self.abs_pos
 available = self._readahead()
-if available  0:
-if whence == 0:
-offset = pos - (current - self._raw_offset())
-else:
-offset = pos
-if -self.pos = offset = available:
-newpos = self.pos + offset
-assert newpos = 0
-self.pos = newpos
-return space.wrap(current - available + offset)
+if whence == 0:
+offset = pos - (current - self._raw_offset())
+else:
+offset = pos
+if -self.pos = offset = available:
+newpos = self.pos + offset
+assert newpos = 0
+self.pos = newpos
+return space.wrap(current - available + offset)
 
 # Fallback: invoke raw seek() method and clear buffer
 with self.lock:
diff --git a/pypy/module/_io/test/test_bufferedio.py 
b/pypy/module/_io/test/test_bufferedio.py
--- a/pypy/module/_io/test/test_bufferedio.py
+++ b/pypy/module/_io/test/test_bufferedio.py
@@ -153,6 +153,19 @@
 assert f.read() == \nc
 f.close()
 
+def test_seek_nocall(self):
+# test that when we're at the end of the buffer,
+# an in-buffer back seek doesn't produce a raw seek
+import _io
+raw = _io.FileIO(self.tmpfile)
+f = _io.BufferedReader(raw, buffer_size=3)
+f.read(1)
+f.seek(3, 0)
+def failing_seek(*args):
+assert False
+raw.seek = failing_seek
+f.seek(-1, 1)
+
 def test_readlines(self):
 import _io
 raw = _io.FileIO(self.tmpfile)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: fix this test: it wasn't testing what it claimed to because it was constructing

2013-02-12 Thread bdkearns
Author: Brian Kearns bdkea...@gmail.com
Branch: 
Changeset: r61160:1aa187fce1db
Date: 2013-02-13 00:30 -0500
http://bitbucket.org/pypy/pypy/changeset/1aa187fce1db/

Log:fix this test: it wasn't testing what it claimed to because it was
constructing seekable sources for a no-seek-available test

diff --git a/rpython/rlib/test/test_streamio.py 
b/rpython/rlib/test/test_streamio.py
--- a/rpython/rlib/test/test_streamio.py
+++ b/rpython/rlib/test/test_streamio.py
@@ -12,18 +12,24 @@
 
 class TSource(streamio.Stream):
 
-def __init__(self, packets):
+def __init__(self, packets, tell=True, seek=True):
 for x in packets:
 assert x
 self.orig_packets = packets[:]
 self.packets = packets[:]
 self.pos = 0
 self.chunks = []
+self._tell = tell
+self._seek = seek
 
 def tell(self):
+if not self._tell:
+raise streamio.MyNotImplementedError
 return self.pos
 
 def seek(self, offset, whence=0):
+if not self._seek:
+raise streamio.MyNotImplementedError
 if whence == 1:
 offset += self.pos
 elif whence == 2:
@@ -391,7 +397,7 @@
 cases = cases[:7]  # pick some cases at random - too slow!
 def f():
 for readto, seekto, whence in cases:
-base = TSource(self.packets)
+base = TSource(self.packets, seek=False)
 file = streamio.BufferingInputStream(base)
 head = file.read(readto)
 assert head == all[:readto]
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit