Inappropriate use of dx causes segfault
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)
-
-
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.
-
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.
-
- edited description
-
It's not clear to me where there is a name clash.
dx
from ufl is in a completely different scope. -
-
assigned issue to
-
assigned issue to
-
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? -
Good catch. Maybe just add all Expr attributes to the blacklist. I'm touching this code now so I can do it.
-
Fix suggested https://bitbucket.org/fenics-project/dolfin/branch/jan/fix-issue-807. Let's see if it breaks the tests or not.
-
@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). -
BTW the brach alone fixes the problem.
-
Will do. I've done some other unrelated fixes as well in one branch.
-
Can this be closed after recent changes?
-
- changed status to resolved
- Log in to comment
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.