| #pragma once |
|
|
| #include <c10/core/impl/PyInterpreter.h> |
| #include <c10/macros/Macros.h> |
| #include <c10/util/python_stub.h> |
|
|
| namespace c10 { |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| struct C10_API SafePyObject { |
| |
| SafePyObject(PyObject* data, c10::impl::PyInterpreter* pyinterpreter) |
| : data_(data), pyinterpreter_(pyinterpreter) {} |
|
|
| |
| |
| SafePyObject(SafePyObject const&) = delete; |
| SafePyObject& operator=(SafePyObject const&) = delete; |
|
|
| ~SafePyObject() { |
| (*pyinterpreter_)->decref(data_, false); |
| } |
|
|
| c10::impl::PyInterpreter& pyinterpreter() const { |
| return *pyinterpreter_; |
| } |
| PyObject* ptr(const c10::impl::PyInterpreter*) const; |
|
|
| private: |
| PyObject* data_; |
| c10::impl::PyInterpreter* pyinterpreter_; |
| }; |
|
|
| |
| |
| |
| struct C10_API SafePyHandle { |
| SafePyHandle() : data_(nullptr), pyinterpreter_(nullptr) {} |
| SafePyHandle(PyObject* data, c10::impl::PyInterpreter* pyinterpreter) |
| : data_(data), pyinterpreter_(pyinterpreter) {} |
|
|
| c10::impl::PyInterpreter& pyinterpreter() const { |
| return *pyinterpreter_; |
| } |
| PyObject* ptr(const c10::impl::PyInterpreter*) const; |
| void reset() { |
| data_ = nullptr; |
| pyinterpreter_ = nullptr; |
| } |
| operator bool() { |
| return data_; |
| } |
|
|
| private: |
| PyObject* data_; |
| c10::impl::PyInterpreter* pyinterpreter_; |
| }; |
|
|
| } |
|
|