Commit 1be32e5c authored by Stefan Behnel's avatar Stefan Behnel

undo C++ to-py helper functions rewrite as it lost the ability to extend the...

undo C++ to-py helper functions rewrite as it lost the ability to extend the set of string-ishly convertible types
parent e5e30b97
......@@ -3075,12 +3075,7 @@ class CppClassType(CType):
def create_to_py_utility_code(self, env):
if self.to_py_function is not None:
return True
elif self.cname in cpp_string_conversions:
env.use_utility_code(UtilityCode.load_cached("CppStringToPy", "CppSupport.cpp"))
# "PyObject" prefix gets specialised by explicit type casts in CoerceToPyTypeNode
self.to_py_function = '__Pyx_PyObject_FromStlString'
return True
elif self.cname in builtin_cpp_conversions:
if self.cname in builtin_cpp_conversions or self.cname in cpp_string_conversions:
X = "XYZABC"
tags = []
declarations = ["cdef extern from *:"]
......@@ -3094,8 +3089,14 @@ class CppClassType(CType):
declarations.append(
" cdef object %s_to_py '%s' (%s)" % (
X[ix], T.to_py_function, X[ix]))
cls = self.cname[5:]
cname = "__pyx_convert_%s_to_py_%s" % (cls, "____".join(tags))
if self.cname in cpp_string_conversions:
cls = 'string'
prefix = 'PyObject_' # gets specialised by explicit type casts in CoerceToPyTypeNode
tags = self.cname.replace(':', '_'),
else:
cls = self.cname[5:]
prefix = ''
cname = "__pyx_convert_%s%s_to_py_%s" % (prefix, cls, "____".join(tags))
context = {
'template_type_declarations': '\n'.join(declarations),
'cname': cname,
......
......@@ -16,6 +16,36 @@ cdef string {{cname}}(object o) except *:
return string(data, length)
#################### string.to_py ####################
#cimport cython
#from libcpp.string cimport string
cdef extern from *:
cdef cppclass string "{{type}}":
char* data()
size_t size()
cdef object __Pyx_PyObject_FromStringAndSize(char*, size_t)
cdef object __Pyx_PyBytes_FromStringAndSize(char*, size_t)
cdef object __Pyx_PyByteArray_FromStringAndSize(char*, size_t)
cdef object __Pyx_PyUnicode_FromStringAndSize(char*, size_t)
@cname("{{cname}}")
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):
return __Pyx_PyUnicode_FromStringAndSize(s.data(), s.size())
@cname("{{cname.replace("PyObject", "PyBytes")}}")
cdef inline object {{cname.replace("PyObject", "PyBytes")}}(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):
return __Pyx_PyByteArray_FromStringAndSize(s.data(), s.size())
#################### vector.from_py ####################
{{template_type_declarations}}
......
......@@ -44,29 +44,3 @@ static void __Pyx_CppExn2PyErr() {
}
}
#endif
/////////////// CppStringToPy.proto ///////////////
static CYTHON_INLINE PyObject *__Pyx_PyObject_FromStlString(std::string const &s);
static CYTHON_INLINE PyObject *__Pyx_PyUnicode_FromStlString(std::string const &s);
static CYTHON_INLINE PyObject *__Pyx_PyBytes_FromStlString(std::string const &s);
static CYTHON_INLINE PyObject *__Pyx_PyByteArray_FromStlString(std::string const &s);
/////////////// CppStringToPy ///////////////
static CYTHON_INLINE PyObject *__Pyx_PyObject_FromStlString(std::string const &s) {
return __Pyx_PyObject_FromStringAndSize(s.data(), s.size());
}
static CYTHON_INLINE PyObject *__Pyx_PyUnicode_FromStlString(std::string const &s) {
return __Pyx_PyUnicode_FromStringAndSize(s.data(), s.size());
}
static CYTHON_INLINE PyObject *__Pyx_PyBytes_FromStlString(std::string const &s) {
return __Pyx_PyBytes_FromStringAndSize(s.data(), s.size());
}
static CYTHON_INLINE PyObject *__Pyx_PyByteArray_FromStlString(std::string const &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