Skip to content
This repository has been archived by the owner on Nov 3, 2022. It is now read-only.

Commit

Permalink
Fixes to seg-fault with moose.le #BhallaLab#423 (BhallaLab#424)
Browse files Browse the repository at this point in the history
moose.le('/elmenent_that_does_not_exists') now raises ValueError like
version 3.1.x and does not fail with a seg-fault.
  • Loading branch information
Dilawar Singh committed Sep 7, 2020
1 parent eafa8b2 commit 16d1bae
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
4 changes: 4 additions & 0 deletions pybind11/helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,10 @@ vector<string> mooseLe(const ObjId& obj)
{
vector<Id> children;
vector<string> chPaths;

if(obj.bad())
throw pybind11::value_error("no such element.");

Neutral::children(obj.eref(), children);
stringstream ss;
ss << "Elements under " << obj.path() << endl;
Expand Down
15 changes: 6 additions & 9 deletions pybind11/pymoose.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
// =====================================================================================
// Description: Python bindings generated by pybind11. This binding replaces
// binding generated in ../pymoose folder.
//
// Description: Python bindings generated by pybind11. This binding replaces
// binding generated in ../pymoose folder. These bindings are easier to
// maintain and more performant. The user API has not changed but the
// internal working has changed.
// These bindings are easier to maintain and more performant. The user API
// is almost the same but the internal working has changed.
//
// Author: Dilawar Singh <dilawar.s.rajput@gmail.com>
// Organization: NCBS Bangalore
//
// =====================================================================================
// Author: Dilawar Singh <dilawar.s.rajput@gmail.com>
// Organization: NCBS Bangalore

#include <map>
#include <typeindex>
Expand Down
1 change: 1 addition & 0 deletions python/moose/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ def le(el=None):
el = _moose.getCwe() if el is None else el
if isinstance(el, str):
el = _moose.element(el)
print(el)
elif isinstance(el, _moose.vec):
el = el[0]
return _moose.le(el)
Expand Down
12 changes: 12 additions & 0 deletions tests/core/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,17 @@ def test_paths():
x = moose.Neutral('///x')
assert x.path == '/x', x.path

def test_le():
# see issue BhallaLab/moose-core#423
x = moose.le('/')
assert len(x) > 5, x
try:
moose.le('/abrakadabra')
except ValueError:
pass
else:
raise RuntimeError("This should have raised ValueError")

def main():
test_paths()
test_children()
Expand All @@ -216,6 +227,7 @@ def main():
test_vec()
test_typing()
test_elements()
test_le()

if __name__ == '__main__':
main()

0 comments on commit 16d1bae

Please sign in to comment.