This commit resulted in a segmentation fault on the OS X buildbots. Johan, could you take a look?
Johannes On Thu, Mar 7, 2013 at 9:08 AM, <nore...@launchpad.net> wrote: > ------------------------------------------------------------ > revno: 7506 > fixes bug: https://launchpad.net/bugs/973906 > committer: Johan Hake <hake....@gmail.com> > branch nick: work-trunk > timestamp: Thu 2013-03-07 09:06:57 +0100 > message: > MeshFunctions now support iterable protocol, fixing bug lp:973906 > modified: > ChangeLog > dolfin/swig/mesh/post.i > test/unit/mesh/python/MeshFunction.py > > > -- > lp:dolfin > https://code.launchpad.net/~dolfin-core/dolfin/trunk > > Your team DOLFIN Core Team is subscribed to branch lp:dolfin. > To unsubscribe from this branch go to > https://code.launchpad.net/~dolfin-core/dolfin/trunk/+edit-subscription > > === modified file 'ChangeLog' > --- ChangeLog 2013-02-28 14:52:56 +0000 > +++ ChangeLog 2013-03-07 08:06:57 +0000 > @@ -1,3 +1,4 @@ > + - MeshFunctions in python now support iterable protocol > - Expose ufc::dofmap::tabulate_entity_dofs to GenericDofMap interface > - Expose ufc::dofmap::num_entity_dofs to GenericDofMap interface > - Allow setting of row dof coordinates in preconditioners (only works with > PETSc backed for now) > > === modified file 'dolfin/swig/mesh/post.i' > --- dolfin/swig/mesh/post.i 2013-01-12 00:38:15 +0000 > +++ dolfin/swig/mesh/post.i 2013-03-07 08:06:57 +0000 > @@ -117,11 +117,11 @@ > // Extend MeshFunction interface for get and set items > %extend dolfin::MeshFunction<TYPE> > { > - TYPE __getitem__(std::size_t i) { return (*self)[i]; } > - void __setitem__(std::size_t i, TYPE val) { (*self)[i] = val; } > + TYPE _getitem(std::size_t i) { return (*self)[i]; } > + void _setitem(std::size_t i, TYPE val) { (*self)[i] = val; } > > - TYPE __getitem__(dolfin::MeshEntity& e) { return (*self)[e]; } > - void __setitem__(dolfin::MeshEntity& e, TYPE val) { (*self)[e] = val; } > + TYPE _getitem(dolfin::MeshEntity& e) { return (*self)[e]; } > + void _setitem(dolfin::MeshEntity& e, TYPE val) { (*self)[e] = val; } > > %pythoncode%{ > def array(self): > @@ -132,6 +132,22 @@ > _attach_base_to_numpy_array(data, self) > return data > > +def __getitem__(self, index): > + try: > + return self._getitem(index) > + except: > + index = index.index() if isinstance(index, Cell) else index > + raise IndexError("Index %d out of bound" % index) > + > +def __setitem__(self, index, value): > + try: > + self._setitem(index, value) > + except RuntimeError: > + index = index.index() if isinstance(index, Cell) else index > + raise IndexError("Index %d out of bound" % index) > + > +def __len__(self): > + return self.size() > %} > } > > > === modified file 'test/unit/mesh/python/MeshFunction.py' > --- test/unit/mesh/python/MeshFunction.py 2013-01-07 22:07:49 +0000 > +++ test/unit/mesh/python/MeshFunction.py 2013-03-07 08:06:57 +0000 > @@ -42,11 +42,11 @@ > for tp in self.tps: > for name in self.names: > if name is "Vertex": > - a = self.funcs[(tp, name)].size() > + a = len(self.funcs[(tp, name)]) > b = self.mesh.num_vertices() > self.assertEqual(a, b) > else: > - a = self.funcs[(tp, name)].size() > + a = len(self.funcs[(tp, name)]) > b = getattr(self.mesh, "num_%ss"%name.lower())() > self.assertEqual(a, b) > > @@ -65,6 +65,21 @@ > self.assertTrue(all(values[i]==self.funcs[(tp, name)][i] > for i in xrange(len(values)))) > > + def test_iterate(self): > + for tp in self.tps: > + for name in self.names: > + for index, value in enumerate(self.funcs[(tp, name)]): > + pass > + self.assertEqual(index, len(self.funcs[(tp, name)])-1) > + self.assertRaises(IndexError, self.funcs[(tp, > name)].__getitem__, len(self.funcs[(tp, name)])) > + > + def test_setvalues(self): > + for tp in self.tps: > + if tp == 'bool': > + continue > + for name in self.names: > + self.assertRaises(TypeError, self.funcs[(tp, > name)].__setitem__, len(self.funcs[(tp, name)]), "jada") > + > class MeshFunctions(unittest.TestCase): > > def setUp(self): > > _______________________________________________ Mailing list: https://launchpad.net/~dolfin Post to : dolfin@lists.launchpad.net Unsubscribe : https://launchpad.net/~dolfin More help : https://help.launchpad.net/ListHelp