Hi,

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.


>>> In your example:
>>>
>>>  #define _fqtypename(o)   (((PyTypeObject*)o)->ob_type->tp_name)
>>>
>>> _fqtypename(a + b) expands to:
>>>
>>> (((PyTypeObject*)a + b)->ob_type->tp_name)
>>
>> And that's definitely not a valid use case of _fqtypename().
> 
> Why is that?  Isn't pointer arithmetic a valid use case?

How do you do pointer arithmetic on Python objects? Remember the declaration:

    cdef inline from MACROS:
        cdef char* _fqtypename(object t)


>>> If you want an inline function, why not just declare it inline?
>>
>> Because for small code snippets that exist solely for performance
>> reasons, the overhead of a function defined in Cython may be too high.
> 
> But if it's declared inline, there's no function call overhead at
> runtime.  Unless you're in a debug build, in which case you'd rather
> have the overhead to help track down bugs, leaks, etc.  Do you mean
> compile time overhead?  Or something else?

There currently is a ref-count overhead. When that is removed, I wouldn't mind
seeing inline functions as a macro replacement in many cases. But I'm pretty
sure even then I see a couple of cases where I'd use macros.


>>> The use cases discussed on the list recently were to get around the fact
>>> that Cython doesn't know all that much about C or C++.  Why not just
>>> teach it more?
>>
>> Does that imply a 'real' syntax for C macros?
> 
> No, it implies having Cython distinguish between references & values
> where appropriate.

Which, admittedly, is the case William brought up, but it's not the only use
case for macros that I am talking about here. I would prefer keeping that a
separate topic.

Stefan

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to