[pypy-commit] pypy revive-dlltool: Fix dlltool: a way to build a .so or .dll which is not
amauryfa
noreply at buildbot.pypy.org
Tue Feb 14 00:16:06 CET 2012
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: revive-dlltool
Changeset: r52435:a1819d03772d
Date: 2012-02-14 00:14 +0100
http://bitbucket.org/pypy/pypy/changeset/a1819d03772d/
Log: Fix dlltool: a way to build a .so or .dll which is not a CPython
extension module.
diff --git a/pypy/translator/c/database.py b/pypy/translator/c/database.py
--- a/pypy/translator/c/database.py
+++ b/pypy/translator/c/database.py
@@ -28,11 +28,13 @@
gctransformer = None
def __init__(self, translator=None, standalone=False,
+ cpython_extension=False,
gcpolicyclass=None,
thread_enabled=False,
sandbox=False):
self.translator = translator
self.standalone = standalone
+ self.cpython_extension = cpython_extension
self.sandbox = sandbox
if gcpolicyclass is None:
gcpolicyclass = gc.RefcountingGcPolicy
diff --git a/pypy/translator/c/dlltool.py b/pypy/translator/c/dlltool.py
--- a/pypy/translator/c/dlltool.py
+++ b/pypy/translator/c/dlltool.py
@@ -14,11 +14,14 @@
CBuilder.__init__(self, *args, **kwds)
def getentrypointptr(self):
+ entrypoints = []
bk = self.translator.annotator.bookkeeper
- graphs = [bk.getdesc(f).cachedgraph(None) for f, _ in self.functions]
- return [getfunctionptr(graph) for graph in graphs]
+ for f, _ in self.functions:
+ graph = bk.getdesc(f).getuniquegraph()
+ entrypoints.append(getfunctionptr(graph))
+ return entrypoints
- def gen_makefile(self, targetdir):
+ def gen_makefile(self, targetdir, exe_name=None):
pass # XXX finish
def compile(self):
diff --git a/pypy/translator/c/extfunc.py b/pypy/translator/c/extfunc.py
--- a/pypy/translator/c/extfunc.py
+++ b/pypy/translator/c/extfunc.py
@@ -106,7 +106,7 @@
yield ('RPYTHON_EXCEPTION_MATCH', exceptiondata.fn_exception_match)
yield ('RPYTHON_TYPE_OF_EXC_INST', exceptiondata.fn_type_of_exc_inst)
yield ('RPYTHON_RAISE_OSERROR', exceptiondata.fn_raise_OSError)
- if not db.standalone:
+ if db.cpython_extension:
yield ('RPYTHON_PYEXCCLASS2EXC', exceptiondata.fn_pyexcclass2exc)
yield ('RPyExceptionOccurred1', exctransformer.rpyexc_occured_ptr.value)
diff --git a/pypy/translator/c/genc.py b/pypy/translator/c/genc.py
--- a/pypy/translator/c/genc.py
+++ b/pypy/translator/c/genc.py
@@ -111,6 +111,7 @@
_compiled = False
modulename = None
split = False
+ cpython_extension = False
def __init__(self, translator, entrypoint, config, gcpolicy=None,
secondary_entrypoints=()):
@@ -138,6 +139,7 @@
raise NotImplementedError("--gcrootfinder=asmgcc requires standalone")
db = LowLevelDatabase(translator, standalone=self.standalone,
+ cpython_extension=self.cpython_extension,
gcpolicyclass=gcpolicyclass,
thread_enabled=self.config.translation.thread,
sandbox=self.config.translation.sandbox)
@@ -236,6 +238,8 @@
CBuilder.have___thread = self.translator.platform.check___thread()
if not self.standalone:
assert not self.config.translation.instrument
+ if self.cpython_extension:
+ defines['PYPY_CPYTHON_EXTENSION'] = 1
else:
defines['PYPY_STANDALONE'] = db.get(pf)
if self.config.translation.instrument:
@@ -307,13 +311,18 @@
class CExtModuleBuilder(CBuilder):
standalone = False
+ cpython_extension = True
_module = None
_wrapper = None
def get_eci(self):
from distutils import sysconfig
python_inc = sysconfig.get_python_inc()
- eci = ExternalCompilationInfo(include_dirs=[python_inc])
+ eci = ExternalCompilationInfo(
+ include_dirs=[python_inc],
+ includes=["Python.h",
+ ],
+ )
return eci.merge(CBuilder.get_eci(self))
def getentrypointptr(self): # xxx
diff --git a/pypy/translator/c/src/exception.h b/pypy/translator/c/src/exception.h
--- a/pypy/translator/c/src/exception.h
+++ b/pypy/translator/c/src/exception.h
@@ -2,7 +2,7 @@
/************************************************************/
/*** C header subsection: exceptions ***/
-#if !defined(PYPY_STANDALONE) && !defined(PYPY_NOT_MAIN_FILE)
+#if defined(PYPY_CPYTHON_EXTENSION) && !defined(PYPY_NOT_MAIN_FILE)
PyObject *RPythonError;
#endif
@@ -74,7 +74,7 @@
RPyRaiseException(RPYTHON_TYPE_OF_EXC_INST(rexc), rexc);
}
-#ifndef PYPY_STANDALONE
+#ifdef PYPY_CPYTHON_EXTENSION
void RPyConvertExceptionFromCPython(void)
{
/* convert the CPython exception to an RPython one */
diff --git a/pypy/translator/c/src/g_include.h b/pypy/translator/c/src/g_include.h
--- a/pypy/translator/c/src/g_include.h
+++ b/pypy/translator/c/src/g_include.h
@@ -2,7 +2,7 @@
/************************************************************/
/*** C header file for code produced by genc.py ***/
-#ifndef PYPY_STANDALONE
+#ifdef PYPY_CPYTHON_EXTENSION
# include "Python.h"
# include "compile.h"
# include "frameobject.h"
diff --git a/pypy/translator/c/src/g_prerequisite.h b/pypy/translator/c/src/g_prerequisite.h
--- a/pypy/translator/c/src/g_prerequisite.h
+++ b/pypy/translator/c/src/g_prerequisite.h
@@ -5,8 +5,6 @@
#ifdef PYPY_STANDALONE
# include "src/commondefs.h"
-#else
-# include "Python.h"
#endif
#ifdef _WIN32
diff --git a/pypy/translator/c/src/pyobj.h b/pypy/translator/c/src/pyobj.h
--- a/pypy/translator/c/src/pyobj.h
+++ b/pypy/translator/c/src/pyobj.h
@@ -2,7 +2,7 @@
/************************************************************/
/*** C header subsection: untyped operations ***/
/*** as OP_XXX() macros calling the CPython API ***/
-
+#ifdef PYPY_CPYTHON_EXTENSION
#define op_bool(r,what) { \
int _retval = what; \
@@ -261,3 +261,5 @@
}
#endif
+
+#endif /* PYPY_CPYTHON_EXTENSION */
diff --git a/pypy/translator/c/src/support.h b/pypy/translator/c/src/support.h
--- a/pypy/translator/c/src/support.h
+++ b/pypy/translator/c/src/support.h
@@ -104,7 +104,7 @@
# define RPyBareItem(array, index) ((array)[index])
#endif
-#ifndef PYPY_STANDALONE
+#ifdef PYPY_CPYTHON_EXTENSION
/* prototypes */
diff --git a/pypy/translator/c/test/test_dlltool.py b/pypy/translator/c/test/test_dlltool.py
--- a/pypy/translator/c/test/test_dlltool.py
+++ b/pypy/translator/c/test/test_dlltool.py
@@ -2,7 +2,6 @@
from pypy.translator.c.dlltool import DLLDef
from ctypes import CDLL
import py
-py.test.skip("fix this if needed")
class TestDLLTool(object):
def test_basic(self):
@@ -16,8 +15,8 @@
d = DLLDef('lib', [(f, [int]), (b, [int])])
so = d.compile()
dll = CDLL(str(so))
- assert dll.f(3) == 3
- assert dll.b(10) == 12
+ assert dll.pypy_g_f(3) == 3
+ assert dll.pypy_g_b(10) == 12
def test_split_criteria(self):
def f(x):
@@ -28,4 +27,5 @@
d = DLLDef('lib', [(f, [int]), (b, [int])])
so = d.compile()
- assert py.path.local(so).dirpath().join('implement.c').check()
+ dirpath = py.path.local(so).dirpath()
+ assert dirpath.join('translator_c_test_test_dlltool.c').check()
diff --git a/pypy/translator/driver.py b/pypy/translator/driver.py
--- a/pypy/translator/driver.py
+++ b/pypy/translator/driver.py
@@ -331,6 +331,7 @@
raise Exception("stand-alone program entry point must return an "
"int (and not, e.g., None or always raise an "
"exception).")
+ annotator.complete()
annotator.simplify()
return s
More information about the pypy-commit
mailing list