mirror of
https://github.com/pocketpy/pocketpy
synced 2025-12-06 18:20:17 +00:00
mark stdout_write and stderr_write as virtual
This commit is contained in:
parent
ca83cdf995
commit
d166766ebf
@ -160,4 +160,15 @@ These two fields are C function pointers `PrintFunc` with the following signatur
|
|||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
typedef void(*PrintFunc)(const char*, int)
|
typedef void(*PrintFunc)(const char*, int)
|
||||||
|
```
|
||||||
|
|
||||||
|
Or you can override these two virtual functions:
|
||||||
|
```cpp
|
||||||
|
virtual void stdout_write(const Str& s){
|
||||||
|
_stdout(s.data, s.size);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void stderr_write(const Str& s){
|
||||||
|
_stderr(s.data, s.size);
|
||||||
|
}
|
||||||
```
|
```
|
||||||
@ -205,10 +205,14 @@ public:
|
|||||||
void _push_varargs(PyObject* _0, PyObject* _1, PyObject* _2){ PUSH(_0); PUSH(_1); PUSH(_2); }
|
void _push_varargs(PyObject* _0, PyObject* _1, PyObject* _2){ PUSH(_0); PUSH(_1); PUSH(_2); }
|
||||||
void _push_varargs(PyObject* _0, PyObject* _1, PyObject* _2, PyObject* _3){ PUSH(_0); PUSH(_1); PUSH(_2); PUSH(_3); }
|
void _push_varargs(PyObject* _0, PyObject* _1, PyObject* _2, PyObject* _3){ PUSH(_0); PUSH(_1); PUSH(_2); PUSH(_3); }
|
||||||
|
|
||||||
void stdout_write(const Str& s){
|
virtual void stdout_write(const Str& s){
|
||||||
_stdout(s.data, s.size);
|
_stdout(s.data, s.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void stderr_write(const Str& s){
|
||||||
|
_stderr(s.data, s.size);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
PyObject* call(PyObject* callable, Args&&... args){
|
PyObject* call(PyObject* callable, Args&&... args){
|
||||||
PUSH(callable);
|
PUSH(callable);
|
||||||
|
|||||||
@ -164,21 +164,20 @@ namespace pkpy{
|
|||||||
#endif
|
#endif
|
||||||
return _exec(code, _module);
|
return _exec(code, _module);
|
||||||
}catch (const Exception& e){
|
}catch (const Exception& e){
|
||||||
Str sum = e.summary() + "\n";
|
stderr_write(e.summary() + "\n");
|
||||||
_stderr(sum.data, sum.size);
|
|
||||||
}
|
}
|
||||||
#if !PK_DEBUG_FULL_EXCEPTION
|
#if !PK_DEBUG_FULL_EXCEPTION
|
||||||
catch(const std::exception& e) {
|
catch(const std::exception& e) {
|
||||||
Str msg = "An std::exception occurred! It could be a bug.\n";
|
Str msg = "An std::exception occurred! It could be a bug.\n";
|
||||||
msg = msg + e.what() + "\n";
|
msg = msg + e.what() + "\n";
|
||||||
_stderr(msg.data, msg.size);
|
stderr_write(msg);
|
||||||
}
|
}
|
||||||
catch(NeedMoreLines){
|
catch(NeedMoreLines){
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
catch(...) {
|
catch(...) {
|
||||||
Str msg = "An unknown exception occurred! It could be a bug. Please report it to @blueloveTH on GitHub.\n";
|
Str msg = "An unknown exception occurred! It could be a bug. Please report it to @blueloveTH on GitHub.\n";
|
||||||
_stderr(msg.data, msg.size);
|
stderr_write(msg);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
callstack.clear();
|
callstack.clear();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user