Replacement for _PyString_Resize in Python 3
I'm porting a module that uses C to extend Python's functionality from 2.x to 3, and can't find in the documents any references on how to resize a string, only how t开发者_如何学JAVAo get its size:
http://docs.python.org/py3k/c-api/unicode.html?highlight=pyunicode#PyUnicode_GetSize
How do I convert this code:
_PyString_Resize(&buffer, (int)res);
to one that python 3 can understand?
While it's not documented in the page you linked, unicodeobject.c does contain both
int _PyUnicode_Resize(PyUnicodeObject **unicode, Py_ssize_t length)
and the wrapper
int PyUnicode_Resize(PyObject **unicode, Py_ssize_t length)
{
return _PyUnicode_Resize((PyUnicodeObject **)unicode, length);
}
I don't know if the lack of documentation is an oversight or a quiet deprecation (never used any of these).
精彩评论