Commit 64b32d13 authored by wlav's avatar wlav
Browse files

merge default into branch

--HG--
branch : cppyy-dev
......@@ -4,6 +4,7 @@ import pytest
import sys, os, math, weakref
from cffi import FFI, VerificationError, VerificationMissing, model, FFIError
from extra_tests.cffi_tests.support import *
from extra_tests.cffi_tests.support import extra_compile_args
lib_m = ['m']
......@@ -14,17 +15,6 @@ if sys.platform == 'win32':
lib_m = ['msvcrt']
pass # no obvious -Werror equivalent on MSVC
else:
if (sys.platform == 'darwin' and
[int(x) for x in os.uname()[2].split('.')] >= [11, 0, 0]):
# assume a standard clang or gcc
extra_compile_args = ['-Werror', '-Wall', '-Wextra', '-Wconversion']
# special things for clang
extra_compile_args.append('-Qunused-arguments')
else:
# assume a standard gcc
extra_compile_args = ['-Werror', '-Wall', '-Wextra', '-Wconversion',
'-Wno-unused-parameter']
class FFI(FFI):
def verify(self, *args, **kwds):
return super(FFI, self).verify(
......
......@@ -35,8 +35,9 @@ def verify(ffi, module_name, source, *args, **kwds):
source = 'extern "C" {\n%s\n}' % (source,)
elif sys.platform != 'win32':
# add '-Werror' to the existing 'extra_compile_args' flags
from extra_tests.cffi_tests.support import extra_compile_args
kwds['extra_compile_args'] = (kwds.get('extra_compile_args', []) +
['-Werror'])
extra_compile_args)
return _verify(ffi, module_name, source, *args, **kwds)
def test_set_source_no_slashes():
......@@ -2039,7 +2040,7 @@ def test_function_returns_float_complex():
ffi.cdef("float _Complex f1(float a, float b);");
lib = verify(ffi, "test_function_returns_float_complex", """
#include <complex.h>
static float _Complex f1(float a, float b) { return a + I*2.0*b; }
static float _Complex f1(float a, float b) { return a + I*2.0f*b; }
""", no_cpp=True) # <complex.h> fails on some systems with C++
result = lib.f1(1.25, 5.1)
assert type(result) == complex
......
......@@ -5,7 +5,7 @@ from cffi import FFI, FFIError, VerificationError, VerificationMissing, model
from cffi import CDefError
from cffi import recompiler
from extra_tests.cffi_tests.support import *
from extra_tests.cffi_tests.support import _verify
from extra_tests.cffi_tests.support import _verify, extra_compile_args
import _cffi_backend
lib_m = ['m']
......@@ -14,18 +14,6 @@ if sys.platform == 'win32':
import distutils.ccompiler
if distutils.ccompiler.get_default_compiler() == 'msvc':
lib_m = ['msvcrt']
extra_compile_args = [] # no obvious -Werror equivalent on MSVC
else:
if (sys.platform == 'darwin' and
[int(x) for x in os.uname()[2].split('.')] >= [11, 0, 0]):
# assume a standard clang or gcc
extra_compile_args = ['-Werror', '-Wall', '-Wextra', '-Wconversion']
# special things for clang
extra_compile_args.append('-Qunused-arguments')
else:
# assume a standard gcc
extra_compile_args = ['-Werror', '-Wall', '-Wextra', '-Wconversion',
'-Wno-unused-parameter']
class FFI(FFI):
error = _cffi_backend.FFI.error
......
# Generated by pypy/tool/import_cffi.py
import sys
import sys, os
if sys.version_info < (3,):
__all__ = ['u']
......@@ -87,3 +87,24 @@ def _verify(ffi, module_name, preamble, *args, **kwds):
if not name.startswith('_') and not hasattr(module.ffi, name):
setattr(ffi, name, NotImplemented)
return module.lib
# For testing, we call gcc with "-Werror". This is fragile because newer
# versions of gcc are always better at producing warnings, particularly for
# auto-generated code. We need here to adapt and silence them as needed.
if sys.platform == 'win32':
extra_compile_args = [] # no obvious -Werror equivalent on MSVC
else:
if (sys.platform == 'darwin' and
[int(x) for x in os.uname()[2].split('.')] >= [11, 0, 0]):
# assume a standard clang or gcc
extra_compile_args = ['-Werror', '-Wall', '-Wextra', '-Wconversion',
'-Wno-unreachable-code']
# special things for clang
extra_compile_args.append('-Qunused-arguments')
else:
# assume a standard gcc
extra_compile_args = ['-Werror', '-Wall', '-Wextra', '-Wconversion',
'-Wno-unused-parameter',
'-Wno-unreachable-code']
......@@ -382,6 +382,11 @@ def _init_non_posix(vars):
vars['EXE'] = '.exe'
vars['VERSION'] = _PY_VERSION_SHORT_NO_DOT
vars['BINDIR'] = os.path.dirname(_safe_realpath(sys.executable))
# pypy only: give us control over the ABI tag in a wheel name
if '__pypy__' in sys.builtin_module_names:
import imp
so_ext = imp.get_suffixes()[0][0]
vars['SOABI']= '-'.join(so_ext.split('.')[1].split('-')[:2])
#
# public APIs
......
......@@ -10,7 +10,7 @@ except ImportError as e:
import os
msg = "\n\nThe _ssl cffi module either doesn't exist or is incompatible with your machine's shared libraries.\n" + \
"If you have a compiler installed, you can try to rebuild it by running:\n" + \
"cd %s\n" % os.path.abspath(os.path.dirname(os.path.dirname(__file__))) + \
"cd %s\n" % os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))) + \
"%s _ssl_build.py\n" % sys.executable
raise ImportError(str(e) + msg)
......
......@@ -96,8 +96,6 @@ typedef unsigned char bool;
typedef unsigned long... chtype;
typedef chtype attr_t;
typedef int... wint_t;
typedef struct
{
short id; /* ID to distinguish multiple devices */
......@@ -376,6 +374,7 @@ void _m_getsyx(int *yx);
if version > (5, 7):
ffi.cdef("""
typedef int... wint_t;
int wget_wch(WINDOW *, wint_t *);
int mvwget_wch(WINDOW *, int, int, wint_t *);
int unget_wch(const wchar_t);
......
Metadata-Version: 1.1
Name: cffi
Version: 1.13.1
Version: 1.13.2
Summary: Foreign Function Interface for Python calling C code.
Home-page: http://cffi.readthedocs.org
Author: Armin Rigo, Maciej Fijalkowski
......
......@@ -5,8 +5,8 @@ from .api import FFI
from .error import CDefError, FFIError, VerificationError, VerificationMissing
from .error import PkgConfigError
__version__ = "1.13.1"
__version_info__ = (1, 13, 1)
__version__ = "1.13.2"
__version_info__ = (1, 13, 2)
# The verifier module file names are based on the CRC32 of a string that
# contains the following version number. It may be older than __version__
......
......@@ -261,12 +261,12 @@ _CFFI_UNUSED_FN static int _cffi_to_c_char32_t(PyObject *o)
return (int)_cffi_to_c_wchar3216_t(o);
}
_CFFI_UNUSED_FN static PyObject *_cffi_from_c_char32_t(int x)
_CFFI_UNUSED_FN static PyObject *_cffi_from_c_char32_t(unsigned int x)
{
if (sizeof(_cffi_wchar_t) == 4)
return _cffi_from_c_wchar_t((_cffi_wchar_t)x);
else
return _cffi_from_c_wchar3216_t(x);
return _cffi_from_c_wchar3216_t((int)x);
}
......
......@@ -224,7 +224,7 @@ static int _cffi_initialize_python(void)
if (f != NULL && f != Py_None) {
PyFile_WriteString("\nFrom: " _CFFI_MODULE_NAME
"\ncompiled with cffi version: 1.13.1"
"\ncompiled with cffi version: 1.13.2"
"\n_cffi_backend module: ", f);
modules = PyImport_GetModuleDict();
mod = PyDict_GetItemString(modules, "_cffi_backend");
......
......@@ -159,9 +159,9 @@ def _warn_for_string_literal(csource):
def _warn_for_non_extern_non_static_global_variable(decl):
if not decl.storage:
import warnings
warnings.warn("Declaration of global variable '%s' in cdef() should "
"be marked 'extern' for consistency (or possibly "
"'static' in API mode)" % (decl.name,))
warnings.warn("Global variable '%s' in cdef(): for consistency "
"with C it should have a storage class specifier "
"(usually 'extern')" % (decl.name,))
def _preprocess(csource):
# Remove comments. NOTE: this only work because the cdef() section
......
......@@ -185,7 +185,9 @@ def pytest_runtest_setup(item):
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
spaceconfig.setdefault('objspace.std.reinterpretasserts', True)
config = item.config
if not (config.getoption('runappdirect') or config.getoption('direct_apptest')):
spaceconfig.setdefault('objspace.std.reinterpretasserts', True)
appclass.obj.space = gettestobjspace(**spaceconfig)
appclass.obj.runappdirect = option.runappdirect
......
"""Test the exec statement functionality.
New for PyPy - Could be incorporated into CPython regression tests.
"""
import pytest
def test_string():
g = {}
l = {}
exec "a = 3" in g, l
assert l['a'] == 3
def test_localfill():
g = {}
exec "a = 3" in g
assert g['a'] == 3
def test_builtinsupply():
g = {}
exec "pass" in g
assert g.has_key('__builtins__')
def test_invalidglobal():
with pytest.raises(TypeError):
exec 'pass' in 1
def test_invalidlocal():
with pytest.raises(TypeError):
exec 'pass' in {}, 2
def test_codeobject():
co = compile("a = 3", '<string>', 'exec')
g = {}
l = {}
exec co in g, l
assert l['a'] == 3
def test_implicit():
a = 4
exec "a = 3"
assert a == 3
def test_tuplelocals():
g = {}
l = {}
exec ("a = 3", g, l)
assert l['a'] == 3
def test_tupleglobals():
g = {}
exec ("a = 3", g)
assert g['a'] == 3
def test_exceptionfallthrough():
with pytest.raises(TypeError):
exec 'raise TypeError' in {}
def test_global_stmt():
g = {}
l = {}
co = compile("global a; a=5", '', 'exec')
#import dis
#dis.dis(co)
exec co in g, l
assert l == {}
assert g['a'] == 5
def test_specialcase_free_load():
exec """if 1:
def f():
exec 'a=3'
return a
x = f()\n"""
assert x == 3
def test_specialcase_free_load2():
exec """if 1:
def f(a):
exec 'a=3'
return a
x = f(4)\n"""
assert x == 3
def test_specialcase_globals_and_exec():
d = {}
exec """if 1:
b = 2
c = 3
d = 4
def f(a):
global b
exec 'd=42 ; b=7'
return a,b,c,d
#import dis
#dis.dis(f)
res = f(3)\n""" in d
r = d['res']
assert r == (3,2,3,42)
def test_nested_names_are_not_confused():
def get_nested_class():
method_and_var = "var"
class Test(object):
def method_and_var(self):
return "method"
def test(self):
return method_and_var
def actual_global(self):
return str("global")
def str(self):
return str(self)
return Test()
t = get_nested_class()
assert t.actual_global() == "global"
assert t.test() == 'var'
assert t.method_and_var() == 'method'
def test_import_star_shadows_global():
d = {'platform' : 3}
exec """if 1:
def f():
from sys import *
return platform
res = f()\n""" in d
import sys
assert d['res'] == sys.platform
def test_import_global_takes_precendence():
d = {'platform' : 3}
exec """if 1:
def f():
global platform
from sys import *
return platform
res = f()\n""" in d
import sys
assert d['platform'] == 3
def test_exec_load_name():
d = {'x': 2}
exec """if 1:
def f():
save = x
exec "x=3"
return x,save
\n""" in d
res = d['f']()
assert res == (3, 2)
def test_space_bug():
d = {}
exec "x=5 " in d
assert d['x'] == 5
def test_synerr():
with pytest.raises(SyntaxError):
exec "1 2"
def test_mapping_as_locals():
import sys
if not hasattr(sys, 'pypy_objspaceclass'):
skip("need PyPy for non-dictionaries in exec statements")
class M(object):
def __getitem__(self, key):
return key
def __setitem__(self, key, value):
self.result[key] = value
def setdefault(self, key, value):
assert key == '__builtins__'
m = M()
m.result = {}
exec "x=m" in {}, m
assert m.result == {'x': 'm'}
exec "y=n" in m # NOTE: this doesn't work in CPython
assert m.result == {'x': 'm', 'y': 'n'}
def test_filename():
with pytest.raises(SyntaxError) as excinfo:
exec "'unmatched_quote"
assert excinfo.value.filename == '<string>'
with pytest.raises(SyntaxError) as excinfo:
eval("'unmatched_quote")
assert excinfo.value.filename == '<string>'
def test_exec_and_name_lookups():
ns = {}
exec """def f():
exec 'x=1' in locals()
return x""" in ns
f = ns['f']
assert f() == 1
def test_exec_unicode():
# 's' is a string
s = "x = u'\xd0\xb9\xd1\x86\xd1\x83\xd0\xba\xd0\xb5\xd0\xbd'"
# 'u' is a unicode
u = s.decode('utf-8')
exec u
assert len(x) == 6
assert ord(x[0]) == 0x0439
assert ord(x[1]) == 0x0446
assert ord(x[2]) == 0x0443
assert ord(x[3]) == 0x043a
assert ord(x[4]) == 0x0435
assert ord(x[5]) == 0x043d
def test_eval_unicode():
u = "u'%s'" % unichr(0x1234)
v = eval(u)
assert v == unichr(0x1234)
def test_compile_unicode():
s = "x = u'\xd0\xb9\xd1\x86\xd1\x83\xd0\xba\xd0\xb5\xd0\xbd'"
u = s.decode('utf-8')
c = compile(u, '<input>', 'exec')
exec c
assert len(x) == 6
assert ord(x[0]) == 0x0439
def test_nested_qualified_exec():
import sys
if sys.version_info < (2, 7, 9):
skip()
code = ["""
def g():
def f():
if True:
exec "" in {}, {}
""", """
def g():
def f():
if True:
exec("", {}, {})
"""]
for c in code:
compile(c, "<code>", "exec")
def test_exec_tuple():
# note: this is VERY different than testing exec("a = 42", d), because
# this specific case is handled specially by the AST compiler
d = {}
x = ("a = 42", d)
exec x
assert d['a'] == 42
......@@ -16,257 +16,3 @@ def test_file(space):
assert 'abc' in g
assert 'cba' in g
''')
class AppTestExecStmt:
def test_string(self):
g = {}
l = {}
exec "a = 3" in g, l
assert l['a'] == 3
def test_localfill(self):
g = {}
exec "a = 3" in g
assert g['a'] == 3
def test_builtinsupply(self):
g = {}
exec "pass" in g
assert g.has_key('__builtins__')
def test_invalidglobal(self):
def f():
exec 'pass' in 1
raises(TypeError,f)
def test_invalidlocal(self):
def f():
exec 'pass' in {}, 2
raises(TypeError,f)
def test_codeobject(self):
co = compile("a = 3", '<string>', 'exec')
g = {}
l = {}
exec co in g, l
assert l['a'] == 3
def test_implicit(self):
a = 4
exec "a = 3"
assert a == 3
def test_tuplelocals(self):
g = {}
l = {}
exec ("a = 3", g, l)
assert l['a'] == 3
def test_tupleglobals(self):
g = {}
exec ("a = 3", g)
assert g['a'] == 3
def test_exceptionfallthrough(self):
def f():
exec 'raise TypeError' in {}
raises(TypeError,f)
def test_global_stmt(self):
g = {}
l = {}
co = compile("global a; a=5", '', 'exec')
#import dis
#dis.dis(co)
exec co in g, l
assert l == {}
assert g['a'] == 5
def test_specialcase_free_load(self):
exec """if 1:
def f():
exec 'a=3'
return a
x = f()\n"""
assert x == 3
def test_specialcase_free_load2(self):
exec """if 1:
def f(a):
exec 'a=3'
return a
x = f(4)\n"""
assert x == 3
def test_specialcase_globals_and_exec(self):
d = {}
exec """if 1:
b = 2
c = 3
d = 4
def f(a):
global b
exec 'd=42 ; b=7'
return a,b,c,d
#import dis
#dis.dis(f)
res = f(3)\n""" in d
r = d['res']
assert r == (3,2,3,42)
def test_nested_names_are_not_confused(self):
def get_nested_class():
method_and_var = "var"
class Test(object):
def method_and_var(self):
return "method"
def test(self):
return method_and_var
def actual_global(self):
return str("global")
def str(self):
return str(self)
return Test()
t = get_nested_class()
assert t.actual_global() == "global"
assert t.test() == 'var'
assert t.method_and_var() == 'method'
def test_import_star_shadows_global(self):
d = {'platform' : 3}
exec """if 1:
def f():
from sys import *
return platform
res = f()\n""" in d
import sys
assert d['res'] == sys.platform
def test_import_global_takes_precendence(self):
d = {'platform' : 3}
exec """if 1:
def f():
global platform
from sys import *
return platform
res = f()\n""" in d
import sys