remove internal_error
parent
5b54c74f2a
commit
7febb8f5b1
|
@ -20,15 +20,6 @@ namespace cubescript {
|
||||||
|
|
||||||
struct state;
|
struct state;
|
||||||
|
|
||||||
/** @brief An internal Cubescript error.
|
|
||||||
*
|
|
||||||
* This is an error that is never expected; it is thrown
|
|
||||||
* when some API call fails due to most likely a bug.
|
|
||||||
*/
|
|
||||||
struct internal_error: std::runtime_error {
|
|
||||||
using std::runtime_error::runtime_error;
|
|
||||||
};
|
|
||||||
|
|
||||||
/** @brief Represents the simplified call stack at a point in time.
|
/** @brief Represents the simplified call stack at a point in time.
|
||||||
*
|
*
|
||||||
* This is a simplified call stack; it is generally carried by errors
|
* This is a simplified call stack; it is generally carried by errors
|
||||||
|
@ -156,7 +147,7 @@ struct LIBCUBESCRIPT_EXPORT error {
|
||||||
buf = request_buf(cs, sz, sp);
|
buf = request_buf(cs, sz, sp);
|
||||||
int written = std::snprintf(buf, sz, msg.data(), args...);
|
int written = std::snprintf(buf, sz, msg.data(), args...);
|
||||||
if (written <= 0) {
|
if (written <= 0) {
|
||||||
throw internal_error{"format error"};
|
throw error{cs, "malformed format string"};
|
||||||
} else if (std::size_t(written) <= sz) {
|
} else if (std::size_t(written) <= sz) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include <cubescript/cubescript.hh>
|
#include <cubescript/cubescript.hh>
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "cs_thread.hh"
|
#include "cs_thread.hh"
|
||||||
|
@ -69,7 +70,7 @@ LIBCUBESCRIPT_EXPORT char *error::request_buf(
|
||||||
nsz = std::snprintf(cb.data(), sz, "%zu: ", *ts.current_line);
|
nsz = std::snprintf(cb.data(), sz, "%zu: ", *ts.current_line);
|
||||||
}
|
}
|
||||||
if (nsz <= 0) {
|
if (nsz <= 0) {
|
||||||
throw internal_error{"format error"};
|
abort(); /* should be unreachable */
|
||||||
} else if (std::size_t(nsz) < sz) {
|
} else if (std::size_t(nsz) < sz) {
|
||||||
sz = std::size_t(nsz);
|
sz = std::size_t(nsz);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <cassert>
|
||||||
#include <cubescript/cubescript.hh>
|
#include <cubescript/cubescript.hh>
|
||||||
|
|
||||||
#include "cs_strman.hh"
|
#include "cs_strman.hh"
|
||||||
|
@ -70,10 +71,14 @@ void string_pool::unref(char const *ptr) {
|
||||||
*/
|
*/
|
||||||
auto sr = std::string_view{ptr, ss->length};
|
auto sr = std::string_view{ptr, ss->length};
|
||||||
auto it = counts.find(sr);
|
auto it = counts.find(sr);
|
||||||
|
/* this should *never* happen unless we have a bug */
|
||||||
|
#ifndef NDEBUG
|
||||||
|
assert(it != counts.end());
|
||||||
|
#else
|
||||||
if (it == counts.end()) {
|
if (it == counts.end()) {
|
||||||
/* internal error: this should *never* happen */
|
abort();
|
||||||
throw internal_error{"no refcount"};
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
/* we're freeing the key */
|
/* we're freeing the key */
|
||||||
counts.erase(it);
|
counts.erase(it);
|
||||||
/* dealloc */
|
/* dealloc */
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "cs_strman.hh"
|
#include "cs_strman.hh"
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <cstdlib>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
|
||||||
namespace cubescript {
|
namespace cubescript {
|
||||||
|
@ -22,7 +23,7 @@ static std::string_view intstr(integer_type v, charbuf &buf) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (n <= 0) {
|
if (n <= 0) {
|
||||||
throw internal_error{"format error"};
|
abort(); /* unreachable, provided a well-formed format string */
|
||||||
}
|
}
|
||||||
return std::string_view{buf.data(), std::size_t(n)};
|
return std::string_view{buf.data(), std::size_t(n)};
|
||||||
}
|
}
|
||||||
|
@ -50,7 +51,7 @@ static std::string_view floatstr(float_type v, charbuf &buf) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (n <= 0) {
|
if (n <= 0) {
|
||||||
throw internal_error{"format error"};
|
abort(); /* unreachable, provided a well-formed format string */
|
||||||
}
|
}
|
||||||
return std::string_view{buf.data(), std::size_t(n)};
|
return std::string_view{buf.data(), std::size_t(n)};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <cstdlib>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
|
||||||
|
@ -148,8 +149,8 @@ LIBCUBESCRIPT_EXPORT void std_init_string(state &cs) {
|
||||||
res.set_string(static_cast<char const *>(buf), ccs);
|
res.set_string(static_cast<char const *>(buf), ccs);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* should pretty much be unreachable */
|
/* should be unreachable */
|
||||||
throw internal_error{"format error"};
|
abort();
|
||||||
});
|
});
|
||||||
|
|
||||||
new_cmd_quiet(cs, "substr", "sii#", [](auto &ccs, auto args, auto &res) {
|
new_cmd_quiet(cs, "substr", "sii#", [](auto &ccs, auto args, auto &res) {
|
||||||
|
|
Loading…
Reference in New Issue