Skip to content

CythonStackAllocation

Jonathan Guyer edited this page Sep 26, 2014 · 1 revision

I am attempting to wrap the Mesh classes in libMesh with Cython. These classes define different iterators to sequentially treat different elements of the Mesh and these iterators are returned by accessor methods. I am unable to write an iteration loop in Cython because I cannot initialize any of these iterators on the stack.

The actual definitions in libMesh are a morass of "Templated forwarding ctor" scattered across a half-dozen headers, but it seems to distill to this:

Table of Contents

accessor.h

accessor.pyx

test_accessor.py

When I attempt to run test_accessor.py, g++ fails with:

libMesh itself calls these accessor methods to stack allocate and initialize these iterators all the time, but I see the difference is that Cython generates:

accessor.cpp

whereas if the generated code was a one-liner like libMesh's internal code:

then this error does not occur.


If I change the Cython to

I get the somewhat more informative

but that doesn't address the fact that the the equivalent initialization is legal C++.

More significantly, in the actual code, where `node_iterator` is declared as a subclass of `Mesh`

results in

This issue with nested declarations seems to have been reported before without solution:




I am running:

 * i686-apple-darwin10-g++-4.2.1
 * Python 2.7.2 via HomeBrew
 * Cython 0.17
 * Mac OS X 10.6.8
Clone this wiki locally