From 353fedfbbedef5a497f7dedd48f7ff1b1d83923d Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Wed, 7 Dec 2022 21:37:21 +0800 Subject: [PATCH] up --- src/__stl__.h | 5 ++++- src/safestl.h | 7 +++++++ src/vm.h | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/__stl__.h b/src/__stl__.h index ed44e8fd..549925cc 100644 --- a/src/__stl__.h +++ b/src/__stl__.h @@ -30,4 +30,7 @@ #define UNREACHABLE() throw std::runtime_error( __FILE__ + std::string(":") + std::to_string(__LINE__) + " UNREACHABLE()!"); #endif -#define PK_VERSION "0.4.7" \ No newline at end of file +#define PK_VERSION "0.4.8" + +//#define PKPY_NO_TYPE_CHECK +//#define PKPY_NO_INDEX_CHECK \ No newline at end of file diff --git a/src/safestl.h b/src/safestl.h index 9c315ab6..09e7df94 100644 --- a/src/safestl.h +++ b/src/safestl.h @@ -13,10 +13,12 @@ class PyVarList: public std::vector { PyVar& at(size_t) = delete; inline void __checkIndex(size_t i) const { +#ifndef PKPY_NO_INDEX_CHECK if (i >= size()){ auto msg = "std::vector index out of range, " + std::to_string(i) + " not in [0, " + std::to_string(size()) + ")"; throw std::out_of_range(msg); } +#endif } public: PyVar& operator[](size_t i) { @@ -40,6 +42,8 @@ class PyVarDict: public emhash8::HashMap<_Str, PyVar> { PyVar& at(const _Str&) = delete; public: + +#ifndef PKPY_NO_INDEX_CHECK PyVar& operator[](const _Str& key) { return emhash8::HashMap<_Str, PyVar>::operator[](key); } @@ -52,6 +56,7 @@ public: } return it->second; } +#endif PyVarDict() : emhash8::HashMap<_Str, PyVar>(5) {} }; @@ -66,10 +71,12 @@ namespace pkpy { uint8_t _size = 0; inline void __checkIndex(uint8_t i) const { +#ifndef PKPY_NO_INDEX_CHECK if (i >= _size){ auto msg = "pkpy:ArgList index out of range, " + std::to_string(i) + " not in [0, " + std::to_string(size()) + ")"; throw std::out_of_range(msg); } +#endif } void __tryAlloc(uint8_t n){ diff --git a/src/vm.h b/src/vm.h index bcc03b7f..c42ba473 100644 --- a/src/vm.h +++ b/src/vm.h @@ -919,7 +919,9 @@ public: } inline void __checkType(const PyVar& obj, const PyVar& type){ +#ifndef PKPY_NO_TYPE_CHECK if(!obj->isType(type)) typeError("expected '" + UNION_TP_NAME(type) + "', but got '" + UNION_TP_NAME(obj) + "'"); +#endif } inline void __checkArgSize(const pkpy::ArgList& args, int size, bool method=false){