[Cython] Compilation failes if a class member is named "INFINITY"

Michael supermihi at posteo.de
Thu Feb 5 09:52:08 CET 2015


Am 31.01.2015 um 19:48 schrieb Matthew Brett:
> Hi,
> 
> On Fri, Jan 30, 2015 at 1:49 AM, Michael <supermihi at posteo.de> wrote:
>> Hello,
>>
>> if I try to compile the following minimal example:
>>
>> cdef class Test:
>>
>>     cdef readonly int INFINITY
>>
>> cython does not complain but gcc refuses with an error message:
>> In file included from /usr/include/math.h:38:0,
>>                  from /usr/include/python2.7/pyport.h:325,
>>                  from /usr/include/python2.7/Python.h:58,
>>                  from testinf.c:16:
>> testinf.c:433:7: error: field '__builtin_inff' declared as a function
>>    int INFINITY;
>>        ^
>> testinf.c: In function '__pyx_pf_7testinf_4Test_8INFINITY___get__':
>> testinf.c:569:50: error: expected identifier before '(' token
>>    __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->INFINITY); if
>> (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10;
>> __pyx_clineno = __LINE__; goto __pyx_L1_error;}
>>                                                   ^
>> Apparently the name "INFINITY" is handled wrongly; any other variable
>> name seems to be fine.
> 
> Maybe you hit the INFINITY gcc macro?
> 
> http://www.gnu.org/software/libc/manual/html_node/Infinity-and-NaN.html

Yes, that's probably the explanation. So should Cython do anything about
the problem, i.e. raise an exception if struct members are named like a
macro?
I don't know about the Cython internals, but I wonder why the name not
altered in the c file:
 struct __pyx_obj_7testinf_Test {
  PyObject_HEAD
  int INFINITY;
};
I would have expected something like "int __pyx_member_INFINITY"?

Michael




More information about the cython-devel mailing list