[Python-Dev] RE: [Python-checkins] python/dist/src/Include objimpl.h, 2.58, 2.59 (original) (raw)
Raymond Hettinger python at rcn.com
Wed Jul 14 10:23:45 CEST 2004
- Previous message: [Python-Dev] Tagged integers
- Next message: [Python-Dev] RE: [Python-checkins] python/dist/src/Include objimpl.h, 2.58, 2.59
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Documented the new PyVISIT macro to simplify implementation of tptraverse handlers. (Tim made me do it. ;)
That Tim has been tyrant lately ;-)
+ /* Utility macro to help write tptraverse functions */ _+ #define PyVISIT(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
- Previous message: [Python-Dev] Tagged integers
- Next message: [Python-Dev] RE: [Python-checkins] python/dist/src/Include objimpl.h, 2.58, 2.59
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]