diff options
author | Yu Feng <feyu@google.com> | 2021-05-18 01:02:25 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-18 10:02:25 +0200 |
commit | 505e90f9131ab2e0fc6a009c07e75c06885ac495 (patch) | |
tree | 71ff62674b12d1bfc7d5fb4ab1abfc11cbf3b896 /tests/compile | |
parent | 9b98c4b872b813bd9118c5abec905b9097dbbf6c (diff) | |
download | cython-505e90f9131ab2e0fc6a009c07e75c06885ac495.tar.gz |
Use std::move in c++ during yield context switch. (GH-4154)
When compiling pyarrow with cython 3.0 we get an error about the copy constructor of an object has been deleted on the generated context switch code.
Also make the "cpp_temp_assignment" test only run in C++11 since it is based on `std::move()`.
Diffstat (limited to 'tests/compile')
-rw-r--r-- | tests/compile/cpp_temp_assignment.pyx | 50 |
1 files changed, 40 insertions, 10 deletions
diff --git a/tests/compile/cpp_temp_assignment.pyx b/tests/compile/cpp_temp_assignment.pyx index 40a2cc671..296fedce9 100644 --- a/tests/compile/cpp_temp_assignment.pyx +++ b/tests/compile/cpp_temp_assignment.pyx @@ -1,9 +1,29 @@ -# tag: cpp +# tag: cpp,cpp11 # mode: compile cdef extern from *: """ - #if __cplusplus >= 201103L + 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() {} @@ -12,15 +32,13 @@ cdef extern from *: NoAssign& operator=(NoAssign&) = delete; NoAssign& operator=(NoAssign&&) { return *this; } void func() {} + NoAssignIterator begin() { + return NoAssignIterator(0); + } + NoAssignIterator end() { + return NoAssignIterator(2); + } }; - #else - // the test becomes meaningless - // (but just declare something to ensure it passes) - class NoAssign { - public: - void func() {} - }; - #endif NoAssign get_NoAssign_Py() { return NoAssign(); @@ -28,9 +46,17 @@ cdef extern from *: 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 * @@ -63,3 +89,7 @@ cdef class AssignToClassAttr: 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 |