python - PyErr_SetString's string argument: is it borrowed? -
How does PyErr_SetString handle passage in C-string? Like it is safe to do:
{int age = 12; Std :: stringstream ostr; Ostr & lt; & Lt; "I am" & lt; & Lt; Age & lt; & Lt; "Year is old and what is this?"; PyErr_SetString (PyExc_RuntimeError, ostr.str (..c_str ()); }
Obviously this is 'converted to a string object', but is it necessary that the content will be copied?
It is safe to do so, copying the contents of the wire before returning the Python. It applies only to other Python string operations.
In general, only reference to python objects (poobect *) can be borrowed or stolen, and unless interpreted otherwise, the interpreter copies the arguments.
Comments
Post a Comment