mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-25 14:00:18 +00:00
some fix about <stdexcept>
This commit is contained in:
parent
5c486d1317
commit
bfaf1f3689
@ -31,4 +31,6 @@ const inline char* kPlatformStrings[] = {
|
|||||||
#define PK_UNREACHABLE() __builtin_unreachable();
|
#define PK_UNREACHABLE() __builtin_unreachable();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define PK_FATAL_ERROR(...) { fprintf(stderr, __VA_ARGS__); std::abort(); }
|
||||||
|
|
||||||
} // namespace pkpy
|
} // namespace pkpy
|
||||||
|
|||||||
@ -9,8 +9,6 @@
|
|||||||
#include "pocketpy/interpreter/frame.hpp"
|
#include "pocketpy/interpreter/frame.hpp"
|
||||||
#include "pocketpy/interpreter/profiler.hpp"
|
#include "pocketpy/interpreter/profiler.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
namespace pkpy {
|
namespace pkpy {
|
||||||
|
|
||||||
/* Stack manipulation macros */
|
/* Stack manipulation macros */
|
||||||
@ -467,15 +465,7 @@ public:
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
Type _find_type_in_cxx_typeid_map() {
|
Type _find_type_in_cxx_typeid_map() {
|
||||||
auto it = _cxx_typeid_map.try_get(typeid(T));
|
auto it = _cxx_typeid_map.try_get(typeid(T));
|
||||||
if(it == nullptr) {
|
if(it == nullptr) PK_FATAL_ERROR("T not found in cxx_typeid_map")
|
||||||
#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
|
|
||||||
}
|
|
||||||
return *it;
|
return *it;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,14 +1,12 @@
|
|||||||
#include "pocketpy/common/any.hpp"
|
#include "pocketpy/common/any.hpp"
|
||||||
|
#include "pocketpy/common/utils.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
namespace pkpy {
|
namespace pkpy {
|
||||||
|
|
||||||
void any::__bad_any_cast(const std::type_index expected, const std::type_index actual) {
|
void any::__bad_any_cast(const std::type_index expected, const std::type_index actual) {
|
||||||
char error[256];
|
PK_FATAL_ERROR("bad_any_cast: expected %s, got %s", expected.name(), actual.name())
|
||||||
snprintf(error, sizeof(error), "bad_any_cast: expected %s, got %s", expected.name(), actual.name());
|
|
||||||
throw std::runtime_error(error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
any::any(any&& other) noexcept : data(other.data), _vt(other._vt) {
|
any::any(any&& other) noexcept : data(other.data), _vt(other._vt) {
|
||||||
|
|||||||
@ -4,7 +4,6 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
namespace pkpy {
|
namespace pkpy {
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
#include "pocketpy/common/str.hpp"
|
#include "pocketpy/common/str.hpp"
|
||||||
#include "pocketpy/common/gil.hpp"
|
#include "pocketpy/common/gil.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@ -17,7 +16,7 @@ int utf8len(unsigned char c, bool suppress) {
|
|||||||
if((c & 0b11111000) == 0b11110000) return 4;
|
if((c & 0b11111000) == 0b11110000) return 4;
|
||||||
if((c & 0b11111100) == 0b11111000) return 5;
|
if((c & 0b11111100) == 0b11111000) return 5;
|
||||||
if((c & 0b11111110) == 0b11111100) return 6;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -380,7 +379,7 @@ StrName StrName::get(std::string_view s) {
|
|||||||
// generate new index
|
// generate new index
|
||||||
// https://github.com/python/cpython/blob/3.12/Objects/dictobject.c#L175
|
// https://github.com/python/cpython/blob/3.12/Objects/dictobject.c#L175
|
||||||
uint16_t index = ((_pesudo_random_index * 5) + 1) & 65535;
|
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);
|
auto res = _r_interned().emplace(index, s);
|
||||||
assert(res.second);
|
assert(res.second);
|
||||||
s = std::string_view(res.first->second);
|
s = std::string_view(res.first->second);
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
#include "pocketpy/objects/stackmemory.hpp"
|
#include "pocketpy/objects/stackmemory.hpp"
|
||||||
#include "pocketpy/interpreter/frame.hpp"
|
#include "pocketpy/interpreter/frame.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
namespace pkpy {
|
namespace pkpy {
|
||||||
PyVar* FastLocals::try_get_name(StrName name) {
|
PyVar* FastLocals::try_get_name(StrName name) {
|
||||||
int index = co->varnames_inv.get(name, -1);
|
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;
|
int next_block = co->lines[target].iblock;
|
||||||
while(i >= 0 && i != next_block)
|
while(i >= 0 && i != next_block)
|
||||||
i = _exit_block(_s, i);
|
i = _exit_block(_s, i);
|
||||||
if(i != next_block) throw std::runtime_error("invalid jump");
|
assert(i == next_block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
#include "pocketpy/objects/namedict.hpp"
|
#include "pocketpy/objects/namedict.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
namespace pkpy {
|
namespace pkpy {
|
||||||
|
|
||||||
#define HASH_PROBE_1(key, ok, i) \
|
#define HASH_PROBE_1(key, ok, i) \
|
||||||
@ -118,7 +116,7 @@ bool NameDict::contains(StrName key) const {
|
|||||||
|
|
||||||
PyVar NameDict::operator[] (StrName key) const {
|
PyVar NameDict::operator[] (StrName key) const {
|
||||||
PyVar* val = try_get_2_likely_found(key);
|
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;
|
return *val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user