[pypy-commit] pypy default: import cffi/181e00f1c6e6
arigo
pypy.commits at gmail.com
Sat Mar 11 02:59:12 EST 2017
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r90628:ec2b0693556e
Date: 2017-03-11 08:58 +0100
http://bitbucket.org/pypy/pypy/changeset/ec2b0693556e/
Log: import cffi/181e00f1c6e6
diff --git a/lib_pypy/cffi/api.py b/lib_pypy/cffi/api.py
--- a/lib_pypy/cffi/api.py
+++ b/lib_pypy/cffi/api.py
@@ -756,21 +756,27 @@
def _load_backend_lib(backend, name, flags):
+ import os
if name is None:
if sys.platform != "win32":
return backend.load_library(None, flags)
name = "c" # Windows: load_library(None) fails, but this works
# (backward compatibility hack only)
- try:
- if '.' not in name and '/' not in name:
- raise OSError("library not found: %r" % (name,))
- return backend.load_library(name, flags)
- except OSError:
- import ctypes.util
- path = ctypes.util.find_library(name)
- if path is None:
- raise # propagate the original OSError
- return backend.load_library(path, flags)
+ first_error = None
+ if '.' in name or '/' in name or os.sep in name:
+ try:
+ return backend.load_library(name, flags)
+ except OSError as e:
+ first_error = e
+ import ctypes.util
+ path = ctypes.util.find_library(name)
+ if path is None:
+ msg = ("ctypes.util.find_library() did not manage "
+ "to locate a library called %r" % (name,))
+ if first_error is not None:
+ msg = "%s. Additionally, %s" % (first_error, msg)
+ raise OSError(msg)
+ return backend.load_library(path, flags)
def _make_ffi_library(ffi, libname, flags):
backend = ffi._backend
diff --git a/lib_pypy/cffi/cparser.py b/lib_pypy/cffi/cparser.py
--- a/lib_pypy/cffi/cparser.py
+++ b/lib_pypy/cffi/cparser.py
@@ -34,6 +34,9 @@
r'(Python|Python\s*\+\s*C|C\s*\+\s*Python)"\s*.')
_r_star_const_space = re.compile( # matches "* const "
r"[*]\s*((const|volatile|restrict)\b\s*)+")
+_r_int_dotdotdot = re.compile(r"(\b(int|long|short|signed|unsigned|char)\s*)+"
+ r"\.\.\.")
+_r_float_dotdotdot = re.compile(r"\b(double|float)\s*\.\.\.")
def _get_parser():
global _parser_cache
@@ -180,6 +183,10 @@
assert csource[p:p+3] == '...'
csource = '%s __dotdotdot%d__ %s' % (csource[:p], number,
csource[p+3:])
+ # Replace "int ..." or "unsigned long int..." with "__dotdotdotint__"
+ csource = _r_int_dotdotdot.sub(' __dotdotdotint__ ', csource)
+ # Replace "float ..." or "double..." with "__dotdotdotfloat__"
+ csource = _r_float_dotdotdot.sub(' __dotdotdotfloat__ ', csource)
# Replace all remaining "..." with the same name, "__dotdotdot__",
# which is declared with a typedef for the purpose of C parsing.
return csource.replace('...', ' __dotdotdot__ '), macros
@@ -252,7 +259,8 @@
typenames += sorted(ctn)
#
csourcelines = ['typedef int %s;' % typename for typename in typenames]
- csourcelines.append('typedef int __dotdotdot__;')
+ csourcelines.append('typedef int __dotdotdotint__, __dotdotdotfloat__,'
+ ' __dotdotdot__;')
csourcelines.append(csource)
csource = '\n'.join(csourcelines)
if lock is not None:
@@ -311,6 +319,8 @@
for decl in iterator:
if decl.name == '__dotdotdot__':
break
+ else:
+ assert 0
#
try:
self._inside_extern_python = '__cffi_extern_python_stop'
@@ -322,15 +332,15 @@
raise CDefError("typedef does not declare any name",
decl)
quals = 0
- if (isinstance(decl.type.type, pycparser.c_ast.IdentifierType)
- and decl.type.type.names[-1] == '__dotdotdot__'):
+ if (isinstance(decl.type.type, pycparser.c_ast.IdentifierType) and
+ decl.type.type.names[-1].startswith('__dotdotdot')):
realtype = self._get_unknown_type(decl)
elif (isinstance(decl.type, pycparser.c_ast.PtrDecl) and
isinstance(decl.type.type, pycparser.c_ast.TypeDecl) and
isinstance(decl.type.type.type,
pycparser.c_ast.IdentifierType) and
- decl.type.type.type.names == ['__dotdotdot__']):
- realtype = model.unknown_ptr_type(decl.name)
+ decl.type.type.type.names[-1].startswith('__dotdotdot')):
+ realtype = self._get_unknown_ptr_type(decl)
else:
realtype, quals = self._get_type_and_quals(
decl.type, name=decl.name, partial_length_ok=True)
@@ -832,24 +842,25 @@
def _get_unknown_type(self, decl):
typenames = decl.type.type.names
- assert typenames[-1] == '__dotdotdot__'
- if len(typenames) == 1:
+ if typenames == ['__dotdotdot__']:
return model.unknown_type(decl.name)
- if (typenames[:-1] == ['float'] or
- typenames[:-1] == ['double']):
- # not for 'long double' so far
- result = model.UnknownFloatType(decl.name)
- else:
- for t in typenames[:-1]:
- if t not in ['int', 'short', 'long', 'signed',
- 'unsigned', 'char']:
- raise FFIError(':%d: bad usage of "..."' %
- decl.coord.line)
- result = model.UnknownIntegerType(decl.name)
+ if typenames == ['__dotdotdotint__']:
+ if self._uses_new_feature is None:
+ self._uses_new_feature = "'typedef int... %s'" % decl.name
+ return model.UnknownIntegerType(decl.name)
- if self._uses_new_feature is None:
- self._uses_new_feature = "'typedef %s... %s'" % (
- ' '.join(typenames[:-1]), decl.name)
+ if typenames == ['__dotdotdotfloat__']:
+ # note: not for 'long double' so far
+ if self._uses_new_feature is None:
+ self._uses_new_feature = "'typedef float... %s'" % decl.name
+ return model.UnknownFloatType(decl.name)
- return result
+ raise FFIError(':%d: unsupported usage of "..." in typedef'
+ % decl.coord.line)
+
+ def _get_unknown_ptr_type(self, decl):
+ if decl.type.type.type.names == ['__dotdotdot__']:
+ return model.unknown_ptr_type(decl.name)
+ raise FFIError(':%d: unsupported usage of "..." in typedef'
+ % decl.coord.line)
diff --git a/pypy/module/test_lib_pypy/cffi_tests/cffi0/test_verify.py b/pypy/module/test_lib_pypy/cffi_tests/cffi0/test_verify.py
--- a/pypy/module/test_lib_pypy/cffi_tests/cffi0/test_verify.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/cffi0/test_verify.py
@@ -2247,10 +2247,10 @@
assert str(e.value) == ("feature not supported with ffi.verify(), but only "
"with ffi.set_source(): 'typedef int... t1'")
ffi = FFI()
- ffi.cdef("typedef unsigned long... t1;")
+ ffi.cdef("typedef double ... t1;")
e = py.test.raises(VerificationError, ffi.verify, "")
assert str(e.value) == ("feature not supported with ffi.verify(), but only "
- "with ffi.set_source(): 'typedef unsigned long... t1'")
+ "with ffi.set_source(): 'typedef float... t1'")
def test_const_fields():
ffi = FFI()
More information about the pypy-commit
mailing list