some fix about <stdexcept>

This commit is contained in:
blueloveTH 2024-06-09 17:55:42 +08:00
parent 5c486d1317
commit bfaf1f3689
7 changed files with 9 additions and 25 deletions

View File

@ -31,4 +31,6 @@ const inline char* kPlatformStrings[] = {
#define PK_UNREACHABLE() __builtin_unreachable();
#endif
#define PK_FATAL_ERROR(...) { fprintf(stderr, __VA_ARGS__); std::abort(); }
} // namespace pkpy

View File

@ -9,8 +9,6 @@
#include "pocketpy/interpreter/frame.hpp"
#include "pocketpy/interpreter/profiler.hpp"
#include <stdexcept>
namespace pkpy {
/* Stack manipulation macros */
@ -467,15 +465,7 @@ public:
template <typename T>
Type _find_type_in_cxx_typeid_map() {
auto it = _cxx_typeid_map.try_get(typeid(T));
if(it == nullptr) {
#if __GNUC__ || __clang__
throw std::runtime_error(__PRETTY_FUNCTION__ + std::string(" failed: T not found"));
#elif _MSC_VER
throw std::runtime_error(__FUNCSIG__ + std::string(" failed: T not found"));
#else
throw std::runtime_error("_find_type_in_cxx_typeid_map() failed: T not found");
#endif
}
if(it == nullptr) PK_FATAL_ERROR("T not found in cxx_typeid_map")
return *it;
}

View File

@ -1,14 +1,12 @@
#include "pocketpy/common/any.hpp"
#include "pocketpy/common/utils.hpp"
#include <stdexcept>
#include <cstdio>
namespace pkpy {
void any::__bad_any_cast(const std::type_index expected, const std::type_index actual) {
char error[256];
snprintf(error, sizeof(error), "bad_any_cast: expected %s, got %s", expected.name(), actual.name());
throw std::runtime_error(error);
PK_FATAL_ERROR("bad_any_cast: expected %s, got %s", expected.name(), actual.name())
}
any::any(any&& other) noexcept : data(other.data), _vt(other._vt) {

View File

@ -4,7 +4,6 @@
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <stdexcept>
namespace pkpy {

View File

@ -1,7 +1,6 @@
#include "pocketpy/common/str.hpp"
#include "pocketpy/common/gil.hpp"
#include <stdexcept>
#include <cassert>
#include <ostream>
#include <algorithm>
@ -17,7 +16,7 @@ int utf8len(unsigned char c, bool suppress) {
if((c & 0b11111000) == 0b11110000) return 4;
if((c & 0b11111100) == 0b11111000) return 5;
if((c & 0b11111110) == 0b11111100) return 6;
if(!suppress) throw std::runtime_error("invalid utf8 char: " + std::to_string(c));
if(!suppress) PK_FATAL_ERROR("invalid utf8 char")
return 0;
}
@ -380,7 +379,7 @@ StrName StrName::get(std::string_view s) {
// generate new index
// https://github.com/python/cpython/blob/3.12/Objects/dictobject.c#L175
uint16_t index = ((_pesudo_random_index * 5) + 1) & 65535;
if(index == 0) throw std::runtime_error("StrName index overflow");
if(index == 0) PK_FATAL_ERROR("StrName index overflow")
auto res = _r_interned().emplace(index, s);
assert(res.second);
s = std::string_view(res.first->second);

View File

@ -1,8 +1,6 @@
#include "pocketpy/objects/stackmemory.hpp"
#include "pocketpy/interpreter/frame.hpp"
#include <stdexcept>
namespace pkpy {
PyVar* FastLocals::try_get_name(StrName name) {
int index = co->varnames_inv.get(name, -1);
@ -72,7 +70,7 @@ void Frame::prepare_jump_break(ValueStack* _s, int target) {
int next_block = co->lines[target].iblock;
while(i >= 0 && i != next_block)
i = _exit_block(_s, i);
if(i != next_block) throw std::runtime_error("invalid jump");
assert(i == next_block);
}
}

View File

@ -1,7 +1,5 @@
#include "pocketpy/objects/namedict.hpp"
#include <stdexcept>
namespace pkpy {
#define HASH_PROBE_1(key, ok, i) \
@ -118,7 +116,7 @@ bool NameDict::contains(StrName key) const {
PyVar NameDict::operator[] (StrName key) const {
PyVar* val = try_get_2_likely_found(key);
if(val == nullptr) { throw std::runtime_error(_S("NameDict key not found: ", key.escape()).str()); }
if(val == nullptr) PK_FATAL_ERROR("NameDict key not found: %s", key.escape().c_str())
return *val;
}