[pypy-commit] pypy refactor-call_release_gil: close to-be-merged branch
Author: Antonio Cuni Branch: refactor-call_release_gil Changeset: r63221:9fcb577847af Date: 2013-04-11 11:26 +0200 http://bitbucket.org/pypy/pypy/changeset/9fcb577847af/ Log:close to-be-merged branch ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: merge (again) the refactor-call_release_gil branch. This fixes a nasty bug
Author: Antonio Cuni Branch: Changeset: r63222:cfe04a93cc3e Date: 2013-04-11 11:27 +0200 http://bitbucket.org/pypy/pypy/changeset/cfe04a93cc3e/ Log:merge (again) the refactor-call_release_gil branch. This fixes a nasty bug which occoured when JITting the call to a cffi function which calls a callback which causes the failure of guard_not_forced: in that case, during blackholing we got the wrong result from call_release_gil, because it was not passed to fail_args. The two tests which demonstrates the bug are - rpython/jit/metainterp/test/test_fficall.py::test_guard_not_forced_f ails - pypy/module/pypyjit/test_pypy_c/test__ffi.py::test_cffi_call_guard_n ot_force d_fails 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 @@ -110,7 +110,6 @@ loops = log.loops_by_id('sleep') assert len(loops) == 1 # make sure that we actually JITted the loop - def test_ctypes_call(self): from rpython.rlib.test.test_clibffi import get_libm_name def main(libm_name): @@ -209,3 +208,65 @@ # so far just check that call_release_gil() is produced. # later, also check that the arguments to call_release_gil() # are constants, and that the numerous raw_mallocs are removed + +def test_cffi_call_guard_not_forced_fails(self): +# this is the test_pypy_c equivalent of +# rpython/jit/metainterp/test/test_fficall::test_guard_not_forced_fails +# +# it requires cffi to be installed for pypy in order to run +def main(): +import sys +try: +import cffi +except ImportError: +sys.stderr.write('SKIP: cannot import cffi\n') +return 0 + +ffi = cffi.FFI() + +ffi.cdef(""" +typedef void (*functype)(int); +int foo(int n, functype func); +""") + +lib = ffi.verify(""" +#include +typedef void (*functype)(int); + +int foo(int n, functype func) { +if (n >= 2000) { +func(n); +} +return n*2; +} +""") + +@ffi.callback("functype") +def mycallback(n): +if n < 5000: +return +# make sure that guard_not_forced fails +d = {} +f = sys._getframe() +while f: +d.update(f.f_locals) +f = f.f_back + +n = 0 +while n < 1: +res = lib.foo(n, mycallback) # ID: cfficall +# this is the real point of the test: before the +# refactor-call_release_gil branch, the assert failed when +# res == 5000 +assert res == n*2 +n += 1 +return n + +log = self.run(main, [], import_site=True) +assert log.result == 1 +loop, = log.loops_by_id('cfficall') +assert loop.match_by_id('cfficall', """ +... +f1 = call_release_gil(..., descr=) +... +""") diff --git a/rpython/jit/backend/llgraph/runner.py b/rpython/jit/backend/llgraph/runner.py --- a/rpython/jit/backend/llgraph/runner.py +++ b/rpython/jit/backend/llgraph/runner.py @@ -840,10 +840,22 @@ # manipulation here (as a hack, instead of really doing # the aroundstate manipulation ourselves) return self.execute_call_may_force(descr, func, *args) +guard_op = self.lltrace.operations[self.current_index + 1] +assert guard_op.getopnum() == rop.GUARD_NOT_FORCED +self.force_guard_op = guard_op call_args = support.cast_call_args_in_order(descr.ARGS, args) -FUNC = lltype.FuncType(descr.ARGS, descr.RESULT) -func_to_call = rffi.cast(lltype.Ptr(FUNC), func) -result = func_to_call(*call_args) +# +func_adr = llmemory.cast_int_to_adr(func) +if hasattr(func_adr.ptr._obj, '_callable'): +# this is needed e.g. by test_fficall.test_guard_not_forced_fails, +# because to actually force the virtualref we need to llinterp the +# graph, not to directly execute the python function +result = self.cpu.maybe_on_top_of_llinterp(func, call_args, descr.RESULT) +else: +FUNC = lltype.FuncType(descr.ARGS, descr.RESULT) +func_to_call = rffi.cast(lltype.Ptr(FUNC), func) +result = func_to_call(*call_args) +del self.force_guard_op return support.cast_result(descr.RESULT, result) def execute_call_assembler(self, descr, *args): diff --git a/rpython/ji
[pypy-commit] pypy virtual-raw-mallocs: bah, more tests in which we need to convince the annotator to see the constructor of VRawBufferValue
Author: Antonio Cuni Branch: virtual-raw-mallocs Changeset: r63224:1eba3e30d044 Date: 2013-04-11 10:54 +0100 http://bitbucket.org/pypy/pypy/changeset/1eba3e30d044/ Log:bah, more tests in which we need to convince the annotator to see the constructor of VRawBufferValue 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 @@ -2,6 +2,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, compile +from rpython.jit.backend.x86.test.test_ztranslation import fix_annotator_for_vrawbuffer class X(object): def __init__(self, x=0): @@ -31,7 +32,8 @@ g._dont_inline_ = True return g -def test_compile_boehm(): +def test_compile_boehm(monkeypatch): +fix_annotator_for_vrawbuffer(monkeypatch) myjitdriver = JitDriver(greens = [], reds = ['n', 'x']) @dont_look_inside def see(lst, n): diff --git a/rpython/jit/backend/x86/test/test_ztranslation_basic.py b/rpython/jit/backend/x86/test/test_ztranslation_basic.py --- a/rpython/jit/backend/x86/test/test_ztranslation_basic.py +++ b/rpython/jit/backend/x86/test/test_ztranslation_basic.py @@ -12,6 +12,7 @@ from rpython.jit.backend.x86.arch import IS_X86_32, IS_X86_64 from rpython.config.translationoption import DEFL_GC from rpython.rlib import rgc +from rpython.jit.backend.x86.test.test_ztranslation import fix_annotator_for_vrawbuffer class TestTranslationX86(CCompiledMixin): CPUClass = getcpuclass() @@ -22,7 +23,7 @@ assert '-msse2' in cbuilder.eci.compile_extra assert '-mfpmath=sse' in cbuilder.eci.compile_extra -def test_stuff_translates(self): +def test_stuff_translates(self, monkeypatch): # this is a basic test that tries to hit a number of features and their # translation: # - jitting of loops and bridges @@ -31,6 +32,7 @@ # - profiler # - full optimizer # - floats neg and abs +fix_annotator_for_vrawbuffer(monkeypatch) class Frame(object): _virtualizable2_ = ['i'] diff --git a/rpython/jit/backend/x86/test/test_ztranslation_call_assembler.py b/rpython/jit/backend/x86/test/test_ztranslation_call_assembler.py --- a/rpython/jit/backend/x86/test/test_ztranslation_call_assembler.py +++ b/rpython/jit/backend/x86/test/test_ztranslation_call_assembler.py @@ -12,6 +12,7 @@ from rpython.jit.backend.x86.arch import IS_X86_32, IS_X86_64 from rpython.config.translationoption import DEFL_GC from rpython.rlib import rgc +from rpython.jit.backend.x86.test.test_ztranslation import fix_annotator_for_vrawbuffer class TestTranslationX86(CCompiledMixin): CPUClass = getcpuclass() @@ -22,9 +23,10 @@ assert '-msse2' in cbuilder.eci.compile_extra assert '-mfpmath=sse' in cbuilder.eci.compile_extra -def test_direct_assembler_call_translates(self): +def test_direct_assembler_call_translates(self, monkeypatch): """Test CALL_ASSEMBLER and the recursion limit""" from rpython.rlib.rstackovf import StackOverflow +fix_annotator_for_vrawbuffer(monkeypatch) class Thing(object): def __init__(self, val): diff --git a/rpython/jit/backend/x86/test/test_ztranslation_external_exception.py b/rpython/jit/backend/x86/test/test_ztranslation_external_exception.py --- a/rpython/jit/backend/x86/test/test_ztranslation_external_exception.py +++ b/rpython/jit/backend/x86/test/test_ztranslation_external_exception.py @@ -12,7 +12,7 @@ from rpython.jit.backend.x86.arch import IS_X86_32, IS_X86_64 from rpython.config.translationoption import DEFL_GC from rpython.rlib import rgc - +from rpython.jit.backend.x86.test.test_ztranslation import fix_annotator_for_vrawbuffer class TestTranslationRemoveTypePtrX86(CCompiledMixin): CPUClass = getcpuclass() @@ -25,7 +25,9 @@ t.config.translation.gcremovetypeptr = True return t -def test_external_exception_handling_translates(self): +def test_external_exception_handling_translates(self, monkeypatch): +fix_annotator_for_vrawbuffer(monkeypatch) + jitdriver = JitDriver(greens = [], reds = ['n', 'total']) class ImDone(Exception): ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy virtual-raw-mallocs: fix after the renaming
Author: Antonio Cuni Branch: virtual-raw-mallocs Changeset: r63223:5eb58cc8fa1e Date: 2013-04-09 17:02 +0100 http://bitbucket.org/pypy/pypy/changeset/5eb58cc8fa1e/ Log:fix after the renaming diff --git a/rpython/jit/metainterp/test/test_resume.py b/rpython/jit/metainterp/test/test_resume.py --- a/rpython/jit/metainterp/test/test_resume.py +++ b/rpython/jit/metainterp/test/test_resume.py @@ -249,7 +249,7 @@ reader = ResumeDataDirectReader(MyMetaInterp(None), FakeStorage(), "deadframe") cache = reader.force_all_virtuals() -assert cache.virtuals_ptr_cache == ["allocated", reader.virtual_default] +assert cache.virtuals_ptr_cache == ["allocated", reader.virtual_ptr_default] # ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy virtual-raw-mallocs: close to-be-merged branch
Author: Antonio Cuni Branch: virtual-raw-mallocs Changeset: r63226:bd33cfd7eba4 Date: 2013-04-11 12:48 +0100 http://bitbucket.org/pypy/pypy/changeset/bd33cfd7eba4/ Log:close to-be-merged branch ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: fix test_whatsnew
Author: Antonio Cuni Branch: Changeset: r63228:8cb41911f59c Date: 2013-04-11 12:53 +0100 http://bitbucket.org/pypy/pypy/changeset/8cb41911f59c/ Log:fix test_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 @@ -46,6 +46,10 @@ Fix a bug which casused cffi to return the wrong result when calling a C function which calls a Python callback which forces the frames +.. branch: virtual-raw-mallocs +JIT optimizations which makes cffi calls even faster, by removing the need to +allocate a temporary buffer where to store the arguments. + .. branches we don't care about .. branch: autoreds .. branch: reflex-support ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] extradoc extradoc: A draft for a blog post
Author: Maciej Fijalkowski Branch: extradoc Changeset: r4965:415fa824cb16 Date: 2013-04-11 15:43 +0200 http://bitbucket.org/pypy/extradoc/changeset/415fa824cb16/ Log:A draft for a blog post diff --git a/blog/draft/web-server-survey.rst b/blog/draft/web-server-survey.rst new file mode 100644 --- /dev/null +++ b/blog/draft/web-server-survey.rst @@ -0,0 +1,104 @@ + +Hello everyone. + +This is a small survey of performance of various wsgi servers available +under CPython and PyPy. Note that while this is of high interest to me, since +it stressed the underlaying runtime quite a lot, there is a high chance +the underlaying web server really does not matter all that much for the +performance of your application. **Measure** first if the web server is +actually the problem. + +The actual benchmark consists of sending a `relatively complex HTTP query`_ +(which is roughly what chrome sends by default if issuing a GET) and +then awaiting response without keeping the connection alive. I wrote +a very crude `benchmarking tool`_ and I would not recommend anyone using it. +In principle, it's broken and assumes fragmentation of packages that happened +to happen on my test machine, but will not happen in the wild. I suggest use +`locust.io`_ or similar. The benchmarks can be found inside +`asynchammer's repository`_. Note that this is precisely a benchmark of +pure (or mostly in case of gevent) Python web servers. In this stupid benchmark, +if you run uWSGI and CPython, it'll be faster, because there is no Python code +involved (it just really executes one function). If you want to benchmark +a full web application, you should do just that and not only a server. + +The benchmarks were run like that:: + + python asynchammer.py --workers=4 --max=12 --warmup=3 --host=localhost: + +Using pypy. The servers were run either ``python`` ``example name`` or +``gunicorn -w 1 gunicorn_example:app``. In all cases the newest released +versions as of today were used, except gevent where a recent git clone +was used of gevent 1.0. Additionally PyPy version used `pypycore`_ for the +gevent loop. You run it like this: +``GEVENT_LOOP=pypycore.loop pypy gevent_example.py`` assuming everything is on +path. PyPy 2.0 beta 2 was used vs CPython 2.7.3. + +What this benchmark does? +- + +We issue 120k requests on a machine that has enough cores (and dies) to run +client and server relatively separated (there is no cache sharing between dies). +First 30k is discarded, in order to warm up the JIT, both on the client and +on the server side. +The requests are issued 10 at once (for each of the 4 workers) and then when +a request finishes, a new one is issued. The workers max out at around 11k req/s +which is what I could get out of apache serving static files. That amount of +load makes 2 apache processes run at around 150% CPU time each. All python +servers were run in a single process. I did run benchmark multiple times +to make sure that the results are at least roughly reproducible, but I did +not run any formal statistics. + +How relevant are those results for me? +-- + +If you're looking for a website performance enhancements, unlikely they're +any relevant. If you're getting (say) 500 req/s from a single worker on your +website, then the web server consumes less than 25% of the time. If you're +seeing numbers in thousands per second than very relevant. If you don't happen +to have benchmarks, then it really doesn't matter. + +CPython: + +twisted.web: 2300 +cyclone.io: 2400 +tornado: 3200 +gunicorn (sync): 3700 +gevent: 4100 +eventlet: 3200 + +PyPy: + +twisted.web: 8300 +cyclone: 7400 +tornado: 7600 +gunicorn (sync): 6900 +gevent: 6400 +eventlet: 6700 + +Giveaways +- + +There are a few obvious results. One is that parsing HTTP headers is quite +a bit of work. PyPy does some work there, but looking at traces it can clearly +be improved. Expect some work in that area. Another one is that an actual +choice of the web server does not quite matter what you choose (as long as it's +running under PyPy :)). Note that the difference here +is that we used a relatively real-life example of HTTP headers, as opposed +to ``ab`` which uses a very simple one. In the case of simple HTTP headers, +it matters more and you get drastically different results, which I'm not going +to publish because I claim they're even less relevant. + +It also looks like the choice for CPython and the choice for PyPy are quite +drastically different, with work from twisted folks helping us a lot, while +with CPython "running a loop in C" is still very important. + +To summarize, it seems that Python, and especially PyPy, is quite fast. +With 11k req/s, apache is running at around 300% CPU in total, +while none of the examples run above 120% CPU, which is normal CPU + +loopback costs. uWSGI in my benchmarks also scored + +I hope this will be one of the series of articles about +"how to compose a
[pypy-commit] pypy default: Merged in sthalik/pypy/unbreak-freebsd (pull request #148)
Author: Brian Kearns Branch: Changeset: r63230:42042ff3b88a Date: 2013-04-11 06:59 -0700 http://bitbucket.org/pypy/pypy/changeset/42042ff3b88a/ Log:Merged in sthalik/pypy/unbreak-freebsd (pull request #148) Use proper linker script on all that is FreeBSD, not just 7.x diff --git a/rpython/translator/platform/posix.py b/rpython/translator/platform/posix.py --- a/rpython/translator/platform/posix.py +++ b/rpython/translator/platform/posix.py @@ -47,7 +47,7 @@ if not eci.export_symbols: return [] -if sys.platform == 'freebsd7': +if sys.platform.startswith('freebsd'): eci.export_symbols += ('__progname', 'environ') response_file = self._make_response_file("dynamic-symbols-") ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy unbreak-freebsd: Use proper linker script on all that is FreeBSD, not just 7.x
Author: Stanislaw Halik Branch: unbreak-freebsd Changeset: r63229:5689b2860a13 Date: 2013-04-11 15:34 +0200 http://bitbucket.org/pypy/pypy/changeset/5689b2860a13/ Log:Use proper linker script on all that is FreeBSD, not just 7.x diff --git a/rpython/translator/platform/posix.py b/rpython/translator/platform/posix.py --- a/rpython/translator/platform/posix.py +++ b/rpython/translator/platform/posix.py @@ -47,7 +47,7 @@ if not eci.export_symbols: return [] -if sys.platform == 'freebsd7': +if sys.platform.startswith('freebsd'): eci.export_symbols += ('__progname', 'environ') response_file = self._make_response_file("dynamic-symbols-") ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: fix whatsnew
Author: Brian Kearns Branch: Changeset: r63231:d0619faead05 Date: 2013-04-11 10:09 -0400 http://bitbucket.org/pypy/pypy/changeset/d0619faead05/ 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 @@ -125,3 +125,4 @@ cffi implementation of sqlite3 .. branch: release-2.0-beta2 +.. branch: unbreak-freebsd ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: move shared code to llsupport
Author: David Schneider Branch: Changeset: r63232:9482149b527a Date: 2013-04-11 16:56 +0200 http://bitbucket.org/pypy/pypy/changeset/9482149b527a/ Log:move shared code to llsupport diff --git a/rpython/jit/backend/arm/assembler.py b/rpython/jit/backend/arm/assembler.py --- a/rpython/jit/backend/arm/assembler.py +++ b/rpython/jit/backend/arm/assembler.py @@ -111,26 +111,6 @@ self.loop_run_counters.append(struct) return struct -@specialize.argtype(1) -def _inject_debugging_code(self, looptoken, operations, tp, number): -if self._debug: -# before doing anything, let's increase a counter -s = 0 -for op in operations: -s += op.getopnum() -looptoken._arm_debug_checksum = s - -newoperations = [] -self._append_debugging_code(newoperations, tp, number, -None) -for op in operations: -newoperations.append(op) -if op.getopnum() == rop.LABEL: -self._append_debugging_code(newoperations, 'l', number, -op.getdescr()) -operations = newoperations -return operations - @staticmethod def _release_gil_shadowstack(): before = rffi.aroundstate.before diff --git a/rpython/jit/backend/llsupport/assembler.py b/rpython/jit/backend/llsupport/assembler.py --- a/rpython/jit/backend/llsupport/assembler.py +++ b/rpython/jit/backend/llsupport/assembler.py @@ -8,6 +8,7 @@ from rpython.rlib.debug import (debug_start, debug_stop, have_debug_prints, debug_print) from rpython.rlib.rarithmetic import r_uint +from rpython.rlib.objectmodel import specialize from rpython.rtyper.annlowlevel import cast_instance_to_gcref from rpython.rtyper.lltypesystem import rffi, lltype @@ -214,6 +215,24 @@ # to incompatibilities in how it's done, we leave it for the # caller to deal with +@specialize.argtype(1) +def _inject_debugging_code(self, looptoken, operations, tp, number): +if self._debug: +s = 0 +for op in operations: +s += op.getopnum() + +newoperations = [] +self._append_debugging_code(newoperations, tp, number, +None) +for op in operations: +newoperations.append(op) +if op.getopnum() == rop.LABEL: +self._append_debugging_code(newoperations, 'l', number, +op.getdescr()) +operations = newoperations +return operations + def _append_debugging_code(self, operations, tp, number, token): counter = self._register_counter(tp, number, token) c_adr = ConstInt(rffi.cast(lltype.Signed, counter)) 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 @@ -743,24 +743,6 @@ targettoken._ll_loop_code += rawstart self.target_tokens_currently_compiling = None -@specialize.argtype(1) -def _inject_debugging_code(self, looptoken, operations, tp, number): -if self._debug: -s = 0 -for op in operations: -s += op.getopnum() - -newoperations = [] -self._append_debugging_code(newoperations, tp, number, -None) -for op in operations: -newoperations.append(op) -if op.getopnum() == rop.LABEL: -self._append_debugging_code(newoperations, 'l', number, -op.getdescr()) -operations = newoperations -return operations - def _assemble(self, regalloc, inputargs, operations): self._regalloc = regalloc regalloc.compute_hint_frame_locations(operations) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: more backend cleanup
Author: David Schneider Branch: Changeset: r63233:5d1d12a617b0 Date: 2013-04-11 17:11 +0200 http://bitbucket.org/pypy/pypy/changeset/5d1d12a617b0/ Log:more backend cleanup diff --git a/rpython/jit/backend/arm/assembler.py b/rpython/jit/backend/arm/assembler.py --- a/rpython/jit/backend/arm/assembler.py +++ b/rpython/jit/backend/arm/assembler.py @@ -47,14 +47,8 @@ self.stack_check_slowpath = 0 self._debug = False self.loop_run_counters = [] -self.debug_counter_descr = cpu.fielddescrof(DEBUG_COUNTER, 'i') self.gcrootmap_retaddr_forced = 0 -def set_debug(self, v): -r = self._debug -self._debug = v -return r - def setup(self, looptoken): assert self.memcpy_addr != 0, 'setup_once() not called?' if we_are_translated(): @@ -80,37 +74,6 @@ def setup_failure_recovery(self): self.failure_recovery_code = [0, 0, 0, 0] -def finish_once(self): -if self._debug: -debug_start('jit-backend-counts') -for i in range(len(self.loop_run_counters)): -struct = self.loop_run_counters[i] -if struct.type == 'l': -prefix = 'TargetToken(%d)' % struct.number -elif struct.type == 'b': -prefix = 'bridge ' + str(struct.number) -else: -prefix = 'entry ' + str(struct.number) -debug_print(prefix + ':' + str(struct.i)) -debug_stop('jit-backend-counts') - -# XXX: merge with x86 -def _register_counter(self, tp, number, token): -# YYY very minor leak -- we need the counters to stay alive -# forever, just because we want to report them at the end -# of the process -struct = lltype.malloc(DEBUG_COUNTER, flavor='raw', - track_allocation=False) -struct.i = 0 -struct.type = tp -if tp == 'b' or tp == 'e': -struct.number = number -else: -assert token -struct.number = compute_unique_id(token) -self.loop_run_counters.append(struct) -return struct - @staticmethod def _release_gil_shadowstack(): before = rffi.aroundstate.before diff --git a/rpython/jit/backend/llsupport/assembler.py b/rpython/jit/backend/llsupport/assembler.py --- a/rpython/jit/backend/llsupport/assembler.py +++ b/rpython/jit/backend/llsupport/assembler.py @@ -8,7 +8,7 @@ from rpython.rlib.debug import (debug_start, debug_stop, have_debug_prints, debug_print) from rpython.rlib.rarithmetic import r_uint -from rpython.rlib.objectmodel import specialize +from rpython.rlib.objectmodel import specialize, compute_unique_id from rpython.rtyper.annlowlevel import cast_instance_to_gcref from rpython.rtyper.lltypesystem import rffi, lltype @@ -63,6 +63,8 @@ self.cpu = cpu self.memcpy_addr = 0 self.rtyper = cpu.rtyper +self.debug_counter_descr = cpu.fielddescrof(DEBUG_COUNTER, 'i') +self._debug = False def setup_once(self): # the address of the function called by 'new' @@ -100,6 +102,11 @@ track_allocation=False) self.gcmap_for_finish[0] = r_uint(1) +def set_debug(self, v): +r = self._debug +self._debug = v +return r + def rebuild_faillocs_from_descr(self, descr, inputargs): locs = [] GPR_REGS = len(self.cpu.gen_regs) @@ -245,6 +252,37 @@ None, descr=self.debug_counter_descr)] operations.extend(ops) +def _register_counter(self, tp, number, token): +# YYY very minor leak -- we need the counters to stay alive +# forever, just because we want to report them at the end +# of the process +struct = lltype.malloc(DEBUG_COUNTER, flavor='raw', + track_allocation=False) +struct.i = 0 +struct.type = tp +if tp == 'b' or tp == 'e': +struct.number = number +else: +assert token +struct.number = compute_unique_id(token) +self.loop_run_counters.append(struct) +return struct + +def finish_once(self): +if self._debug: +debug_start('jit-backend-counts') +for i in range(len(self.loop_run_counters)): +struct = self.loop_run_counters[i] +if struct.type == 'l': +prefix = 'TargetToken(%d)' % struct.number +elif struct.type == 'b': +prefix = 'bridge ' + str(struct.number) +else: +prefix = 'entry ' + str(struct.number) +debug_print(prefix + ':' + str(struct.i)) +debug_stop('jit-backend-counts') + + def debug_bridge(descr_number, rawstart, codeendpos): debug_start("jit-bac
[pypy-commit] pypy longdouble2: Clean up remnants of NonNativeXXX
Author: Ronan Lamy Branch: longdouble2 Changeset: r63234:1229ee4da9dc Date: 2013-04-11 17:44 +0100 http://bitbucket.org/pypy/pypy/changeset/1229ee4da9dc/ Log:Clean up remnants of NonNativeXXX 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 @@ -329,9 +329,6 @@ def min(self, v1, v2): return min(v1, v2) -class NonNativePrimitive(Primitive): -_mixin_ = True - class Bool(BaseType, Primitive): _attrs_ = () @@ -419,7 +416,6 @@ return 1 return 0 -NonNativeBool = Bool class Integer(Primitive): _mixin_ = True @@ -540,22 +536,17 @@ def signbit(self, v): return v < 0 -class NonNativeInteger(NonNativePrimitive, Integer): -_mixin_ = True - class Int8(BaseType, Integer): _attrs_ = () spec = int8_spec BoxType = interp_boxes.W_Int8Box format_code = "b" -NonNativeInt8 = Int8 class UInt8(BaseType, Integer): _attrs_ = () spec = uint8_spec BoxType = interp_boxes.W_UInt8Box format_code = "B" -NonNativeUInt8 = UInt8 class Int16(BaseType, Integer): _attrs_ = () @@ -563,113 +554,55 @@ BoxType = interp_boxes.W_Int16Box format_code = "h" -class NonNativeInt16(BaseType, NonNativeInteger): -_attrs_ = () -spec = int16_spec -BoxType = interp_boxes.W_Int16Box -format_code = "h" - class UInt16(BaseType, Integer): _attrs_ = () spec = uint16_spec BoxType = interp_boxes.W_UInt16Box format_code = "H" -class NonNativeUInt16(BaseType, NonNativeInteger): -_attrs_ = () -spec = uint16_spec -BoxType = interp_boxes.W_UInt16Box -format_code = "H" - class Int32(BaseType, Integer): _attrs_ = () spec = int32_spec BoxType = interp_boxes.W_Int32Box format_code = "i" -class NonNativeInt32(BaseType, NonNativeInteger): -_attrs_ = () -spec = int32_spec -BoxType = interp_boxes.W_Int32Box -format_code = "i" - class UInt32(BaseType, Integer): _attrs_ = () spec = uint32_spec BoxType = interp_boxes.W_UInt32Box format_code = "I" -class NonNativeUInt32(BaseType, NonNativeInteger): -_attrs_ = () -spec = uint32_spec -BoxType = interp_boxes.W_UInt32Box -format_code = "I" - class Long(BaseType, Integer): _attrs_ = () spec = long_spec BoxType = interp_boxes.W_LongBox format_code = "l" -class NonNativeLong(BaseType, NonNativeInteger): -_attrs_ = () -spec = long_spec -BoxType = interp_boxes.W_LongBox -format_code = "l" - class ULong(BaseType, Integer): _attrs_ = () spec = ulong_spec BoxType = interp_boxes.W_ULongBox format_code = "L" -class NonNativeULong(BaseType, NonNativeInteger): -_attrs_ = () -spec = ulong_spec -BoxType = interp_boxes.W_ULongBox -format_code = "L" - -def _int64_coerce(self, space, w_item): -try: -return self._base_coerce(space, w_item) -except OperationError, e: -if not e.match(space, space.w_OverflowError): -raise -bigint = space.bigint_w(w_item) -try: -value = bigint.tolonglong() -except OverflowError: -raise OperationError(space.w_OverflowError, space.w_None) -return self.box(value) - class Int64(BaseType, Integer): _attrs_ = () spec = int64_spec BoxType = interp_boxes.W_Int64Box format_code = "q" -_coerce = func_with_new_name(_int64_coerce, '_coerce') +def _coerce(self, space, w_item): +try: +return self._base_coerce(space, w_item) +except OperationError, e: +if not e.match(space, space.w_OverflowError): +raise +bigint = space.bigint_w(w_item) +try: +value = bigint.tolonglong() +except OverflowError: +raise OperationError(space.w_OverflowError, space.w_None) +return self.box(value) -class NonNativeInt64(BaseType, NonNativeInteger): -_attrs_ = () -spec = int64_spec -BoxType = interp_boxes.W_Int64Box -format_code = "q" - -_coerce = func_with_new_name(_int64_coerce, '_coerce') - -def _uint64_coerce(self, space, w_item): -try: -return self._base_coerce(space, w_item) -except OperationError, e: -if not e.match(space, space.w_OverflowError): -raise -bigint = space.bigint_w(w_item) -try: -value = bigint.toulonglong() -except OverflowError: -raise OperationError(space.w_OverflowError, space.w_None) -return self.box(value) class UInt64(BaseType, Integer): _attrs_ = () @@ -677,15 +610,19 @@ BoxType = interp_boxes.W_UInt64Box format_code = "Q" -_coerce = func_with_new_name(_uint64_coerce, '_coerce') +def _coerce(self, space, w_item): +try: +return self._base_coerce(space, w_item) +except OperationError, e: +if not e.match(space, space.w
[pypy-commit] pypy improve-docs-2: shuffle stuff around
Author: Maciej Fijalkowski Branch: improve-docs-2 Changeset: r63235:2c6afe71e2e8 Date: 2013-04-11 19:08 +0200 http://bitbucket.org/pypy/pypy/changeset/2c6afe71e2e8/ Log:shuffle stuff around diff --git a/pypy/doc/index.rst b/pypy/doc/index.rst --- a/pypy/doc/index.rst +++ b/pypy/doc/index.rst @@ -49,6 +49,9 @@ * `potential project ideas`_: In case you want to get your feet wet... +* `more stuff`_: this is a collection of documentation that's there, but not + particularly organized + Documentation for the PyPy Python Interpreter = @@ -112,202 +115,6 @@ .. _`speed.pypy.org`: http://speed.pypy.org .. _`RPython toolchain`: translation.html .. _`potential project ideas`: project-ideas.html - -Project Documentation -= - -`architecture`_ gives a complete view of PyPy's basic design. - -`coding guide`_ helps you to write code for PyPy (especially also describes -coding in RPython a bit). - -`sprint reports`_ lists reports written at most of our sprints, from -2003 to the present. - -`papers, talks and related projects`_ lists presentations -and related projects as well as our published papers. - -`PyPy video documentation`_ is a page linking to the videos (e.g. of talks and -introductions) that are available. - -`Technical reports`_ is a page that contains links to the -reports that we submitted to the European Union. - -`development methodology`_ describes our sprint-driven approach. - -`LICENSE`_ contains licensing details (basically a straight MIT-license). - -`Glossary`_ of PyPy words to help you align your inner self with -the PyPy universe. - -Status -=== - -PyPy can be used to run Python programs on Linux, OS/X, -Windows. -To dig into PyPy it is recommended to try out the current -Mercurial default branch, which is always working or mostly working, -instead of the latest release, which is `2.0 beta1`__. - -.. __: release-2.0.0-beta1.html - -PyPy is mainly developed on Linux and Mac OS X. Windows is supported, -but platform-specific bugs tend to take longer before we notice and fix -them. Linux 64-bit machines are supported (though it may also take some -time before we notice and fix bugs). - -PyPy's own tests `summary`_, daily updated, run through BuildBot infrastructure. -You can also find CPython's compliance tests run with compiled ``pypy-c`` -executables there. - - -Source Code Documentation -=== - -`object spaces`_ discusses the object space interface -and several implementations. - -`bytecode interpreter`_ explains the basic mechanisms -of the bytecode interpreter and virtual machine. - -`interpreter optimizations`_ describes our various strategies for -improving the performance of our interpreter, including alternative -object implementations (for strings, dictionaries and lists) in the -standard object space. - -`translation`_ is a detailed overview of our translation process. The -rtyper_ is the largest component of our translation process. - -`dynamic-language translation`_ is a paper that describes -the translation process, especially the flow object space -and the annotator in detail. (This document is one -of the `EU reports`_.) - -`low-level encapsulation`_ describes how our approach hides -away a lot of low level details. This document is also part -of the `EU reports`_. - -`translation aspects`_ describes how we weave different -properties into our interpreter during the translation -process. This document is also part of the `EU reports`_. - -`garbage collector`_ strategies that can be used by the virtual -machines produced by the translation process. - -`parser`_ contains (outdated, unfinished) documentation about -the parser. - -`rlib`_ describes some modules that can be used when implementing programs in -RPython. - -`configuration documentation`_ describes the various configuration options that -allow you to customize PyPy. - -`pypy on windows`_ - -`command line reference`_ - -`CLI backend`_ describes the details of the .NET backend. - -`JIT Generation in PyPy`_ describes how we produce the Python Just-in-time Compiler -from our Python interpreter. - -`directory cross-reference`_ - -.. _`garbage collector`: garbage_collection.html -.. _`directory cross-reference`: dir-reference.html -.. _`pypy on windows`: windows.html -.. _`command line reference`: commandline_ref.html -.. _`FAQ`: faq.html -.. _Glossary: glossary.html -.. _`PyPy video documentation`: video-index.html -.. _parser: parser.html -.. _`development methodology`: dev_method.html -.. _`sprint reports`: sprint-reports.html -.. _`papers, talks and related projects`: extradoc.html -.. _`object spaces`: objspace.html -.. _`interpreter optimizations`: interpreter-optimizations.html -.. _`translation`: translation.html -.. _`dynamic-language translation`: https://bitbucket.org/pypy/extradoc/raw/tip/eu-report/D05.1_Publish_on_translating_a_very
[pypy-commit] pypy improve-docs-2: change the sentence after alex suggestion
Author: Maciej Fijalkowski Branch: improve-docs-2 Changeset: r63237:106a992b99f0 Date: 2013-04-11 19:30 +0200 http://bitbucket.org/pypy/pypy/changeset/106a992b99f0/ Log:change the sentence after alex suggestion diff --git a/pypy/doc/how-to-contribute.rst b/pypy/doc/how-to-contribute.rst --- a/pypy/doc/how-to-contribute.rst +++ b/pypy/doc/how-to-contribute.rst @@ -21,8 +21,8 @@ of very high quality requirements for compilers and partly because there is simply no other way to get around such complex project, that will keep you sane. There are probably people out there who are smart enough not to need it, we're -not one of those. Familiarity with `pytest`_ is a must-have before -doing anything else. +not one of those. You may consider familiarizing yourself with `pytest`_, +since this is a tool we use for tests. This leads to the next issue: Layers ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy improve-docs-2: close to be merged branch
Author: Maciej Fijalkowski Branch: improve-docs-2 Changeset: r63239:31a216b51485 Date: 2013-04-11 19:42 +0200 http://bitbucket.org/pypy/pypy/changeset/31a216b51485/ Log:close to be merged branch ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy improve-docs-2: address a giant XXX, needs expanding but it's better than before
Author: Maciej Fijalkowski Branch: improve-docs-2 Changeset: r63238:a69e4ae03353 Date: 2013-04-11 19:42 +0200 http://bitbucket.org/pypy/pypy/changeset/a69e4ae03353/ Log:address a giant XXX, needs expanding but it's better than before diff --git a/pypy/doc/getting-started-dev.rst b/pypy/doc/getting-started-dev.rst --- a/pypy/doc/getting-started-dev.rst +++ b/pypy/doc/getting-started-dev.rst @@ -4,14 +4,50 @@ .. contents:: +RPython is a subset of Python that can be statically compiled. The PyPy +interpreter is written mostly in RPython (with pieces in Python), while +the RPython compiler is written in Python. The hard to understand part +is that Python is a meta-programming language for RPython, that is, +RPython is considered from live objects **after** the imports are done. +This might require more explanation. You start writing RPython from +``entry_point``, a good starting point is +``rpython/translator/goal/targetnopstandalone.py``. This does not do all that +much, but is a start. Now if code analyzed (in this case ``entry_point``) +calls some functions, those calls will be followed. Those followed calls +have to be RPython themselves (and everything they call etc.), however not +entire module files. To show how you can use metaprogramming, we can do +a silly example (note that closures are not RPython):: -This should really write a word of two about **WHAT** is RPython + def generator(operation): + if operation == 'add': + def f(a, b): + return a + b + else: + def f(a, b): + return a - b + return f -XXX ltratt blog post -XXX "how to write interpreters" links -XXX -XXX -XXX + add = generator('add') + sub = generator('sub') + + def entry_point(argv): + print add(sub(int(argv[1]), 3) 4) + return 0 + +In this example ``entry_point`` is RPython, ``add`` and ``sub`` are RPython, +however, ``generator`` is not. + +A good introductory level articles are available: + +* Laurence Tratt -- `Fast Enough VMs in Fast Enough Time`_. + +* `How to write interpreters in RPython`_ and `part 2`_ by Andrew Brown. + +.. _`Fast Enough VMs in Fast Enough Time`: http://tratt.net/laurie/tech_articles/articles/fast_enough_vms_in_fast_enough_time + +.. _`How to write interpreters in RPython`: http://morepypy.blogspot.com/2011/04/tutorial-writing-interpreter-with-pypy.html + +.. _`part 2`: http://morepypy.blogspot.com/2011/04/tutorial-part-2-adding-jit.html .. _`try out the translator`: ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: attack the docs
Author: Maciej Fijalkowski Branch: Changeset: r63240:41bbdcefb3ac Date: 2013-04-11 19:43 +0200 http://bitbucket.org/pypy/pypy/changeset/41bbdcefb3ac/ Log:attack the docs diff --git a/README.rst b/README.rst --- a/README.rst +++ b/README.rst @@ -13,9 +13,9 @@ http://pypy.org/ -The getting-started document will help guide you: +If you want to help developing PyPy, this document might help you: -http://doc.pypy.org/en/latest/getting-started.html +http://doc.pypy.org/ It will also point you to the rest of the documentation which is generated from files in the pypy/doc directory within the source repositories. Enjoy diff --git a/pypy/doc/dir-reference.rst b/pypy/doc/dir-reference.rst new file mode 100644 --- /dev/null +++ b/pypy/doc/dir-reference.rst @@ -0,0 +1,140 @@ +PyPy directory cross-reference +-- + +Here is a fully referenced alphabetical two-level deep +directory overview of PyPy: + += +Directory explanation/links += +`pypy/bin/`_ command-line scripts, mainly + `pypy/bin/pyinteractive.py`_ + +`pypy/config/`_handles the numerous options for building + and running PyPy + +`pypy/doc/`_ text versions of PyPy developer + documentation + +`pypy/doc/config/`_documentation for the numerous translation + options + +`pypy/doc/discussion/`_drafts of ideas and documentation + +``doc/*/`` other specific documentation topics or tools + +`pypy/interpreter/`_ `bytecode interpreter`_ and related objects + (frames, functions, modules,...) + +`pypy/interpreter/pyparser/`_ interpreter-level Python source parser + +`pypy/interpreter/astcompiler/`_ interpreter-level bytecode compiler, + via an AST representation + +`pypy/module/`_contains `mixed modules`_ + implementing core modules with + both application and interpreter level code. + Not all are finished and working. Use + the ``--withmod-xxx`` + or ``--allworkingmodules`` translation + options. + +`pypy/objspace/`_ `object space`_ implementations + +`pypy/objspace/std/`_ the StdObjSpace_ implementing CPython's + objects and types + +`pypy/tool/`_ various utilities and hacks used + from various places + +`pypy/tool/algo/`_ general-purpose algorithmic and mathematic + tools + +`pypy/tool/pytest/`_ support code for our `testing methods`_ + + +`rpython/annotator/`_ `type inferencing code`_ for + `RPython`_ programs + +`rpython/config/`_ handles the numerous options for RPython + + +`rpython/flowspace/`_ the FlowObjSpace_ implementing + `abstract interpretation`_ + +`rpython/rlib/`_ a `"standard library"`_ for RPython_ + programs + +`rpython/rtyper/`_ the `RPython Typer`_ + +`rpython/rtyper/lltypesystem/`_the `low-level type system`_ for + C-like backends + +`rpython/rtyper/ootypesystem/`_the `object-oriented type system`_ + for OO backends + +`rpython/memory/`_ the `garbage collector`_ construction + framework + +`rpython/translator/`_ translation_ backends and support code + +`rpython/translator/backendopt/`_ general optimizations that run before a + backend generates code + +`rpython/translator/c/`_ the `GenC backend`_, producing C code + from an + RPython program (generally via the rtyper_) + +`rpython/translator/cli/`_ the `CLI backend`_ for `.NET`_ + (Microsoft CLR or Mono_) + +`pypy/goal/`_ our `main PyPy-translation scripts`_ + live here + +`rpython/translator/jvm/`_ the Java backend + +`rpython/translator/tool/`_helper tools for translation + +`dotviewer/`_ `graph viewer`_ + +``*/test/``many directories have a tes
[pypy-commit] benchmarks default: have runner.py support --niceness option
Author: Brian Kearns Branch: Changeset: r203:6f149a47d993 Date: 2013-04-11 14:03 -0400 http://bitbucket.org/pypy/benchmarks/changeset/6f149a47d993/ Log:have runner.py support --niceness option diff --git a/benchmarks.py b/benchmarks.py --- a/benchmarks.py +++ b/benchmarks.py @@ -82,6 +82,7 @@ 'raytrace-simple', 'crypto_pyaes', 'bm_mako', 'bm_chameleon', 'json_bench', 'pidigits', 'hexiom2', 'eparse']: _register_new_bm(name, name, globals(), **opts.get(name, {})) + for name in ['names', 'iteration', 'tcp', 'pb', ]:#'web']:#, 'accepts']: if name == 'web': iteration_scaling = 0.2 @@ -90,13 +91,12 @@ _register_new_bm_twisted(name, 'twisted_' + name, globals(), bm_env={'PYTHONPATH': ':'.join(TWISTED)}, iteration_scaling=iteration_scaling) + _register_new_bm('spitfire', 'spitfire', globals(), extra_args=['--benchmark=spitfire_o4']) _register_new_bm('spitfire', 'spitfire_cstringio', globals(), extra_args=['--benchmark=python_cstringio']) - - # = # translate.py benchmark # = diff --git a/runner.py b/runner.py --- a/runner.py +++ b/runner.py @@ -5,6 +5,7 @@ import json import socket import sys +import os import benchmarks from saveresults import save @@ -207,6 +208,8 @@ "--force-host", default=None, action="store", help=("Force the hostname. This option will also be used when " "uploading the baseline result.")) +parser.add_option("--niceness", default=None, type="int", + help="Set absolute niceness for process") # upload baseline group upload_baseline_group = optparse.OptionGroup( @@ -271,6 +274,9 @@ revision = options.upload_revision force_host = options.force_host +if options.niceness: +os.nice(options.niceness - os.nice(0)) + results = run_and_store(benchmarks, output_filename, changed_path, revision, args=args, fast=fast, baseline_path=baseline_path, ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] buildbot default: have benchmark run set niceness
Author: Brian Kearns Branch: Changeset: r777:33564e2e9fc7 Date: 2013-04-11 14:09 -0400 http://bitbucket.org/pypy/buildbot/changeset/33564e2e9fc7/ Log:have benchmark run set niceness diff --git a/bot2/pypybuildbot/builds.py b/bot2/pypybuildbot/builds.py --- a/bot2/pypybuildbot/builds.py +++ b/bot2/pypybuildbot/builds.py @@ -118,7 +118,7 @@ 'latest.html') symlink_force(self.masterdest, symname) except OSError: -pass +pass class Translate(ShellCmd): name = "translate" @@ -145,7 +145,6 @@ class PytestCmd(ShellCmd): - def commandComplete(self, cmd): from pypybuildbot.summary import RevisionOutcomeSet if 'pytestLog' not in cmd.logs: @@ -176,7 +175,6 @@ d[key] = summary builder.saveYourself() - # ___ class UpdateCheckout(ShellCmd): @@ -353,8 +351,8 @@ "pypy/module/pypyjit/test_pypy_c"], logfiles={'pytestLog': 'pypyjit_new.log'})) +# -# class Own(factory.BuildFactory): def __init__(self, platform='linux', cherrypick='', extra_cfgs=[], **kwargs): @@ -523,6 +521,7 @@ if trigger: # if provided trigger schedulers that are depend on this one self.addStep(Trigger(schedulerNames=[trigger])) + class JITBenchmark(factory.BuildFactory): def __init__(self, platform='linux', host='tannit', postfix=''): factory.BuildFactory.__init__(self) @@ -568,6 +567,7 @@ locks=[lock.access('exclusive')], description="run benchmarks on top of pypy-c", command=["python", "runner.py", '--output-filename', 'result.json', + '--niceness', '-10', '--changed', pypy_c_rel, '--baseline', pypy_c_rel, '--args', ',--jit off', ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] buildbot default: settle for niceness 0
Author: Brian Kearns Branch: Changeset: r778:c5df804d3d58 Date: 2013-04-11 14:38 -0400 http://bitbucket.org/pypy/buildbot/changeset/c5df804d3d58/ Log:settle for niceness 0 diff --git a/bot2/pypybuildbot/builds.py b/bot2/pypybuildbot/builds.py --- a/bot2/pypybuildbot/builds.py +++ b/bot2/pypybuildbot/builds.py @@ -567,7 +567,7 @@ locks=[lock.access('exclusive')], description="run benchmarks on top of pypy-c", command=["python", "runner.py", '--output-filename', 'result.json', - '--niceness', '-10', + '--niceness', '0', # can't get limits.conf to allow -10 '--changed', pypy_c_rel, '--baseline', pypy_c_rel, '--args', ',--jit off', ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: merge heads
Author: David Schneider Branch: Changeset: r63242:fec8fb85c22d Date: 2013-04-11 21:08 +0200 http://bitbucket.org/pypy/pypy/changeset/fec8fb85c22d/ Log:merge heads diff --git a/README.rst b/README.rst --- a/README.rst +++ b/README.rst @@ -13,9 +13,9 @@ http://pypy.org/ -The getting-started document will help guide you: +If you want to help developing PyPy, this document might help you: -http://doc.pypy.org/en/latest/getting-started.html +http://doc.pypy.org/ It will also point you to the rest of the documentation which is generated from files in the pypy/doc directory within the source repositories. Enjoy diff --git a/pypy/doc/dir-reference.rst b/pypy/doc/dir-reference.rst new file mode 100644 --- /dev/null +++ b/pypy/doc/dir-reference.rst @@ -0,0 +1,140 @@ +PyPy directory cross-reference +-- + +Here is a fully referenced alphabetical two-level deep +directory overview of PyPy: + += +Directory explanation/links += +`pypy/bin/`_ command-line scripts, mainly + `pypy/bin/pyinteractive.py`_ + +`pypy/config/`_handles the numerous options for building + and running PyPy + +`pypy/doc/`_ text versions of PyPy developer + documentation + +`pypy/doc/config/`_documentation for the numerous translation + options + +`pypy/doc/discussion/`_drafts of ideas and documentation + +``doc/*/`` other specific documentation topics or tools + +`pypy/interpreter/`_ `bytecode interpreter`_ and related objects + (frames, functions, modules,...) + +`pypy/interpreter/pyparser/`_ interpreter-level Python source parser + +`pypy/interpreter/astcompiler/`_ interpreter-level bytecode compiler, + via an AST representation + +`pypy/module/`_contains `mixed modules`_ + implementing core modules with + both application and interpreter level code. + Not all are finished and working. Use + the ``--withmod-xxx`` + or ``--allworkingmodules`` translation + options. + +`pypy/objspace/`_ `object space`_ implementations + +`pypy/objspace/std/`_ the StdObjSpace_ implementing CPython's + objects and types + +`pypy/tool/`_ various utilities and hacks used + from various places + +`pypy/tool/algo/`_ general-purpose algorithmic and mathematic + tools + +`pypy/tool/pytest/`_ support code for our `testing methods`_ + + +`rpython/annotator/`_ `type inferencing code`_ for + `RPython`_ programs + +`rpython/config/`_ handles the numerous options for RPython + + +`rpython/flowspace/`_ the FlowObjSpace_ implementing + `abstract interpretation`_ + +`rpython/rlib/`_ a `"standard library"`_ for RPython_ + programs + +`rpython/rtyper/`_ the `RPython Typer`_ + +`rpython/rtyper/lltypesystem/`_the `low-level type system`_ for + C-like backends + +`rpython/rtyper/ootypesystem/`_the `object-oriented type system`_ + for OO backends + +`rpython/memory/`_ the `garbage collector`_ construction + framework + +`rpython/translator/`_ translation_ backends and support code + +`rpython/translator/backendopt/`_ general optimizations that run before a + backend generates code + +`rpython/translator/c/`_ the `GenC backend`_, producing C code + from an + RPython program (generally via the rtyper_) + +`rpython/translator/cli/`_ the `CLI backend`_ for `.NET`_ + (Microsoft CLR or Mono_) + +`pypy/goal/`_ our `main PyPy-translation scripts`_ + live here + +`rpython/translator/jvm/`_ the Java backend + +`rpython/translator/tool/`_helper tools for translation + +`dotviewer/`_ `graph viewer`_ + +``*/test/``many directories have a test subdi
[pypy-commit] pypy default: update arm tests
Author: David Schneider Branch: Changeset: r63243:5dd20a9b2d3a Date: 2013-04-11 21:27 +0200 http://bitbucket.org/pypy/pypy/changeset/5dd20a9b2d3a/ Log:update arm tests diff --git a/rpython/jit/backend/arm/test/test_zrpy_releasegil.py b/rpython/jit/backend/arm/test/test_zrpy_releasegil.py --- a/rpython/jit/backend/arm/test/test_zrpy_releasegil.py +++ b/rpython/jit/backend/arm/test/test_zrpy_releasegil.py @@ -1,4 +1,4 @@ from rpython.jit.backend.arm.test.support import skip_unless_run_slow_tests skip_unless_run_slow_tests() -from rpython.jit.backend.llsupport.test.zrpy_releasegil_test import TestShadowStack, TestAsmGcc +from rpython.jit.backend.llsupport.test.zrpy_releasegil_test import TestShadowStack diff --git a/rpython/jit/backend/arm/test/test_ztranslation_basic.py b/rpython/jit/backend/arm/test/test_ztranslation_basic.py --- a/rpython/jit/backend/arm/test/test_ztranslation_basic.py +++ b/rpython/jit/backend/arm/test/test_ztranslation_basic.py @@ -5,9 +5,9 @@ skip_unless_run_slow_tests() -class TestTranslationX86(TranslationTest): -def _check_cbuilder(self, cbuilder): -# We assume here that we have sse2. If not, the CPUClass -# needs to be changed to CPU386_NO_SSE2, but well. -assert '-msse2' in cbuilder.eci.compile_extra -assert '-mfpmath=sse' in cbuilder.eci.compile_extra +class TestTranslationARM(TranslationTest): +def _get_TranslationContext(self): +t = TranslationContext() +t.config.translation.gc = DEFL_GC # 'hybrid' or 'minimark' +t.config.translation.gcrootfinder = 'shadowstack' +return t diff --git a/rpython/jit/backend/arm/test/test_ztranslation_call_assembler.py b/rpython/jit/backend/arm/test/test_ztranslation_call_assembler.py --- a/rpython/jit/backend/arm/test/test_ztranslation_call_assembler.py +++ b/rpython/jit/backend/arm/test/test_ztranslation_call_assembler.py @@ -5,9 +5,9 @@ skip_unless_run_slow_tests() -class TestTranslationCallAssemblerX86(TranslationTestCallAssembler): -def _check_cbuilder(self, cbuilder): -# We assume here that we have sse2. If not, the CPUClass -# needs to be changed to CPU386_NO_SSE2, but well. -assert '-msse2' in cbuilder.eci.compile_extra -assert '-mfpmath=sse' in cbuilder.eci.compile_extra \ No newline at end of file +class TestTranslationCallAssemblerARM(TranslationTestCallAssembler): +def _get_TranslationContext(self): +t = TranslationContext() +t.config.translation.gc = DEFL_GC # 'hybrid' or 'minimark' +t.config.translation.gcrootfinder = 'shadowstack' +return t diff --git a/rpython/jit/backend/arm/test/test_ztranslation_external_exception.py b/rpython/jit/backend/arm/test/test_ztranslation_external_exception.py --- a/rpython/jit/backend/arm/test/test_ztranslation_external_exception.py +++ b/rpython/jit/backend/arm/test/test_ztranslation_external_exception.py @@ -5,11 +5,11 @@ skip_unless_run_slow_tests() -class TestTranslationRemoveTypePtrX86(TranslationRemoveTypePtrTest): +class TestTranslationRemoveTypePtrARM(TranslationRemoveTypePtrTest): def _get_TranslationContext(self): t = TranslationContext() t.config.translation.gc = DEFL_GC # 'hybrid' or 'minimark' -t.config.translation.gcrootfinder = 'asmgcc' +t.config.translation.gcrootfinder = 'shadowstack' t.config.translation.list_comprehension_operations = True t.config.translation.gcremovetypeptr = True -return t +return t \ No newline at end of file diff --git a/rpython/jit/backend/arm/test/test_ztranslation_jit_stats.py b/rpython/jit/backend/arm/test/test_ztranslation_jit_stats.py --- a/rpython/jit/backend/arm/test/test_ztranslation_jit_stats.py +++ b/rpython/jit/backend/arm/test/test_ztranslation_jit_stats.py @@ -5,9 +5,9 @@ skip_unless_run_slow_tests() -class TestTranslationJITStatsX86(TranslationTestJITStats): -def _check_cbuilder(self, cbuilder): -# We assume here that we have sse2. If not, the CPUClass -# needs to be changed to CPU386_NO_SSE2, but well. -assert '-msse2' in cbuilder.eci.compile_extra -assert '-mfpmath=sse' in cbuilder.eci.compile_extra \ No newline at end of file +class TestTranslationJITStatsARM(TranslationTestJITStats): +def _get_TranslationContext(self): +t = TranslationContext() +t.config.translation.gc = DEFL_GC # 'hybrid' or 'minimark' +t.config.translation.gcrootfinder = 'shadowstack' +return t ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy longdouble2: move ENABLED_LONG_DOUBLE def to typespec.py
Author: Ronan Lamy Branch: longdouble2 Changeset: r63244:d6af37df55fe Date: 2013-04-11 20:42 +0100 http://bitbucket.org/pypy/pypy/changeset/d6af37df55fe/ Log:move ENABLED_LONG_DOUBLE def to typespec.py 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 @@ -12,20 +12,12 @@ from rpython.rlib.objectmodel import specialize from rpython.tool.sourcetools import func_with_new_name from pypy.module.micronumpy.arrayimpl.voidbox import VoidBoxStorage +from pypy.module.micronumpy.typespec import (ENABLED_LONG_DOUBLE, +long_double_size) MIXIN_32 = (int_typedef,) if LONG_BIT == 32 else () MIXIN_64 = (int_typedef,) if LONG_BIT == 64 else () -# Is this the proper place for this? -ENABLED_LONG_DOUBLE = False -long_double_size = rffi.sizeof_c_type('long double', ignore_errors=True) - -import os -if long_double_size == 8 and os.name == 'nt': -# this is a lie, or maybe a wish, MS fakes longdouble math with double -long_double_size = 12 - - def new_dtype_getter(name): def _get_dtype(space): from pypy.module.micronumpy.interp_dtype import get_dtype_cache diff --git a/pypy/module/micronumpy/interp_dtype.py b/pypy/module/micronumpy/interp_dtype.py --- a/pypy/module/micronumpy/interp_dtype.py +++ b/pypy/module/micronumpy/interp_dtype.py @@ -12,6 +12,8 @@ from rpython.rlib import jit from pypy.module.micronumpy.arrayimpl.concrete import SliceArray +from pypy.module.micronumpy.typespec import (ENABLED_LONG_DOUBLE, +long_double_size) UNSIGNEDLTR = "u" @@ -517,7 +519,7 @@ aliases=["complex"], float_type = self.w_float64dtype, ) -if interp_boxes.ENABLED_LONG_DOUBLE and interp_boxes.long_double_size > 8: +if ENABLED_LONG_DOUBLE and long_double_size > 8: self.w_longdouble = W_Dtype( types.Float80_instance, num=13, @@ -538,17 +540,17 @@ aliases=["clongdouble", "clongfloat"], float_type = self.w_longdouble, ) -if interp_boxes.long_double_size == 12: +if long_double_size == 12: self.w_longdouble.name = "float96" self.w_float96dtype = self.w_longdouble self.w_clongdouble.name = "complex192" self.w_complex192dtype = self.w_clongdouble -elif interp_boxes.long_double_size == 16: +elif long_double_size == 16: self.w_longdouble.name = "float128" self.w_float128dtype = self.w_longdouble self.w_clongdouble.name = "complex256" self.w_complex256dtype = self.w_clongdouble -elif interp_boxes.ENABLED_LONG_DOUBLE: +elif ENABLED_LONG_DOUBLE: self.w_float64dtype.aliases += ["longdouble", "longfloat"] self.w_complex128dtype.aliases += ["clongdouble", "clongfloat"] self.w_longdouble = self.w_float64dtype @@ -628,7 +630,7 @@ self.w_float32dtype, self.w_float64dtype, ] complex_dtypes = [self.w_complex64dtype, self.w_complex128dtype] -if interp_boxes.ENABLED_LONG_DOUBLE: +if ENABLED_LONG_DOUBLE: float_dtypes.append(self.w_longdouble) complex_dtypes.append(self.w_clongdouble) self.builtin_dtypes = [ @@ -702,7 +704,7 @@ 'FLOAT': self.w_float32dtype, 'BOOL': self.w_booldtype, } -if interp_boxes.ENABLED_LONG_DOUBLE: +if ENABLED_LONG_DOUBLE: typeinfo_full['LONGDOUBLE'] = self.w_longdouble typeinfo_full['CLONGDOUBLE'] = self.w_clongdouble 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 @@ -23,6 +23,8 @@ int16_spec, uint16_spec, int32_spec, uint32_spec, long_spec, ulong_spec, int64_spec, uint64_spec, float32_spec, float64_spec, float16_spec) +from pypy.module.micronumpy.typespec import (ENABLED_LONG_DOUBLE, +long_double_size) degToRad = math.pi / 180.0 log2 = math.log(2) @@ -1461,7 +1463,7 @@ BoxType = interp_boxes.W_Complex128Box FloatType = Float64_instance -if interp_boxes.ENABLED_LONG_DOUBLE and interp_boxes.long_double_size > 8: +if ENABLED_LONG_DOUBLE and long_double_size > 8: class Float80(BaseType, Float): _attrs_ = () spec = longdouble_spec @@ -1485,8 +1487,8 @@ BoxType = interp_boxes.W_CLongDoubleBox FloatType = Float80_instance -if interp_boxes.long_double_size in (12, 16): -Float80.storage_bytes = interp_boxes.long_double_size +if long_double_size in (12, 16): +Float80.storage_bytes = long_double_size else: raise ImportError("Unsupported size for long double") diff --git a/pyp
[pypy-commit] pypy longdouble2: add missing longdouble_spec
Author: Ronan Lamy Branch: longdouble2 Changeset: r63245:246f17c620ac Date: 2013-04-11 20:55 +0100 http://bitbucket.org/pypy/pypy/changeset/246f17c620ac/ Log:add missing longdouble_spec 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 @@ -22,7 +22,7 @@ from pypy.module.micronumpy.typespec import (bool_spec, int8_spec, uint8_spec, int16_spec, uint16_spec, int32_spec, uint32_spec, long_spec, ulong_spec, int64_spec, uint64_spec, float32_spec, float64_spec, -float16_spec) +float16_spec, longdouble_spec) from pypy.module.micronumpy.typespec import (ENABLED_LONG_DOUBLE, long_double_size) diff --git a/pypy/module/micronumpy/typespec.py b/pypy/module/micronumpy/typespec.py --- a/pypy/module/micronumpy/typespec.py +++ b/pypy/module/micronumpy/typespec.py @@ -33,5 +33,6 @@ if long_double_size == 8 and os.name == 'nt': # this is a lie, or maybe a wish, MS fakes longdouble math with double long_double_size = 12 +longdouble_spec = TypeSpec("float80", rffi.LONGDOUBLE) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3k: add a null check to PyMemoryView_FromBuffer. test_FillWithObject seems to
Author: Philip Jenvey Branch: py3k Changeset: r63247:ea6d963fbdba Date: 2013-04-11 13:36 -0700 http://bitbucket.org/pypy/pypy/changeset/ea6d963fbdba/ Log:add a null check to PyMemoryView_FromBuffer. test_FillWithObject seems to require an extra del for correct cleanup diff --git a/pypy/module/cpyext/memoryobject.py b/pypy/module/cpyext/memoryobject.py --- a/pypy/module/cpyext/memoryobject.py +++ b/pypy/module/cpyext/memoryobject.py @@ -1,3 +1,4 @@ +from pypy.interpreter.error import OperationError from pypy.module.cpyext.api import cpython_api, Py_buffer from pypy.module.cpyext.pyobject import PyObject, from_ref from pypy.module.cpyext.buffer import CBuffer @@ -14,6 +15,9 @@ The memoryview object then owns the buffer represented by view, which means you shouldn't try to call PyBuffer_Release() yourself: it will be done on deallocation of the memoryview object.""" +if not view.c_buf: +msg = "cannot make memory view from a buffer with a NULL data pointer" +raise OperationError(space.w_ValueError, space.wrap(msg)) w_obj = from_ref(space, view.c_obj) buf = CBuffer(space, view.c_buf, view.c_len, w_obj) return space.wrap(W_MemoryView(space.wrap(buf))) diff --git a/pypy/module/cpyext/test/test_memoryobject.py b/pypy/module/cpyext/test/test_memoryobject.py --- a/pypy/module/cpyext/test/test_memoryobject.py +++ b/pypy/module/cpyext/test/test_memoryobject.py @@ -36,5 +36,20 @@ """)]) result = module.fillinfo() assert b"hello, world." == result +del result - +def test_fill_from_NULL_pointer(self): +module = self.import_extension('foo', [ +("fillinfo_NULL", "METH_VARARGS", + """ + Py_buffer info; + if (PyBuffer_FillInfo(&info, NULL, NULL, 1, 1, + PyBUF_FULL_RO) < 0) { + return NULL; + } + return PyMemoryView_FromBuffer(&info); + """)]) +exc = raises(ValueError, module.fillinfo_NULL) +expected = ("cannot make memory view from a buffer with a NULL data " +"pointer") +assert str(exc.value) == expected ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3k: PyInt_ apis -> PyLong_
Author: Philip Jenvey Branch: py3k Changeset: r63246:8bc3fa4eca19 Date: 2013-04-11 13:35 -0700 http://bitbucket.org/pypy/pypy/changeset/8bc3fa4eca19/ Log:PyInt_ apis -> PyLong_ diff --git a/pypy/module/cpyext/dictobject.py b/pypy/module/cpyext/dictobject.py --- a/pypy/module/cpyext/dictobject.py +++ b/pypy/module/cpyext/dictobject.py @@ -157,8 +157,8 @@ Py_ssize_t pos = 0; while (PyDict_Next(self->dict, &pos, &key, &value)) { -int i = PyInt_AS_LONG(value) + 1; -PyObject *o = PyInt_FromLong(i); +int i = PyLong_AS_LONG(value) + 1; +PyObject *o = PyLong_FromLong(i); if (o == NULL) return -1; if (PyDict_SetItem(self->dict, key, o) < 0) { diff --git a/pypy/module/cpyext/test/comparisons.c b/pypy/module/cpyext/test/comparisons.c --- a/pypy/module/cpyext/test/comparisons.c +++ b/pypy/module/cpyext/test/comparisons.c @@ -1,5 +1,9 @@ #include "Python.h" +#if PY_MAJOR_VERSION >= 3 +#define PyInt_CheckExact PyLong_CheckExact +#endif + typedef struct CmpObject { PyObject_HEAD } CmpObject; diff --git a/pypy/module/cpyext/test/foo.c b/pypy/module/cpyext/test/foo.c --- a/pypy/module/cpyext/test/foo.c +++ b/pypy/module/cpyext/test/foo.c @@ -1,6 +1,11 @@ #include "Python.h" #include "structmember.h" +#if PY_MAJOR_VERSION >= 3 +#define PyInt_FromLong PyLong_FromLong +#define PyInt_AsLong PyLong_AsLong +#endif + typedef struct { PyObject_HEAD intfoo;/* the context holder */ diff --git a/pypy/module/cpyext/test/test_borrow.py b/pypy/module/cpyext/test/test_borrow.py --- a/pypy/module/cpyext/test/test_borrow.py +++ b/pypy/module/cpyext/test/test_borrow.py @@ -42,7 +42,7 @@ module = self.import_extension('foo', [ ("test_borrow_destroy", "METH_NOARGS", """ -PyObject *i = PyInt_FromLong(42); +PyObject *i = PyLong_FromLong(42); PyObject *j; PyObject *t1 = PyTuple_Pack(1, i); PyObject *t2 = PyTuple_Pack(1, i); @@ -52,7 +52,7 @@ PyTuple_GetItem(t2, 0); Py_DECREF(t2); -j = PyInt_FromLong(PyInt_AsLong(i)); +j = PyLong_FromLong(PyLong_AsLong(i)); Py_DECREF(t1); return j; """), diff --git a/pypy/module/cpyext/test/test_cpyext.py b/pypy/module/cpyext/test/test_cpyext.py --- a/pypy/module/cpyext/test/test_cpyext.py +++ b/pypy/module/cpyext/test/test_cpyext.py @@ -738,7 +738,7 @@ mod = self.import_extension('foo', [ ('get_hash', 'METH_NOARGS', ''' - return PyInt_FromLong(_Py_HashPointer(Py_None)); + return PyLong_FromLong(_Py_HashPointer(Py_None)); ''' ), ]) diff --git a/pypy/module/cpyext/test/test_getargs.py b/pypy/module/cpyext/test/test_getargs.py --- a/pypy/module/cpyext/test/test_getargs.py +++ b/pypy/module/cpyext/test/test_getargs.py @@ -18,7 +18,7 @@ if (!PyArg_ParseTuple(args, "i", &l)) { return NULL; } -return PyInt_FromLong(l); +return PyLong_FromLong(l); ''') assert oneargint(1) == 1 raises(TypeError, oneargint, None) @@ -36,7 +36,7 @@ if (!PyArg_ParseTuple(args, "i:oneargandstuff", &l)) { return NULL; } -return PyInt_FromLong(l); +return PyLong_FromLong(l); ''') assert oneargandform(1) == 1 @@ -94,7 +94,7 @@ if (b) Py_INCREF(b); else -b = PyInt_FromLong(42); +b = PyLong_FromLong(42); /* return an owned reference */ return b; ''') diff --git a/pypy/module/cpyext/test/test_listobject.py b/pypy/module/cpyext/test/test_listobject.py --- a/pypy/module/cpyext/test/test_listobject.py +++ b/pypy/module/cpyext/test/test_listobject.py @@ -70,16 +70,16 @@ ("newlist", "METH_NOARGS", """ PyObject *lst = PyList_New(3); - PyList_SetItem(lst, 0, PyInt_FromLong(3)); - PyList_SetItem(lst, 2, PyInt_FromLong(1000)); - PyList_SetItem(lst, 1, PyInt_FromLong(-5)); + PyList_SetItem(lst, 0, PyLong_FromLong(3)); + PyList_SetItem(lst, 2, PyLong_FromLong(1000)); + PyList_SetItem(lst, 1, PyLong_FromLong(-5)); return lst; """ ), ("setlistitem", "METH_VARARGS", """ PyObject *l = PyTuple_GetItem(args, 0); - int index = PyInt_AsLong(PyTuple_GetItem(args, 1)); + int index = PyLong_AsLong(PyTuple_GetItem(args, 1)); Py_INCREF(Py_None); if (PyList_SetItem(l, index, Py_None) < 0) return NULL; diff --git a/pypy/module/cpyext/test/test_number.py
[pypy-commit] pypy default: add one extra assert here
Author: Maciej Fijalkowski Branch: Changeset: r63249:fa879c4fc72f Date: 2013-04-11 23:47 +0200 http://bitbucket.org/pypy/pypy/changeset/fa879c4fc72f/ Log:add one extra assert here diff --git a/rpython/rtyper/rlist.py b/rpython/rtyper/rlist.py --- a/rpython/rtyper/rlist.py +++ b/rpython/rtyper/rlist.py @@ -952,6 +952,7 @@ ll_assert(start <= l1.ll_length(), "l[start:x] = l with start > len(l)") ll_assert(count == stop - start, "setslice cannot resize lists in RPython") +ll_assert(stop <= l1.ll_length(), "stop cannot be past the end of l1") # XXX ...but it would be easy enough to support if really needed ll_arraycopy(l2, l1, 0, start, count) ll_listsetslice.oopspec = 'list.setslice(l1, start, stop, l2)' ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] lang-smalltalk default: (cfbolz, lwassermann): refactored wrap_uint to enable inlining the general case
Author: Lars Wassermann Branch: Changeset: r253:26ab2618ed58 Date: 2013-04-10 21:30 +0200 http://bitbucket.org/pypy/lang-smalltalk/changeset/26ab2618ed58/ Log:(cfbolz, lwassermann): refactored wrap_uint to enable inlining the general case added hint to unwrap_array to enable unrolling for common case of constant array diff --git a/spyvm/objspace.py b/spyvm/objspace.py --- a/spyvm/objspace.py +++ b/spyvm/objspace.py @@ -193,11 +193,14 @@ if bytes_len <= 4: return self.wrap_positive_32bit_int(intmask(val)) else: -w_result = model.W_BytesObject(self, -self.classtable['w_LargePositiveInteger'], bytes_len) -for i in range(bytes_len): -w_result.setchar(i, chr(intmask((val >> i*8) & 255))) -return w_result +return self._wrap_uint_loop(val, bytes_len) + +def _wrap_uint_loop(self, val, bytes_len): +w_result = model.W_BytesObject(self, +self.classtable['w_LargePositiveInteger'], bytes_len) +for i in range(bytes_len): +w_result.setchar(i, chr(intmask((val >> i*8) & 255))) +return w_result def wrap_positive_32bit_int(self, val): # This will always return a positive value. @@ -298,6 +301,8 @@ if not isinstance(w_v, model.W_PointersObject): raise UnwrappingError() return w_v + +@jit.look_inside_iff(lambda self, w_array: jit.isconstant(w_array.size())) def unwrap_array(self, w_array): # Check that our argument has pointers format and the class: if not w_array.getclass(self).is_same_object(self.w_Array): ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] lang-smalltalk default: running version of BitBlt
Author: Lars Wassermann Branch: Changeset: r250:9a05c60e44e1 Date: 2013-04-10 17:27 +0200 http://bitbucket.org/pypy/lang-smalltalk/changeset/9a05c60e44e1/ Log:running version of BitBlt diff --git a/BitBltSim.19.cs b/BitBltSim.19.cs --- a/BitBltSim.19.cs +++ b/BitBltSim.19.cs @@ -94,7 +94,8 @@ simDestRaster _ destForm width - 1 // WordSize + 1. sourceForm notNil ifTrue: [simSourceBits _ sourceForm bits. - simSourceRaster _ sourceForm width - 1 // WordSize + 1]. + simSourceRaster _ sourceForm width - 1 // WordSize + 1] + ifFalse: [simSourceRaster _ 0]. halftoneForm notNil ifTrue: [simHalftoneBits _ halftoneForm bits]. simSkew _ (simSx - simDx) bitAnd: WordSize0. @@ -141,7 +142,9 @@ ifTrue: [prevWord _ prevWord bitAnd: simSkewMask. "XXX: Hack to work around out-of-bounds access" - thisWord := simSourceBits at: (simSourceIndex \\ simSourceBits size) + 1. + thisWord := (simSourceIndex < 0 or: [simSourceIndex >= simSourceBits size]) + ifTrue: [simSourceBits at: 1] + ifFalse: [simSourceBits at: simSourceIndex + 1]. "pick up next word" skewWord _ prevWord bitOr: (thisWord bitAnd: simSkewMask bitInvert32). @@ -190,7 +193,6 @@ destForm unhibernate. sourceForm - ifNil: [sourceForm := destForm] ifNotNil: [sourceForm unhibernate]. halftoneForm ifNotNil: [ (halftoneForm isKindOf: Form) @@ -220,6 +222,7 @@ simDy _ clipY]. simDy + simH > (clipY + clipHeight) ifTrue: [simH _ simH - ((simDy + simH) - (clipY + clipHeight))]. + sourceForm isNil ifTrue: [^nil]. simSx < 0 ifTrue: [simDx _ simDx - simSx. simW _ simW + simSx. simSx _ 0]. simSx + simW > sourceForm width diff --git a/images/minibluebookdebug.image b/images/minibluebookdebug.image index 55870b1f6092dbfa3dcb4e4d0c46fec62b223bf2..77abab25338f3dab9a3e19883f8686ca98ac49c9 GIT binary patch [cut] ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] lang-smalltalk default: refactored sdl connection to avoid double blitting
Author: Lars Wassermann Branch: Changeset: r251:32ca02e56ca2 Date: 2013-04-10 21:26 +0200 http://bitbucket.org/pypy/lang-smalltalk/changeset/32ca02e56ca2/ Log:refactored sdl connection to avoid double blitting diff --git a/spyvm/display.py b/spyvm/display.py --- a/spyvm/display.py +++ b/spyvm/display.py @@ -1,6 +1,7 @@ from rpython.rlib.rarithmetic import r_uint from rpython.rtyper.lltypesystem import lltype, rffi from rpython.rlib.runicode import unicode_encode_utf_8 +from rpython.rlib import jit from rsdl import RSDL, RSDL_helper @@ -58,26 +59,11 @@ self.depth = d self.screen = RSDL.SetVideoMode(w, h, 32, 0) assert self.screen -# self.fillwhite() -def set_pixelbuffer(self, pixelbuffer): -if self.has_surface: -RSDL.FreeSurface(self.surface) -pitch = 4 * self.width -rmask, gmask, bmask, amask = r_uint(0x00FF), r_uint(0xFF00), r_uint(0x00FF), r_uint(0xFF00) -self.surface = RSDL.CreateRGBSurfaceFrom(rffi.cast(rffi.VOIDP, pixelbuffer), - self.width, self.height, 32, pitch, - rmask, gmask, bmask, amask) -self.has_surface = True +def get_pixelbuffer(self): +return self.screen.c_pixels -def fillwhite(self): -fmt = self.screen.c_format -color = RSDL.MapRGB(fmt, 255, 255, 255) -RSDL.FillRect(self.screen, lltype.nullptr(RSDL.Rect), color) -RSDL.Flip(self.screen) - -def blit(self): -RSDL.BlitSurface(self.surface, lltype.nullptr(RSDL.Rect), self.screen, lltype.nullptr(RSDL.Rect)) +def flip(self): RSDL.Flip(self.screen) def get_next_event(self): diff --git a/spyvm/model.py b/spyvm/model.py --- a/spyvm/model.py +++ b/spyvm/model.py @@ -698,14 +698,11 @@ def __init__(self, space, w_class, size, depth, display): W_AbstractObjectWithClassReference.__init__(self, space, w_class) -bytelen = NATIVE_DEPTH / depth * size -self.pixelbuffer = lltype.malloc(rffi.ULONGP.TO, bytelen, flavor='raw') +self._real_depth_buffer = [0] * size +self.pixelbuffer = display.get_pixelbuffer() self._realsize = size self.display = display -def __del__(self): -lltype.free(self.pixelbuffer, flavor='raw') - def at0(self, space, index0): val = self.getword(index0) return space.wrap_uint(val) @@ -715,7 +712,7 @@ self.setword(index0, word) def flush_to_screen(self): -self.display.blit() +self.display.flip() def size(self): return self._realsize @@ -739,28 +736,23 @@ class W_DisplayBitmap1Bit(W_DisplayBitmap): -@jit.unroll_safe def getword(self, n): -word = r_uint(0) -pos = n * NATIVE_DEPTH -for i in xrange(32): -word <<= 1 -pixel = self.pixelbuffer[pos] -word |= r_uint(pixel & 0x1) -pos += 1 -return ~word +return self._real_depth_buffer[n] @jit.unroll_safe def setword(self, n, word): -pos = n * NATIVE_DEPTH +self._real_depth_buffer[n] = word +pos = n * NATIVE_DEPTH * 4 mask = r_uint(1) mask <<= 31 for i in xrange(32): bit = mask & word -pixel = r_uint((0x00ff * (bit == 0)) | r_uint(0xff00)) -self.pixelbuffer[pos] = pixel +self.pixelbuffer[pos] = rffi.r_uchar(0xff * (bit == 0)) +self.pixelbuffer[pos + 1] = rffi.r_uchar(0xff * (bit == 0)) +self.pixelbuffer[pos + 2] = rffi.r_uchar(0xff * (bit == 0)) +self.pixelbuffer[pos + 3] = rffi.r_uchar(0xff) mask >>= 1 -pos += 1 +pos += 4 # XXX Shouldn't compiledmethod have class reference for subclassed compiled diff --git a/spyvm/objspace.py b/spyvm/objspace.py --- a/spyvm/objspace.py +++ b/spyvm/objspace.py @@ -1,5 +1,6 @@ from spyvm import constants, model, shadow, wrapper from spyvm.error import UnwrappingError, WrappingError, PrimitiveFailedError +from rpython.rlib import jit from rpython.rlib.objectmodel import instantiate, specialize from rpython.rlib.rarithmetic import intmask, r_uint, int_between diff --git a/spyvm/primitives.py b/spyvm/primitives.py --- a/spyvm/primitives.py +++ b/spyvm/primitives.py @@ -592,15 +592,18 @@ w_prev_bitmap = w_prev_display.fetch(interp.space, 0) if isinstance(w_prev_bitmap, model.W_DisplayBitmap): sdldisplay = w_prev_bitmap.display +sdldisplay.set_video_mode(width, height, depth) if isinstance(w_bitmap, model.W_DisplayBitmap): assert (sdldisplay is None) or (sdldisplay is w_bitmap.display) sdldisplay = w_bitmap.display +sdldisplay.set_video_mode(width, height, depth) w_display_bitmap = w_bitmap else: assert isinstance(w_bitmap, mo
[pypy-commit] lang-smalltalk default: some small optimizations to the blitting algorithm
Author: Lars Wassermann Branch: Changeset: r256:a6652f5187c9 Date: 2013-04-11 15:05 +0200 http://bitbucket.org/pypy/lang-smalltalk/changeset/a6652f5187c9/ Log:some small optimizations to the blitting algorithm diff --git a/BitBltSim.19.cs b/BitBltSim.19.cs --- a/BitBltSim.19.cs +++ b/BitBltSim.19.cs @@ -119,47 +119,37 @@ !BitBlt methodsFor: 'simulation' stamp: 'tfel 3/17/2013 16:17'! copyLoop - | prevWord thisWord skewWord mergeMask - halftoneWord mergeWord | - 1 to: simH do: "here is the vertical loop" + | prevWord thisWord skewWord mergeMask halftoneWord mergeWord noSimSkewMask | + noSimSkewMask _ simSkewMask bitInvert32. + 1 to: simH do: [:i | - (halftoneForm notNil) - ifTrue: - "XXX Accessing simHalftoneBits with wrap-around ... different from BlueBook" - [halftoneWord _ simHalftoneBits at: (1 + (simDy \\ simHalftoneBits size)). + halftoneForm notNil + ifTrue: + [halftoneWord _ simHalftoneBits at: 1 + (simDy \\ simHalftoneBits size). simDy _ simDy + simVDir] ifFalse: [halftoneWord _ AllOnes]. skewWord _ halftoneWord. simPreload - ifTrue: [prevWord _ simSourceBits at: simSourceIndex + 1. - "load the 32bit shifter. TODO: check if this is WordSize dependent" - simSourceIndex _ simSourceIndex + simHDir] + ifTrue: + [prevWord _ simSourceBits at: simSourceIndex + 1. + simSourceIndex _ simSourceIndex + simHDir] ifFalse: [prevWord _ 0]. mergeMask _ simMask1. - 1 to: simNWords do: "here is the inner horizontal loop" - [:word | - sourceForm notNil "if source is used" - ifTrue: - [prevWord _ prevWord bitAnd: simSkewMask. - "XXX: Hack to work around out-of-bounds access" - thisWord := (simSourceIndex < 0 or: [simSourceIndex >= simSourceBits size]) - ifTrue: [simSourceBits at: 1] - ifFalse: [simSourceBits at: simSourceIndex + 1]. - "pick up next word" - skewWord _ - prevWord bitOr: (thisWord bitAnd: simSkewMask bitInvert32). - prevWord _ thisWord. - "Change from BB: bitAnd: AllOnes to stay in word bounds" - skewWord _ ((skewWord bitShift: simSkew) bitAnd: AllOnes) bitOr: - (skewWord bitShift: simSkew - WordSize)]. - "WordSize-bit rotate" - mergeWord _ self merge: (skewWord bitAnd: halftoneWord) - with: (simDestBits at: simDestIndex + 1). - simDestBits - at: simDestIndex + 1 - put: ((mergeMask bitAnd: mergeWord) - bitOr: (mergeMask bitInvert32 - bitAnd: (simDestBits at: simDestIndex + 1))). + 1 to: simNWords do: + [:word | + sourceForm notNil + ifTrue: + [thisWord _ (simSourceIndex <= 0 or: [simSourceIndex >= simSourceBits size]) + ifTrue: [simSourceBits at: 1] + ifFalse: [simSourceBits at: simSourceIndex + 1]. + prevWord _ (prevWord bitAnd: simSkewMask) bitShift: simSkew. + skewWord _ prevWord bitOr: ((thisWord bitAnd: noSimSkewMask) bitShift: simSkew - WordSize). + prevWord _ thisWord]. + halftoneForm notNil + ifTrue: [mergeWord _ self merge: (skewWord bitAnd: halftoneWord) + with: (simDestBits at: simDestIndex + 1)]. +
[pypy-commit] lang-smalltalk default: added primitive 19 which fails, except when (probably) calling the debugger. Then it quits gracefully.
Author: Lars Wassermann Branch: Changeset: r252:975a2cd34dda Date: 2013-04-10 21:28 +0200 http://bitbucket.org/pypy/lang-smalltalk/changeset/975a2cd34dda/ Log:added primitive 19 which fails, except when (probably) calling the debugger. Then it quits gracefully. diff --git a/spyvm/primitives.py b/spyvm/primitives.py --- a/spyvm/primitives.py +++ b/spyvm/primitives.py @@ -321,6 +321,14 @@ FAIL = 19 +@expose_primitive(FAIL) +def func(interp, s_frame, argcount): +from spyvm.interpreter import ReturnFromTopLevel +if s_frame.w_method()._likely_methodname == 'doesNotUnderstand:': +print 'Probably Debugger called...' +raise ReturnFromTopLevel(interp.space.wrap_string("debugger called")) +raise PrimitiveFailedError() + # ___ # Subscript and Stream Primitives ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] lang-smalltalk default: (cfbolz, lwassermann): prepared a typetest for s_class field
Author: Lars Wassermann Branch: Changeset: r254:db4538a2badf Date: 2013-04-11 15:03 +0200 http://bitbucket.org/pypy/lang-smalltalk/changeset/db4538a2badf/ Log:(cfbolz, lwassermann): prepared a typetest for s_class field diff --git a/spyvm/model.py b/spyvm/model.py --- a/spyvm/model.py +++ b/spyvm/model.py @@ -17,7 +17,7 @@ import sys from spyvm import constants, error -from rpython.rlib import rrandom, objectmodel, jit +from rpython.rlib import rrandom, objectmodel, jit, signature from rpython.rlib.rarithmetic import intmask, r_uint from rpython.tool.pairtype import extendabletype from rpython.rlib.objectmodel import instantiate, compute_hash @@ -373,7 +373,7 @@ def size(self): return 2 - +@signature.finishsigs class W_AbstractObjectWithClassReference(W_AbstractObjectWithIdentityHash): """Objects with arbitrary class (ie not CompiledMethod, SmallInteger or Float).""" @@ -422,9 +422,13 @@ def has_class(self): return self.s_class is not None +# we would like the following, but that leads to a recursive import +#@signature(signature.types.self(), signature.type.any(), +# returns=signature.types.instance(ClassShadow)) def shadow_of_my_class(self, space): -assert self.s_class is not None -return self.s_class +s_class = self.s_class +assert s_class is not None +return s_class class W_PointersObject(W_AbstractObjectWithClassReference): """Common object.""" @@ -525,10 +529,13 @@ # Should only be used during squeak-image loading. def as_class_get_penumbra(self, space): from spyvm.shadow import ClassShadow -assert self._shadow is None or isinstance(self._shadow, ClassShadow) -if self._shadow is None: -self.store_shadow(ClassShadow(space, self)) -return self._shadow +s_class = self._shadow +if s_class is None: +s_class = ClassShadow(space, self) +self.store_shadow(s_class) +else: +assert isinstance(s_class, ClassShadow) +return s_class def as_blockcontext_get_shadow(self, space): from spyvm.shadow import BlockContextShadow ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] lang-smalltalk default: (cfbolz, lwassermann): implemented unwrap_uint using polymorphism to get rid of loop and extensive branches
Author: Lars Wassermann Branch: Changeset: r255:8f0af90c962e Date: 2013-04-11 15:04 +0200 http://bitbucket.org/pypy/lang-smalltalk/changeset/8f0af90c962e/ Log:(cfbolz, lwassermann): implemented unwrap_uint using polymorphism to get rid of loop and extensive branches diff --git a/spyvm/model.py b/spyvm/model.py --- a/spyvm/model.py +++ b/spyvm/model.py @@ -127,6 +127,9 @@ def rshift(self, space, shift): raise error.PrimitiveFailedError() +def unwrap_uint(self, space): +raise error.UnwrappingError("Got unexpected class in unwrap_uint") + class W_SmallInteger(W_Object): """Boxed integer value""" # TODO can we tell pypy that its never larger then 31-bit? @@ -165,6 +168,14 @@ def rshift(self, space, shift): return space.wrap_int(self.value >> shift) +def unwrap_uint(self, space): +from rpython.rlib.rarithmetic import r_uint +val = self.value +if val < 0: +raise error.UnwrappingError("got negative integer") +return r_uint(val) + + @jit.elidable def as_repr_string(self): return "W_SmallInteger(%d)" % self.value @@ -262,6 +273,10 @@ # and only in this case we do need such a mask return space.wrap_int((self.value >> shift) & mask) +def unwrap_uint(self, space): +from rpython.rlib.rarithmetic import r_uint +return r_uint(self.value) + def clone(self, space): return W_LargePositiveInteger1Word(self.value) @@ -651,6 +666,16 @@ w_result.bytes = list(self.bytes) return w_result +def unwrap_uint(self, space): +# TODO: Completely untested! This failed translation bigtime... +# XXX Probably we want to allow all subclasses +if not self.getclass(space).is_same_object(space.w_LargePositiveInteger): +raise error.UnwrappingError("Failed to convert bytes to word") +word = 0 +for i in range(self.size()): +word += r_uint(ord(self.getchar(i))) << 8*i +return word + class W_WordsObject(W_AbstractObjectWithClassReference): _attrs_ = ['words'] diff --git a/spyvm/objspace.py b/spyvm/objspace.py --- a/spyvm/objspace.py +++ b/spyvm/objspace.py @@ -251,24 +251,7 @@ raise UnwrappingError("expected a W_SmallInteger or W_LargePositiveInteger1Word, got %s" % (w_value,)) def unwrap_uint(self, w_value): -if isinstance(w_value, model.W_SmallInteger): -val = w_value.value -if val < 0: -raise UnwrappingError("got negative integer") -return r_uint(w_value.value) -elif isinstance(w_value, model.W_LargePositiveInteger1Word): -return r_uint(w_value.value) -elif isinstance(w_value, model.W_BytesObject): -# TODO: Completely untested! This failed translation bigtime... -# XXX Probably we want to allow all subclasses -if not w_value.getclass(self).is_same_object(self.w_LargePositiveInteger): -raise UnwrappingError("Failed to convert bytes to word") -word = 0 -for i in range(w_value.size()): -word += r_uint(ord(w_value.getchar(i))) << 8*i -return word -else: -raise UnwrappingError("Got unexpected class in unwrap_uint") +return w_value.unwrap_uint(self) def unwrap_positive_32bit_int(self, w_value): if isinstance(w_value, model.W_SmallInteger): ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] lang-smalltalk default: added type hints for instance variables of non-varsized pointers objects
Author: Lars Wassermann Branch: Changeset: r257:720555f9465b Date: 2013-04-11 20:36 +0200 http://bitbucket.org/pypy/lang-smalltalk/changeset/720555f9465b/ Log:added type hints for instance variables of non-varsized pointers objects diff --git a/spyvm/fieldtypes.py b/spyvm/fieldtypes.py new file mode 100644 --- /dev/null +++ b/spyvm/fieldtypes.py @@ -0,0 +1,133 @@ +from spyvm import model, shadow + +from rpython.rlib import jit, signature + +LPI = object() +int +float + +object + +maps = dict() + +class VarSizedFieldTypes(): +_immutable_fields_ = [] +_attrs_ = [] +_settled_ = True + +@staticmethod +def of_length(s_class, n): +return nilTyper + +def __init__(self): +pass + +def fetch(self, w_obj, n0): +return w_obj._vars[n0] + +def store(self, w_obj, n0, w_val): +w_obj._vars[n0] = w_val + +class FieldTypes(VarSizedFieldTypes): +_immutable_fields_ = ['types'] +_attrs_ = ['types', 'parent', 'siblings', 'diff'] +_settled_ = True + +def __init__(self, types, parent=None, change=(-1, object)): +self.types = types +self.parent = parent +if parent is not None: +assert change != (-1, object) +self.diff = change + +self.siblings = dict() + +def fetch(self, w_object, n0): +w_result = w_object._vars[n0] +types = self.types +if types[n0] is int: +jit.record_known_class(w_result, model.W_SmallInteger) +elif types[n0] is LPI: +jit.record_known_class(w_result, model.W_LargePositiveInteger1Word) +elif types[n0] is float: +jit.record_known_class(w_result, model.W_Float) +return w_result + +def store(self, w_object, n0, w_value): +types = self.types +changed_type = w_value.fieldtype() +if types[n0] is not changed_type: +w_object.fieldtypes = self.sibling(n0, changed_type) +w_object._vars[n0] = w_value + + +def sibling(self, n0, changed_type): +assert self.types[n0] is not changed_type +change = (n0, changed_type) +parent = self.parent +siblings = self.siblings +if change in siblings: +return siblings[change] +elif parent is None: +return self.descent([change]) +else: +new_fieldtype = parent.ascent([change, self.diff]) +assert new_fieldtype.types == self.types[0:n0] + [changed_type] + self.types[n0+1:] +siblings[change] = new_fieldtype +return new_fieldtype + +def ascent(self, changes): +parent = self.parent +if parent is None: +return self.descent(sorted(changes)) +else: +change = self.diff +if changes[0][0] != change[0]: +changes.append(change) +return parent.ascent(changes) + +def descent(self, changes): +if changes == []: +return self + +change = changes[0] +siblings = self.siblings +if change in siblings: +return siblings[change].descent(changes[1:]) +else: +new_types = list(self.types) +new_types[change[0]] = change[1] +new_fieldtype = FieldTypes(new_types, self, change) +siblings[change] = new_fieldtype +return new_fieldtype.descent(changes[1:]) + + +@staticmethod +def of_length(n): +if n not in maps: +maps[n] = FieldTypes([object] * n) +return maps[n] + + +nilTyper = VarSizedFieldTypes() +def fieldtypes_of_length(s_class, size): +if s_class is None or s_class.isvariable(): +return nilTyper +else: +return FieldTypes.of_length(size) + +def fieldtypes_of(w_obj): +try: +if w_obj.s_class.isvariable(): +return nilTyper +else: +vars = w_obj._vars +size = len(vars) +typer = FieldTypes.of_length(size) +for i, w_val in enumerate(vars): +changed_type = w_val.fieldtype() +if changed_type is not object: +typer = typer.sibling(i, changed_type) +return typer +except AttributeError: +return nilTyper \ No newline at end of file diff --git a/spyvm/model.py b/spyvm/model.py --- a/spyvm/model.py +++ b/spyvm/model.py @@ -130,6 +130,9 @@ def unwrap_uint(self, space): raise error.UnwrappingError("Got unexpected class in unwrap_uint") +def fieldtype(self): +return object + class W_SmallInteger(W_Object): """Boxed integer value""" # TODO can we tell pypy that its never larger then 31-bit? @@ -200,6 +203,9 @@ def clone(self, space): return self +def fieldtype(self): +return int + class W_AbstractObjectWithIdentityHash(W_Object): """Object with explicit hash (ie all except small ints and floats).""" @@ -303,6 +309,10 @@ def inv
[pypy-commit] lang-smalltalk default: added fieldtypes tests for testing correctnes of neighbour finding
Author: Lars Wassermann Branch: Changeset: r258:4d577f6b6b0c Date: 2013-04-11 22:25 +0200 http://bitbucket.org/pypy/lang-smalltalk/changeset/4d577f6b6b0c/ Log:added fieldtypes tests for testing correctnes of neighbour finding changed fieldtypes tags to enable translating added quicksort implementation for changes sorting diff --git a/spyvm/fieldtypes.py b/spyvm/fieldtypes.py --- a/spyvm/fieldtypes.py +++ b/spyvm/fieldtypes.py @@ -1,14 +1,16 @@ from spyvm import model, shadow -from rpython.rlib import jit, signature +from rpython.rlib import objectmodel, jit, signature -LPI = object() -int -float +class TypeTag(): +pass -object +LPI = TypeTag() +SInt = TypeTag() +flt = TypeTag() +obj = TypeTag() -maps = dict() +maps = {} class VarSizedFieldTypes(): _immutable_fields_ = [] @@ -33,23 +35,24 @@ _attrs_ = ['types', 'parent', 'siblings', 'diff'] _settled_ = True -def __init__(self, types, parent=None, change=(-1, object)): +def __init__(self, types, parent=None, change=(-1, obj)): self.types = types self.parent = parent if parent is not None: -assert change != (-1, object) +assert change != (-1, obj) self.diff = change -self.siblings = dict() +self.siblings = {} def fetch(self, w_object, n0): w_result = w_object._vars[n0] +assert w_result is not None types = self.types -if types[n0] is int: +if types[n0] is SInt: jit.record_known_class(w_result, model.W_SmallInteger) elif types[n0] is LPI: jit.record_known_class(w_result, model.W_LargePositiveInteger1Word) -elif types[n0] is float: +elif types[n0] is flt: jit.record_known_class(w_result, model.W_Float) return w_result @@ -72,14 +75,16 @@ return self.descent([change]) else: new_fieldtype = parent.ascent([change, self.diff]) -assert new_fieldtype.types == self.types[0:n0] + [changed_type] + self.types[n0+1:] +if not objectmodel.we_are_translated(): +assert new_fieldtype.types == self.types[0:n0] + [changed_type] + self.types[n0+1:] siblings[change] = new_fieldtype return new_fieldtype def ascent(self, changes): parent = self.parent if parent is None: -return self.descent(sorted(changes)) +sort(changes) +return self.descent(changes) else: change = self.diff if changes[0][0] != change[0]: @@ -105,7 +110,7 @@ @staticmethod def of_length(n): if n not in maps: -maps[n] = FieldTypes([object] * n) +maps[n] = FieldTypes([obj] * n) return maps[n] @@ -126,8 +131,37 @@ typer = FieldTypes.of_length(size) for i, w_val in enumerate(vars): changed_type = w_val.fieldtype() -if changed_type is not object: +if changed_type is not obj: typer = typer.sibling(i, changed_type) return typer except AttributeError: -return nilTyper \ No newline at end of file +return nilTyper + +def sort(an_array): +end = len(an_array) - 1 +sort_quick_inplace(an_array, 0, end) + + +def sort_quick_inplace(an_array, start, end): +assert start >= 0 and end < len(an_array) + +def partition(an_array, start, end): +key = an_array[start][0] +i = start - 1 +j = end + 1 +while True: +i += 1 +j -= 1 +while not an_array[j][0] <= key: +j -= 1 +while not an_array[i][0] >= key: +i += 1 +if j <= i: +return j +else: +an_array[i], an_array[j] = an_array[j], an_array[i] + +if start < end: +mid = partition(an_array, start, end) +sort_quick_inplace(an_array, start, mid) +sort_quick_inplace(an_array, mid + 1, end) \ No newline at end of file diff --git a/spyvm/model.py b/spyvm/model.py --- a/spyvm/model.py +++ b/spyvm/model.py @@ -131,7 +131,8 @@ raise error.UnwrappingError("Got unexpected class in unwrap_uint") def fieldtype(self): -return object +from spyvm.fieldtypes import obj +return obj class W_SmallInteger(W_Object): """Boxed integer value""" @@ -204,7 +205,8 @@ return self def fieldtype(self): -return int +from spyvm.fieldtypes import SInt +return SInt class W_AbstractObjectWithIdentityHash(W_Object): """Object with explicit hash (ie all except small @@ -310,7 +312,7 @@ return isinstance(self.value, int) def fieldtype(self): -from spyvm.fieldtype import LPI +from spyvm.fieldtypes import LPI return LPI class W_Float(W_AbstractObjectWi
[pypy-commit] pypy default: move assert for clarity
Author: Brian Kearns Branch: Changeset: r63252:613641427033 Date: 2013-04-11 18:13 -0400 http://bitbucket.org/pypy/pypy/changeset/613641427033/ Log:move assert for clarity diff --git a/rpython/rtyper/rlist.py b/rpython/rtyper/rlist.py --- a/rpython/rtyper/rlist.py +++ b/rpython/rtyper/rlist.py @@ -950,9 +950,9 @@ count = l2.ll_length() ll_assert(start >= 0, "l[start:x] = l with unexpectedly negative start") ll_assert(start <= l1.ll_length(), "l[start:x] = l with start > len(l)") +ll_assert(stop <= l1.ll_length(), "stop cannot be past the end of l1") ll_assert(count == stop - start, "setslice cannot resize lists in RPython") -ll_assert(stop <= l1.ll_length(), "stop cannot be past the end of l1") # XXX ...but it would be easy enough to support if really needed ll_arraycopy(l2, l1, 0, start, count) ll_listsetslice.oopspec = 'list.setslice(l1, start, stop, l2)' ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3k: Fixes applevel tests to pass with -A.
Author: Amaury Forgeot d'Arc Branch: py3k Changeset: r63254:24d0665f1432 Date: 2013-04-12 00:20 +0200 http://bitbucket.org/pypy/pypy/changeset/24d0665f1432/ Log:Fixes applevel tests to pass with -A. diff --git a/pypy/objspace/std/test/test_index.py b/pypy/objspace/std/test/test_index.py --- a/pypy/objspace/std/test/test_index.py +++ b/pypy/objspace/std/test/test_index.py @@ -1,44 +1,35 @@ from py.test import raises class AppTest_IndexProtocol: -def setup_class(self): -w_oldstyle = self.space.appexec([], """(): +def setup_class(cls): +cls.w_o = cls.space.appexec([], """(): class oldstyle: def __index__(self): return self.ind -return oldstyle""") +return oldstyle()""") -w_newstyle = self.space.appexec([], """(): +cls.w_n = cls.space.appexec([], """(): class newstyle(object): def __index__(self): return self.ind -return newstyle""") +return newstyle()""") -w_oldstyle_no_index = self.space.appexec([], """(): +cls.w_o_no_index = cls.space.appexec([], """(): class oldstyle_no_index: pass -return oldstyle_no_index""") +return oldstyle_no_index()""") -w_newstyle_no_index = self.space.appexec([], """(): +cls.w_n_no_index = cls.space.appexec([], """(): class newstyle_no_index(object): pass -return newstyle_no_index""") +return newstyle_no_index()""") -w_TrapInt = self.space.appexec([], """(): +cls.w_TrapInt = cls.space.appexec([], """(): class TrapInt(int): def __index__(self): return self return TrapInt""") -self.w_oldstyle = w_oldstyle -self.w_o = self.space.call_function(w_oldstyle) -self.w_o_no_index = self.space.call_function(w_oldstyle_no_index) -self.w_newstyle = w_newstyle -self.w_n = self.space.call_function(w_newstyle) -self.w_n_no_index = self.space.call_function(w_newstyle_no_index) - -self.w_TrapInt = w_TrapInt - def test_basic(self): self.o.ind = -2 self.n.ind = 2 @@ -92,31 +83,26 @@ # This test case isn't run directly. It just defines common tests # to the different sequence types below def setup_method(self, method): -w_oldstyle = self.space.appexec([], """(): -class oldstyle: -def __index__(self): -return self.ind -return oldstyle""") +for name in ('w_o', 'w_o2'): +setattr(self, name, self.space.appexec([], """(): +class oldstyle: +def __index__(self): +return self.ind +return oldstyle()""")) -w_newstyle = self.space.appexec([], """(): -class newstyle(object): -def __index__(self): -return self.ind -return newstyle""") +for name in ('w_n', 'w_n2'): +setattr(self, name, self.space.appexec([], """(): +class newstyle(object): +def __index__(self): +return self.ind +return newstyle()""")) -w_TrapInt = self.space.appexec([], """(): +self.w_TrapInt = self.space.appexec([], """(): class TrapInt(int): def __index__(self): return self return TrapInt""") -self.w_o = self.space.call_function(w_oldstyle) -self.w_n = self.space.call_function(w_newstyle) -self.w_o2 = self.space.call_function(w_oldstyle) -self.w_n2 = self.space.call_function(w_newstyle) - -self.w_TrapInt = w_TrapInt - def test_index(self): self.o.ind = -2 self.n.ind = 2 @@ -204,6 +190,7 @@ SeqTestCase.setup_method(self, method) self.w_seq = self.space.newtuple([self.space.wrap(x) for x in (0,10,20,30,40,50)]) + class StringTestCase(object): def test_startswith(self): self.o.ind = 1 @@ -257,9 +244,9 @@ class AppTest_OverflowTestCase: -def setup_class(self): -self.w_pos = self.space.wrap(2**100) -self.w_neg = self.space.wrap(-2**100) +def setup_class(cls): +cls.w_pos = cls.space.wrap(2**100) +cls.w_neg = cls.space.wrap(-2**100) def test_large_longs(self): assert self.pos.__index__() == self.pos diff --git a/pypy/objspace/std/test/test_newformat.py b/pypy/objspace/std/test/test_newformat.py --- a/pypy/objspace/std/test/test_newformat.py +++ b/pypy/objspace/std/test/test_newformat.py @@ -175,7 +175,8 @@ class AppTestUnicodeFormat(BaseStringFormatTests): def setup_class(cls): -cls.w_s = cls.space.w_unicode +cls.w_s = cls.space.appexec( +
[pypy-commit] pypy sqlite-cffi: close merged branch
Author: Brian Kearns Branch: sqlite-cffi Changeset: r63253:783ea6d7ecbf Date: 2013-04-11 18:20 -0400 http://bitbucket.org/pypy/pypy/changeset/783ea6d7ecbf/ Log:close merged branch ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: test and fix for BytesIO.write() return value
Author: Brian Kearns Branch: Changeset: r63256:5fadf0b41675 Date: 2013-04-11 19:52 -0400 http://bitbucket.org/pypy/pypy/changeset/5fadf0b41675/ Log:test and fix for BytesIO.write() return value diff --git a/pypy/module/_io/interp_bytesio.py b/pypy/module/_io/interp_bytesio.py --- a/pypy/module/_io/interp_bytesio.py +++ b/pypy/module/_io/interp_bytesio.py @@ -96,7 +96,7 @@ buf = space.buffer_w(w_data) length = buf.getlength() if length <= 0: -return +return space.wrap(0) if self.pos + length > len(self.buf): self.buf.extend(['\0'] * (self.pos + length - len(self.buf))) diff --git a/pypy/module/_io/test/test_bytesio.py b/pypy/module/_io/test/test_bytesio.py --- a/pypy/module/_io/test/test_bytesio.py +++ b/pypy/module/_io/test/test_bytesio.py @@ -24,6 +24,7 @@ def test_write(self): import _io f = _io.BytesIO() +assert f.write("") == 0 assert f.write("hello") == 5 import gc; gc.collect() assert f.getvalue() == "hello" ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: test BytesIO.readinto()
Author: Brian Kearns Branch: Changeset: r63257:62db528827f5 Date: 2013-04-11 19:55 -0400 http://bitbucket.org/pypy/pypy/changeset/62db528827f5/ Log:test BytesIO.readinto() diff --git a/pypy/module/_io/test/test_bytesio.py b/pypy/module/_io/test/test_bytesio.py --- a/pypy/module/_io/test/test_bytesio.py +++ b/pypy/module/_io/test/test_bytesio.py @@ -74,7 +74,10 @@ import _io b = _io.BytesIO("hello") +a = bytearray('testing') +assert b.readinto(a) == 5 b.close() +assert a == "hellong" raises(ValueError, b.readinto, bytearray("hello")) def test_readline(self): ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] benchmarks default: fix --niceness 0
Author: Brian Kearns Branch: Changeset: r204:5c09140d7755 Date: 2013-04-11 23:45 -0400 http://bitbucket.org/pypy/benchmarks/changeset/5c09140d7755/ Log:fix --niceness 0 diff --git a/runner.py b/runner.py --- a/runner.py +++ b/runner.py @@ -274,7 +274,7 @@ revision = options.upload_revision force_host = options.force_host -if options.niceness: +if options.niceness is not None: os.nice(options.niceness - os.nice(0)) results = run_and_store(benchmarks, output_filename, changed_path, ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] buildbot default: just remove niceness until sysadmin can get limits.conf working
Author: Brian Kearns Branch: Changeset: r779:fc24b0bbf3dd Date: 2013-04-11 23:46 -0400 http://bitbucket.org/pypy/buildbot/changeset/fc24b0bbf3dd/ Log:just remove niceness until sysadmin can get limits.conf working diff --git a/bot2/pypybuildbot/builds.py b/bot2/pypybuildbot/builds.py --- a/bot2/pypybuildbot/builds.py +++ b/bot2/pypybuildbot/builds.py @@ -567,7 +567,6 @@ locks=[lock.access('exclusive')], description="run benchmarks on top of pypy-c", command=["python", "runner.py", '--output-filename', 'result.json', - '--niceness', '0', # can't get limits.conf to allow -10 '--changed', pypy_c_rel, '--baseline', pypy_c_rel, '--args', ',--jit off', ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: test and fix for StringIO.readline(None)
Author: Brian Kearns Branch: Changeset: r63258:63d556a4cffc Date: 2013-04-12 00:37 -0400 http://bitbucket.org/pypy/pypy/changeset/63d556a4cffc/ Log:test and fix for StringIO.readline(None) diff --git a/pypy/module/_io/interp_stringio.py b/pypy/module/_io/interp_stringio.py --- a/pypy/module/_io/interp_stringio.py +++ b/pypy/module/_io/interp_stringio.py @@ -169,9 +169,9 @@ self.pos = end return space.wrap(u''.join(self.buf[start:end])) -@unwrap_spec(limit=int) -def readline_w(self, space, limit=-1): +def readline_w(self, space, w_limit=None): self._check_closed(space) +limit = convert_size(space, w_limit) if self.pos >= len(self.buf): return space.wrap(u"") diff --git a/pypy/module/_io/test/test_stringio.py b/pypy/module/_io/test/test_stringio.py --- a/pypy/module/_io/test/test_stringio.py +++ b/pypy/module/_io/test/test_stringio.py @@ -32,7 +32,7 @@ raises(ValueError, sio.read, 1) raises(ValueError, sio.write, u"text") -def testRead(self): +def test_read(self): import io buf = u"1234567890" sio = io.StringIO(buf) @@ -42,6 +42,13 @@ assert buf[5:] == sio.read(900) assert u"" == sio.read() +def test_readline(self): +import io +sio = io.StringIO(u'123\n456') +assert sio.readline(2) == '12' +assert sio.readline(None) == '3\n' +assert sio.readline() == '456' + def test_seek(self): import io ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: just set pos directly here instead of calling seek
Author: Brian Kearns Branch: Changeset: r63259:a3aa1bdf3048 Date: 2013-04-11 23:16 -0400 http://bitbucket.org/pypy/pypy/changeset/a3aa1bdf3048/ Log:just set pos directly here instead of calling seek diff --git a/rpython/rlib/rStringIO.py b/rpython/rlib/rStringIO.py --- a/rpython/rlib/rStringIO.py +++ b/rpython/rlib/rStringIO.py @@ -156,7 +156,7 @@ i += 1 if finished: break -self.seek(i) +self.pos = i return ''.join(self.bigbuffer[p:i]) def truncate(self, size): ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: change BytesIO to use RStringIO
Author: Brian Kearns Branch: Changeset: r63261:4da612f571cc Date: 2013-04-12 01:08 -0400 http://bitbucket.org/pypy/pypy/changeset/4da612f571cc/ Log:change BytesIO to use RStringIO diff --git a/pypy/module/_io/interp_bytesio.py b/pypy/module/_io/interp_bytesio.py --- a/pypy/module/_io/interp_bytesio.py +++ b/pypy/module/_io/interp_bytesio.py @@ -2,37 +2,25 @@ TypeDef, generic_new_descr, GetSetProperty) from pypy.interpreter.gateway import interp2app, unwrap_spec from pypy.interpreter.error import OperationError, operationerrfmt +from rpython.rlib.rStringIO import RStringIO from rpython.rlib.rarithmetic import r_longlong from pypy.module._io.interp_bufferedio import W_BufferedIOBase from pypy.module._io.interp_iobase import convert_size import sys -def buffer2string(buffer, start, end): -from rpython.rlib.rstring import StringBuilder -builder = StringBuilder(end - start) -for i in range(start, end): -builder.append(buffer[i]) -return builder.build() -class W_BytesIO(W_BufferedIOBase): +class W_BytesIO(RStringIO, W_BufferedIOBase): def __init__(self, space): W_BufferedIOBase.__init__(self, space) -self.pos = 0 -self.string_size = 0 -self.buf = None +RStringIO.__init__(self) def descr_init(self, space, w_initial_bytes=None): -# In case __init__ is called multiple times -self.buf = [] -self.string_size = 0 -self.pos = 0 - if not space.is_none(w_initial_bytes): self.write_w(space, w_initial_bytes) -self.pos = 0 +self.seek(0) def _check_closed(self, space, message=None): -if self.buf is None: +if self.is_closed(): if message is None: message = "I/O operation on closed file" raise OperationError(space.w_ValueError, space.wrap(message)) @@ -40,36 +28,12 @@ def read_w(self, space, w_size=None): self._check_closed(space) size = convert_size(space, w_size) - -# adjust invalid sizes -available = self.string_size - self.pos -if not 0 <= size <= available: -size = available -if size < 0: -size = 0 - -output = buffer2string(self.buf, self.pos, self.pos + size) -self.pos += size -return space.wrap(output) +return space.wrap(self.read(size)) def readline_w(self, space, w_limit=None): self._check_closed(space) limit = convert_size(space, w_limit) - -cur_pos = self.pos -if limit < 0: -end_pos = self.string_size -else: -end_pos = min(cur_pos + limit, self.string_size) -while cur_pos != end_pos: -if self.buf[cur_pos] == '\n': -cur_pos += 1 -break -cur_pos += 1 - -output = buffer2string(self.buf, self.pos, cur_pos) -self.pos = cur_pos -return space.wrap(output) +return space.wrap(self.readline(limit)) def read1_w(self, space, w_size): return self.read_w(space, w_size) @@ -79,56 +43,27 @@ rwbuffer = space.rwbuffer_w(w_buffer) size = rwbuffer.getlength() -if self.pos + size > self.string_size: -size = self.string_size - self.pos - -output = buffer2string(self.buf, self.pos, self.pos + size) -length = len(output) +output = self.read(size) rwbuffer.setslice(0, output) -self.pos += length -return space.wrap(length) +return space.wrap(len(output)) def write_w(self, space, w_data): self._check_closed(space) if space.isinstance_w(w_data, space.w_unicode): raise OperationError(space.w_TypeError, space.wrap( "bytes string of buffer expected")) -buf = space.buffer_w(w_data) -length = buf.getlength() +buf = space.bufferstr_w(w_data) +length = len(buf) if length <= 0: return space.wrap(0) - -if self.pos + length > len(self.buf): -self.buf.extend(['\0'] * (self.pos + length - len(self.buf))) - -if self.pos > self.string_size: -# In case of overseek, pad with null bytes the buffer region -# between the end of stream and the current position. -# -# 0 lo string_size hi -# | |<---used--->|<--available--->| -# | |<--to pad-->|<---to write--->| -# 0 buf position -for i in range(self.string_size, self.pos): -self.buf[i] = '\0' - -# Copy the data to the internal buffer, overwriting some of the -# existing data if self->pos < self->string_size. -for i in range(length): -self.buf[self.pos + i] = buf.getitem(i) -self.pos += length - -# S
[pypy-commit] pypy default: improve BytesIO.readinto() test
Author: Brian Kearns Branch: Changeset: r63260:9c7ae3bdbde7 Date: 2013-04-12 01:17 -0400 http://bitbucket.org/pypy/pypy/changeset/9c7ae3bdbde7/ Log:improve BytesIO.readinto() test diff --git a/pypy/module/_io/test/test_bytesio.py b/pypy/module/_io/test/test_bytesio.py --- a/pypy/module/_io/test/test_bytesio.py +++ b/pypy/module/_io/test/test_bytesio.py @@ -74,10 +74,13 @@ import _io b = _io.BytesIO("hello") -a = bytearray('testing') -assert b.readinto(a) == 5 +a1 = bytearray('t') +a2 = bytearray('testing') +assert b.readinto(a1) == 1 +assert b.readinto(a2) == 4 b.close() -assert a == "hellong" +assert a1 == "h" +assert a2 == "elloing" raises(ValueError, b.readinto, bytearray("hello")) def test_readline(self): ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: mangle RStringIO attr names so they don't clash with implementations
Author: Brian Kearns Branch: Changeset: r63262:1a0242a40bd1 Date: 2013-04-11 21:52 -0400 http://bitbucket.org/pypy/pypy/changeset/1a0242a40bd1/ Log:mangle RStringIO attr names so they don't clash with implementations diff --git a/rpython/rlib/rStringIO.py b/rpython/rlib/rStringIO.py --- a/rpython/rlib/rStringIO.py +++ b/rpython/rlib/rStringIO.py @@ -12,166 +12,166 @@ def __init__(self): # The real content is the join of the following data: -# * the list of characters self.bigbuffer; -# * each of the strings in self.strings. +# * the list of characters self.__bigbuffer; +# * each of the strings in self.__strings. # -self.closed = False -self.strings = None -self.bigbuffer = None -self.pos = AT_END +self.__closed = False +self.__strings = None +self.__bigbuffer = None +self.__pos = AT_END def close(self): -self.closed = True -self.strings = None -self.bigbuffer = None -self.pos = AT_END +self.__closed = True +self.__strings = None +self.__bigbuffer = None +self.__pos = AT_END def is_closed(self): -return self.closed +return self.__closed -def _copy_into_bigbuffer(self): -"""Copy all the data into the list of characters self.bigbuffer.""" -if self.bigbuffer is None: -self.bigbuffer = [] -if self.strings is not None: -self.bigbuffer += self.strings.build() -self.strings = None +def __copy_into_bigbuffer(self): +"""Copy all the data into the list of characters self.__bigbuffer.""" +if self.__bigbuffer is None: +self.__bigbuffer = [] +if self.__strings is not None: +self.__bigbuffer += self.__strings.build() +self.__strings = None def getvalue(self): -"""If self.strings contains more than 1 string, join all the +"""If self.__strings contains more than 1 string, join all the strings together. Return the final single string.""" -if self.bigbuffer is not None: -self._copy_into_bigbuffer() -return ''.join(self.bigbuffer) -if self.strings is not None: -return self.strings.build() +if self.__bigbuffer is not None: +self.__copy_into_bigbuffer() +return ''.join(self.__bigbuffer) +if self.__strings is not None: +return self.__strings.build() return '' def getsize(self): result = 0 -if self.bigbuffer is not None: -result += len(self.bigbuffer) -if self.strings is not None: -result += self.strings.getlength() +if self.__bigbuffer is not None: +result += len(self.__bigbuffer) +if self.__strings is not None: +result += self.__strings.getlength() return result def write(self, buffer): # Idea: for the common case of a sequence of write() followed -# by only getvalue(), self.bigbuffer remains empty. It is only +# by only getvalue(), self.__bigbuffer remains empty. It is only # used to handle the more complicated cases. -if self.pos == AT_END: -self._fast_write(buffer) +if self.__pos == AT_END: +self.__fast_write(buffer) else: -self._slow_write(buffer) +self.__slow_write(buffer) -def _fast_write(self, buffer): -if self.strings is None: -self.strings = StringBuilder() -self.strings.append(buffer) +def __fast_write(self, buffer): +if self.__strings is None: +self.__strings = StringBuilder() +self.__strings.append(buffer) -def _slow_write(self, buffer): -p = self.pos +def __slow_write(self, buffer): +p = self.__pos assert p >= 0 endp = p + len(buffer) -if self.bigbuffer is not None and len(self.bigbuffer) >= endp: -# semi-fast path: the write is entirely inside self.bigbuffer +if self.__bigbuffer is not None and len(self.__bigbuffer) >= endp: +# semi-fast path: the write is entirely inside self.__bigbuffer for i in range(len(buffer)): -self.bigbuffer[p + i] = buffer[i] +self.__bigbuffer[p + i] = buffer[i] else: -# slow path: collect all data into self.bigbuffer and +# slow path: collect all data into self.__bigbuffer and # handle the various cases -self._copy_into_bigbuffer() -fitting = len(self.bigbuffer) - p +self.__copy_into_bigbuffer() +fitting = len(self.__bigbuffer) - p if fitting > 0: # the write starts before the end of the data fitting = min(len(buffer), fitting) for
[pypy-commit] pypy default: fix translation
Author: Brian Kearns Branch: Changeset: r63263:7a2e0a6b013b Date: 2013-04-11 23:17 -0400 http://bitbucket.org/pypy/pypy/changeset/7a2e0a6b013b/ Log:fix translation diff --git a/pypy/module/_io/interp_bytesio.py b/pypy/module/_io/interp_bytesio.py --- a/pypy/module/_io/interp_bytesio.py +++ b/pypy/module/_io/interp_bytesio.py @@ -12,7 +12,7 @@ class W_BytesIO(RStringIO, W_BufferedIOBase): def __init__(self, space): W_BufferedIOBase.__init__(self, space) -RStringIO.__init__(self) +self.init() def descr_init(self, space, w_initial_bytes=None): if not space.is_none(w_initial_bytes): diff --git a/pypy/module/cStringIO/interp_stringio.py b/pypy/module/cStringIO/interp_stringio.py --- a/pypy/module/cStringIO/interp_stringio.py +++ b/pypy/module/cStringIO/interp_stringio.py @@ -146,7 +146,7 @@ class W_OutputType(RStringIO, W_InputOutputType): def __init__(self, space): -RStringIO.__init__(self) +self.init() self.space = space def descr_truncate(self, w_size=None): diff --git a/rpython/rlib/rStringIO.py b/rpython/rlib/rStringIO.py --- a/rpython/rlib/rStringIO.py +++ b/rpython/rlib/rStringIO.py @@ -11,6 +11,9 @@ _mixin_ = True# for interp_stringio.py def __init__(self): +self.init() + +def init(self): # The real content is the join of the following data: # * the list of characters self.__bigbuffer; # * each of the strings in self.__strings. ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: test and fix for truncate differences between cStringIO and BytesIO
Author: Brian Kearns Branch: Changeset: r63264:f2929b44b45b Date: 2013-04-12 00:58 -0400 http://bitbucket.org/pypy/pypy/changeset/f2929b44b45b/ Log:test and fix for truncate differences between cStringIO and BytesIO diff --git a/pypy/module/_io/test/test_bytesio.py b/pypy/module/_io/test/test_bytesio.py --- a/pypy/module/_io/test/test_bytesio.py +++ b/pypy/module/_io/test/test_bytesio.py @@ -52,6 +52,8 @@ f.seek(3) assert f.truncate() == 3 assert f.getvalue() == "hel" +assert f.truncate(2) == 2 +assert f.tell() == 3 def test_setstate(self): # state is (content, position, __dict__) diff --git a/pypy/module/cStringIO/interp_stringio.py b/pypy/module/cStringIO/interp_stringio.py --- a/pypy/module/cStringIO/interp_stringio.py +++ b/pypy/module/cStringIO/interp_stringio.py @@ -159,6 +159,7 @@ if size < 0: raise OperationError(space.w_IOError, space.wrap("negative size")) self.truncate(size) +self.seek(0, 2) @unwrap_spec(buffer='bufferstr') def descr_write(self, buffer): diff --git a/pypy/module/cStringIO/test/test_interp_stringio.py b/pypy/module/cStringIO/test/test_interp_stringio.py --- a/pypy/module/cStringIO/test/test_interp_stringio.py +++ b/pypy/module/cStringIO/test/test_interp_stringio.py @@ -142,8 +142,11 @@ f.write(' world') f.truncate(30) assert f.getvalue() == '\x00' * 20 + 'hello worl' +assert f.tell() == 30 +f.seek(0) f.truncate(25) assert f.getvalue() == '\x00' * 20 + 'hello' +assert f.tell() == 25 f.write('baz') f.write('egg') f.truncate(3) diff --git a/rpython/rlib/rStringIO.py b/rpython/rlib/rStringIO.py --- a/rpython/rlib/rStringIO.py +++ b/rpython/rlib/rStringIO.py @@ -163,9 +163,6 @@ return ''.join(self.__bigbuffer[p:i]) def truncate(self, size): -# NB. 'size' is mandatory. This has the same un-Posix-y semantics -# than CPython: it never grows the buffer, and it sets the current -# position to the end. assert size >= 0 if self.__bigbuffer is None or size > len(self.__bigbuffer): self.__copy_into_bigbuffer() @@ -177,4 +174,3 @@ del self.__bigbuffer[size:] if len(self.__bigbuffer) == 0: self.__bigbuffer = None -self.__pos = AT_END ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: another test and fix for BytesIO.truncate()
Author: Brian Kearns Branch: Changeset: r63265:7c83049dafd8 Date: 2013-04-12 02:49 -0400 http://bitbucket.org/pypy/pypy/changeset/7c83049dafd8/ Log:another test and fix for BytesIO.truncate() diff --git a/pypy/module/_io/interp_bytesio.py b/pypy/module/_io/interp_bytesio.py --- a/pypy/module/_io/interp_bytesio.py +++ b/pypy/module/_io/interp_bytesio.py @@ -62,8 +62,9 @@ def truncate_w(self, space, w_size=None): self._check_closed(space) +pos = self.tell() if space.is_none(w_size): -size = self.tell() +size = pos else: size = space.r_longlong_w(w_size) @@ -72,6 +73,7 @@ "negative size value")) self.truncate(size) +self.seek(pos) return space.wrap(size) def getvalue_w(self, space): diff --git a/pypy/module/_io/test/test_bytesio.py b/pypy/module/_io/test/test_bytesio.py --- a/pypy/module/_io/test/test_bytesio.py +++ b/pypy/module/_io/test/test_bytesio.py @@ -48,7 +48,12 @@ def test_truncate(self): import _io -f = _io.BytesIO("hello") +f = _io.BytesIO() +f.write("hello") +assert f.truncate(0) == 0 +assert f.tell() == 5 +f.seek(0) +f.write("hello") f.seek(3) assert f.truncate() == 3 assert f.getvalue() == "hel" ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit