Author: Ronan Lamy <[email protected]>
Branch: bootstrap-clarity
Changeset: r83076:006b04e6249a
Date: 2016-03-15 19:06 +0000
http://bitbucket.org/pypy/pypy/changeset/006b04e6249a/
Log: Create space._is_runtime attribute.
This is meant to allow cleanly separating translation-time objspace
configuration from run-time interpreter initialisation.
The attribute is initially False and must be set to True before
running space.startup() or exectuting any annotator-visible RPython
code.
diff --git a/pypy/bin/pyinteractive.py b/pypy/bin/pyinteractive.py
--- a/pypy/bin/pyinteractive.py
+++ b/pypy/bin/pyinteractive.py
@@ -42,7 +42,7 @@
StrOption("warn",
"warning control (arg is action:message:category:module:lineno)",
default=None, cmdline="-W"),
-
+
])
pypy_init = gateway.applevel('''
@@ -118,7 +118,7 @@
# set warning control options (if any)
warn_arg = interactiveconfig.warn
if warn_arg is not None:
- space.appexec([space.wrap(warn_arg)], """(arg):
+ space.appexec([space.wrap(warn_arg)], """(arg):
import sys
sys.warnoptions.append(arg)""")
@@ -167,6 +167,7 @@
try:
def do_start():
+ space._is_runtime = True
space.startup()
pypy_init(space, space.wrap(not interactiveconfig.no_site_import))
if main.run_toplevel(space, do_start,
@@ -200,6 +201,6 @@
if __name__ == '__main__':
if hasattr(sys, 'setrecursionlimit'):
- # for running "python -i pyinteractive.py -Si -- py.py -Si"
+ # for running "python -i pyinteractive.py -Si -- py.py -Si"
sys.setrecursionlimit(3000)
sys.exit(main_(sys.argv))
diff --git a/pypy/goal/targetpypystandalone.py
b/pypy/goal/targetpypystandalone.py
--- a/pypy/goal/targetpypystandalone.py
+++ b/pypy/goal/targetpypystandalone.py
@@ -292,7 +292,7 @@
self.hack_for_cffi_modules(driver)
return self.get_entry_point(config)
-
+
def hack_for_cffi_modules(self, driver):
# HACKHACKHACK
# ugly hack to modify target goal from compile_* to build_cffi_imports
@@ -319,7 +319,7 @@
while not basedir.join('include').exists():
_basedir = basedir.dirpath()
if _basedir == basedir:
- raise ValueError('interpreter %s not inside pypy repo',
+ raise ValueError('interpreter %s not inside pypy repo',
str(exename))
basedir = _basedir
modules = self.config.objspace.usemodules.getpaths()
@@ -350,6 +350,7 @@
app = gateway.applevel(open(filename).read(), 'app_main.py',
'app_main')
app.hidden_applevel = False
w_dict = app.getwdict(space)
+ space._is_runtime = True
entry_point, _ = create_entry_point(space, w_dict)
return entry_point, None, PyPyAnnotatorPolicy()
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -374,6 +374,7 @@
def __init__(self, config=None):
"NOT_RPYTHON: Basic initialization of objects."
+ self._is_runtime = False
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
@@ -391,7 +392,7 @@
self.check_signal_action = None # changed by the signal module
self.user_del_action = UserDelAction(self)
self._code_of_sys_exc_info = None
-
+
# can be overridden to a subclass
self.initialize()
@@ -643,21 +644,14 @@
# you should not see frames while you translate
# so we make sure that the threadlocals never *have* an
# ExecutionContext during translation.
- if not we_are_translated():
- if self.config.translating:
- assert self.threadlocals.get_ec() is None, (
- "threadlocals got an ExecutionContext during translation!")
- try:
- return self._ec_during_translation
- except AttributeError:
- ec = self.createexecutioncontext()
- self._ec_during_translation = ec
- return ec
- else:
- ec = self.threadlocals.get_ec()
- if ec is None:
- self.threadlocals.enter_thread(self)
- ec = self.threadlocals.get_ec()
+ if not self._is_runtime:
+ assert self.threadlocals.get_ec() is None, (
+ "threadlocals got an ExecutionContext during translation!")
+ try:
+ return self._ec_during_translation
+ except AttributeError:
+ ec = self.createexecutioncontext()
+ self._ec_during_translation = ec
return ec
else:
# translated case follows. self.threadlocals is either from
@@ -693,13 +687,11 @@
"""Return an interp-level Lock object if threads are enabled,
and a dummy object if they are not."""
from rpython.rlib import rthread
+ # There is no threading at objspace configuration time
+ if not self._is_runtime:
+ raise CannotHaveLock()
if not self.config.objspace.usemodules.thread:
return rthread.dummy_lock
- # hack: we can't have prebuilt locks if we're translating.
- # In this special situation we should just not lock at all
- # (translation is not multithreaded anyway).
- if not we_are_translated() and self.config.translating:
- raise CannotHaveLock()
try:
return rthread.allocate_lock()
except rthread.error:
diff --git a/pypy/interpreter/test/test_targetpypy.py
b/pypy/interpreter/test/test_targetpypy.py
--- a/pypy/interpreter/test/test_targetpypy.py
+++ b/pypy/interpreter/test/test_targetpypy.py
@@ -9,6 +9,7 @@
entry_point(['pypy-c' , '-S', '-c', 'print 3'])
def test_execute_source(space):
+ space._is_runtime = True
_, d = create_entry_point(space, None)
execute_source = d['pypy_execute_source']
lls = rffi.str2charp("import sys; sys.modules['xyz'] = 3")
diff --git a/pypy/module/_codecs/interp_codecs.py
b/pypy/module/_codecs/interp_codecs.py
--- a/pypy/module/_codecs/interp_codecs.py
+++ b/pypy/module/_codecs/interp_codecs.py
@@ -130,8 +130,7 @@
Looks up a codec tuple in the Python codec registry and returns
a tuple of functions.
"""
- assert not (space.config.translating and not we_are_translated()), \
- "lookup_codec() should not be called during translation"
+ assert space._is_runtime
state = space.fromcache(CodecState)
normalized_encoding = encoding.replace(" ", "-").lower()
w_result = state.get_codec_from_cache(normalized_encoding)
diff --git a/pypy/module/sys/__init__.py b/pypy/module/sys/__init__.py
--- a/pypy/module/sys/__init__.py
+++ b/pypy/module/sys/__init__.py
@@ -103,7 +103,7 @@
}
def startup(self, space):
- if space.config.translating and not we_are_translated():
+ if not space._is_runtime:
# don't get the filesystemencoding at translation time
assert self.filesystemencoding is None
diff --git a/pypy/tool/pytest/objspace.py b/pypy/tool/pytest/objspace.py
--- a/pypy/tool/pytest/objspace.py
+++ b/pypy/tool/pytest/objspace.py
@@ -29,6 +29,7 @@
if config is None:
config = make_config(option)
space = make_objspace(config)
+ space._is_runtime = True
space.startup() # Initialize all builtin modules
space.setitem(space.builtin.w_dict, space.wrap('AssertionError'),
appsupport.build_pytest_assertion(space))
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit