Inappropriate use of dx causes segfault

Issue #807 resolved
Kristian Ejlebjerg Jensen created an issue

The below script produces a segfault because dx is redefined.

from dolfin import *
f = Expression("1",degree=2)
u = Expression("2*dx",dx=f,degree=2)
mesh = RectangleMesh(Point(0.,0.),Point(2.,1.),20,10)
V = FunctionSpace(mesh,'CG',1)
v = interpolate(u,V)

Comments (14)

  1. Martin Sandve Alnæs

    Thanks. This is reproducable in dev.

    Do you have some evidence for the diagnosis "because dx is redefined"? I don't even understand what that means.

    Changing dx= to e.g. f= does avoid the segfault though, so something strange is going on here that involves the name.

  2. Kristian Ejlebjerg Jensen reporter

    What I mean to say is that there is no segfault, if dx is replaced with something else.

    I would suggest to throw an error, whenever a user tries to redefine dx. I just tried ds/dS and they do not cause segfaults.

  3. Jan Blechta

    The reason could be that SWIG does not correctly wrap dx due to a name clash because it is already imported. There is a lot of involved code, the dolfin SWIG interface files, function/expression.py, compilemodules/expressions.py, compilemodule/compilemodule.py, and it seemed to me that this is not that easy to debug.

    Obvious fix would be to raise an error when creating such an expression, but due to a complexity of the code it is not that obvious which all the names will cause the same problem.

  4. Martin Sandve Alnæs

    It's not clear to me where there is a name clash. dx from ufl is in a completely different scope.

  5. Jan Blechta

    There's a method ufl.Expr.dx

    >>> c = Constant(1.0)
    >>> c.dx
    <bound method Constant._dx of Coefficient(FunctionSpace(None, FiniteElement('Real', None, 0)), 3)>
    

    Do we just put dx member to the blacklist?

  6. Martin Sandve Alnæs

    Good catch. Maybe just add all Expr attributes to the blacklist. I'm touching this code now so I can do it.

  7. Jan Blechta

    @martinal, I see you're working on it much thoroughly. Maybe you could merge from jan/fix-issue-807 and take care of it so that I don't break your improvements (if you haven't fixed the issue already).

  8. Log in to comment