Skip to content

Commit 195a8f1

Browse files
committed
Fix cadabra2-cli exit hang on macos.
1 parent 19ef2f9 commit 195a8f1

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

core/cadabra2-cli.cc

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -487,25 +487,22 @@ void Shell::handle_error()
487487
void Shell::handle_error(py::error_already_set& err)
488488
{
489489
if(err.matches(PyExc_SystemExit)) {
490-
std::cerr << "SystemExit" << std::endl;
491490
auto value = err.value();
492-
if (PyExceptionInstance_Check(value.ptr())) {
493-
_Py_Identifier PyId_code;
494-
PyId_code.string = "code";
495-
#if PY_VERSION_HEX < 0x030a0000
496-
PyId_code.object = 0;
497-
PyId_code.next = 0;
498-
#endif
499-
PyObject* code = _PyObject_GetAttrId(value.ptr(), &PyId_code);
500-
if (code)
491+
if(PyExceptionInstance_Check(value.ptr())) {
492+
py::object code = py::reinterpret_borrow<py::object>(value.ptr()).attr("code");
493+
if (code) {
501494
value = py::reinterpret_borrow<py::object>(code);
495+
}
502496
}
503-
if (!value || value.is_none())
497+
if (!value || value.is_none()) {
504498
throw ExitRequest{};
505-
else if (PyLong_Check(value.ptr()))
499+
}
500+
else if(PyLong_Check(value.ptr())) {
506501
throw ExitRequest{ static_cast<int>(PyLong_AsLong(value.ptr())) };
507-
else
502+
}
503+
else {
508504
throw ExitRequest{ str(value) };
505+
}
509506
}
510507
else {
511508
err.restore();

0 commit comments

Comments
 (0)