Commit 71807217 authored by Stefan Behnel's avatar Stefan Behnel

improve safety of cname substring replacements for C++ string conversion...

improve safety of cname substring replacements for C++ string conversion functions: only replace first occurrence as there may be a user defined portion following
parent 1be32e5c
......@@ -11173,9 +11173,9 @@ class CoerceToPyTypeNode(CoercionNode):
func = arg_type.to_py_function
if arg_type.is_string or arg_type.is_cpp_string:
if self.type in (bytes_type, str_type, unicode_type):
func = func.replace("Object", self.type.name.title())
func = func.replace("Object", self.type.name.title(), 1)
elif self.type is bytearray_type:
func = func.replace("Object", "ByteArray")
func = func.replace("Object", "ByteArray", 1)
funccall = "%s(%s)" % (func, self.arg.result())
code.putln('%s = %s; %s' % (
......
......@@ -33,16 +33,16 @@ cdef extern from *:
cdef inline object {{cname}}(const string& s):
return __Pyx_PyObject_FromStringAndSize(s.data(), s.size())
@cname("{{cname.replace("PyObject", "PyUnicode")}}")
cdef inline object {{cname.replace("PyObject", "PyUnicode")}}(const string& s):
@cname("{{cname.replace("PyObject", "PyUnicode", 1)}}")
cdef inline object {{cname.replace("PyObject", "PyUnicode", 1)}}(const string& s):
return __Pyx_PyUnicode_FromStringAndSize(s.data(), s.size())
@cname("{{cname.replace("PyObject", "PyBytes")}}")
cdef inline object {{cname.replace("PyObject", "PyBytes")}}(const string& s):
@cname("{{cname.replace("PyObject", "PyBytes", 1)}}")
cdef inline object {{cname.replace("PyObject", "PyBytes", 1)}}(const string& s):
return __Pyx_PyBytes_FromStringAndSize(s.data(), s.size())
@cname("{{cname.replace("PyObject", "PyByteArray")}}")
cdef inline object {{cname.replace("PyObject", "PyByteArray")}}(const string& s):
@cname("{{cname.replace("PyObject", "PyByteArray", 1)}}")
cdef inline object {{cname.replace("PyObject", "PyByteArray", 1)}}(const string& s):
return __Pyx_PyByteArray_FromStringAndSize(s.data(), s.size())
......
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