[pypy-commit] pypy callback-jit: write an actual test
fijal
noreply at buildbot.pypy.org
Wed Dec 26 19:23:40 CET 2012
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: callback-jit
Changeset: r59568:702bfe8a7734
Date: 2012-12-26 20:18 +0200
http://bitbucket.org/pypy/pypy/changeset/702bfe8a7734/
Log: write an actual test
diff --git a/pypy/jit/metainterp/test/test_warmspot.py b/pypy/jit/metainterp/test/test_warmspot.py
--- a/pypy/jit/metainterp/test/test_warmspot.py
+++ b/pypy/jit/metainterp/test/test_warmspot.py
@@ -519,6 +519,43 @@
self.check_trace_count(1)
+ def test_callback_jit_merge_point(self):
+ from pypy.rlib.objectmodel import register_around_callback_hook
+ from pypy.rpython.lltypesystem import lltype, rffi
+ from pypy.translator.tool.cbuild import ExternalCompilationInfo
+
+ callback_jit_driver = JitDriver(greens = ['name'], reds = 'auto')
+
+ def callback_merge_point(name):
+ callback_jit_driver.jit_merge_point(name=name)
+
+ @callback_jit_driver.inline(callback_merge_point)
+ def callback_hook(name):
+ pass
+
+ def callback(a, b):
+ if a > b:
+ return 1
+ return -1
+
+ CB_TP = rffi.CCallback([lltype.Signed, lltype.Signed], lltype.Signed)
+ eci = ExternalCompilationInfo(includes=['stdlib.h'])
+ qsort = rffi.llexternal('qsort',
+ [rffi.VOIDP, lltype.Signed, lltype.Signed,
+ CB_TP], lltype.Void, compilation_info=eci)
+ ARR = rffi.CArray(lltype.Signed)
+
+ def main():
+ register_around_callback_hook(callback_hook)
+ raw = lltype.malloc(ARR, 10, flavor='raw')
+ for i in range(10):
+ raw[i] = 10 - i
+ qsort(raw, 10, rffi.sizeof(lltype.Signed), callback)
+ lltype.free(raw, flavor='raw')
+
+ self.meta_interp(main, [])
+
+
class TestLLWarmspot(WarmspotTests, LLJitMixin):
CPUClass = runner.LLtypeCPU
type_system = 'lltype'
diff --git a/pypy/rlib/objectmodel.py b/pypy/rlib/objectmodel.py
--- a/pypy/rlib/objectmodel.py
+++ b/pypy/rlib/objectmodel.py
@@ -595,14 +595,11 @@
""" Register a hook that's called before a callback from C calls RPython.
Primary usage is for JIT to have 'started from' hook.
"""
- from pypy.rpython.lltypesystem import lltype, rffi, rstr
+ from pypy.rpython.lltypesystem import rffi
from pypy.rpython.annlowlevel import llhelper
- CallbackHookPtr = lltype.Ptr(lltype.FuncType([rstr.STR], lltype.Void))
-
- hook._always_inline_ = True
rffi.aroundstate.callback_hook = hook
- llhelper(CallbackHookPtr, hook)
+ llhelper(rffi.CallbackHookPtr, hook)
def is_in_callback():
from pypy.rpython.lltypesystem import rffi
diff --git a/pypy/rpython/lltypesystem/rffi.py b/pypy/rpython/lltypesystem/rffi.py
--- a/pypy/rpython/lltypesystem/rffi.py
+++ b/pypy/rpython/lltypesystem/rffi.py
@@ -1,6 +1,6 @@
import py
from pypy.annotation import model as annmodel
-from pypy.rpython.lltypesystem import lltype
+from pypy.rpython.lltypesystem import lltype, rstr
from pypy.rpython.lltypesystem import ll2ctypes
from pypy.rpython.lltypesystem.llmemory import cast_adr_to_ptr, cast_ptr_to_adr
from pypy.rpython.lltypesystem.llmemory import itemoffsetof, raw_memcopy
@@ -13,7 +13,7 @@
from pypy.rlib.unroll import unrolling_iterable
from pypy.rpython.tool.rfficache import platform, sizeof_c_type
from pypy.translator.tool.cbuild import ExternalCompilationInfo
-from pypy.rpython.annlowlevel import llhelper
+from pypy.rpython.annlowlevel import llhelper, llstr
from pypy.rlib.objectmodel import we_are_translated
from pypy.rlib.rstring import StringBuilder, UnicodeBuilder, assert_str0
from pypy.rlib import jit
@@ -288,7 +288,7 @@
after()
callback_hook = aroundstate.callback_hook
if callback_hook:
- callback_hook("%s")
+ callback_hook(llstr("%s"))
# from now on we hold the GIL
stackcounter.stacks_counter += 1
try:
@@ -314,6 +314,7 @@
miniglobals = locals().copy()
miniglobals['Exception'] = Exception
miniglobals['os'] = os
+ miniglobals['llstr'] = llstr
miniglobals['we_are_translated'] = we_are_translated
miniglobals['stackcounter'] = stackcounter
exec source.compile() in miniglobals
@@ -321,6 +322,7 @@
_make_wrapper_for._annspecialcase_ = 'specialize:memo'
AroundFnPtr = lltype.Ptr(lltype.FuncType([], lltype.Void))
+CallbackHookPtr = lltype.Ptr(lltype.FuncType([lltype.Ptr(rstr.STR)], lltype.Void))
class AroundState:
def _cleanup_(self):
More information about the pypy-commit
mailing list