Message123552
The problem I see here is that there is no public way to simply get a C string from a unicode object similar to PyBytes_AsString() for bytes. That's bad because we don't want to rewrite the whole code to duplicate strings all the time and free every string we get from a MyPyUnicode_AsString() like function.
I used the following, but this clearly has a memory leak:
static const char *MyPyUnicode_AsString(PyObject *op) {
PyObject *bytes = PyUnicode_AsEncodedString(op,0,0);
return bytes ? PyBytes_AS_STRING(bytes) : 0;
}
I now use the following which has no memory leak, but needs an internal function (I would use _PyUnicode_AsString, but I need Python 2.X compatibility as well):
static const char *MyPyUnicode_AsString(PyObject *op) {
PyObject *bytes = _PyUnicode_AsDefaultEncodedString(op, 0);
return bytes ? PyBytes_AS_STRING(bytes) : 0;
}
So could something be done about this? |
|
Date |
User |
Action |
Args |
2010-12-07 14:18:04 | jak | set | recipients:
+ jak, lemburg, loewis, jpe, scoder, vstinner, alexandre.vassalotti, ezio.melotti, bhy |
2010-12-07 14:18:04 | jak | set | messageid: <1291731484.69.0.595987855977.issue2799@psf.upfronthosting.co.za> |
2010-12-07 14:18:03 | jak | link | issue2799 messages |
2010-12-07 14:18:03 | jak | create | |
|