aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Shah <dave@ds0.me>2020-03-04 07:22:37 +0000
committerGitHub <noreply@github.com>2020-03-04 07:22:37 +0000
commita957e9039642c1f5fe4270895d7a23452fab281b (patch)
tree66c2bac5eac916fe8416c1a90ce4d846bc2bec5c
parentc06827cd505444fca4e05c8b9dbe8067a66cf1a9 (diff)
parent4a9981ee77e92f51d07f6a1f2993f94d5f4cfb94 (diff)
downloadnextpnr-a957e9039642c1f5fe4270895d7a23452fab281b.tar.gz
nextpnr-a957e9039642c1f5fe4270895d7a23452fab281b.tar.bz2
nextpnr-a957e9039642c1f5fe4270895d7a23452fab281b.zip
Merge pull request #405 from smunaut/fix_key_error
pycontainers: Properly handle KeyErrors
-rw-r--r--common/pycontainers.h16
1 files changed, 11 insertions, 5 deletions
diff --git a/common/pycontainers.h b/common/pycontainers.h
index 5de2f6d2..04c670cc 100644
--- a/common/pycontainers.h
+++ b/common/pycontainers.h
@@ -35,7 +35,11 @@ NEXTPNR_NAMESPACE_BEGIN
using namespace boost::python;
-inline void KeyError() { PyErr_SetString(PyExc_KeyError, "Key not found"); }
+inline void KeyError()
+{
+ PyErr_SetString(PyExc_KeyError, "Key not found");
+ boost::python::throw_error_already_set();
+}
/*
A wrapper for a Pythonised nextpnr Iterator. The actual class wrapped is a
@@ -325,7 +329,9 @@ template <typename T, typename value_conv> struct map_wrapper
if (x.base.find(k) != x.base.end())
return value_conv()(x.ctx, x.base.at(k));
KeyError();
- std::terminate();
+
+ // Should be unreachable, but prevent control may reach end of non-void
+ throw std::runtime_error("unreachable");
}
static void set(wrapped_map &x, std::string const &i, V const &v)
@@ -342,7 +348,6 @@ template <typename T, typename value_conv> struct map_wrapper
x.base.erase(k);
else
KeyError();
- std::terminate();
}
static bool contains(wrapped_map &x, std::string const &i)
@@ -452,7 +457,9 @@ template <typename T> struct map_wrapper_uptr
if (x.base.find(k) != x.base.end())
return PythonConversion::ContextualWrapper<Vr>(x.ctx, *x.base.at(k).get());
KeyError();
- std::terminate();
+
+ // Should be unreachable, but prevent control may reach end of non-void
+ throw std::runtime_error("unreachable");
}
static void set(wrapped_map &x, std::string const &i, V const &v)
@@ -469,7 +476,6 @@ template <typename T> struct map_wrapper_uptr
x.base.erase(k);
else
KeyError();
- std::terminate();
}
static bool contains(wrapped_map &x, std::string const &i)