← Back to team overview

dolfin team mailing list archive

[Bug 42] New: Inline algebraic operators on vectors are unsafe in pydolfin

 

http://www.fenics.org/cgi-bin/bugzilla/show_bug.cgi?id=42

           Summary: Inline algebraic operators on vectors are unsafe in
                    pydolfin
           Product: DOLFIN
           Version: development version
          Platform: All
        OS/Version: Linux
            Status: NEW
          Severity: critical
          Priority: P2
         Component: general
        AssignedTo: dolfin-dev@xxxxxxxxxx
        ReportedBy: martinal@xxxxxxxxx


Given 
  v = Vector()
  u = Vector()
  ... initialize v, u

The operations
  v *= -1.0
  v -+= u

are unsafe, causing possible memory corruption. This seems to be because swig
creates new python objects for the vectors, causing deletion the C++ object if
the original reference count goes to zero.

Temporary workaround:
  tmp = numpy.zeros(v.size())
  v.get(tmp)
  v.set(3.0*tmp)
is mathematically equivalent with
  v *= 3.0
and
  tmp1 = numpy.zeros(v.size())
  tmp2 = numpy.zeros(v.size())
  u.get(tmp1)
  v.get(tmp2)
  v.set(tmp1+tmp2)
is mathematically equivalent with
  v += u


-- 
Configure bugmail: http://www.fenics.org/cgi-bin/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.