Commit d929ac08 authored by Stefan Behnel's avatar Stefan Behnel

fix crash in Python object to C++ string conversion

--HG--
extra : amend_source : 6a5e7668208a89296264b05bbfe7640514318a1d
parent 9f01d288
......@@ -109,6 +109,8 @@ Bugs fixed
* Fixed a bug which prevented overriding const methods of C++ classes.
* Fixed a crash when converting Python objects to C++ strings fails.
Other changes
-------------
......
......@@ -7,7 +7,7 @@ cdef extern from *:
cdef cppclass string "std::string":
string()
string(char* c_str, size_t size)
cdef char* __Pyx_PyObject_AsStringAndSize(object, Py_ssize_t*)
cdef char* __Pyx_PyObject_AsStringAndSize(object, Py_ssize_t*) except NULL
@cname("{{cname}}")
cdef string {{cname}}(object o) except *:
......
......@@ -8,6 +8,17 @@ b_asdf = b'asdf'
b_asdg = b'asdg'
b_s = b's'
def test_conversion(py_obj):
"""
>>> test_conversion(b_asdf) == b_asdf or test_conversion(b_asdf)
True
>>> test_conversion(123) # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: expected ..., int found
"""
cdef string s = py_obj
return s
def test_indexing(char *py_str):
"""
>>> test_indexing(b_asdf)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment