Author: Ronan Lamy <[email protected]>
Branch:
Changeset: r93549:9d239f4dad8a
Date: 2017-12-22 13:08 +0100
http://bitbucket.org/pypy/pypy/changeset/9d239f4dad8a/
Log: Make ctypes_tests independent of rpython
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c
b/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c
--- a/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c
+++ b/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c
@@ -3,9 +3,7 @@
#define MS_WIN32
#endif
-#include "src/precommondefs.h"
-
-#define EXPORT(x) RPY_EXPORTED x
+#define EXPORT(x) extern x
#include <stdlib.h>
#include <math.h>
@@ -272,7 +270,7 @@
{
double x, sum=0.0, dx=(b-a)/(double)nstep;
for(x=a+0.5*dx; (b-x)*(x-a)>0.0; x+=dx)
- {
+ {
double y = f(x);
printf("f(x)=%.1f\n", y);
sum += f(x);
@@ -287,7 +285,7 @@
static void _xxx_init(void *(*Xalloc)(int), void (*Xfree)(void *))
{
void *ptr;
-
+
printf("_xxx_init got %p %p\n", Xalloc, Xfree);
printf("calling\n");
ptr = Xalloc(32);
@@ -438,7 +436,7 @@
#endif
/********/
-
+
#ifndef MS_WIN32
typedef struct {
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/conftest.py
b/pypy/module/test_lib_pypy/ctypes_tests/conftest.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/conftest.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/conftest.py
@@ -1,14 +1,91 @@
-import py, pytest
+import py
+import pytest
import sys
+import os
def pytest_ignore_collect(path):
if '__pypy__' not in sys.builtin_module_names:
return True
+# XXX: copied from pypy/tool/cpyext/extbuild.py
+if os.name != 'nt':
+ so_ext = 'so'
+else:
+ so_ext = 'dll'
+
+def _build(cfilenames, outputfilename, compile_extra, link_extra,
+ include_dirs, libraries, library_dirs):
+ try:
+ # monkeypatch distutils for some versions of msvc compiler
+ import setuptools
+ except ImportError:
+ # XXX if this fails and is required,
+ # we must call pypy -mensurepip after translation
+ pass
+ from distutils.ccompiler import new_compiler
+ from distutils import sysconfig
+
+ # XXX for Darwin running old versions of CPython 2.7.x
+ sysconfig.get_config_vars()
+
+ compiler = new_compiler(force=1)
+ sysconfig.customize_compiler(compiler) # XXX
+ objects = []
+ for cfile in cfilenames:
+ cfile = py.path.local(cfile)
+ old = cfile.dirpath().chdir()
+ try:
+ res = compiler.compile([cfile.basename],
+ include_dirs=include_dirs, extra_preargs=compile_extra)
+ assert len(res) == 1
+ cobjfile = py.path.local(res[0])
+ assert cobjfile.check()
+ objects.append(str(cobjfile))
+ finally:
+ old.chdir()
+
+ compiler.link_shared_object(
+ objects, str(outputfilename),
+ libraries=libraries,
+ extra_preargs=link_extra,
+ library_dirs=library_dirs)
+
+def c_compile(cfilenames, outputfilename,
+ compile_extra=None, link_extra=None,
+ include_dirs=None, libraries=None, library_dirs=None):
+ compile_extra = compile_extra or []
+ link_extra = link_extra or []
+ include_dirs = include_dirs or []
+ libraries = libraries or []
+ library_dirs = library_dirs or []
+ if sys.platform == 'win32':
+ link_extra = link_extra + ['/DEBUG'] # generate .pdb file
+ if sys.platform == 'darwin':
+ # support Fink & Darwinports
+ for s in ('/sw/', '/opt/local/'):
+ if (s + 'include' not in include_dirs
+ and os.path.exists(s + 'include')):
+ include_dirs.append(s + 'include')
+ if s + 'lib' not in library_dirs and os.path.exists(s + 'lib'):
+ library_dirs.append(s + 'lib')
+
+ outputfilename = py.path.local(outputfilename).new(ext=so_ext)
+ saved_environ = os.environ.copy()
+ try:
+ _build(
+ cfilenames, outputfilename,
+ compile_extra, link_extra,
+ include_dirs, libraries, library_dirs)
+ finally:
+ # workaround for a distutils bugs where some env vars can
+ # become longer and longer every time it is used
+ for key, value in saved_environ.items():
+ if os.environ.get(key) != value:
+ os.environ[key] = value
+ return outputfilename
+# end copy
+
def compile_so_file():
- from rpython.translator.platform import platform
- from rpython.translator.tool.cbuild import ExternalCompilationInfo
- from rpython.translator import cdir
udir = pytest.ensuretemp('_ctypes_test')
cfile = py.path.local(__file__).dirpath().join("_ctypes_test.c")
@@ -16,11 +93,8 @@
libraries = ['oleaut32']
else:
libraries = []
- eci = ExternalCompilationInfo(libraries=libraries,
- include_dirs=[cdir])
- return platform.compile([cfile], eci, str(udir.join('_ctypes_test')),
- standalone=False)
+ return c_compile([cfile], str(udir / '_ctypes_test'), libraries=libraries)
# we need to run after the "tmpdir" plugin which installs pytest.ensuretemp
@pytest.mark.trylast
diff --git a/pypy/tool/cpyext/extbuild.py b/pypy/tool/cpyext/extbuild.py
--- a/pypy/tool/cpyext/extbuild.py
+++ b/pypy/tool/cpyext/extbuild.py
@@ -199,7 +199,7 @@
# monkeypatch distutils for some versions of msvc compiler
import setuptools
except ImportError:
- # XXX if this fails and is required,
+ # XXX if this fails and is required,
# we must call pypy -mensurepip after translation
pass
from distutils.ccompiler import new_compiler
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit