FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian GCC

 
 
LinkBack Thread Tools
 
Old 08-07-2012, 09:04 PM
Raphael Plasson
 
Default 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]];

res /= val;
return Py_BuildValue("d", res);
}

static PyMethodDef module_methods[] = {
{"func", func, METH_VARARGS, func_doc},
{NULL, NULL, 0, NULL}
};

PyMODINIT_FUNC initessai(void)
{
Py_InitModule("essai", module_methods);
import_array();
}




-- System Information:
Debian Release: wheezy/sid
APT prefers unstable
APT policy: (500, 'unstable'), (500, 'testing'), (500, 'stable'), (1, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

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

Versions of packages gcc-4.7 suggests:
pn binutils-gold <none>
pn gcc-4.7-doc <none>
pn gcc-4.7-locales <none>
ii gcc-4.7-multilib 4.7.1-6
pn libgcc1-dbg <none>
pn libgomp1-dbg <none>
pn libitm1-dbg <none>
pn libmudflap0-4.7-dev <none>
pn libmudflap0-dbg <none>
pn libquadmath0-dbg <none>

-- no debconf information


--
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
 
Old 08-08-2012, 02:31 PM
Matthias Klose
 
Default 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
 
Old 08-08-2012, 02:49 PM
Raphael Plasson
 
Default 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
 

Thread Tools




All times are GMT. The time now is 10:27 PM.

VBulletin, Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2007 - 2008, www.linux-archive.org