Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
PyPy
pypy
Commits
996a05a25ef6
Commit
df1bcbdd
authored
Dec 04, 2022
by
Carl Friedrich Bolz-Tereick
Browse files
merge default
--HG-- branch : fix-intutils-ovf-bug
parents
fa80408e38b9
3790b2ab46e2
Pipeline
#59140
passed with stage
in 16 minutes and 17 seconds
Changes
72
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
.hgtags
View file @
996a05a2
...
...
@@ -145,3 +145,12 @@ d00b0afd2a5dd3c13fcda75d738262c864c62fa7 release-pypy3.8-v7.3.8
7e0ae751533460d5f89f3ac48ce366d8642d1db5 release-pypy3.7-v7.3.9
4b1398fe9d76ad762155d03684c2a153d230b2ef release-pypy3.8-v7.3.9
05fbe3aa5b0845e6c37239768aa455451aa5faba release-pypy3.9-v7.3.9
b59d72e9703800c986f3ee0508a7d4444c191d66 release-pypy2.7-v7.3.10rc1
983095e8878fc01e8e5e9e0c05e045125469c07d release-pypy3.8-v7.3.10rc1
e3422b03172ea2fca6041a01e6c49a1b043b395d release-pypy3.9-v7.3.10rc1
b59d72e9703800c986f3ee0508a7d4444c191d66 release-pypy2.7-v7.3.10rc2
983095e8878fc01e8e5e9e0c05e045125469c07d release-pypy3.8-v7.3.10rc2
bc58732e1737279ed3f090ea3b8f95543893d40f release-pypy3.9-v7.3.10rc2
59ee452d464d6ef83a47bf0d6189c42747c1503a release-pypy2.7-v7.3.10rc3
19d4bf93b07277769b80cd4f384515cf56342ff6 release-pypy3.8-v7.3.10rc3
27701b51ceb07e359281c991e8a38d08da6de56e release-pypy3.9-v7.3.10rc3
LICENSE
View file @
996a05a2
...
...
@@ -78,6 +78,7 @@ copyrighted by one or more of the following people and organizations:
Romain Guillebert
Ronny Pfannschmidt
Justin Peel
Yusuke Izawa
Raffael Tfirst
David Edelsohn
Anders Hammarquist
...
...
@@ -85,23 +86,22 @@ copyrighted by one or more of the following people and organizations:
Gregor Wegberg
Guido Wesdorp
Lawrence Oluyede
Bartosz Skowron
Stefano Rivera
Bartosz Skowron
Daniel Roberts
Adrien Di Mascio
Niko Matsakis
Batuhan Taskaya
Alexander Hesse
Ludovic Aubry
Batuhan Taskaya
stian
Jacob Hallen
Jason Creighton
Mark Young
Andrew Lawrence
Alex Martelli
Ondrej Baranovič
Alex Martelli
Spenser Bauman
Yusuke Izawa
Michal Bendowski
Jan de Mooij
Stefan Beyer
...
...
@@ -132,8 +132,8 @@ copyrighted by one or more of the following people and organizations:
Konstantin Lopuhin
Wenzhu Man
John Witulski
Jeremy Thurgood
Julian Berman
Jeremy Thurgood
Adrian Kuhn
Dario Bertini
Greg Price
...
...
@@ -147,6 +147,7 @@ copyrighted by one or more of the following people and organizations:
Pavel Vinogradov
William Leslie
Paweł Piotr Przeradowski
Michał Górny
Paul deGrandis
Ilya Osadchiy
Tobias Oberstein
...
...
@@ -156,8 +157,8 @@ copyrighted by one or more of the following people and organizations:
Taavi Burns
Joannah Nanjekye
Georg Brandl
Michał Górny
quejebo
Tadeu Zagallo
Vanessa Freudenberg
Gerald Klix
Wanja Saatkamp
...
...
@@ -179,6 +180,7 @@ copyrighted by one or more of the following people and organizations:
Lukas Renggli
Dusty Phillips
Guenter Jantzen
Nils Müller
Amit Regmi
Ned Batchelder
Jasper Schulz
...
...
@@ -218,7 +220,6 @@ copyrighted by one or more of the following people and organizations:
Aaron Iles
Christian Hudon
Daniel Patrick
Ricky Zhou
Justas Sadzevicius
Gasper Zejn
Neil Shepperd
...
...
@@ -228,6 +229,7 @@ copyrighted by one or more of the following people and organizations:
Berkin Ilbeyi
Mihnea Saracin
Matt Jackson
Ricky Zhou
Jonathan David Riehl
Anders Qvist
Beatrice During
...
...
@@ -283,6 +285,7 @@ copyrighted by one or more of the following people and organizations:
Thomas Hisch
Barry Hart
Tomasz Dziopa
Wenzel Jakob
Lutz Paelike
Ignas Mikalajunas
Martin Blais
...
...
@@ -312,8 +315,10 @@ copyrighted by one or more of the following people and organizations:
Antoine Dupre
Bernd Schoeller
Catalin Fierut
Chris Burr
nimaje
Pierre-Yves DAVID
Alessandro Ogier
Gustavo Niemeyer
Andrew Thompson
Joshua Gilbert
...
...
@@ -371,6 +376,7 @@ copyrighted by one or more of the following people and organizations:
Dennis Sweeney
Kevin Lee
h-vertini
Maxwell Bernstein
Anna Ravencroft
Dinu Gherman
Michael Chermside
...
...
@@ -473,7 +479,6 @@ copyrighted by one or more of the following people and organizations:
shaolo1
Chris AtLee
Christoph Reiter
Chris Burr
Brad Kish
Michael Cho
Ian Clester
...
...
extra_tests/cffi_tests/cffi0/backend_tests.py
View file @
996a05a2
This diff is collapsed.
Click to expand it.
extra_tests/cffi_tests/cffi0/test_cdata.py
View file @
996a05a2
# Generated by pypy/tool/import_cffi.py
import
py
from
cffi
import
FFI
class
FakeBackend
(
object
):
...
...
extra_tests/cffi_tests/cffi0/test_ctypes.py
View file @
996a05a2
# Generated by pypy/tool/import_cffi.py
import
py
,
sys
import
sys
import
pytest
from
extra_tests.cffi_tests.cffi0
import
backend_tests
from
cffi.backend_ctypes
import
CTypesBackend
...
...
@@ -12,33 +13,33 @@ class TestCTypes(backend_tests.BackendTests):
TypeRepr
=
"<class 'ffi.CData<%s>'>"
def
test_array_of_func_ptr
(
self
):
py
.
test
.
skip
(
"ctypes backend: not supported: "
pytest
.
skip
(
"ctypes backend: not supported: "
"initializers for function pointers"
)
def
test_structptr_argument
(
self
):
py
.
test
.
skip
(
"ctypes backend: not supported: passing a list "
pytest
.
skip
(
"ctypes backend: not supported: passing a list "
"for a pointer argument"
)
def
test_array_argument_as_list
(
self
):
py
.
test
.
skip
(
"ctypes backend: not supported: passing a list "
pytest
.
skip
(
"ctypes backend: not supported: passing a list "
"for a pointer argument"
)
def
test_cast_to_array_type
(
self
):
py
.
test
.
skip
(
"ctypes backend: not supported: casting to array"
)
pytest
.
skip
(
"ctypes backend: not supported: casting to array"
)
def
test_nested_anonymous_struct
(
self
):
py
.
test
.
skip
(
"ctypes backend: not supported: nested anonymous struct"
)
pytest
.
skip
(
"ctypes backend: not supported: nested anonymous struct"
)
def
test_nested_field_offset_align
(
self
):
py
.
test
.
skip
(
"ctypes backend: not supported: nested anonymous struct"
)
pytest
.
skip
(
"ctypes backend: not supported: nested anonymous struct"
)
def
test_nested_anonymous_union
(
self
):
py
.
test
.
skip
(
"ctypes backend: not supported: nested anonymous union"
)
pytest
.
skip
(
"ctypes backend: not supported: nested anonymous union"
)
def
test_nested_anonymous_struct_2
(
self
):
py
.
test
.
skip
(
"ctypes backend: not supported: nested anonymous union"
)
pytest
.
skip
(
"ctypes backend: not supported: nested anonymous union"
)
def
test_CData_CType_2
(
self
):
if
sys
.
version_info
>=
(
3
,):
py
.
test
.
skip
(
"ctypes backend: not supported in Python 3: CType"
)
pytest
.
skip
(
"ctypes backend: not supported in Python 3: CType"
)
backend_tests
.
BackendTests
.
test_CData_CType_2
(
self
)
extra_tests/cffi_tests/cffi0/test_ffi_backend.py
View file @
996a05a2
# Generated by pypy/tool/import_cffi.py
import
py
,
sys
,
platform
import
sys
,
platform
import
pytest
from
extra_tests.cffi_tests.cffi0
import
backend_tests
,
test_function
,
test_ownlib
from
extra_tests.cffi_tests.support
import
u
...
...
@@ -19,7 +19,7 @@ class TestFFI(backend_tests.BackendTests,
def
test_not_supported_bitfield_in_result
(
self
):
ffi
=
FFI
(
backend
=
self
.
Backend
())
ffi
.
cdef
(
"struct foo_s { int a,b,c,d,e; int x:1; };"
)
e
=
py
.
test
.
raises
(
NotImplementedError
,
ffi
.
callback
,
e
=
pytest
.
raises
(
NotImplementedError
,
ffi
.
callback
,
"struct foo_s foo(void)"
,
lambda
:
42
)
assert
str
(
e
.
value
)
==
(
"struct foo_s(*)(): "
"callback with unsupported argument or return type or with '...'"
)
...
...
@@ -38,7 +38,7 @@ class TestFFI(backend_tests.BackendTests,
assert
ffi
.
typeof
(
p
)
==
ffi
.
typeof
(
"void *"
)
assert
ffi
.
from_handle
(
p
)
is
o
assert
ffi
.
from_handle
(
ffi
.
cast
(
"char *"
,
p
))
is
o
py
.
test
.
raises
(
RuntimeError
,
ffi
.
from_handle
,
ffi
.
NULL
)
pytest
.
raises
(
RuntimeError
,
ffi
.
from_handle
,
ffi
.
NULL
)
def
test_callback_onerror
(
self
):
ffi
=
FFI
(
backend
=
self
.
Backend
())
...
...
@@ -106,29 +106,29 @@ class TestFFI(backend_tests.BackendTests,
def
test_ffi_new_allocator_4
(
self
):
ffi
=
FFI
(
backend
=
self
.
Backend
())
py
.
test
.
raises
(
TypeError
,
ffi
.
new_allocator
,
free
=
lambda
x
:
None
)
pytest
.
raises
(
TypeError
,
ffi
.
new_allocator
,
free
=
lambda
x
:
None
)
#
def
myalloc2
(
size
):
raise
LookupError
alloc2
=
ffi
.
new_allocator
(
myalloc2
)
py
.
test
.
raises
(
LookupError
,
alloc2
,
"int[5]"
)
pytest
.
raises
(
LookupError
,
alloc2
,
"int[5]"
)
#
def
myalloc3
(
size
):
return
42
alloc3
=
ffi
.
new_allocator
(
myalloc3
)
e
=
py
.
test
.
raises
(
TypeError
,
alloc3
,
"int[5]"
)
e
=
pytest
.
raises
(
TypeError
,
alloc3
,
"int[5]"
)
assert
str
(
e
.
value
)
==
"alloc() must return a cdata object (got int)"
#
def
myalloc4
(
size
):
return
ffi
.
cast
(
"int"
,
42
)
alloc4
=
ffi
.
new_allocator
(
myalloc4
)
e
=
py
.
test
.
raises
(
TypeError
,
alloc4
,
"int[5]"
)
e
=
pytest
.
raises
(
TypeError
,
alloc4
,
"int[5]"
)
assert
str
(
e
.
value
)
==
"alloc() must return a cdata pointer, not 'int'"
#
def
myalloc5
(
size
):
return
ffi
.
NULL
alloc5
=
ffi
.
new_allocator
(
myalloc5
)
py
.
test
.
raises
(
MemoryError
,
alloc5
,
"int[5]"
)
pytest
.
raises
(
MemoryError
,
alloc5
,
"int[5]"
)
def
test_new_struct_containing_struct_containing_array_varsize
(
self
):
ffi
=
FFI
(
backend
=
self
.
Backend
())
...
...
@@ -340,11 +340,11 @@ class TestBitfield:
q
=
ffi
.
cast
(
"struct foo_s *"
,
p
)
assert
q
.
x
==
100
assert
ffi
.
typeof
(
q
.
a
)
is
ffi
.
typeof
(
"int *"
)
# no length recorded
py
.
test
.
raises
(
TypeError
,
len
,
q
.
a
)
pytest
.
raises
(
TypeError
,
len
,
q
.
a
)
assert
q
.
a
[
0
]
==
200
assert
q
.
a
[
1
]
==
300
assert
q
.
a
[
2
]
==
400
py
.
test
.
raises
(
TypeError
,
list
,
q
.
a
)
pytest
.
raises
(
TypeError
,
list
,
q
.
a
)
@
pytest
.
mark
.
skipif
(
"sys.platform != 'win32'"
)
def
test_getwinerror
(
self
):
...
...
@@ -383,9 +383,9 @@ class TestBitfield:
assert
p
[
2
]
==
b
"c"
#
assert
p
==
ffi
.
from_buffer
(
b
"abcd"
,
require_writable
=
False
)
py
.
test
.
raises
((
TypeError
,
BufferError
),
ffi
.
from_buffer
,
pytest
.
raises
((
TypeError
,
BufferError
),
ffi
.
from_buffer
,
"char[]"
,
b
"abcd"
,
True
)
py
.
test
.
raises
((
TypeError
,
BufferError
),
ffi
.
from_buffer
,
b
"abcd"
,
pytest
.
raises
((
TypeError
,
BufferError
),
ffi
.
from_buffer
,
b
"abcd"
,
require_writable
=
True
)
def
test_release
(
self
):
...
...
@@ -443,7 +443,7 @@ class TestBitfield:
assert
list
(
p
)
==
[
ord
(
"a"
),
ord
(
"b"
),
ord
(
"c"
),
0
,
0
]
ffi
.
memmove
(
p
,
bytearray
(
b
"ABCDE"
),
2
)
assert
list
(
p
)
==
[
ord
(
"A"
),
ord
(
"B"
),
ord
(
"c"
),
0
,
0
]
py
.
test
.
raises
((
TypeError
,
BufferError
),
ffi
.
memmove
,
b
"abcde"
,
p
,
3
)
pytest
.
raises
((
TypeError
,
BufferError
),
ffi
.
memmove
,
b
"abcde"
,
p
,
3
)
ba
=
bytearray
(
b
"xxxxx"
)
ffi
.
memmove
(
dest
=
ba
,
src
=
p
,
n
=
3
)
assert
ba
==
bytearray
(
b
"ABcxx"
)
...
...
@@ -506,7 +506,7 @@ class TestBitfield:
def
test_ffi_def_extern
(
self
):
ffi
=
FFI
()
py
.
test
.
raises
(
ValueError
,
ffi
.
def_extern
)
pytest
.
raises
(
ValueError
,
ffi
.
def_extern
)
def
test_introspect_typedef
(
self
):
ffi
=
FFI
()
...
...
@@ -566,19 +566,19 @@ class TestBitfield:
def
test_negative_array_size
(
self
):
ffi
=
FFI
()
py
.
test
.
raises
(
ValueError
,
ffi
.
cast
,
"int[-5]"
,
0
)
pytest
.
raises
(
ValueError
,
ffi
.
cast
,
"int[-5]"
,
0
)
def
test_cannot_instantiate_manually
(
self
):
ffi
=
FFI
()
ct
=
type
(
ffi
.
typeof
(
"void *"
))
py
.
test
.
raises
(
TypeError
,
ct
)
py
.
test
.
raises
(
TypeError
,
ct
,
ffi
.
NULL
)
pytest
.
raises
(
TypeError
,
ct
)
pytest
.
raises
(
TypeError
,
ct
,
ffi
.
NULL
)
for
cd
in
[
type
(
ffi
.
cast
(
"void *"
,
0
)),
type
(
ffi
.
new
(
"char[]"
,
3
)),
type
(
ffi
.
gc
(
ffi
.
NULL
,
lambda
x
:
None
))]:
py
.
test
.
raises
(
TypeError
,
cd
)
py
.
test
.
raises
(
TypeError
,
cd
,
ffi
.
NULL
)
py
.
test
.
raises
(
TypeError
,
cd
,
ffi
.
typeof
(
"void *"
))
pytest
.
raises
(
TypeError
,
cd
)
pytest
.
raises
(
TypeError
,
cd
,
ffi
.
NULL
)
pytest
.
raises
(
TypeError
,
cd
,
ffi
.
typeof
(
"void *"
))
def
test_explicitly_defined_char16_t
(
self
):
ffi
=
FFI
()
...
...
extra_tests/cffi_tests/cffi0/test_function.py
View file @
996a05a2
# Generated by pypy/tool/import_cffi.py
import
py
import
pytest
from
cffi
import
FFI
,
CDefError
import
math
,
os
,
sys
import
ctypes.util
from
cffi.backend_ctypes
import
CTypesBackend
from
extra_tests.cffi_tests.udir
import
udir
from
extra_tests.cffi_tests.support
import
FdWriteCapture
,
StdErrCapture
from
extra_tests.cffi_tests.support
import
FdWriteCapture
,
StdErrCapture
,
is_musl
from
.backend_tests
import
needs_dlopen_none
try
:
...
...
@@ -14,6 +13,12 @@ try:
except
ImportError
:
from
io
import
StringIO
try
:
from
packaging.tags
import
platform_tags
_platform_tags_cached
=
set
(
platform_tags
())
_is_musl
=
any
(
t
.
startswith
(
'musllinux'
)
for
t
in
_platform_tags_cached
)
except
ImportError
:
_is_musl
=
False
lib_m
=
'm'
if
sys
.
platform
==
'win32'
:
...
...
@@ -21,6 +26,8 @@ if sys.platform == 'win32':
import
distutils.ccompiler
if
distutils
.
ccompiler
.
get_default_compiler
()
==
'msvc'
:
lib_m
=
'msvcrt'
elif
is_musl
:
lib_m
=
'c'
class
TestFunction
(
object
):
Backend
=
CTypesBackend
...
...
@@ -36,7 +43,7 @@ class TestFunction(object):
def
test_sinf
(
self
):
if
sys
.
platform
==
'win32'
:
py
.
test
.
skip
(
"no sinf found in the Windows stdlib"
)
pytest
.
skip
(
"no sinf found in the Windows stdlib"
)
ffi
=
FFI
(
backend
=
self
.
Backend
())
ffi
.
cdef
(
"""
float sinf(float x);
...
...
@@ -61,7 +68,7 @@ class TestFunction(object):
def
test_dlopen_filename
(
self
):
path
=
ctypes
.
util
.
find_library
(
lib_m
)
if
not
path
:
py
.
test
.
skip
(
"%s not found"
%
lib_m
)
pytest
.
skip
(
"%s not found"
%
lib_m
)
ffi
=
FFI
(
backend
=
self
.
Backend
())
ffi
.
cdef
(
"""
double cos(double x);
...
...
@@ -97,9 +104,9 @@ class TestFunction(object):
def
test_tlsalloc
(
self
):
if
sys
.
platform
!=
'win32'
:
py
.
test
.
skip
(
"win32 only"
)
pytest
.
skip
(
"win32 only"
)
if
self
.
Backend
is
CTypesBackend
:
py
.
test
.
skip
(
"ctypes complains on wrong calling conv"
)
pytest
.
skip
(
"ctypes complains on wrong calling conv"
)
ffi
=
FFI
(
backend
=
self
.
Backend
())
ffi
.
cdef
(
"long TlsAlloc(void); int TlsFree(long);"
)
lib
=
ffi
.
dlopen
(
'KERNEL32.DLL'
)
...
...
@@ -110,7 +117,7 @@ class TestFunction(object):
def
test_fputs
(
self
):
if
not
sys
.
platform
.
startswith
(
'linux'
):
py
.
test
.
skip
(
"probably no symbol 'stderr' in the lib"
)
pytest
.
skip
(
"probably no symbol 'stderr' in the lib"
)
ffi
=
FFI
(
backend
=
self
.
Backend
())
ffi
.
cdef
(
"""
int fputs(const char *, void *);
...
...
@@ -127,7 +134,7 @@ class TestFunction(object):
def
test_fputs_without_const
(
self
):
if
not
sys
.
platform
.
startswith
(
'linux'
):
py
.
test
.
skip
(
"probably no symbol 'stderr' in the lib"
)
pytest
.
skip
(
"probably no symbol 'stderr' in the lib"
)
ffi
=
FFI
(
backend
=
self
.
Backend
())
ffi
.
cdef
(
"""
int fputs(char *, void *);
...
...
@@ -144,7 +151,7 @@ class TestFunction(object):
def
test_vararg
(
self
):
if
not
sys
.
platform
.
startswith
(
'linux'
):
py
.
test
.
skip
(
"probably no symbol 'stderr' in the lib"
)
pytest
.
skip
(
"probably no symbol 'stderr' in the lib"
)
ffi
=
FFI
(
backend
=
self
.
Backend
())
ffi
.
cdef
(
"""
int fprintf(void *, const char *format, ...);
...
...
@@ -166,11 +173,15 @@ class TestFunction(object):
ffi
.
cast
(
"long long"
,
168
))
ffi
.
C
.
fprintf
(
ffi
.
C
.
stderr
,
b
"hello %p
\n
"
,
ffi
.
NULL
)
res
=
fd
.
getvalue
()
if
is_musl
:
nil_repr
=
b
'0'
else
:
nil_repr
=
b
'(nil)'
assert
res
==
(
b
"hello with no arguments
\n
"
b
"hello, world!
\n
"
b
"hello, world2!
\n
"
b
"hello int 42 long 84 long long 168
\n
"
b
"hello
(nil)
\n
"
)
b
"hello
"
+
nil_repr
+
b
"
\n
"
)
def
test_must_specify_type_of_vararg
(
self
):
ffi
=
FFI
(
backend
=
self
.
Backend
())
...
...
@@ -179,7 +190,7 @@ class TestFunction(object):
"""
)
needs_dlopen_none
()
ffi
.
C
=
ffi
.
dlopen
(
None
)
e
=
py
.
test
.
raises
(
TypeError
,
ffi
.
C
.
printf
,
b
"hello %d
\n
"
,
42
)
e
=
pytest
.
raises
(
TypeError
,
ffi
.
C
.
printf
,
b
"hello %d
\n
"
,
42
)
assert
str
(
e
.
value
)
==
(
"argument 2 passed in the variadic part "
"needs to be a cdata object (got int)"
)
...
...
@@ -207,7 +218,7 @@ class TestFunction(object):
assert
res
==
42
#
if
not
sys
.
platform
.
startswith
(
'linux'
):
py
.
test
.
skip
(
"probably no symbol 'stderr' in the lib"
)
pytest
.
skip
(
"probably no symbol 'stderr' in the lib"
)
ffi
.
cdef
(
"""
int fputs(const char *, void *);
extern void *stderr;
...
...
@@ -239,7 +250,7 @@ class TestFunction(object):
def
test_callback_returning_struct_three_bytes
(
self
):
if
self
.
Backend
is
CTypesBackend
:
py
.
test
.
skip
(
"not supported with the ctypes backend"
)
pytest
.
skip
(
"not supported with the ctypes backend"
)
ffi
=
FFI
(
backend
=
self
.
Backend
())
ffi
.
cdef
(
"""
typedef struct {
...
...
@@ -266,8 +277,8 @@ class TestFunction(object):
assert
res
==
5
def
test_write_variable
(
self
):
if
not
sys
.
platform
.
startswith
(
'linux'
):
py
.
test
.
skip
(
"probably no symbol 'stdout' in the lib"
)
if
not
sys
.
platform
.
startswith
(
'linux'
)
or
_is_musl
:
pytest
.
skip
(
"probably no symbol 'stdout' in the lib"
)
ffi
=
FFI
(
backend
=
self
.
Backend
())
ffi
.
cdef
(
"""
extern void *stdout;
...
...
@@ -293,10 +304,10 @@ class TestFunction(object):
def
test_function_with_struct_argument
(
self
):
if
sys
.
platform
==
'win32'
:
py
.
test
.
skip
(
"no 'inet_ntoa'"
)
pytest
.
skip
(
"no 'inet_ntoa'"
)
if
(
self
.
Backend
is
CTypesBackend
and
'__pypy__'
in
sys
.
builtin_module_names
):
py
.
test
.
skip
(
"ctypes limitation on pypy"
)
pytest
.
skip
(
"ctypes limitation on pypy"
)
ffi
=
FFI
(
backend
=
self
.
Backend
())
ffi
.
cdef
(
"""
struct in_addr { unsigned int s_addr; };
...
...
@@ -320,7 +331,7 @@ class TestFunction(object):
def
test_fputs_custom_FILE
(
self
):
if
self
.
Backend
is
CTypesBackend
:
py
.
test
.
skip
(
"FILE not supported with the ctypes backend"
)
pytest
.
skip
(
"FILE not supported with the ctypes backend"
)
filename
=
str
(
udir
.
join
(
'fputs_custom_FILE'
))
ffi
=
FFI
(
backend
=
self
.
Backend
())
ffi
.
cdef
(
"int fputs(const char *, FILE *);"
)
...
...
@@ -359,7 +370,7 @@ class TestFunction(object):
def
test_signed_char_star_accepts_string
(
self
):
if
self
.
Backend
is
CTypesBackend
:
py
.
test
.
skip
(
"not supported by the ctypes backend"
)
pytest
.
skip
(
"not supported by the ctypes backend"
)
ffi
=
FFI
(
backend
=
self
.
Backend
())
ffi
.
cdef
(
"""int strlen(signed char *);"""
)
needs_dlopen_none
()
...
...
@@ -369,7 +380,7 @@ class TestFunction(object):
def
test_unsigned_char_star_accepts_string
(
self
):
if
self
.
Backend
is
CTypesBackend
:
py
.
test
.
skip
(
"not supported by the ctypes backend"
)
pytest
.
skip
(
"not supported by the ctypes backend"
)
ffi
=
FFI
(
backend
=
self
.
Backend
())
ffi
.
cdef
(
"""int strlen(unsigned char *);"""
)
needs_dlopen_none
()
...
...
@@ -403,7 +414,7 @@ class TestFunction(object):
def
test_free_callback_cycle
(
self
):
if
self
.
Backend
is
CTypesBackend
:
py
.
test
.
skip
(
"seems to fail with the ctypes backend on windows"
)
pytest
.
skip
(
"seems to fail with the ctypes backend on windows"
)
import
weakref
def
make_callback
(
data
):
container
=
[
data
]
...
...
@@ -426,9 +437,9 @@ class TestFunction(object):
def
test_windows_stdcall
(
self
):
if
sys
.
platform
!=
'win32'
:
py
.
test
.
skip
(
"Windows-only test"
)
pytest
.
skip
(
"Windows-only test"
)
if
self
.
Backend
is
CTypesBackend
:
py
.
test
.
skip
(
"not with the ctypes backend"
)
pytest
.
skip
(
"not with the ctypes backend"
)
ffi
=
FFI
(
backend
=
self
.
Backend
())
ffi
.
cdef
(
"""
BOOL QueryPerformanceFrequency(LONGLONG *lpFrequency);
...
...
@@ -441,9 +452,9 @@ class TestFunction(object):
def
test_explicit_cdecl_stdcall
(
self
):
if
sys
.
platform
!=
'win32'
:
py
.
test
.
skip
(
"Windows-only test"
)
pytest
.
skip
(
"Windows-only test"
)
if
self
.
Backend
is
CTypesBackend
:
py
.
test
.
skip
(
"not with the ctypes backend"
)
pytest
.
skip
(
"not with the ctypes backend"
)
win64
=
(
sys
.
maxsize
>
2
**
32
)
#
ffi
=
FFI
(
backend
=
self
.
Backend
())
...
...
@@ -489,8 +500,8 @@ class TestFunction(object):
fns
=
ffi
.
cast
(
"fns_t"
,
0
)
ffi
.
new
(
"fnc_t[]"
,
[
fnc
])
if
not
win64
:
py
.
test
.
raises
(
TypeError
,
ffi
.
new
,
"fnc_t[]"
,
[
fns
])
py
.
test
.
raises
(
TypeError
,
ffi
.
new
,
"fns_t[]"
,
[
fnc
])
pytest
.
raises
(
TypeError
,
ffi
.
new
,
"fnc_t[]"
,
[
fns
])
pytest
.
raises
(
TypeError
,
ffi
.
new
,
"fns_t[]"
,
[
fnc
])
ffi
.
new
(
"fns_t[]"
,
[
fns
])
def
test_stdcall_only_on_windows
(
self
):
...
...
@@ -519,25 +530,25 @@ class TestFunction(object):
def
test_dlclose
(
self
):
if
self
.
Backend
is
CTypesBackend
:
py
.
test
.
skip
(
"not with the ctypes backend"
)
pytest
.
skip
(
"not with the ctypes backend"
)
ffi
=
FFI
(
backend
=
self
.
Backend
())
ffi
.
cdef
(
"int foobar(void); extern int foobaz;"
)
lib
=
ffi
.
dlopen
(
lib_m
)
ffi
.
dlclose
(
lib
)
e
=
py
.
test
.
raises
(
ValueError
,
getattr
,
lib
,
'foobar'
)
e
=
pytest
.
raises
(
ValueError
,
getattr
,
lib
,
'foobar'
)
assert
str
(
e
.
value
).
startswith
(
"library '"
)
assert
str
(
e
.
value
).
endswith
(
"' has already been closed"
)
e
=
py
.
test
.
raises
(
ValueError
,
getattr
,
lib
,
'foobaz'
)
e
=
pytest
.
raises
(
ValueError
,
getattr
,
lib
,
'foobaz'
)
assert
str
(
e
.
value
).
startswith
(
"library '"
)
assert
str
(
e
.
value
).
endswith
(
"' has already been closed"
)
e
=
py
.
test
.
raises
(
ValueError
,
setattr
,
lib
,
'foobaz'
,
42
)
e
=
pytest
.
raises
(
ValueError
,
setattr
,
lib
,
'foobaz'
,
42
)
assert
str
(
e
.
value
).
startswith
(
"library '"
)
assert
str
(
e
.
value
).
endswith
(
"' has already been closed"
)
ffi
.
dlclose
(
lib
)
# does not raise
def
test_passing_large_list
(
self
):
if
self
.
Backend
is
CTypesBackend
:
py
.
test
.
skip
(
"the ctypes backend doesn't support this"
)
pytest
.
skip
(
"the ctypes backend doesn't support this"
)
ffi
=
FFI
(
backend
=
self
.
Backend
())
ffi
.
cdef
(
"""
void getenv(char *);
...
...
extra_tests/cffi_tests/cffi0/test_model.py
View file @
996a05a2
...
...
@@ -55,8 +55,17 @@ def test_const_pointer_type():
ptr_type
=
ConstPointerType
(
PrimitiveType
(
"int"
))
assert
ptr_type
.
get_c_name
(
"x"
)
==
"int const * x"
ptr_type
=
ConstPointerType
(
ArrayType
(
PrimitiveType
(
"int"
),
5
))
assert
ptr_type
.
get_c_name
(
""
)
==
"int(const *)[5]"
assert
ptr_type
.
get_c_name
(
"*x"
)
==
"int(const * *x)[5]"
assert
ptr_type
.
get_c_name
(
""
)
==
"int const (*)[5]"
assert
ptr_type
.
get_c_name
(
"*x"
)
==
"int const (* *x)[5]"
ptr_type
=
ConstPointerType
(
ArrayType
(
ConstPointerType
(
PrimitiveType
(
"int"
)),
5
))
assert
ptr_type
.
get_c_name
(
"x"
)
==
"int const * const (* x)[5]"
ptr_type
=
PointerType
(
ArrayType
(
ConstPointerType
(
PrimitiveType
(
"int"
)),
5
))
assert
ptr_type
.
get_c_name
(
"x"
)
==
"int const *(* x)[5]"
ptr_type
=
ConstPointerType
(
ArrayType
(
PointerType
(
PrimitiveType
(
"int"
)),
5
))
assert
ptr_type
.
get_c_name
(
"x"
)
==
"int * const (* x)[5]"
def
test_qual_pointer_type
():
ptr_type
=
PointerType
(
PrimitiveType
(
"long long"
),
Q_RESTRICT
)
...
...
extra_tests/cffi_tests/cffi0/test_ownlib.py
View file @
996a05a2
# Generated by pypy/tool/import_cffi.py
import
py
,
sys
,
os
import
sys
,
os
import
subprocess
,
weakref
import
pytest
from
cffi
import
FFI
from
cffi.backend_ctypes
import
CTypesBackend
from
extra_tests.cffi_tests.support
import
u
from
extra_tests.cffi_tests.support
import
u
,
is_musl
SOURCE
=
"""
\
...
...
@@ -181,9 +182,9 @@ class TestOwnLib(object):
def
test_getting_errno
(
self
):
if
self
.
module
is
None
: