> Documented the new Py_VISIT macro to simplify implementation of > tp_traverse handlers. (Tim made me do it. ;) That Tim has been tyrant lately ;-) > + /* Utility macro to help write tp_traverse functions */ > + #define Py_VISIT(op) \ > + do { \ > + if (op) { \ > + int vret = visit((op), arg); \ > + if (vret) \ > + return vret; \ > + } \ > + } while (0) I tried out this macro with the itertools module and found that it did a nice job of compacting boilerplate code. One thought jumped out though. The macro assumes that the enclosing function has consistent with the use of the variable names "visit" and "arg": static int islice_traverse(isliceobject *lz, visitproc visit, void *arg) { Py_VISIT(lz->it); return 0; } If the parameters are named something else ("vfunc" for example), MSVC++6.0 complains: C:\py24\Modules\itertoolsmodule.c(1118) : warning C4013: 'visit' undefined; assuming extern returning int Don't know if it is worth it, but you could safeguard the macro by including visit and arg in the parameter list. Raymond Hettinger
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