Bug#684214: gcc-4.7: Fail to build functional python/numpy extension
Package: gcc-4.7
Version: 4.7.1-6
Severity: normal
When building a C extension to Python that uses Numpy (more precisely that tries
to access a Numpy array from C), the resulting module segfaults when used. I
spent some time figuring out what was the origin of the problem (similar extension
I wrote did work in the past), and the problem is solved when compiling the
module with olde gcc version (both gcc-4.5 and gcc-4.6 did build functional modules,
I couldn't install older version of gcc-4.7 for further testing), so I assume there
is a problem with this version for compiling numpy modules.
Here is an minimal example, I hope it can reproduce the bug (and that the fault is
not from my code, sorry if it is the case...). It works correctly when compiled
with gcc-4.[56], and segfaults when compiled with gcc-4.7. It can be compiled by:
gcc-4.[5-7] -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c essai.c -o essai.o -march=native -g0
gcc-4.[5-7] -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro essai.o -o essai.so
(the compile options are as automatically generated by distutils stuff).
For testing it, you can simply do on a python shell:
>>> from essai import func
>>> import numpy as N
>>> x = N.zeros((10,10))+1.
>>> func(x,4)
It should return 25.25. It segfaults during the PyArray_ContiguousFromObject call (when
getting access to the numpy array from C).
Here is the code:
#include <Python.h>
#include <stdio.h>
#include <numpy/arrayobject.h>
static char func_doc[] = "func(data, val)
";
static PyObject* func(PyObject *self, PyObject *args)
{
PyObject *input;
PyArrayObject *data;
double res=1.;
int val;
int i,j;
if (!PyArg_ParseTuple(args, "Ol", &input, &val)) return NULL;
data = (PyArrayObject *) PyArray_ContiguousFromObject(input, PyArray_DOUBLE, 2, 2);
if (data == NULL) return NULL;
for (i = 0; i < (int) data->dimensions[0]; ++i)
for (j = 0; j < (int) data->dimensions[1]; ++j)
res += ((double *)data->data)[i + j*data->dimensions[0]];
Kernel: Linux 3.4-trunk-amd64 (SMP w/24 CPU cores)
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Versions of packages gcc-4.7 depends on:
ii binutils 2.22-7.1
ii cpp-4.7 4.7.1-6
ii gcc-4.7-base 4.7.1-6
ii libc6 2.13-35
ii libgcc1 1:4.7.1-6
ii libgmp10 2:5.0.5+dfsg-2
ii libgomp1 4.7.1-6
ii libitm1 4.7.1-6
ii libmpc2 0.9-4
ii libmpfr4 3.1.0-5
ii libquadmath0 4.7.1-6
ii zlib1g 1:1.2.7.dfsg-13
Versions of packages gcc-4.7 recommends:
ii libc6-dev 2.13-35
--
To UNSUBSCRIBE, email to debian-gcc-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 20120807210407.12855.78458.reportbug@Dixie.rowland .org">http://lists.debian.org/20120807210407.12855.78458.reportbug@Dixie.rowland .org
08-08-2012, 02:31 PM
Matthias Klose
Bug#684214: gcc-4.7: Fail to build functional python/numpy extension
tags 684214 + moreinfo
thanks
On 07.08.2012 23:04, Raphael Plasson wrote:
> Here is an minimal example, I hope it can reproduce the bug (and that the fault is
> not from my code, sorry if it is the case...). It works correctly when compiled
> with gcc-4.[56], and segfaults when compiled with gcc-4.7. It can be compiled by:
> gcc-4.[5-7] -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c essai.c -o essai.o -march=native -g0
> gcc-4.[5-7] -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro essai.o -o essai.so
> (the compile options are as automatically generated by distutils stuff).
-march=native is generated by distutils? Please find the correct -march= option,
or else this is not reproducible.
--
To UNSUBSCRIBE, email to debian-gcc-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 50227848.4010208@debian.org">http://lists.debian.org/50227848.4010208@debian.org
08-08-2012, 02:49 PM
Raphael Plasson
Bug#684214: gcc-4.7: Fail to build functional python/numpy extension
On 08/08/2012 10:31, Matthias Klose wrote:
-march=native is generated by distutils? Please find the correct
-march= option, or else this is not reproducible.
Oups, you are right, the "-march=native -g0" comes from my setupe.py
(don't remember exactly why I put them, not sure if they are really
useful, indeed...).
I however tried compiling by removing these two options, i.e. with the
only options generated by distutils. Nothing is changed, the resulting
module is still segfaulting.
Raphaël
--
To UNSUBSCRIBE, email to debian-gcc-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 50227C8C.6080302@gmail.com">http://lists.debian.org/50227C8C.6080302@gmail.com