Segfault when converting a mesh entity iterator to a list (in Python)

Asked by Maximilian Albert

The following code snippet results in a segfault:

==>
from dolfin import *
mesh = BoxMesh(0, 0, 0, 1, 1, 1, 1, 1, 1)
c = list(cells(mesh))[0]
print c.volume() # --> segfault
<==

On the other hand, the following works fine:

==>
from dolfin import *
mesh = BoxMesh(0, 0, 0, 1, 1, 1, 1, 1, 1)
for c in cells(mesh):
    print c.volume()
<==

The problem seems to be the conversion of cells(mesh) to a list (since calling any other method on 'c' in the first example also results in a segfault). Is this a bug, or is it simply not recommended to do this? Is there another, robust way of converting cells(mesh) to a list?

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Johan Hake
Solved:
Last query:
Last reply:
Revision history for this message
Best Johan Hake (johan-hake) said :
#1

On 03/13/2013 07:01 PM, Maximilian Albert wrote:
> New question #224186 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/224186
>
> The following code snippet results in a segfault:
>
> ==>
> from dolfin import *
> mesh = BoxMesh(0, 0, 0, 1, 1, 1, 1, 1, 1)
> c = list(cells(mesh))[0]
> print c.volume() # --> segfault
> <==
>
> On the other hand, the following works fine:
>
> ==>
> from dolfin import *
> mesh = BoxMesh(0, 0, 0, 1, 1, 1, 1, 1, 1)
> for c in cells(mesh):
> print c.volume()
> <==
>
> The problem seems to be the conversion of cells(mesh) to a list (since calling any other method on 'c' in the first example also results in a segfault). Is this a bug, or is it simply not recommended to do this? Is there another, robust way of converting cells(mesh) to a list?

This is a bug and is fixed in trunk. Thanks for reporting :)

Johan

Revision history for this message
Maximilian Albert (cilix) said :
#2

Thanks! I seem to have the right touch with reporting bugs that are already fixed. ;-)

Revision history for this message
Maximilian Albert (cilix) said :
#3

Thanks Johan Hake, that solved my question.

Revision history for this message
Johan Hake (johan-hake) said :
#4

On 03/13/2013 09:26 PM, Maximilian Albert wrote:
> Question #224186 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/224186
>
> Status: Answered => Solved
>
> Maximilian Albert confirmed that the question is solved:
> Thanks! I seem to have the right touch with reporting bugs that are
> already fixed. ;-)

Well this one I fixed because you reported it. The other one was already
fixed.

Johan