Stefan Behnel, 26.08.2012 11:36: > Christoph Gohlke, 26.08.2012 10:03: >> On 8/25/2012 6:51 AM, Stefan Behnel wrote: >>> Christoph Gohlke, 25.08.2012 04:07: >>>> On 8/24/2012 12:43 PM, Stefan Behnel wrote: >>>>> Christoph Gohlke, 24.08.2012 07:20: >>>>>> On 64 bit Python 2.7 and 3.2 with msvc9 compiler, python.exe crashes >>>>>> during >>>>>> `test_slice_assignment (memslice.__test__)`. I tested two computers. The >>>>>> Windows executive can not identify in which specific module it >>>>>> crashes, and >>>>>> neither enabling faulthandler nor building with debug symbols gives any >>>>>> useful information. Can anyone reproduce this? It seems compiler specific >>>>>> since Python 3.3, which is using msvc10, does not crash. >>>>> >>>>> Hmm, yes, sounds like a problem with the compiler. Would be good to get >>>>> this sorted out, but it's almost impossible to debug something like this >>>>> from a distance. >>>> >>>> Maybe the following simple example is related. It fails (not crash) when >>>> compiled with 64 bit msvc9, but does work with 32 bit msvc9 and msvc10 (32 >>>> and 64 bit): >>>> >>>> ``` >>>> from cython.view cimport array as cvarray >>>> import numpy as np >>>> >>>> narr = np.arange(8 * 14 * 11).reshape((8, 14, 11)) >>>> >>>> cdef int[:, :, ::1] a = narr >>>> cdef int[:, :, :] b = a[2:8:2, -4:1:-1, 1:3] >>>> >>>> print narr[2:8:2, -4:1:-1, 1:3].shape >>>> print b.shape[0], b.shape[1], b.shape[2] >>>> ``` >>>> >>>> On win-amd64-py2.x the shape of b is (3, 9, 3) but it should be (3, 9, 2) >>> >>> I'll leave that for the others to comment. >> >> This failure and the test crash disappear when auto-inlining is disabled, >> e.g. using the `/Ob1` compiler switch >> <http://msdn.microsoft.com/en-us/library/47238hez%28v=vs.100%29.aspx> > > Thanks for figuring that out. > > >> Is there a way to add a C pre-processor `#pragma` to a Cython generated C >> file? > > I don't think so, not in arbitrary places. > > >> I tried `cdef void emit_pragma '#pragma auto_inline(off) //' ()` but >> the pragma ends up inside the Python module init function, which fails to >> compile with `error C2156: pragma must be outside function`. > > As a quick fix, we could wrap (or just start) our utility code section with > that pragma. It starts after all user code. According to the docs, the > pragma only disables automatic inlining in the specific range, not > explicitly requested inlining. > > http://msdn.microsoft.com/en-us/library/ah08w5c3%28v=vs.71%29.aspx > > We usually know what we consider worth inlining and what doesn't need to > be. If we can find out what exact functions trigger this, we can start > being more specific about where to enable the pragma, but I think it's ok > to enable it on all utility code for now. > > Could you figure out a suitable preprocessor guard that only enables it for > the affected compilers?
A patch would essentially look like this: diff -r 18fed0dec20e Cython/Compiler/Code.py --- a/Cython/Compiler/Code.py Sun Aug 26 00:54:01 2012 +0200 +++ b/Cython/Compiler/Code.py Sun Aug 26 11:39:29 2012 +0200 @@ -893,6 +893,8 @@ code.write('\n#line 1 "cython_utility"\n') code.putln("") code.putln("/* Runtime support code */") + code.putln("#pragma auto_inline(off)") + code.putln("") def finalize_main_c_code(self): self.close_global_decls() Stefan _______________________________________________ cython-devel mailing list cython-devel@python.org http://mail.python.org/mailman/listinfo/cython-devel