c++ - Python 3.3 C string handling (wchar_t vs char) -
i'm trying embed python 3.3 in our c++ project. python 3.3 seems have introduced utf-8 preferred storage, pep 393: "the specification chooses utf-8 recommended way of exposing strings c code."
i wrote initialization code, seems simple , intuitive:
#include <python.h> #include "log.h" void python_init(const char *program_name) { if (not py_isinitialized()) { py_setprogramname(program_name); py_initialize(); const char *py_version = py_getversion(); log::msg("initialized python %s", py_version); } }
but compiling fails:
/home/jj/devel/openage/src/engine/python.cpp:13:3: error: no matching function call 'py_setprogramname' py_setprogramname(program_name); ^~~~~~~~~~~~~~~~~ /usr/include/python3.3/pythonrun.h:25:18: note: candidate function not viable: no known conversion 'const char *' 'wchar_t *' 1st argument pyapi_func(void) py_setprogramname(wchar_t *); ^
so yeah, need wchar_t *
here, don't see reason why char *
not job here.
what best practice here? convert char *
wchar *
, deal locales (mbstowcs), introduce unnecessary dynamic memory allocs?
also, if python decided go wchar
entirely, why py_getversion()
return char *
expected it?
i found similar question python <3.3 , hope python 3.3 different (pep 393?).
the code has cross-platform capable.
=> what's fast , efficient solution pass c strings (char *
) python 3.3?
// convert sequence of strings array of wchar pointers pywintypes_export void pywinobject_freewchararray(lpwstr *wchars, dword str_cnt);
can use this...?
Comments
Post a Comment