This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jak
Recipients alexandre.vassalotti, bhy, ezio.melotti, jak, jpe, lemburg, loewis, scoder, vstinner
Date 2010-12-07.14:18:03
SpamBayes Score 5.4928284e-13
Marked as misclassified No
Message-id <1291731484.69.0.595987855977.issue2799@psf.upfronthosting.co.za>
In-reply-to
Content
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?
History
Date User Action Args
2010-12-07 14:18:04jaksetrecipients: + jak, lemburg, loewis, jpe, scoder, vstinner, alexandre.vassalotti, ezio.melotti, bhy
2010-12-07 14:18:04jaksetmessageid: <1291731484.69.0.595987855977.issue2799@psf.upfronthosting.co.za>
2010-12-07 14:18:03jaklinkissue2799 messages
2010-12-07 14:18:03jakcreate