Calvin Spealman schrieb: > Could we use and add this macro to object.h? It could be a much > cleaner and safer way of dealing with new references you want to clean > up in the same scope. The first one will make sure to decref your new > reference when you are done with it. The second one will make sure to > set a borrowed reference to NULL afterward, so you can't access it > after you are done with it. The second might be useless, but it seems > like it might be useful for debugging and being sure you stopped using > a reference when you thought you did. > > Anyone, please let me know if this is a dumb idea. > > /* Obtain a New Reference and clean it up at the end of the scope. */ > #define Py_CLEANREF(_refname, _newref, _scopecode)\ > (PyObject *) _refname = _newref;\ > _scopecode;\ > Py_XDECREF(_refname); > > /* Obtain a Borrowed Reference and forget about it at the end of the scope. */ > #define Py_FORGETREF(_refname, _newref, _scopecode)\ > (PyObject *) _refname = _newref; > _scopecode;\ > _refname = NULL; In most cases, you will have error checking in _scopecode which DECREFs the variable and returns, or jumps to a "cleanup" label. I can't see how this would be possible with these macros. Georg
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4