[pypy-svn] r73510 - in pypy/branch/cpython-extension/pypy/translator/c: . test
afa at codespeak.net
afa at codespeak.net
Wed Apr 7 18:25:18 CEST 2010
Author: afa
Date: Wed Apr 7 18:25:15 2010
New Revision: 73510
Modified:
pypy/branch/cpython-extension/pypy/translator/c/genc.py
pypy/branch/cpython-extension/pypy/translator/c/test/test_standalone.py
Log:
Fix the test for --shared on Linux
Modified: pypy/branch/cpython-extension/pypy/translator/c/genc.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/c/genc.py (original)
+++ pypy/branch/cpython-extension/pypy/translator/c/genc.py Wed Apr 7 18:25:15 2010
@@ -79,8 +79,15 @@
self.profbased = profbased
def _build(self, eci=ExternalCompilationInfo(), shared=False):
+ outputfilename = self.outputfilename
+ if shared:
+ if outputfilename:
+ basename = outputfilename
+ else:
+ basename = self.cfiles[0].purebasename
+ outputfilename = 'lib' + basename
return self.platform.compile(self.cfiles, self.eci.merge(eci),
- outputfilename=self.outputfilename,
+ outputfilename=outputfilename,
standalone=not shared)
def build(self, shared=False):
@@ -468,26 +475,33 @@
return res.out, res.err
return res.out
- def build_main_for_shared(self, shared_library_name, entrypoint):
+ def build_main_for_shared(self, shared_library_name, entrypoint, exe_name):
+ import time
+ time.sleep(1)
self.shared_library_name = shared_library_name
# build main program
eci = self.get_eci()
+ kw = {}
+ if self.translator.platform.so_ext == 'so':
+ kw['libraries'] = [self.shared_library_name.purebasename[3:]]
+ kw['library_dirs'] = [self.targetdir]
+ else:
+ kw['libraries'] = [self.shared_library_name.new(ext='')]
eci = eci.merge(ExternalCompilationInfo(
separate_module_sources=['''
- int %s(argc, argv);
+ int %s(int argc, char* argv[]);
int main(int argc, char* argv[])
- { %s(argc, argv); }
+ { return %s(argc, argv); }
''' % (entrypoint, entrypoint)
],
- libraries=[self.shared_library_name.new(ext='')]
+ **kw
))
eci = eci.convert_sources_to_files(
cache_dir=self.targetdir)
- outfilename = self.shared_library_name.new(ext='')
return self.translator.platform.compile(
[], eci,
- outputfilename=str(outfilename))
+ outputfilename=exe_name)
def compile(self, exe_name=None):
assert self.c_source_filename
@@ -510,7 +524,7 @@
self.executable_name = compiler.build(shared=shared)
if shared:
self.executable_name = self.build_main_for_shared(
- self.executable_name, "pypy_main_startup")
+ self.executable_name, "pypy_main_startup", exe_name)
assert self.executable_name
self._compiled = True
return self.executable_name
Modified: pypy/branch/cpython-extension/pypy/translator/c/test/test_standalone.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/c/test/test_standalone.py (original)
+++ pypy/branch/cpython-extension/pypy/translator/c/test/test_standalone.py Wed Apr 7 18:25:15 2010
@@ -589,7 +589,7 @@
# The traceback stops at f() because it's the first function that
# captures the AssertionError, which makes the program abort.
- def test_shared(self):
+ def test_shared(self, monkeypatch):
def f(argv):
print len(argv)
def entry_point(argv):
@@ -598,6 +598,8 @@
t, cbuilder = self.compile(entry_point, shared=True)
assert cbuilder.shared_library_name is not None
assert cbuilder.shared_library_name != cbuilder.executable_name
+ monkeypatch.setenv('LD_LIBRARY_PATH',
+ cbuilder.shared_library_name.dirpath())
out, err = cbuilder.cmdexec("a b")
assert out == "3"
More information about the Pypy-commit
mailing list