I have been thinking the same thing myself. Just wanted to also point in the direction of inlineable functions in pxd-file in my draft on the wiki (under enhancements). The more features Cython gets, the more cases can be solved by inlineable functions written in Cython instead of with macros (the benefit being of course that one can stick to Cython as the language). No problems with doing both though...
Dag Sverre Seljebotn -----Original Message----- From: Stefan Behnel <[EMAIL PROTECTED]> Date: Friday, Mar 21, 2008 8:38 am Subject: [Cython] Syntax for writing C macros in a Cython .pxd To: Cython-dev <[email protected]> Hi, since William brought up this topic lately, I think there are a couple of very valid cases where you want to define a macro in C and use it as a function in Cython. This currently means: 1) write a macros.h file to hold the macro 2) add a 'cdef extern from "macros.h"' to your favourite .pxd file to define your macros in Cython So this requires you to keep track of two files for things that may just be a couple of lines in C. I think this is so common that it would help if you could write inline C code in a .pxd file and have it written into your generated C file automatically. I could imagine a syntax like this: # macros.pxd MACROS = """ #define _isString(obj) (PyString_CheckExact(obj) || \ PyUnicode_CheckExact(obj) || \ PyObject_TypeCheck(obj, &PyBaseString_Type)) #define _fqtypename(o) (((PyTypeObject*)o)->ob_type->tp_name) """ cdef inline from MACROS: cdef int _isString(object obj) cdef char* _fqtypename(object t) Instead of an '#include "macros.h"', this would write the string given by MACROS verbatimly into the C file, directly behind the #include section. It could also keep track of the strings in a set to make sure they are only written out once, even when cimported redundantly at various places. Any comments on this? Stefan _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
