forked from mesonbuild/meson
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# This is taken from Cython's limited API tests and | ||
# as a result is under Apache 2.0 | ||
|
||
import cython | ||
|
||
@cython.binding(False) | ||
def fib(int n): | ||
cdef int a, b | ||
a, b = 0, 1 | ||
while b < n: | ||
a, b = b, a + b | ||
return b | ||
|
||
def lsum(values): | ||
cdef long result = 0 | ||
for value in values: | ||
result += value | ||
if type(values) is list: | ||
for value in reversed(<list>values): | ||
result += value | ||
elif type(values) is tuple: | ||
for value in reversed(<tuple>values): | ||
result += value | ||
return result | ||
|
||
@cython.binding(False) | ||
def raises(): | ||
raise RuntimeError() | ||
|
||
def decode(bytes b, bytearray ba): | ||
return b.decode("utf-8") + ba.decode("utf-8") | ||
|
||
def cast_float(object o): | ||
return float(o) | ||
|
||
class C: | ||
pass | ||
|
||
cdef class D: | ||
pass | ||
|
||
cdef class E(D): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
project('cython limited api', ['cython', 'c']) | ||
|
||
cythonc = meson.get_compiler('cython') | ||
if cythonc.version() < '3.0' | ||
error('MESON_SKIP_TEST: Cython compiler version does not support limited API') | ||
endif | ||
|
||
py3 = import('python').find_installation() | ||
|
||
ext_mod = py3.extension_module('limited', | ||
'limited.pyx', | ||
limited_api: '3.10' | ||
) | ||
|
||
test('limited_api runner', | ||
py3, | ||
args : files('run.py'), | ||
env : ['PYTHONPATH=' + meson.current_build_dir()] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# This is taken from Cython's limited API tests and | ||
# as a result is under Apache 2.0 | ||
|
||
import limited | ||
|
||
limited.fib(11) | ||
|
||
assert limited.lsum(list(range(10))) == 90 | ||
assert limited.lsum(tuple(range(10))) == 90 | ||
assert limited.lsum(iter(range(10))) == 45 | ||
|
||
try: | ||
limited.raises() | ||
except RuntimeError: | ||
pass | ||
|
||
limited.C() | ||
limited.D() | ||
limited.E() | ||
|
||
assert limited.decode(b'a', bytearray(b'b')) == "ab" | ||
|
||
assert limited.cast_float(1) == 1.0 | ||
assert limited.cast_float("2.0") == 2.0 | ||
assert limited.cast_float(bytearray(b"3")) == 3.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"matrix": { | ||
"options": { | ||
"cython_language": [ | ||
{ "val": "c" }, | ||
{ "val": "cpp" } | ||
] | ||
} | ||
} | ||
} |