开发者

Swig binding for Python using UCS-4

开发者 https://www.devze.com 2023-03-28 11:48 出处:网络
Does anyone know if there is a way to make SWIG encode strings as UCS-4 for Python? The SWIG documentation states that this may be possible using typemaps, but does not provide any other details or ex

Does anyone know if there is a way to make SWIG encode strings as UCS-4 for Python? The SWIG documentation states that this may be possible using typemaps, but does not provide any other details or examples.

For context, I'm working on extending the Blender 3D software with a set of Python scripts. We need 开发者_JAVA百科to interface these scripts with a variety of robotics software, we do this using SWIG to compile Python libraries. Blender uses its own Python 3.2 precompiled with the --with-wide-unicode option, so it uses UCS-4 unicode strings. However, by defatult SWIG encodes strings as UCS-2, and so when interfacing with Blender I always get an error along the lines of: "undefined symbol: PyUnicodeUCS2_*".


This is from the SWIG docs, maybe you have seen this:

At this time, SWIG provides limited support for Unicode and wide-character strings (the C wchar_t type). Some languages provide typemaps for wchar_t, but bear in mind these might not be portable across different operating systems. This is a delicate topic that is poorly understood by many programmers and not implemented in a consistent manner across languages. For those scripting languages that provide Unicode support, Unicode strings are often available in an 8-bit representation such as UTF-8 that can be mapped to the char * type (in which case the SWIG interface will probably work). If the program you are wrapping uses Unicode, there is no guarantee that Unicode characters in the target language will use the same internal representation (e.g., UCS-2 vs. UCS-4). You may need to write some special conversion functions.

So it sounds like you should map it to char* and then figure out how to manually convert it if necessary. It sounds like it is messy to begin with.

0

精彩评论

暂无评论...
验证码 换一张
取 消