| #include <torch/csrc/Export.h> |
| #include <torch/csrc/python_headers.h> |
| class TORCH_PYTHON_API THPPointer { |
| THPPointer() : ptr(nullptr){}; |
| explicit THPPointer(T* ptr) noexcept : ptr(ptr){}; |
| THPPointer(THPPointer&& p) noexcept { |
| THPPointer& operator=(T* new_ptr) noexcept { |
| THPPointer& operator=(THPPointer&& p) noexcept { |
| explicit operator bool() const { |
| * An RAII-style, owning pointer to a PyObject. You must protect |
| * destruction of this object with the GIL. |
| * WARNING: Think twice before putting this as a field in a C++ |
| * struct. This class does NOT take out the GIL on destruction, |
| * so if you will need to ensure that the destructor of your struct |
| * is either (a) always invoked when the GIL is taken or (b) takes |
| * out the GIL itself. Easiest way to avoid this problem is to |
| * not use THPPointer in this situation. |
| using THPObjectPtr = THPPointer<PyObject>; |
| using THPCodeObjectPtr = THPPointer<PyCodeObject>; |
| using THPFrameObjectPtr = THPPointer<PyFrameObject>; |