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

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -