Author: Antonio Cuni <[email protected]>
Branch: hpy
Changeset: r98126:c427e9f459bf
Date: 2019-11-21 15:51 +0100
http://bitbucket.org/pypy/pypy/changeset/c427e9f459bf/
Log: extend checkmodule to be able to invoke the C compiler if requested.
Use the new functionality to test hpy_universal translation, which
currently fails during the C compilation step due to a misdeclared
type in the HPyContextS Struct. Will be fixed in next commits
diff --git a/pypy/module/hpy_universal/test/test_ztranslation.py
b/pypy/module/hpy_universal/test/test_ztranslation.py
--- a/pypy/module/hpy_universal/test/test_ztranslation.py
+++ b/pypy/module/hpy_universal/test/test_ztranslation.py
@@ -1,6 +1,17 @@
-
+from rpython.translator.c.test.test_standalone import StandaloneTests
+from rpython.config.translationoption import get_combined_translation_config
+from pypy.config.pypyoption import get_pypy_config
from pypy.objspace.fake.checkmodule import checkmodule
+from pypy.objspace.fake.objspace import FakeObjSpace
+from pypy.module.hpy_universal.state import State
def test_checkmodule():
- checkmodule('hpy_universal')
+ def extra_func(space):
+ state = space.fromcache(State)
+ state.setup()
+ config_opts = {'translation.gc': 'boehm'}
+ checkmodule('hpy_universal',
+ extra_func=extra_func,
+ c_compile=True,
+ config_opts=config_opts)
diff --git a/pypy/objspace/fake/checkmodule.py
b/pypy/objspace/fake/checkmodule.py
--- a/pypy/objspace/fake/checkmodule.py
+++ b/pypy/objspace/fake/checkmodule.py
@@ -2,14 +2,29 @@
from pypy.config.pypyoption import get_pypy_config
-def checkmodule(*modnames, **kwds):
- translate_startup = kwds.pop('translate_startup', True)
- ignore = set(kwds.pop('ignore', ()))
- assert not kwds
+def checkmodule(modname, translate_startup=True, ignore=(),
+ c_compile=False, extra_func=None, config_opts=None):
+ """
+ Check that the module 'modname' translates.
+
+ Options:
+ translate_startup: TODO, document me
+
+ ignore: list of module interpleveldefs/appleveldefs to ignore
+
+ c_compile: determine whether to inokve the C compiler after rtyping
+
+ extra_func: extra function which will be annotated and called. It takes
+ a single "space" argment
+
+ config_opts: dictionary containing extra configuration options which
+ will be passed to TranslationContext
+ """
config = get_pypy_config(translating=True)
space = FakeObjSpace(config)
seeobj_w = []
modules = []
+ modnames = [modname]
for modname in modnames:
mod = __import__(
'pypy.module.%s.moduledef' % modname, None, None, ['__doc__'])
@@ -34,5 +49,8 @@
if not translate_startup:
func() # call it now
func = None
+
+ opts = {'translation.list_comprehension_operations': True}
+ opts.update(config_opts)
space.translates(func, seeobj_w=seeobj_w,
- **{'translation.list_comprehension_operations': True})
+ c_compile=c_compile, extra_func=extra_func, **opts)
diff --git a/pypy/objspace/fake/objspace.py b/pypy/objspace/fake/objspace.py
--- a/pypy/objspace/fake/objspace.py
+++ b/pypy/objspace/fake/objspace.py
@@ -1,4 +1,5 @@
from rpython.annotator.model import SomeInstance, s_None
+from rpython.annotator.listdef import s_list_of_strings
from rpython.rlib.objectmodel import (instantiate, we_are_translated,
specialize,
not_rpython)
from rpython.rlib.nonconst import NonConstant
@@ -7,6 +8,7 @@
from rpython.rtyper.lltypesystem import lltype
from rpython.tool.sourcetools import compile2, func_with_new_name
from rpython.translator.translator import TranslationContext
+from rpython.translator.c.genc import CStandaloneBuilder
from pypy.tool.option import make_config
from pypy.interpreter import argument, gateway
@@ -387,7 +389,9 @@
# ----------
- def translates(self, func=None, argtypes=None, seeobj_w=[], **kwds):
+ def translates(self, func=None, argtypes=None, seeobj_w=[],
+ extra_func=None, c_compile=False,
+ **kwds):
config = make_config(None, **kwds)
if func is not None:
if argtypes is None:
@@ -397,10 +401,14 @@
t = TranslationContext(config=config)
self.t = t # for debugging
ann = t.buildannotator()
- def _do_startup():
+
+ def entry_point(argv):
self.threadlocals.enter_thread(self)
W_SliceObject(w_some_obj(), w_some_obj(), w_some_obj())
- ann.build_types(_do_startup, [], complete_now=False)
+ if extra_func:
+ extra_func(self)
+ return 0
+ ann.build_types(entry_point, [s_list_of_strings], complete_now=False)
if func is not None:
ann.build_types(func, argtypes, complete_now=False)
if seeobj_w:
@@ -422,6 +430,12 @@
#t.viewcg()
t.buildrtyper().specialize()
t.checkgraphs()
+ if c_compile:
+ cbuilder = CStandaloneBuilder(t, entry_point, t.config)
+ cbuilder.generate_source(defines=cbuilder.DEBUG_DEFINES)
+ cbuilder.compile()
+ return t, cbuilder
+
def setup(space):
for name in (ObjSpace.ConstantTable +
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit