It's simple to create a member for an object in a Python C extension with a base type of char *
, using the T_STRING
define in the PyMemberDef
declaration.
Why does there not seem to be an equivalent for wchar_t *
? And if there actually is one, what is it?
e.g.
struct object
contains char *text
PyMemberDef
array has {"text", T_STRING, offsetof(struct object, text), READONLY, "This is a normal character string."}
versus something like
struct object
contains wchar_t *wtext
PyMemberDef
array has {"wtext", T_WSTRING, offsetof(struct object, wtext), READONLY, "This is a wide character string"}
I understand that something like PyUnicode_AsString()
and its related methods can be used to encode the data in UTF-8, store it in a basic char string, and decode later, but doing it that way would require wrapping the generic getattr
and setattr
methods/functions with ones that account for the encoded text, and it's not very useful when you want character arrays of fixed element size within a struct and don't want the effective number of characters that can be stored in it to vary.