summaryrefslogtreecommitdiff
path: root/tests/compile
diff options
context:
space:
mode:
Diffstat (limited to 'tests/compile')
-rw-r--r--tests/compile/branch_hints.pyx91
-rw-r--r--tests/compile/buildenv.pyx17
-rw-r--r--tests/compile/builtinbuffer.py1
-rw-r--r--tests/compile/c_directives.pyx2
-rw-r--r--tests/compile/cascmp.pyx17
-rw-r--r--tests/compile/cast_ctypedef_array_T518.pyx2
-rw-r--r--tests/compile/cdefemptysue.pyx43
-rw-r--r--tests/compile/cdefexternblock.pyx23
-rw-r--r--tests/compile/cimport_package_module_T4.pyx2
-rw-r--r--tests/compile/cimportfrom_T248.pyx2
-rw-r--r--tests/compile/complex_annotations.pyx7
-rw-r--r--tests/compile/complex_decorators.pyx10
-rw-r--r--tests/compile/const_decl.pyx15
-rw-r--r--tests/compile/cpp_enums.h11
-rw-r--r--tests/compile/cpp_enums.pyx27
-rw-r--r--tests/compile/cpp_nogil.pyx2
-rw-r--r--tests/compile/cpp_rvalue_reference_binding.pyx22
-rw-r--r--tests/compile/cpp_temp_assignment.pyx98
-rw-r--r--tests/compile/cpp_templates.pyx2
-rw-r--r--tests/compile/cppenum.pyx31
-rw-r--r--tests/compile/crunchytype.h5
-rw-r--r--tests/compile/crunchytype.pxd8
-rw-r--r--tests/compile/ctypedef_public_class_T355.pyx2
-rw-r--r--tests/compile/cython_compiled_folding.pxd1
-rw-r--r--tests/compile/cython_compiled_folding.py39
-rw-r--r--tests/compile/declarations.srctree2
-rw-r--r--tests/compile/ellipsis_T488.pyx2
-rw-r--r--tests/compile/excvalcheck.h6
-rw-r--r--tests/compile/excvaldecl.pyx8
-rw-r--r--tests/compile/find_pxd.srctree2
-rw-r--r--tests/compile/fromimport.pyx24
-rw-r--r--tests/compile/fromimport_star.pyx7
-rw-r--r--tests/compile/funcptr.pyx12
-rw-r--r--tests/compile/fused_buffers.pyx16
-rw-r--r--tests/compile/fused_no_numpy.pyx13
-rw-r--r--tests/compile/fused_redeclare_T3111.pyx17
-rw-r--r--tests/compile/fused_unused.pyx9
-rw-r--r--tests/compile/fused_wraparound.pyx22
-rw-r--r--tests/compile/nogil.h12
-rw-r--r--tests/compile/packed_structs.pyx (renamed from tests/compile/extern_packed_struct.pyx)5
-rw-r--r--tests/compile/posix_pxds.pyx54
-rw-r--r--tests/compile/publicapi_pxd_mix.pxd2
-rw-r--r--tests/compile/publicapi_pxd_mix.pyx2
-rw-r--r--tests/compile/pxd_mangling_names.srctree46
-rw-r--r--tests/compile/tree_assertions.pyx20
-rw-r--r--tests/compile/types_and_names.pyx13
-rw-r--r--tests/compile/volatile.pyx17
-rw-r--r--tests/compile/weakref_T276.pyx2
48 files changed, 650 insertions, 143 deletions
diff --git a/tests/compile/branch_hints.pyx b/tests/compile/branch_hints.pyx
new file mode 100644
index 000000000..e6bd0b5c3
--- /dev/null
+++ b/tests/compile/branch_hints.pyx
@@ -0,0 +1,91 @@
+# mode: compile
+# tag: if, unlikely
+
+cimport cython
+
+
+@cython.test_assert_path_exists(
+ "//IfClauseNode",
+ "//IfClauseNode[not(@branch_hint)]",
+)
+def if_simple(x):
+ if x:
+ x = 2
+
+
+@cython.test_assert_path_exists(
+ "//IfClauseNode",
+ "//IfClauseNode[not(@branch_hint)]",
+)
+def if_return(x):
+ if x:
+ return 1
+ raise TypeError()
+
+
+@cython.test_assert_path_exists(
+ "//IfClauseNode",
+ "//IfClauseNode[@branch_hint = 'unlikely']",
+)
+def if_raise_else(x):
+ if x:
+ raise TypeError()
+ else:
+ return 1
+
+
+@cython.test_assert_path_exists(
+ "//IfClauseNode",
+ "//IfClauseNode[@branch_hint = 'likely']",
+)
+def if_else_raise(x):
+ if x:
+ return 1
+ else:
+ raise TypeError()
+
+
+@cython.test_assert_path_exists(
+ "//IfClauseNode",
+ "//IfClauseNode[@branch_hint = 'unlikely']",
+)
+def if_raise_else_raise(x):
+ if x:
+ raise ValueError()
+ else:
+ raise TypeError()
+
+
+@cython.test_assert_path_exists(
+ "//IfClauseNode",
+ "//IfClauseNode[@branch_hint = 'unlikely']",
+)
+@cython.test_fail_if_path_exists(
+ "//IfClauseNode[@branch_hint = 'likely']",
+ "//IfClauseNode[not(@branch_hint)]",
+)
+def if_elif_raise_else_raise(x):
+ if x:
+ raise ValueError()
+ elif not x:
+ raise AttributeError()
+ else:
+ raise TypeError()
+
+
+@cython.test_assert_path_exists(
+ "//IfClauseNode",
+ "//IfClauseNode[@branch_hint = 'unlikely']",
+ "//IfClauseNode[@branch_hint = 'unlikely']//GILStatNode",
+)
+@cython.test_fail_if_path_exists(
+ "//IfClauseNode[@branch_hint = 'likely']",
+ "//IfClauseNode[not(@branch_hint)]",
+)
+cpdef int nogil_if_raise(int x) except -1 nogil:
+ if x:
+ raise TypeError()
+ elif not x:
+ raise ValueError()
+ else:
+ x = 2
diff --git a/tests/compile/buildenv.pyx b/tests/compile/buildenv.pyx
index f4c48ceca..0f06ccc71 100644
--- a/tests/compile/buildenv.pyx
+++ b/tests/compile/buildenv.pyx
@@ -34,8 +34,9 @@ cdef extern from *:
# Cython config
cdef int CYTHON_COMPILING_IN_CPYTHON
+ cdef int CYTHON_COMPILING_IN_LIMITED_API
cdef int CYTHON_COMPILING_IN_PYPY
- cdef int CYTHON_COMPILING_IN_PYSTON
+ cdef int CYTHON_COMPILING_IN_GRAAL
cdef int CYTHON_COMPILING_IN_NOGIL
cdef int CYTHON_USE_PYLONG_INTERNALS
cdef int CYTHON_USE_PYLIST_INTERNALS
@@ -43,6 +44,7 @@ cdef extern from *:
cdef int CYTHON_USE_UNICODE_WRITER
cdef int CYTHON_AVOID_BORROWED_REFS
cdef int CYTHON_ASSUME_SAFE_MACROS
+ cdef int CYTHON_USE_TYPE_SLOTS
cdef int CYTHON_UNPACK_METHODS
cdef int CYTHON_FAST_THREAD_STATE
cdef int CYTHON_FAST_PYCALL
@@ -77,8 +79,9 @@ Python {sys.version_info}
PY_VERSION_HEX 0x{PY_VERSION_HEX:X}
CYTHON_COMPILING_IN_CPYTHON {CYTHON_COMPILING_IN_CPYTHON}
+CYTHON_COMPILING_IN_LIMITED_API {CYTHON_COMPILING_IN_LIMITED_API}
CYTHON_COMPILING_IN_PYPY {CYTHON_COMPILING_IN_PYPY}
-CYTHON_COMPILING_IN_PYSTON {CYTHON_COMPILING_IN_PYSTON}
+CYTHON_COMPILING_IN_GRAAL {CYTHON_COMPILING_IN_GRAAL}
CYTHON_COMPILING_IN_NOGIL {CYTHON_COMPILING_IN_NOGIL}
CYTHON_USE_PYLONG_INTERNALS {CYTHON_USE_PYLONG_INTERNALS}
@@ -87,6 +90,7 @@ CYTHON_USE_UNICODE_INTERNALS {CYTHON_USE_UNICODE_INTERNALS}
CYTHON_USE_UNICODE_WRITER {CYTHON_USE_UNICODE_WRITER}
CYTHON_AVOID_BORROWED_REFS {CYTHON_AVOID_BORROWED_REFS}
CYTHON_ASSUME_SAFE_MACROS {CYTHON_ASSUME_SAFE_MACROS}
+CYTHON_USE_TYPE_SLOTS {CYTHON_USE_TYPE_SLOTS}
CYTHON_UNPACK_METHODS {CYTHON_UNPACK_METHODS}
CYTHON_FAST_THREAD_STATE {CYTHON_FAST_THREAD_STATE}
CYTHON_FAST_PYCALL {CYTHON_FAST_PYCALL}
@@ -109,6 +113,15 @@ SIZEOF_VOID_P {SIZEOF_VOID_P} ({sizeof(void*)})
SIZEOF_UINTPTR_T {SIZEOF_UINTPTR_T} ({sizeof(unsigned int *)})
SIZEOF_OFF_T {SIZEOF_OFF_T}
+Paths:
+sys.executable = {sys.executable}
+sys.exec_prefix = {sys.exec_prefix}
+sys.base_exec_prefix = {getattr(sys, 'base_exec_prefix', "")}
+sys.prefix = {sys.prefix}
+sys.path = {sys.path}
+PYTHONPATH (env) = {get_env('PYTHONPATH', '')}
+PYTHONHOME (env) = {get_env('PYTHONHOME', '')}
+
Distutils:
INCDIR = {sysconfig.get_python_inc()}
LIBS = {config_var('LIBS')}
diff --git a/tests/compile/builtinbuffer.py b/tests/compile/builtinbuffer.py
index c18ec1bf7..833fa9954 100644
--- a/tests/compile/builtinbuffer.py
+++ b/tests/compile/builtinbuffer.py
@@ -4,4 +4,3 @@ import cython
@cython.cclass
class BuiltinRef:
cython.declare(pybuf = 'Py_buffer')
-
diff --git a/tests/compile/c_directives.pyx b/tests/compile/c_directives.pyx
index 0ede90ba8..ee19e652f 100644
--- a/tests/compile/c_directives.pyx
+++ b/tests/compile/c_directives.pyx
@@ -2,6 +2,8 @@
# cython: boundscheck = False
# cython: ignoreme = OK
# cython: warn.undeclared = False
+# cython: test_assert_c_code_has = Generated by Cython
+# cython: test_fail_if_c_code_has = Generated by Python
# This testcase is most useful if you inspect the generated C file
diff --git a/tests/compile/cascmp.pyx b/tests/compile/cascmp.pyx
deleted file mode 100644
index c36997fbb..000000000
--- a/tests/compile/cascmp.pyx
+++ /dev/null
@@ -1,17 +0,0 @@
-# mode: compile
-
-cdef void foo():
- cdef int bool, int1=0, int2=0, int3=0, int4=0
- cdef object obj1, obj2, obj3, obj4
- obj1 = 1
- obj2 = 2
- obj3 = 3
- obj4 = 4
- bool = int1 < int2 < int3
- bool = obj1 < obj2 < obj3
- bool = int1 < int2 < obj3
- bool = obj1 < 2 < 3
- bool = obj1 < 2 < 3 < 4
- bool = int1 < (int2 == int3) < int4
-
-foo()
diff --git a/tests/compile/cast_ctypedef_array_T518.pyx b/tests/compile/cast_ctypedef_array_T518.pyx
index a62f4cf4c..6a52374c3 100644
--- a/tests/compile/cast_ctypedef_array_T518.pyx
+++ b/tests/compile/cast_ctypedef_array_T518.pyx
@@ -1,4 +1,4 @@
-# ticket: 518
+# ticket: t518
# mode: compile
cdef extern from "cast_ctypedef_array_T518_helper.h":
diff --git a/tests/compile/cdefemptysue.pyx b/tests/compile/cdefemptysue.pyx
new file mode 100644
index 000000000..1baf67d36
--- /dev/null
+++ b/tests/compile/cdefemptysue.pyx
@@ -0,0 +1,43 @@
+# mode: compile
+# tag: struct, union, enum, cdefextern
+
+cdef extern from *:
+ """
+ struct spam { int a; };
+ struct flat_spam { int a; };
+ typedef struct { int a; } flat_spam_type;
+
+ typedef union { int a; long b; } eggs;
+ typedef union { int a; long b; } flat_eggs;
+
+ enum ham { TOAST };
+ enum flat_ham { FLAT_TOAST };
+ """
+
+ cdef struct spam:
+ pass
+
+ cdef struct flat_spam: pass
+
+ ctypedef struct flat_spam_type: pass
+
+ ctypedef union eggs:
+ pass
+
+ ctypedef union flat_eggs: pass
+
+ cdef enum ham:
+ pass
+
+ cdef enum flat_ham: pass
+
+
+cdef extern spam s
+cdef extern flat_spam fs
+cdef extern flat_spam_type fst
+
+cdef extern eggs e
+cdef extern flat_eggs fe
+
+cdef extern ham h
+cdef extern flat_ham fh
diff --git a/tests/compile/cdefexternblock.pyx b/tests/compile/cdefexternblock.pyx
new file mode 100644
index 000000000..865a59345
--- /dev/null
+++ b/tests/compile/cdefexternblock.pyx
@@ -0,0 +1,23 @@
+# mode: compile
+# tag: struct, union, enum, cdefextern
+
+cdef extern from "cheese.h":
+
+ ctypedef int camembert
+
+ struct roquefort:
+ int x
+
+ char *swiss
+
+ void cheddar()
+
+ # FIXME: find a real declaration here.
+ #class external.runny [object runny_obj]:
+ # cdef int a
+ # def __init__(self):
+ # pass
+
+
+#cdef runny r = runny()
+#r.a = 42
diff --git a/tests/compile/cimport_package_module_T4.pyx b/tests/compile/cimport_package_module_T4.pyx
index 28403f122..717f0bf8f 100644
--- a/tests/compile/cimport_package_module_T4.pyx
+++ b/tests/compile/cimport_package_module_T4.pyx
@@ -1,4 +1,4 @@
-# ticket: 4
+# ticket: t4
# mode: compile
from a cimport b
diff --git a/tests/compile/cimportfrom_T248.pyx b/tests/compile/cimportfrom_T248.pyx
index 13796baf1..1be252f3c 100644
--- a/tests/compile/cimportfrom_T248.pyx
+++ b/tests/compile/cimportfrom_T248.pyx
@@ -1,4 +1,4 @@
-# ticket: 248
+# ticket: t248
# mode: compile
from ewing8 cimport (Foo,
diff --git a/tests/compile/complex_annotations.pyx b/tests/compile/complex_annotations.pyx
new file mode 100644
index 000000000..5d95611ac
--- /dev/null
+++ b/tests/compile/complex_annotations.pyx
@@ -0,0 +1,7 @@
+# mode: compile
+
+# Complex numbers defined in annotations weren't having their utility code imported directly
+# leading to compile-errors that the type wasn't defined. The test is intentionally minimal since
+# anything more thorough ends up creating the utility code
+cdef f(x: complex):
+ pass
diff --git a/tests/compile/complex_decorators.pyx b/tests/compile/complex_decorators.pyx
new file mode 100644
index 000000000..e8d65244d
--- /dev/null
+++ b/tests/compile/complex_decorators.pyx
@@ -0,0 +1,10 @@
+# mode: compile
+
+cimport cython
+
+# Complex numbers defined in "cython.locals" weren't having their utility code imported directly
+# leading to compile-errors that the type wasn't defined. The test is intentionally minimal since
+# anything more thorough ends up creating the utility code
+@cython.locals(x=complex)
+cdef f(x):
+ pass
diff --git a/tests/compile/const_decl.pyx b/tests/compile/const_decl.pyx
index 5424c8f90..c47f952df 100644
--- a/tests/compile/const_decl.pyx
+++ b/tests/compile/const_decl.pyx
@@ -1,12 +1,17 @@
# mode: compile
-cdef const_args(const int a, const int *b, const (int*) c, int *const d):
+cdef const_args(const int a, const int *b, const (int*) c, int *const d, int **const e, int *const *f):
print a
print b[0]
- b = NULL # OK, the pointer itself is not const
- c[0] = 4 # OK, the value is not const
- d[0] = 7 # OK, the value is not const
+ b = NULL # OK, the pointer itself is not const
+ c[0] = 4 # OK, the value is not const
+ d[0] = 7 # OK, the value is not const
+ e[0][0] = 1 # OK, the value is not const
+ e[0] = NULL # OK, the pointed pointer is not const
+ f[0][0] = 1 # OK, the value is not const
+ f = NULL # OK, the pointer is not const
def call_const_args(x):
cdef int k = x
- const_args(x, &k, &k, &k)
+ cdef int* arr = [x]
+ const_args(x, &k, &k, &k, &arr, &arr)
diff --git a/tests/compile/cpp_enums.h b/tests/compile/cpp_enums.h
deleted file mode 100644
index 4ea444ee4..000000000
--- a/tests/compile/cpp_enums.h
+++ /dev/null
@@ -1,11 +0,0 @@
-enum Enum1 {
- Item1,
- Item2
-};
-
-namespace Namespace1 {
- enum Enum2 {
- Item3,
- Item4
- };
-}
diff --git a/tests/compile/cpp_enums.pyx b/tests/compile/cpp_enums.pyx
deleted file mode 100644
index b738dee05..000000000
--- a/tests/compile/cpp_enums.pyx
+++ /dev/null
@@ -1,27 +0,0 @@
-# tag: cpp
-# mode: compile
-
-cdef extern from "cpp_enums.h":
- cdef enum Enum1:
- Item1
- Item2
-
-a = Item1
-b = Item2
-
-cdef Enum1 x, y
-x = Item1
-y = Item2
-
-cdef extern from "cpp_enums.h" namespace "Namespace1":
- cdef enum Enum2:
- Item3
- Item4
-
-c = Item3
-d = Item4
-
-cdef Enum2 z, w
-z = Item3
-w = Item4
-
diff --git a/tests/compile/cpp_nogil.pyx b/tests/compile/cpp_nogil.pyx
index 1007054dc..658dc37cb 100644
--- a/tests/compile/cpp_nogil.pyx
+++ b/tests/compile/cpp_nogil.pyx
@@ -19,5 +19,5 @@ with nogil:
# We can override nogil methods as with gil methods.
cdef cppclass WithGilSubclass(NoGilTest1):
- void doSomething() with gil:
+ void doSomething() noexcept with gil:
print "have the gil"
diff --git a/tests/compile/cpp_rvalue_reference_binding.pyx b/tests/compile/cpp_rvalue_reference_binding.pyx
new file mode 100644
index 000000000..492a950ac
--- /dev/null
+++ b/tests/compile/cpp_rvalue_reference_binding.pyx
@@ -0,0 +1,22 @@
+# tag: cpp, cpp11
+# mode: compile
+
+cdef extern from *:
+ """
+ template <typename T>
+ void accept(T&& x) { (void) x; }
+ """
+ cdef void accept[T](T&& x)
+
+cdef int make_int_py() except *:
+ # might raise Python exception (thus needs a temp)
+ return 1
+
+cdef int make_int_cpp() except +:
+ # might raise C++ exception (thus needs a temp)
+ return 1
+
+def test_func_arg():
+ # won't compile if move() isn't called on the temp:
+ accept(make_int_py())
+ accept(make_int_cpp())
diff --git a/tests/compile/cpp_temp_assignment.pyx b/tests/compile/cpp_temp_assignment.pyx
new file mode 100644
index 000000000..58ae39a70
--- /dev/null
+++ b/tests/compile/cpp_temp_assignment.pyx
@@ -0,0 +1,98 @@
+# tag: cpp,cpp11
+# mode: compile
+# tag: no-cpp-locals
+# TODO cpp_locals works fine with the standard library that comes with gcc11
+# but not with gcc8. Therefore disable the test for now
+
+cdef extern from *:
+ """
+ class NoAssignIterator {
+ public:
+ explicit NoAssignIterator(int pos) : pos_(pos) {}
+ NoAssignIterator(NoAssignIterator&) = delete;
+ NoAssignIterator(NoAssignIterator&&) {}
+ NoAssignIterator& operator=(NoAssignIterator&) = delete;
+ NoAssignIterator& operator=(NoAssignIterator&&) { return *this; }
+ // Default constructor of temp variable is needed by Cython
+ // as of 3.0a6.
+ NoAssignIterator() : pos_(0) {}
+ int operator*() {
+ return pos_;
+ }
+ NoAssignIterator operator++() {
+ return NoAssignIterator(pos_ + 1);
+ }
+ int operator!=(NoAssignIterator other) {
+ return pos_ != other.pos_;
+ }
+ int pos_;
+ };
+ class NoAssign {
+ public:
+ NoAssign() {}
+ NoAssign(NoAssign&) = delete;
+ NoAssign(NoAssign&&) {}
+ NoAssign& operator=(NoAssign&) = delete;
+ NoAssign& operator=(NoAssign&&) { return *this; }
+ void func() {}
+ NoAssignIterator begin() {
+ return NoAssignIterator(0);
+ }
+ NoAssignIterator end() {
+ return NoAssignIterator(2);
+ }
+ };
+
+ NoAssign get_NoAssign_Py() {
+ return NoAssign();
+ }
+ NoAssign get_NoAssign_Cpp() {
+ return NoAssign();
+ }
+
+ """
+ cdef cppclass NoAssignIterator:
+ int operator*()
+ NoAssignIterator operator++()
+ int operator!=(NoAssignIterator)
+
+ cdef cppclass NoAssign:
+ void func()
+ NoAssignIterator begin()
+ NoAssignIterator end()
+
+ # might raise Python exception (thus needs a temp)
+ NoAssign get_NoAssign_Py() except *
+ # might raise C++ exception (thus needs a temp)
+ NoAssign get_NoAssign_Cpp() except +
+
+cdef internal_cpp_func(NoAssign arg):
+ pass
+
+def test_call_to_function():
+ # will fail to compile if move constructors aren't used
+ internal_cpp_func(get_NoAssign_Py())
+ internal_cpp_func(get_NoAssign_Cpp())
+
+def test_assignment_to_name():
+ # will fail if move constructors aren't used
+ cdef NoAssign value
+ value = get_NoAssign_Py()
+ value = get_NoAssign_Cpp()
+
+def test_assignment_to_scope():
+ cdef NoAssign value
+ value = get_NoAssign_Py()
+ value = get_NoAssign_Cpp()
+ def inner():
+ value.func()
+
+cdef class AssignToClassAttr:
+ cdef NoAssign attr
+ def __init__(self):
+ self.attr = get_NoAssign_Py()
+ self.attr = get_NoAssign_Cpp()
+
+def test_generator_cpp_iterator_as_temp():
+ for i in get_NoAssign_Py():
+ yield i
diff --git a/tests/compile/cpp_templates.pyx b/tests/compile/cpp_templates.pyx
index cab981e38..7952a1610 100644
--- a/tests/compile/cpp_templates.pyx
+++ b/tests/compile/cpp_templates.pyx
@@ -1,6 +1,6 @@
# tag: cpp
# mode: compile
-# ticket: 767
+# ticket: t767
cdef extern from "templates.h":
cdef cppclass TemplateTest1[T]:
diff --git a/tests/compile/cppenum.pyx b/tests/compile/cppenum.pyx
new file mode 100644
index 000000000..8431ac83b
--- /dev/null
+++ b/tests/compile/cppenum.pyx
@@ -0,0 +1,31 @@
+# mode: compile
+# tag: cpp,cpp11
+
+
+cpdef enum class Spam:
+ a, b
+ c
+ d
+ e
+ f = 42
+
+
+cpdef enum class Cheese(unsigned int):
+ x = 1
+ y = 2
+
+
+cdef enum struct parrot_state:
+ alive = 1
+ dead = 0
+
+
+cdef void eggs():
+ cdef Spam s1
+ s1 = Spam.a
+ s2 = Spam.b
+
+ cdef Cheese c1
+ c1 = Cheese.x
+
+eggs()
diff --git a/tests/compile/crunchytype.h b/tests/compile/crunchytype.h
deleted file mode 100644
index 6ea0e37c0..000000000
--- a/tests/compile/crunchytype.h
+++ /dev/null
@@ -1,5 +0,0 @@
-
-struct CrunchyType {
- int number;
- PyObject* string;
-};
diff --git a/tests/compile/crunchytype.pxd b/tests/compile/crunchytype.pxd
index c03e38dad..c1f2b555b 100644
--- a/tests/compile/crunchytype.pxd
+++ b/tests/compile/crunchytype.pxd
@@ -1,4 +1,10 @@
-cdef extern from "crunchytype.h":
+cdef extern from *:
+ """
+ struct CrunchyType {
+ int number;
+ PyObject* string;
+ };
+ """
cdef class crunchytype.Crunchy [ object CrunchyType ]:
cdef int number
cdef object string
diff --git a/tests/compile/ctypedef_public_class_T355.pyx b/tests/compile/ctypedef_public_class_T355.pyx
index 505f9d67f..ceb2d65e4 100644
--- a/tests/compile/ctypedef_public_class_T355.pyx
+++ b/tests/compile/ctypedef_public_class_T355.pyx
@@ -1,4 +1,4 @@
-# ticket: 355
+# ticket: t355
# mode: compile
ctypedef public class Time [type MyTime_Type, object MyTimeObject]:
diff --git a/tests/compile/cython_compiled_folding.pxd b/tests/compile/cython_compiled_folding.pxd
new file mode 100644
index 000000000..4c85d4311
--- /dev/null
+++ b/tests/compile/cython_compiled_folding.pxd
@@ -0,0 +1 @@
+from libc.math cimport sin, cos, sqrt, tan, log
diff --git a/tests/compile/cython_compiled_folding.py b/tests/compile/cython_compiled_folding.py
new file mode 100644
index 000000000..047b61689
--- /dev/null
+++ b/tests/compile/cython_compiled_folding.py
@@ -0,0 +1,39 @@
+# mode: compile
+
+# libc sin, cos and sqrt cimported in the pxd file
+
+import cython
+from cython import compiled
+
+if not cython.compiled:
+ from math import sin
+
+if cython.compiled:
+ pass
+else:
+ from math import cos
+
+if "aa" == "bb":
+ pass
+elif cython.compiled:
+ pass
+elif True:
+ from math import sqrt
+
+if "aa" == "bb":
+ pass
+elif compiled:
+ pass
+else:
+ from math import tan
+
+# log10 isn't defined in the pxd file
+from math import log10
+
+@cython.test_fail_if_path_exists("//FromImportStatNode//ImportNode")
+@cython.test_assert_path_exists("//AddNode")
+def import_log(x, y):
+ if compiled:
+ return x+y
+ else:
+ from math import log
diff --git a/tests/compile/declarations.srctree b/tests/compile/declarations.srctree
index babf2e4e3..bfbbcd4b3 100644
--- a/tests/compile/declarations.srctree
+++ b/tests/compile/declarations.srctree
@@ -40,7 +40,7 @@ cdef extern int a(int[][3], int[][3][5])
cdef void f():
cdef void *p=NULL
global ifnp, cpa
- ifnp = <int (*)()>p
+ ifnp = <int (*)() noexcept>p
cdef char *g():
pass
diff --git a/tests/compile/ellipsis_T488.pyx b/tests/compile/ellipsis_T488.pyx
index d90d21634..804b18497 100644
--- a/tests/compile/ellipsis_T488.pyx
+++ b/tests/compile/ellipsis_T488.pyx
@@ -1,4 +1,4 @@
-# ticket: 488
+# ticket: t488
# mode: compile
#from ... import foo
diff --git a/tests/compile/excvalcheck.h b/tests/compile/excvalcheck.h
index 4c92acd2b..ba7a760e1 100644
--- a/tests/compile/excvalcheck.h
+++ b/tests/compile/excvalcheck.h
@@ -1,12 +1,6 @@
-#ifdef __cplusplus
-extern "C" {
-#endif
extern DL_EXPORT(int) spam(void);
extern DL_EXPORT(void) grail(void);
extern DL_EXPORT(char *)tomato(void);
-#ifdef __cplusplus
-}
-#endif
int spam(void) {return 0;}
void grail(void) {return;}
diff --git a/tests/compile/excvaldecl.pyx b/tests/compile/excvaldecl.pyx
index 06af71ce0..63f3c65dc 100644
--- a/tests/compile/excvaldecl.pyx
+++ b/tests/compile/excvaldecl.pyx
@@ -18,17 +18,9 @@ cdef int brian() except? 0:
cdef int silly() except -1:
pass
-cdef int not_so_silly() noexcept:
- pass
-
-cdef int not_so_silly_and_gilless() noexcept nogil:
- pass
-
spam()
eggs()
grail()
tomato()
brian()
silly()
-not_so_silly()
-not_so_silly_and_gilless()
diff --git a/tests/compile/find_pxd.srctree b/tests/compile/find_pxd.srctree
index 75d2765c9..23fc5c5c7 100644
--- a/tests/compile/find_pxd.srctree
+++ b/tests/compile/find_pxd.srctree
@@ -41,7 +41,7 @@ ctypedef int my_type
######## path/numpy/__init__.pxd ########
-# gh-2905: This should be found before Cython/Inlude/numpy/__init__.pxd
+# gh-2905: This should be found before Cython/Includes/numpy/__init__.pxd
ctypedef int my_type
diff --git a/tests/compile/fromimport.pyx b/tests/compile/fromimport.pyx
index 46f7b5442..e84b26a97 100644
--- a/tests/compile/fromimport.pyx
+++ b/tests/compile/fromimport.pyx
@@ -6,10 +6,34 @@ def f():
from spam import eggs as ova
from . import spam
from ... import spam
+ from .. . import spam
+ from . .. import spam
+ from . . . import spam
from .. import spam, foo
+ from . . import spam, foo
from ... import spam, foobar
+ from .. . import spam, foobar
+ from . .. import spam, foobar
+ from . . . import spam, foobar
from .spam import foo
+ from . spam import foo
from ...spam import foo, bar
+ from .. . spam import foo, bar
+ from . .. spam import foo, bar
+ from . . . spam import foo, bar
from ...spam.foo import bar
+ from ... spam.foo import bar
+ from .. . spam.foo import bar
+ from . .. spam.foo import bar
+ from . . . spam.foo import bar
from ...spam.foo import foo, bar
+ from ... spam.foo import foo, bar
+ from .. . spam.foo import foo, bar
+ from . .. spam.foo import foo, bar
+ from . . . spam.foo import foo, bar
from ...spam.foo import (foo, bar)
+ from ... spam.foo import (foo, bar)
+ from .. . spam.foo import (foo, bar)
+ from .. . spam.foo import (foo, bar)
+ from . .. spam.foo import (foo, bar)
+ from . . . spam.foo import (foo, bar)
diff --git a/tests/compile/fromimport_star.pyx b/tests/compile/fromimport_star.pyx
index 6c19476b7..80542dddb 100644
--- a/tests/compile/fromimport_star.pyx
+++ b/tests/compile/fromimport_star.pyx
@@ -2,5 +2,12 @@
from spam import *
from ...spam.foo import *
+from ... spam.foo import *
+from .. . spam.foo import *
+from . . . spam.foo import *
+from . .. spam.foo import *
from . import *
from ... import *
+from .. . import *
+from . .. import *
+from . . . import *
diff --git a/tests/compile/funcptr.pyx b/tests/compile/funcptr.pyx
deleted file mode 100644
index 504238358..000000000
--- a/tests/compile/funcptr.pyx
+++ /dev/null
@@ -1,12 +0,0 @@
-# mode: compile
-
-cdef int grail():
- cdef int (*spam)()
- spam = &grail
- spam = grail
- spam()
-
-ctypedef int funcptr_t()
-
-cdef inline funcptr_t* dummy():
- return &grail
diff --git a/tests/compile/fused_buffers.pyx b/tests/compile/fused_buffers.pyx
new file mode 100644
index 000000000..73b0315ed
--- /dev/null
+++ b/tests/compile/fused_buffers.pyx
@@ -0,0 +1,16 @@
+# mode: compile
+
+# cython: test_assert_c_code_has = __Pyx_ImportNumPyArrayTypeIfAvailable
+# cython: test_assert_c_code_has = ndarray
+
+# counterpart test to fused_no_numpy - buffer types are compared against Numpy
+# dtypes as a quick test. fused_no_numpy tests that the mechanism isn't
+# accidentally generated, while this just confirms that the same mechanism is
+# still in use
+
+ctypedef fused IntOrFloat:
+ int
+ float
+
+def f(IntOrFloat[:] x):
+ return x
diff --git a/tests/compile/fused_no_numpy.pyx b/tests/compile/fused_no_numpy.pyx
new file mode 100644
index 000000000..efb49c322
--- /dev/null
+++ b/tests/compile/fused_no_numpy.pyx
@@ -0,0 +1,13 @@
+# mode: compile
+
+# cython: test_fail_if_c_code_has = __Pyx_ImportNumPyArrayTypeIfAvailable
+
+ctypedef fused IntOrFloat:
+ int
+ float
+
+# This function does not use buffers so has no reason to import numpy to
+# look up dtypes. fused_buffers.pyx is the corresponding test for the case
+# where numpy is imported
+def f(IntOrFloat x):
+ return x
diff --git a/tests/compile/fused_redeclare_T3111.pyx b/tests/compile/fused_redeclare_T3111.pyx
index c7064e7c0..53f087717 100644
--- a/tests/compile/fused_redeclare_T3111.pyx
+++ b/tests/compile/fused_redeclare_T3111.pyx
@@ -22,10 +22,15 @@ def foo(dtype_t[:] a, dtype_t_out[:, :] b):
# "__pyxutil:16:4: '___pyx_npy_uint8' redeclared". The remaining warnings are
# unrelated to this test.
_WARNINGS = """
-20:10: 'cpdef_method' redeclared
-31:10: 'cpdef_cname_method' redeclared
-448:72: Argument evaluation order in C function call is undefined and may not be as expected
-448:72: Argument evaluation order in C function call is undefined and may not be as expected
-751:34: Argument evaluation order in C function call is undefined and may not be as expected
-751:34: Argument evaluation order in C function call is undefined and may not be as expected
+# cpdef redeclaration bug, from TestCythonScope.pyx
+25:10: 'cpdef_method' redeclared
+36:10: 'cpdef_cname_method' redeclared
+
+# from MemoryView.pyx
+980:29: Ambiguous exception value, same as default return value: 0
+980:29: Ambiguous exception value, same as default return value: 0
+1021:46: Ambiguous exception value, same as default return value: 0
+1021:46: Ambiguous exception value, same as default return value: 0
+1111:29: Ambiguous exception value, same as default return value: 0
+1111:29: Ambiguous exception value, same as default return value: 0
"""
diff --git a/tests/compile/fused_unused.pyx b/tests/compile/fused_unused.pyx
new file mode 100644
index 000000000..9aac0b7fb
--- /dev/null
+++ b/tests/compile/fused_unused.pyx
@@ -0,0 +1,9 @@
+# mode: compile
+# tag: fused
+
+# This previously lead to a crash due to an empty module body.
+
+ctypedef fused cinteger:
+ int
+ long
+ Py_ssize_t
diff --git a/tests/compile/fused_wraparound.pyx b/tests/compile/fused_wraparound.pyx
new file mode 100644
index 000000000..e9facf9c1
--- /dev/null
+++ b/tests/compile/fused_wraparound.pyx
@@ -0,0 +1,22 @@
+# mode: compile
+# tag: fused, werror
+
+"""
+Very short test for https://github.com/cython/cython/issues/3492
+(Needs its own file since werror fails on the main fused-test files)
+wraparound and boundscheck directives shouldn't break the fused
+dispatcher function
+"""
+
+cimport cython
+
+ctypedef fused fused_t:
+ str
+ int
+ long
+ complex
+
+@cython.wraparound(False)
+@cython.boundscheck(False)
+def func(fused_t a, cython.floating b):
+ return a, b
diff --git a/tests/compile/nogil.h b/tests/compile/nogil.h
index 42878109b..764a3fc8a 100644
--- a/tests/compile/nogil.h
+++ b/tests/compile/nogil.h
@@ -1,25 +1,13 @@
-#ifdef __cplusplus
-extern "C" {
-#endif
extern DL_EXPORT(void) e1(void);
extern DL_EXPORT(int*) e2(void);
-#ifdef __cplusplus
-}
-#endif
void e1(void) {return;}
int* e2(void) {return 0;}
-#ifdef __cplusplus
-extern "C" {
-#endif
extern DL_EXPORT(PyObject *) g(PyObject*);
extern DL_EXPORT(void) g2(PyObject*);
-#ifdef __cplusplus
-}
-#endif
PyObject *g(PyObject* o) {if (o) {}; return 0;}
void g2(PyObject* o) {if (o) {}; return;}
diff --git a/tests/compile/extern_packed_struct.pyx b/tests/compile/packed_structs.pyx
index 6df4d20d0..6e722b46d 100644
--- a/tests/compile/extern_packed_struct.pyx
+++ b/tests/compile/packed_structs.pyx
@@ -3,3 +3,8 @@
cdef extern from *:
cdef packed struct MyStruct:
char a
+
+cdef public packed struct PublicStruct:
+ int a
+ unsigned char b
+ int c
diff --git a/tests/compile/posix_pxds.pyx b/tests/compile/posix_pxds.pyx
index f83f41d32..e5862b666 100644
--- a/tests/compile/posix_pxds.pyx
+++ b/tests/compile/posix_pxds.pyx
@@ -1,19 +1,33 @@
# tag: posix
# mode: compile
+# This file is generated by `Tools/gen_tests_for_posix_pxds.py`.
+
cimport posix
-cimport posix.unistd
-from posix cimport unistd
-from posix.unistd cimport *
+cimport posix.dlfcn
+from posix cimport dlfcn
+from posix.dlfcn cimport *
cimport posix.fcntl
from posix cimport fcntl
-from posix.fcntl cimport *
+from posix.fcntl cimport *
-cimport posix.types
-from posix cimport types
-from posix.types cimport *
+cimport posix.ioctl
+from posix cimport ioctl
+from posix.ioctl cimport *
+
+cimport posix.mman
+from posix cimport mman
+from posix.mman cimport *
+
+cimport posix.resource
+from posix cimport resource
+from posix.resource cimport *
+
+cimport posix.select
+from posix cimport select
+from posix.select cimport *
cimport posix.signal
from posix cimport signal
@@ -31,22 +45,26 @@ cimport posix.stdlib
from posix cimport stdlib
from posix.stdlib cimport *
+cimport posix.strings
+from posix cimport strings
+from posix.strings cimport *
+
cimport posix.time
from posix cimport time
from posix.time cimport *
-cimport posix.resource
-from posix cimport resource
-from posix.resource cimport *
+cimport posix.types
+from posix cimport types
+from posix.types cimport *
+
+cimport posix.uio
+from posix cimport uio
+from posix.uio cimport *
+
+cimport posix.unistd
+from posix cimport unistd
+from posix.unistd cimport *
cimport posix.wait
from posix cimport wait
from posix.wait cimport *
-
-cimport posix.mman
-from posix cimport mman
-from posix.mman cimport *
-
-cimport posix.dlfcn
-from posix cimport dlfcn
-from posix.dlfcn cimport *
diff --git a/tests/compile/publicapi_pxd_mix.pxd b/tests/compile/publicapi_pxd_mix.pxd
index 09452f116..414274d45 100644
--- a/tests/compile/publicapi_pxd_mix.pxd
+++ b/tests/compile/publicapi_pxd_mix.pxd
@@ -61,7 +61,7 @@ cdef public api void bar3()
cdef inline void* spam (object o) except NULL: return NULL
cdef void* spam0(object o) except NULL
cdef public void* spam1(object o) except NULL
-cdef api void* spam2(object o) nogil except NULL
+cdef api void* spam2(object o) except NULL nogil
cdef public api void* spam3(object o) except NULL with gil
# --
diff --git a/tests/compile/publicapi_pxd_mix.pyx b/tests/compile/publicapi_pxd_mix.pyx
index 588f6b79c..dd748053f 100644
--- a/tests/compile/publicapi_pxd_mix.pyx
+++ b/tests/compile/publicapi_pxd_mix.pyx
@@ -15,7 +15,7 @@ cdef public api void bar3(): pass
cdef void* spam0(object o) except NULL: return NULL
cdef public void* spam1(object o) except NULL: return NULL
-cdef api void* spam2(object o) nogil except NULL: return NULL
+cdef api void* spam2(object o) except NULL nogil: return NULL
cdef public api void* spam3(object o) except NULL with gil: return NULL
cdef int i0 = 0 # XXX This should not be required!
diff --git a/tests/compile/pxd_mangling_names.srctree b/tests/compile/pxd_mangling_names.srctree
new file mode 100644
index 000000000..3797fc0f9
--- /dev/null
+++ b/tests/compile/pxd_mangling_names.srctree
@@ -0,0 +1,46 @@
+# mode: compile
+# ticket: 2940
+
+PYTHON setup.py build_ext --inplace
+PYTHON -c "import a; a.test()"
+
+######## setup.py ########
+
+from Cython.Build import cythonize
+from Cython.Distutils.extension import Extension
+from distutils.core import setup
+
+setup(
+ ext_modules=cythonize([Extension("a", ["a.py", "b.c"])]),
+)
+
+######## a.pxd ########
+
+cdef public int foo()
+
+cdef extern from "b.h":
+ cpdef int bar()
+
+######## a.py ########
+
+def foo():
+ return 42
+
+def test():
+ assert bar() == 42
+
+######## b.h ########
+
+#ifndef B_H
+#define B_H
+
+int bar();
+
+#endif
+
+######## b.c ########
+
+#include "a.h"
+
+int bar() { return foo(); }
+
diff --git a/tests/compile/tree_assertions.pyx b/tests/compile/tree_assertions.pyx
new file mode 100644
index 000000000..e311bfd25
--- /dev/null
+++ b/tests/compile/tree_assertions.pyx
@@ -0,0 +1,20 @@
+# mode: compile
+
+# This is a sort of meta test - to test the functionality of "test_assert_path_exists"
+
+cimport cython
+
+@cython.test_assert_path_exists("//ReturnStatNode")
+def not_in_inner_compiler_directives():
+ # used to fail because ReturnStatNode wasn't in *this* CompilerDirectivesNode
+ with cython.boundscheck(False):
+ pass
+ return 1 # should pass
+
+@cython.test_assert_path_exists("//ReturnStatNode")
+def in_inner_compiler_directives():
+ # used to fail because ReturnStatNode wasn't in *this* CompilerDirectivesNode
+ with cython.boundscheck(False):
+ return 1
+
+# it's hard to come up with a corresponding test for fail_if_path_exists..
diff --git a/tests/compile/types_and_names.pyx b/tests/compile/types_and_names.pyx
index 8ded94e4d..2637d4ba6 100644
--- a/tests/compile/types_and_names.pyx
+++ b/tests/compile/types_and_names.pyx
@@ -23,3 +23,16 @@ cdef A a
foo(2, 3, [], [], P, P, &P)
a.point("something", 3, "anything", [], "an object", P, &P)
+
+# Test that internally generated names do not conflict.
+cdef class A_spec:
+ pass
+
+cdef class A_members:
+ pass
+
+cdef class A_methods:
+ pass
+
+cdef class A_slots:
+ pass
diff --git a/tests/compile/volatile.pyx b/tests/compile/volatile.pyx
new file mode 100644
index 000000000..d69d8b355
--- /dev/null
+++ b/tests/compile/volatile.pyx
@@ -0,0 +1,17 @@
+# mode: compile
+
+cdef volatile int x = 1
+
+cdef const volatile char* greeting1 = "hello world"
+cdef volatile const char* greeting2 = "goodbye"
+
+
+cdef extern from "stdlib.h":
+ volatile void* malloc(size_t)
+
+cdef volatile long* test(volatile size_t s):
+ cdef volatile long* arr = <long*><volatile long*>malloc(s)
+ return arr
+
+
+test(64)
diff --git a/tests/compile/weakref_T276.pyx b/tests/compile/weakref_T276.pyx
index d56f67303..7fbc52819 100644
--- a/tests/compile/weakref_T276.pyx
+++ b/tests/compile/weakref_T276.pyx
@@ -1,4 +1,4 @@
-# ticket: 276
+# ticket: t276
# mode: compile
__doc__ = u"""