[pypy-commit] pypy default: Add more embedding API, I think this is right, but very hard to test
fijal
noreply at buildbot.pypy.org
Mon May 13 16:17:04 CEST 2013
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch:
Changeset: r64029:a1b20d7f239c
Date: 2013-05-13 16:16 +0200
http://bitbucket.org/pypy/pypy/changeset/a1b20d7f239c/
Log: Add more embedding API, I think this is right, but very hard to test
diff --git a/pypy/goal/targetpypystandalone.py b/pypy/goal/targetpypystandalone.py
--- a/pypy/goal/targetpypystandalone.py
+++ b/pypy/goal/targetpypystandalone.py
@@ -2,6 +2,7 @@
import os, sys
+import pypy
from pypy.interpreter import gateway
from pypy.interpreter.error import OperationError
from pypy.tool.ann_override import PyPyAnnotatorPolicy
@@ -80,6 +81,24 @@
from rpython.rlib.entrypoint import entrypoint
from rpython.rtyper.lltypesystem import rffi
+ @entrypoint('main', [rffi.CCHARP], c_name='pypy_setup_home')
+ def pypy_setup_home(ll_home):
+ from pypy.module.sys.initpath import pypy_find_stdlib
+ if ll_home:
+ home = rffi.charp2str(ll_home)
+ else:
+ home = pypydir
+ pypy_find_stdlib(space, home)
+ space.startup()
+ # import site
+ try:
+ import_ = space.getattr(space.getbuiltinmodule('__builtin__'),
+ space.wrap('__import__'))
+ space.call_function(import_, space.wrap('site'))
+ return 0
+ except OperationError:
+ return 1
+
@entrypoint('main', [rffi.CCHARP], c_name='pypy_execute_source')
def pypy_execute_source(ll_source):
source = rffi.charp2str(ll_source)
@@ -101,7 +120,8 @@
return 1
return 0
- return entry_point, _pypy_execute_source # for tests
+ return entry_point, {'pypy_execute_source': pypy_execute_source,
+ 'pypy_setup_home': pypy_setup_home}
def call_finish(space):
space.finish()
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
@@ -1,5 +1,6 @@
from pypy.goal.targetpypystandalone import get_entry_point, create_entry_point
from pypy.config.pypyoption import get_pypy_config
+from rpython.rtyper.lltypesystem import rffi, lltype
class TestTargetPyPy(object):
def test_run(self):
@@ -8,11 +9,20 @@
entry_point(['pypy-c' , '-S', '-c', 'print 3'])
def test_exeucte_source(space):
- _, execute_source = create_entry_point(space, None)
- execute_source("import sys; sys.modules['xyz'] = 3")
+ _, d = create_entry_point(space, None)
+ execute_source = d['pypy_execute_source']
+ lls = rffi.str2charp("import sys; sys.modules['xyz'] = 3")
+ execute_source(lls)
+ lltype.free(lls, flavor='raw')
x = space.int_w(space.getitem(space.getattr(space.builtin_modules['sys'],
space.wrap('modules')),
space.wrap('xyz')))
assert x == 3
- execute_source("sys")
+ lls = rffi.str2charp("sys")
+ execute_source(lls)
+ lltype.free(lls, flavor='raw')
# did not crash - the same globals
+ pypy_setup_home = d['pypy_setup_home']
+ lls = rffi.str2charp(__file__)
+ pypy_setup_home(lls)
+ lltype.free(lls, flavor='raw')
diff --git a/rpython/rlib/entrypoint.py b/rpython/rlib/entrypoint.py
--- a/rpython/rlib/entrypoint.py
+++ b/rpython/rlib/entrypoint.py
@@ -29,6 +29,7 @@
if not we_are_translated():
import traceback
traceback.print_exc()
+ raise
else:
print str(e)
pypy_debug_catch_fatal_exception()
More information about the pypy-commit
mailing list