[Python-Dev] Automatic Scope Macros (original) (raw)
Georg Brandl g.brandl at gmx.net
Tue Apr 24 22:59:35 CEST 2007
- Previous message: [Python-Dev] Automatic Scope Macros
- Next message: [Python-Dev] Automatic Scope Macros
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 PyCLEANREF(refname, newref, scopecode)_ _(PyObject ) refname = newref;_ _scopecode;_ PyXDECREF(refname); _/ Obtain a Borrowed Reference and forget about it at the end of the scope. */_ _#define PyFORGETREF(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
- Previous message: [Python-Dev] Automatic Scope Macros
- Next message: [Python-Dev] Automatic Scope Macros
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]