summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2021-07-13 21:52:00 +0200
committerStefan Behnel <stefan_ml@behnel.de>2021-07-13 21:53:35 +0200
commit22891e074d0742a85aaa652560e3f9909e595c62 (patch)
treed817d463e86e9acfc48147c2064090a7e73dde5a
parenta46ed3f401b0f7520566cacd25261d612784b3a4 (diff)
parent06607884c9653da58c9c352dc9a76a3f1d4a02ad (diff)
downloadcython-22891e074d0742a85aaa652560e3f9909e595c62.tar.gz
Merge branch '0.29.x'
-rw-r--r--CHANGES.rst14
-rw-r--r--Cython/Includes/libcpp/string.pxd15
-rw-r--r--tests/run/cpp_stl_string.pyx32
3 files changed, 56 insertions, 5 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index a01a5460f..8be5874b3 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -738,11 +738,25 @@ Bugs fixed
C code if the module that imported from them does not use memory views.
Patch by David Woods. (Github issue :issue:`1415`)
+* Several declarations in ``libcpp.string`` were added and corrected.
+ Patch by Janek Bevendorff. (Github issue :issue:`4268`)
+
+* Pickling unbound Cython compiled methods failed.
+ Patch by Pierre Glaser. (Github issue :issue:`2972`)
+
+* The tracing code was adapted to work with CPython 3.10.
+
* The optimised ``in`` operator failed on unicode strings in Py3.9 and later
that were constructed from an external ``wchar_t`` source.
Also, related C compiler warnings about deprecated C-API usage were resolved.
(Github issue :issue:`3925`)
+* Some compiler crashes were resolved.
+ Patch by David Woods. (Github issues :issue:`4214`, :issue:`2811`)
+
+* An incorrect warning about 'unused' generator expressions was removed.
+ (GIthub issue :issue:`1699`)
+
* The attributes ``gen.gi_frame`` and ``coro.cr_frame`` of Cython compiled
generators and coroutines now return an actual frame object for introspection,
instead of ``None``.
diff --git a/Cython/Includes/libcpp/string.pxd b/Cython/Includes/libcpp/string.pxd
index b5c5c5ee1..a894144f1 100644
--- a/Cython/Includes/libcpp/string.pxd
+++ b/Cython/Includes/libcpp/string.pxd
@@ -7,6 +7,7 @@ cdef extern from "<string>" namespace "std::string" nogil:
cdef extern from "<string>" namespace "std" nogil:
cdef cppclass string:
+
cppclass iterator:
iterator()
char& operator*()
@@ -15,6 +16,7 @@ cdef extern from "<string>" namespace "std" nogil:
iterator operator--()
bint operator==(iterator)
bint operator!=(iterator)
+
cppclass reverse_iterator:
char& operator*()
iterator operator++()
@@ -27,8 +29,10 @@ cdef extern from "<string>" namespace "std" nogil:
bint operator>(reverse_iterator)
bint operator<=(reverse_iterator)
bint operator>=(reverse_iterator)
+
cppclass const_iterator(iterator):
pass
+
cppclass const_reverse_iterator(reverse_iterator):
pass
@@ -62,6 +66,7 @@ cdef extern from "<string>" namespace "std" nogil:
void reserve(size_t) except +
void clear()
bint empty()
+
iterator erase(iterator first, iterator last)
iterator erase(iterator p)
iterator erase(const_iterator first, const_iterator last)
@@ -90,11 +95,11 @@ cdef extern from "<string>" namespace "std" nogil:
void push_back(char c) except +
void pop_back()
- string& assign (const string& s) except +
- string& assign (const string& s, size_t subpos, size_t sublen) except +
- string& assign (const char* s, size_t n) except +
- string& assign (const char* s) except +
- string& assign (size_t n, char c) except +
+ string& assign(const string& s) except +
+ string& assign(const string& s, size_t subpos, size_t sublen) except +
+ string& assign(const char* s, size_t n) except +
+ string& assign(const char* s) except +
+ string& assign(size_t n, char c) except +
string& insert(size_t pos, const string& s, size_t subpos, size_t sublen) except +
string& insert(size_t pos, const string& s) except +
diff --git a/tests/run/cpp_stl_string.pyx b/tests/run/cpp_stl_string.pyx
index fb69a9dee..ff7757b08 100644
--- a/tests/run/cpp_stl_string.pyx
+++ b/tests/run/cpp_stl_string.pyx
@@ -406,6 +406,38 @@ def test_stof(char *a):
cdef string s = string(a)
return stof(s)
+def test_to_string(x):
+ """
+ >>> print(test_to_string(5))
+ si=5 sl=5 ss=5 sss=5
+ >>> print(test_to_string(-5))
+ si=-5 sl=-5 ss=5 sss=-5
+ """
+ si = to_string(<int>x).decode('ascii')
+ sl = to_string(<long>x).decode('ascii')
+ ss = to_string(<size_t>abs(x)).decode('ascii')
+ sss = to_string(<ssize_t>x).decode('ascii')
+ return f"si={si} sl={sl} ss={ss} sss={sss}"
+
+
+def test_stoi(char *a):
+ """
+ >>> test_stoi(b'5')
+ 5
+ """
+ cdef string s = string(a)
+ return stoi(s)
+
+
+def test_stof(char *a):
+ """
+ >>> test_stof(b'5.5')
+ 5.5
+ """
+ cdef string s = string(a)
+ return stof(s)
+
+
_WARNINGS = """
21:31: Cannot pass Python object as C++ data structure reference (string &), will pass by copy.
"""