A value which is a PyUnicodeObject need to be passed to PyObject variable. Is there any conversion method for that?
thanks karnol
A value which is a PyUnicodeObject need to be passed to PyObject variable. Is there any conversion method for that?
thanks karnol
PyUnicodeObject
is a subset of PyObject
so there shouldn't be any problem passing it.
You can just use a cast in your C code for this purpose:
PyUnicodeObject *p = ...whatever...;
callsomefun((PyObject*)p);
All the various specific, concrete types PyWhateverObject
can be thought of as being "derived from" PyObject. Now C does have the concept of inheritance so there's no "derived" in it, but the Python VM synthesizes it very simply, by ensuring every such object's memory layout "starts with" a header that exactly corresponds to what a PyObject
struct would be (there's a macro for that). This guarantees that normal C casting of pointers (although technically "risky" as the compiler cannot check that correctness -- if you cast the wrong thing you'll just crash during runtime;-) works as intended when used correctly between a pointer to PyObject and any pointer to a specific, concrete Python type struct.