fix a bug

Update vm.h

Update obj.h

Update obj.h
This commit is contained in:
blueloveTH 2022-11-15 18:24:25 +08:00
parent d7db109394
commit bff5002b65
3 changed files with 15 additions and 14 deletions

View File

@ -75,7 +75,11 @@ typedef std::variant<_Int,_Float,bool,_Str,PyVarList,_CppFunc,_Func,std::shared_
const int _SIZEOF_VALUE = sizeof(_Value); const int _SIZEOF_VALUE = sizeof(_Value);
#define UNREACHABLE() throw std::runtime_error("unreachable code! (this should be a bug, please report it)"); #ifdef POCKETPY_H
#define UNREACHABLE() throw std::runtime_error( "L" + std::to_string(__LINE__) + ": UNREACHABLE()! This should be a bug, please report it");
#else
#define UNREACHABLE() throw std::runtime_error( __FILE__ + ":" + std::to_string(__LINE__) + " UNREACHABLE()!");
#endif
struct PyObject { struct PyObject {
PyVarDict attribs; PyVarDict attribs;

View File

@ -581,9 +581,9 @@ extern "C" {
const char* type; // "int", "str", "float" ... const char* type; // "int", "str", "float" ...
const char* json; // json representation const char* json; // json representation
PyObjectDump(const char* _type, const char* _json){ PyObjectDump(_Str _type, _Str _json){
type = strdup(_type); type = strdup(_type.c_str());
json = strdup(_json); json = strdup(_json.c_str());
} }
~PyObjectDump(){ ~PyObjectDump(){
@ -597,9 +597,9 @@ extern "C" {
const char* _stdout; const char* _stdout;
const char* _stderr; const char* _stderr;
PyOutputDump(const char* _stdout, const char* _stderr){ PyOutputDump(_Str _stdout, _Str _stderr){
_stdout = strdup(_stdout); this->_stdout = strdup(_stdout.c_str());
_stderr = strdup(_stderr); this->_stderr = strdup(_stderr.c_str());
} }
~PyOutputDump(){ ~PyOutputDump(){
@ -657,8 +657,8 @@ extern "C" {
PyVar ret = vm->exec(code); PyVar ret = vm->exec(code);
if(ret == nullptr) return nullptr; if(ret == nullptr) return nullptr;
return new PyObjectDump( return new PyObjectDump(
ret->getTypeName().c_str(), ret->getTypeName(),
vm->PyStr_AS_C(vm->asJson(ret)).c_str() vm->PyStr_AS_C(vm->asJson(ret))
); );
} }
@ -711,10 +711,7 @@ extern "C" {
_StrStream* s_out = dynamic_cast<_StrStream*>(vm->_stdout); _StrStream* s_out = dynamic_cast<_StrStream*>(vm->_stdout);
_StrStream* s_err = dynamic_cast<_StrStream*>(vm->_stderr); _StrStream* s_err = dynamic_cast<_StrStream*>(vm->_stderr);
if(s_out == nullptr || s_err == nullptr) UNREACHABLE(); if(s_out == nullptr || s_err == nullptr) UNREACHABLE();
PyOutputDump* dump = new PyOutputDump( PyOutputDump* dump = new PyOutputDump(*s_out, *s_err);
s_out->str().c_str(),
s_out->str().c_str()
);
s_out->str(""); s_out->str("");
s_err->str(""); s_err->str("");
return dump; return dump;

View File

@ -927,7 +927,7 @@ enum ThreadState {
}; };
class ThreadedVM : public VM { class ThreadedVM : public VM {
std::thread* _thread; std::thread* _thread = nullptr;
std::atomic<ThreadState> state = THREAD_READY; std::atomic<ThreadState> state = THREAD_READY;
public: public:
ThreadedVM(bool use_stdio) : VM(use_stdio) {} ThreadedVM(bool use_stdio) : VM(use_stdio) {}