1 Feb 14:08
Re: [Cython] Cython code fails to compile with gcc 2.95
From: Sven Berkvens-Matthijsse <sven@...>
Subject: Re: [Cython] Cython code fails to compile with gcc 2.95
Newsgroups: gmane.comp.python.cython.devel
Date: 2008-02-01 13:08:50 GMT
Subject: Re: [Cython] Cython code fails to compile with gcc 2.95
Newsgroups: gmane.comp.python.cython.devel
Date: 2008-02-01 13:08:50 GMT
> Hi,
>
> I know, that's a pretty old compiler, but I know someone with a Solaris
> production setup that still uses it. Here is the compile error he gets:
>
> --------------------------------
> src/lxml/lxml.etree.c: In function `__pyx_PyInt_AsLongLong':
> src/lxml/lxml.etree.c:110165: parse error before `long'
> src/lxml/lxml.etree.c:110167: `val' undeclared (first use in this function)
> src/lxml/lxml.etree.c:110167: (Each undeclared identifier is reported only once
> src/lxml/lxml.etree.c:110167: for each function it appears in.)
> src/lxml/lxml.etree.c: In function `__pyx_PyInt_AsUnsignedLongLong':
> src/lxml/lxml.etree.c:110185: parse error before `long'
> src/lxml/lxml.etree.c:110187: `val' undeclared (first use in this function)
> error: command 'gcc' failed with exit status 1
> --------------------------------
>
> The problem lies in the new type conversion functions:
>
> --------------------------------
> 110156 static INLINE PY_LONG_LONG __pyx_PyInt_AsLongLong(PyObject* x) {
> 110157 if (PyInt_CheckExact(x)) {
> 110158 return PyInt_AS_LONG(x);
> 110159 }
> 110160 else if (PyLong_CheckExact(x)) {
> 110161 return PyLong_AsLongLong(x);
> 110162 }
> 110163 else {
> 110164 PyObject* tmp = PyNumber_Int(x); if (!tmp) return
> (PY_LONG_LONG)-1;
> 110165 PY_LONG_LONG val = __pyx_PyInt_AsLongLong(tmp);
> 110166 Py_DECREF(tmp);
> 110167 return val;
> 110168 }
> 110169 }
> 110170
> 110171 static INLINE unsigned PY_LONG_LONG
> __pyx_PyInt_AsUnsignedLongLong(PyObject* x) {
> 110172 if (PyInt_CheckExact(x)) {
> 110173 long val = PyInt_AS_LONG(x);
> 110174 if (unlikely(val < 0)) {
> 110175 PyErr_SetString(PyExc_TypeError, "Negative assignment to
> unsigned type.");
> 110176 return (unsigned PY_LONG_LONG)-1;
> 110177 }
> 110178 return val;
> 110179 }
> 110180 else if (PyLong_CheckExact(x)) {
> 110181 return PyLong_AsUnsignedLongLong(x);
> 110182 }
> 110183 else {
> 110184 PyObject* tmp = PyNumber_Int(x); if (!tmp) return
> (PY_LONG_LONG)-1;
> 110185 PY_LONG_LONG val = __pyx_PyInt_AsUnsignedLongLong(tmp);
> 110186 Py_DECREF(tmp);
> 110187 return val;
> 110188 }
> 110189 }
> --------------------------------
>
> So it seems like this line doesn't compile:
>
> --------------------------------
> PY_LONG_LONG val = __pyx_PyInt_AsLongLong(tmp);
> --------------------------------
>
> Given the error, I would say that "PY_LONG_LONG" gets expanded to the usual
> "long long".
>
> Any idea what could go wrong here and what to do about it?
The problem is that GCC 2.95 does not follow C99 semantics, and the C
version that it adheres to does not allow variables to be declared in
the middle of a block. All variables must be declared at the top of a
block. In the above case:
110164 PyObject* tmp = PyNumber_Int(x); if (!tmp) return (PY_LONG_LONG)-1;
110165 PY_LONG_LONG val = __pyx_PyInt_AsLongLong(tmp);
the 'if' statement on line 110164 terminates the end of the variable
declarations in the block. Line 110165 tries to declare one in the
middle of some statements, which was not allowed before C99.
> Stefan
--
--
Sven
RSS Feed