Skip to content

Commit 16d1bae

Browse files
authored
Fixes to seg-fault with moose.le ##423 (#424)
moose.le('/elmenent_that_does_not_exists') now raises ValueError like version 3.1.x and does not fail with a seg-fault.
1 parent eafa8b2 commit 16d1bae

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

pybind11/helper.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,10 @@ vector<string> mooseLe(const ObjId& obj)
550550
{
551551
vector<Id> children;
552552
vector<string> chPaths;
553+
554+
if(obj.bad())
555+
throw pybind11::value_error("no such element.");
556+
553557
Neutral::children(obj.eref(), children);
554558
stringstream ss;
555559
ss << "Elements under " << obj.path() << endl;

pybind11/pymoose.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
// =====================================================================================
1+
// Description: Python bindings generated by pybind11. This binding replaces
2+
// binding generated in ../pymoose folder.
23
//
3-
// Description: Python bindings generated by pybind11. This binding replaces
4-
// binding generated in ../pymoose folder. These bindings are easier to
5-
// maintain and more performant. The user API has not changed but the
6-
// internal working has changed.
4+
// These bindings are easier to maintain and more performant. The user API
5+
// is almost the same but the internal working has changed.
76
//
8-
// Author: Dilawar Singh <dilawar.s.rajput@gmail.com>
9-
// Organization: NCBS Bangalore
10-
//
11-
// =====================================================================================
7+
// Author: Dilawar Singh <dilawar.s.rajput@gmail.com>
8+
// Organization: NCBS Bangalore
129

1310
#include <map>
1411
#include <typeindex>

python/moose/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ def le(el=None):
600600
el = _moose.getCwe() if el is None else el
601601
if isinstance(el, str):
602602
el = _moose.element(el)
603+
print(el)
603604
elif isinstance(el, _moose.vec):
604605
el = el[0]
605606
return _moose.le(el)

tests/core/test_api.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,17 @@ def test_paths():
203203
x = moose.Neutral('///x')
204204
assert x.path == '/x', x.path
205205

206+
def test_le():
207+
# see issue BhallaLab/moose-core#423
208+
x = moose.le('/')
209+
assert len(x) > 5, x
210+
try:
211+
moose.le('/abrakadabra')
212+
except ValueError:
213+
pass
214+
else:
215+
raise RuntimeError("This should have raised ValueError")
216+
206217
def main():
207218
test_paths()
208219
test_children()
@@ -216,6 +227,7 @@ def main():
216227
test_vec()
217228
test_typing()
218229
test_elements()
230+
test_le()
219231

220232
if __name__ == '__main__':
221233
main()

0 commit comments

Comments
 (0)