[pypy-commit] pypy win64-stage1: a bit of progress with libffi and friends. 16 tests pass, 5 fail.
ctismer
noreply at buildbot.pypy.org
Thu Dec 1 21:38:19 CET 2011
Author: Christian Tismer <tismer at stackless.com>
Branch: win64-stage1
Changeset: r50042:fd39e63b03e0
Date: 2011-12-01 21:37 +0100
http://bitbucket.org/pypy/pypy/changeset/fd39e63b03e0/
Log: a bit of progress with libffi and friends. 16 tests pass, 5 fail.
There is still a problem with pointers and sizes...
diff --git a/pypy/annotation/model.py b/pypy/annotation/model.py
--- a/pypy/annotation/model.py
+++ b/pypy/annotation/model.py
@@ -770,12 +770,15 @@
#
# safety check that no-one is trying to make annotation and translation
# faster by providing the -O option to Python.
-try:
- assert False
-except AssertionError:
- pass # fine
-else:
- raise RuntimeError("The annotator relies on 'assert' statements from the\n"
+import os
+if "WINGDB_PYTHON" not in os.environ:
+ # ...but avoiding this boring check in the IDE
+ try:
+ assert False
+ except AssertionError:
+ pass # fine
+ else:
+ raise RuntimeError("The annotator relies on 'assert' statements from the\n"
"\tannotated program: you cannot run it with 'python -O'.")
# this has the side-effect of registering the unary and binary operations
diff --git a/pypy/rlib/libffi.py b/pypy/rlib/libffi.py
--- a/pypy/rlib/libffi.py
+++ b/pypy/rlib/libffi.py
@@ -79,16 +79,20 @@
types._import()
+# this was '_fits_into_long', which is not adequate, because long is
+# not necessary the type where we compute with. Actually meant is
+# the type 'Signed'.
+
@specialize.arg(0)
-def _fits_into_long(TYPE):
+def _fits_into_signed(TYPE):
if isinstance(TYPE, lltype.Ptr):
- return True # pointers always fits into longs
+ return True # pointers always fits into Signeds
if not isinstance(TYPE, lltype.Primitive):
return False
if TYPE is lltype.Void or TYPE is rffi.FLOAT or TYPE is rffi.DOUBLE:
return False
sz = rffi.sizeof(TYPE)
- return sz <= rffi.sizeof(rffi.LONG)
+ return sz <= rffi.sizeof(rffi.SIGNED)
# ======================================================================
@@ -115,7 +119,7 @@
def arg(self, val):
TYPE = lltype.typeOf(val)
_check_type(TYPE)
- if _fits_into_long(TYPE):
+ if _fits_into_signed(TYPE):
cls = IntArg
val = rffi.cast(rffi.LONG, val)
elif TYPE is rffi.DOUBLE:
@@ -250,7 +254,7 @@
if is_struct:
assert types.is_struct(self.restype)
res = self._do_call_raw(self.funcsym, ll_args)
- elif _fits_into_long(RESULT):
+ elif _fits_into_signed(RESULT):
assert not types.is_struct(self.restype)
res = self._do_call_int(self.funcsym, ll_args)
elif RESULT is rffi.DOUBLE:
diff --git a/pypy/rlib/test/autopath.py b/pypy/rlib/test/autopath.py
new file mode 100644
--- /dev/null
+++ b/pypy/rlib/test/autopath.py
@@ -0,0 +1,131 @@
+"""
+self cloning, automatic path configuration
+
+copy this into any subdirectory of pypy from which scripts need
+to be run, typically all of the test subdirs.
+The idea is that any such script simply issues
+
+ import autopath
+
+and this will make sure that the parent directory containing "pypy"
+is in sys.path.
+
+If you modify the master "autopath.py" version (in pypy/tool/autopath.py)
+you can directly run it which will copy itself on all autopath.py files
+it finds under the pypy root directory.
+
+This module always provides these attributes:
+
+ pypydir pypy root directory path
+ this_dir directory where this autopath.py resides
+
+"""
+
+def __dirinfo(part):
+ """ return (partdir, this_dir) and insert parent of partdir
+ into sys.path. If the parent directories don't have the part
+ an EnvironmentError is raised."""
+
+ import sys, os
+ try:
+ head = this_dir = os.path.realpath(os.path.dirname(__file__))
+ except NameError:
+ head = this_dir = os.path.realpath(os.path.dirname(sys.argv[0]))
+
+ error = None
+ while head:
+ partdir = head
+ head, tail = os.path.split(head)
+ if tail == part:
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
+ if not os.path.exists(checkfile):
+ error = "Cannot find %r" % (os.path.normpath(checkfile),)
+ break
+ else:
+ error = "Cannot find the parent directory %r of the path %r" % (
+ partdir, this_dir)
+ if not error:
+ # check for bogus end-of-line style (e.g. files checked out on
+ # Windows and moved to Unix)
+ f = open(__file__.replace('.pyc', '.py'), 'r')
+ data = f.read()
+ f.close()
+ if data.endswith('\r\n') or data.endswith('\r'):
+ error = ("Bad end-of-line style in the .py files. Typically "
+ "caused by a zip file or a checkout done on Windows and "
+ "moved to Unix or vice-versa.")
+ if error:
+ raise EnvironmentError("Invalid source tree - bogus checkout! " +
+ error)
+
+ pypy_root = os.path.join(head, '')
+ try:
+ sys.path.remove(head)
+ except ValueError:
+ pass
+ sys.path.insert(0, head)
+
+ munged = {}
+ for name, mod in sys.modules.items():
+ if '.' in name:
+ continue
+ fn = getattr(mod, '__file__', None)
+ if not isinstance(fn, str):
+ continue
+ newname = os.path.splitext(os.path.basename(fn))[0]
+ if not newname.startswith(part + '.'):
+ continue
+ path = os.path.join(os.path.dirname(os.path.realpath(fn)), '')
+ if path.startswith(pypy_root) and newname != part:
+ modpaths = os.path.normpath(path[len(pypy_root):]).split(os.sep)
+ if newname != '__init__':
+ modpaths.append(newname)
+ modpath = '.'.join(modpaths)
+ if modpath not in sys.modules:
+ munged[modpath] = mod
+
+ for name, mod in munged.iteritems():
+ if name not in sys.modules:
+ sys.modules[name] = mod
+ if '.' in name:
+ prename = name[:name.rfind('.')]
+ postname = name[len(prename)+1:]
+ if prename not in sys.modules:
+ __import__(prename)
+ if not hasattr(sys.modules[prename], postname):
+ setattr(sys.modules[prename], postname, mod)
+
+ return partdir, this_dir
+
+def __clone():
+ """ clone master version of autopath.py into all subdirs """
+ from os.path import join, walk
+ if not this_dir.endswith(join('pypy','tool')):
+ raise EnvironmentError("can only clone master version "
+ "'%s'" % join(pypydir, 'tool',_myname))
+
+
+ def sync_walker(arg, dirname, fnames):
+ if _myname in fnames:
+ fn = join(dirname, _myname)
+ f = open(fn, 'rwb+')
+ try:
+ if f.read() == arg:
+ print "checkok", fn
+ else:
+ print "syncing", fn
+ f = open(fn, 'w')
+ f.write(arg)
+ finally:
+ f.close()
+ s = open(join(pypydir, 'tool', _myname), 'rb').read()
+ walk(pypydir, sync_walker, s)
+
+_myname = 'autopath.py'
+
+# set guaranteed attributes
+
+pypydir, this_dir = __dirinfo('pypy')
+
+if __name__ == '__main__':
+ __clone()
diff --git a/pypy/rlib/test/test_libffi.py b/pypy/rlib/test/test_libffi.py
--- a/pypy/rlib/test/test_libffi.py
+++ b/pypy/rlib/test/test_libffi.py
@@ -1,6 +1,6 @@
import sys
-import py
+import py, autopath
from pypy.rlib.libffi import (CDLL, Func, get_libc_name, ArgChain, types,
IS_32_BIT, array_getitem, array_setitem)
@@ -121,7 +121,9 @@
exports.append(match.group(1))
#
c_file.write(py.code.Source('\n'.join(snippets)))
- eci = ExternalCompilationInfo(export_symbols=exports)
+ eci = ExternalCompilationInfo(
+ export_symbols=exports,
+ include_dirs = [str(py.path.local(autopath.pypydir).join('translator', 'c'))])
cls.libfoo_name = str(platform.compile([c_file], eci, 'x',
standalone=False))
@@ -235,9 +237,11 @@
def test_pointer_as_argument(self):
"""#include <stdlib.h>
- long inc(long* x)
+ #include "src/signed_defn.h"
+
+ Signed inc(Signed* x)
{
- long oldval;
+ Signed oldval;
if (x == NULL)
return -1;
oldval = *x;
@@ -247,14 +251,13 @@
"""
libfoo = self.get_libfoo()
func = (libfoo, 'inc', [types.pointer], types.slong)
- LONGP = lltype.Ptr(rffi.CArray(rffi.LONG))
- null = lltype.nullptr(LONGP.TO)
- res = self.call(func, [null], rffi.LONG)
+ null = lltype.nullptr(rffi.SIGNEDP.TO)
+ res = self.call(func, [null], rffi.SIGNED)
assert res == -1
#
ptr_result = lltype.malloc(LONGP.TO, 1, flavor='raw')
ptr_result[0] = 41
- res = self.call(func, [ptr_result], rffi.LONG)
+ res = self.call(func, [ptr_result], rffi.SIGNED)
if self.__class__ is TestLibffiCall:
# the function was called only once
assert res == 41
@@ -436,7 +439,7 @@
libfoo = CDLL(self.libfoo_name)
make_point = (libfoo, 'make_point', [types.slong, types.slong], ffi_point)
#
- PTR = lltype.Ptr(rffi.CArray(rffi.LONG))
+ PTR = lltype.Ptr(rffi.CArray(rffi.SIGNED))
p = self.call(make_point, [12, 34], PTR, is_struct=True,
jitif=["byval"])
assert p[0] == 12
diff --git a/pypy/rpython/lltypesystem/rffi.py b/pypy/rpython/lltypesystem/rffi.py
--- a/pypy/rpython/lltypesystem/rffi.py
+++ b/pypy/rpython/lltypesystem/rffi.py
@@ -647,8 +647,9 @@
# float *
FLOATP = lltype.Ptr(lltype.Array(FLOAT, hints={'nolength': True}))
-# Signed *
-SIGNEDP = lltype.Ptr(lltype.Array(lltype.Signed, hints={'nolength': True}))
+# Signed, Signed *
+SIGNED = lltype.Signed
+SIGNEDP = lltype.Ptr(lltype.Array(SIGNED, hints={'nolength': True}))
# various type mapping
More information about the pypy-commit
mailing list