How Does String Conversion Between PyUnicode String and C String Work?

Viewed 5811

I have a PyUnicode object I'm trying to convert back to a C string (char *).

The way I am trying to do it does not seem to be working. Here is my code:

PyObject * objectCompName = PyTuple_GET_ITEM(compTuple, (Py_ssize_t) 0);
PyObject * ooCompName = PyUnicode_AsASCIIString(objectCompName);
char * compName = PyBytes_AsString(ooCompName);
Py_DECREF(ooCompName);

Is there another/better way I should be doing this?

2 Answers
Related