Commit ea071f25 authored by Stefan Behnel's avatar Stefan Behnel

factor out redundancy in std::string -> Python object helper code

parent 76254d22
......@@ -24,31 +24,15 @@ 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_PyStr_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", 1)}}")
cdef inline object {{cname.replace("PyObject", "PyUnicode", 1)}}(const string& s):
return __Pyx_PyUnicode_FromStringAndSize(s.data(), s.size())
@cname("{{cname.replace("PyObject", "PyStr", 1)}}")
cdef inline object {{cname.replace("PyObject", "PyStr", 1)}}(const string& s):
return __Pyx_PyStr_FromStringAndSize(s.data(), s.size())
@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())
{{for py_type in ['PyObject', 'PyUnicode', 'PyStr', 'PyBytes', 'PyByteArray']}}
cdef extern from *:
cdef object __Pyx_{{py_type}}_FromStringAndSize(char*, size_t)
@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())
@cname("{{cname.replace("PyObject", py_type, 1)}}")
cdef inline object {{cname.replace("PyObject", py_type, 1)}}(const string& s):
return __Pyx_{{py_type}}_FromStringAndSize(s.data(), s.size())
{{endfor}}
#################### vector.from_py ####################
......
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