On Mar 23, 2008, at 10:12 AM, Stefan Behnel wrote: > Hi, > > Neal Becker wrote: >> Stefan Behnel wrote: >>> Martin C. Martin wrote: >>>> Stefan Behnel wrote: >>>>> Well, in most cases macros are rather short code snippets, not >>>>> function >>>>> replacing code blocks. So I don't care about their symbols. >>>> That's surprising to me. Don't you think you'd want to step >>>> through >>>> even short snippets in a debugger? To have them show up as a >>>> separate >>>> item in a profile, rather than spread around all the places that >>>> call >>>> them? Same with memory leaks or corruption? >>> Again: there are valid use cases for macros. They are mostly for >>> speed, >>> not for improved debugability. >>> >> >> I don't see this argument. There is no speed advantage of macros >> over >> inline, providing your compiler supports inline. Maybe you're >> talking >> about C compilers that don't support inline? > > Maybe a different example would help. How would you write this in > Cython: > > // --- FILE defs.h > #define PY_NEW(T) \ > (((PyTypeObject*)(T))->tp_new( \ > (PyTypeObject*)(T), __pyx_empty_tuple, NULL))
One would declare the type object as having a function pointer field tp_new with the right signature. (In fact, when we support builtin- types, this should be available by default at T.tp_new((), NULL)). > # --- FILE some.pyx > cdef extern from "defs.h": > # macro call to 't->tp_new()' for fast instantiation > cdef DTD NEW_DTD "PY_NEW" (object t) > > dtd = NEW_DTD(DTD) This can only be done because one is dealing with two separate namespaces. I do think there are valid uses for C macros/arbitrary C in some Cython code. I also hope that the need for such special use cases goes down as Cython improves. But if one wants to muck around with stuff like this I think one should write an actual .c or .h file and include stuff from there, rather than provide an easy (and IMHO ugly) way to embed raw C code strings in Cython files. - Robert _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
