Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
TExceptionState.cpp63 linesDownload Raw Back to greenlet
1#ifndef GREENLET_EXCEPTION_STATE_CPP
2#define GREENLET_EXCEPTION_STATE_CPP
3
4#include <Python.h>
5#include "TGreenlet.hpp"
6
7namespace greenlet {
8
9
10ExceptionState::ExceptionState()
11{
12    this->clear();
13}
14
15void ExceptionState::operator<<(const PyThreadState *const tstate) noexcept
16{
17    this->exc_info = tstate->exc_info;
18    this->exc_state = tstate->exc_state;
19}
20
21void ExceptionState::operator>>(PyThreadState *const tstate) noexcept
22{
23    tstate->exc_state = this->exc_state;
24    tstate->exc_info =
25        this->exc_info ? this->exc_info : &tstate->exc_state;
26    this->clear();
27}
28
29void ExceptionState::clear() noexcept
30{
31    this->exc_info = nullptr;
32    this->exc_state.exc_value = nullptr;
33#if !GREENLET_PY311
34    this->exc_state.exc_type = nullptr;
35    this->exc_state.exc_traceback = nullptr;
36#endif
37    this->exc_state.previous_item = nullptr;
38}
39
40int ExceptionState::tp_traverse(visitproc visit, void* arg) noexcept
41{
42    Py_VISIT(this->exc_state.exc_value);
43#if !GREENLET_PY311
44    Py_VISIT(this->exc_state.exc_type);
45    Py_VISIT(this->exc_state.exc_traceback);
46#endif
47    return 0;
48}
49
50void ExceptionState::tp_clear() noexcept
51{
52    Py_CLEAR(this->exc_state.exc_value);
53#if !GREENLET_PY311
54    Py_CLEAR(this->exc_state.exc_type);
55    Py_CLEAR(this->exc_state.exc_traceback);
56#endif
57}
58
59
60}; // namespace greenlet
61
62#endif // GREENLET_EXCEPTION_STATE_CPP
63 
codekingpro/portable-devtools · Team Ai