[SciPy-Dev] Weird segfault in call to PyArray_SIZE
Jaime Fernández del Río
jaime.frio at gmail.com
Tue Jun 27 04:26:19 EDT 2017
After some more probing around, it was an import_array() kind of issue. The
magical incantation that banished the segfault was to add:
#define PY_ARRAY_UNIQUE_SYMBOL _scipy_ndimage_ARRAY_API
at the top of every *.c file. I suppose the technical term is that it
should be defined to the same value in every "compilation unit" that wants
to use the NumPy API.
I will open a documentation bug with numpy: all google could find was
buried in 5+ year old mailing list discussions, and there seems to be no
coherent explanation of how the whole thing works anywhere.
Thanks everyone for your suggestions!
Jaime
On Mon, Jun 26, 2017 at 7:04 PM, Christoph Gohlke <cgohlke at uci.edu> wrote:
>
>
> On 6/25/2017 2:08 PM, Jaime Fernández del Río wrote:
>
>> While working in scipy.ndimage I tried to replace the following code, see
>> here <https://github.com/scipy/scipy/blob/master/scipy/ndimage/
>> src/ni_support.c#L95> for the source:
>>
>> npy_intp max_lines;
>> int ii;
>>
>> for (ii = 0; ii < array->nd; ii++)
>> max_lines *= array->dimensions[ii];
>>
>> with the in theory equivalent:
>>
>> max_lines = PyArray_SIZE(array);
>>
>> Oddly enough, the result is a segfault as soon as PyArray_SIZE is called,
>> e.g. by running the ndimage tests.
>>
>> Both numpy and scipy are the latest development versions, built by myself
>> on OSX. Unfortunately I don't have Python and friends built with debug
>> symbols, so the best I have been able to figure out, through printf
>> debugging, is that the segfault happens before PyArray_MultiplyList is
>> entered, which made me suspicious of it being related to import_array() not
>> being called, but that doesn't seem to be the case.
>>
>> Any thoughts on what may be causing this?
>>
>> Jaime
>>
>>
> On Windows the proposed change throws a link error:
>
> ni_support.obj : error LNK2001: unresolved external symbol PyArray_API
>
> Christoph
>
> _______________________________________________
> SciPy-Dev mailing list
> SciPy-Dev at python.org
> https://mail.python.org/mailman/listinfo/scipy-dev
>
--
(\__/)
( O.o)
( > <) Este es Conejo. Copia a Conejo en tu firma y ayúdale en sus planes
de dominación mundial.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20170627/676564b2/attachment.html>
More information about the SciPy-Dev
mailing list