mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Relands #103907 after it was reverted. This PR makes the new `ignore_hermetic_tls` argument of `check_pyobj` optional to avoid causing a compilation error in torchdistx Part of #91395 Pull Request resolved: https://github.com/pytorch/pytorch/pull/109039 Approved by: https://github.com/ezyang
57 lines
1.4 KiB
C
57 lines
1.4 KiB
C
#ifndef THP_STORAGE_INC
|
|
#define THP_STORAGE_INC
|
|
|
|
#include <torch/csrc/Types.h>
|
|
|
|
#define THPStorageStr "torch.UntypedStorage"
|
|
|
|
struct THPStorage {
|
|
PyObject_HEAD;
|
|
c10::MaybeOwned<c10::Storage> cdata;
|
|
bool is_hermetic;
|
|
};
|
|
|
|
TORCH_PYTHON_API PyObject* THPStorage_Wrap(c10::Storage storage);
|
|
TORCH_PYTHON_API PyObject* THPStorage_NewWithStorage(
|
|
PyTypeObject* type,
|
|
c10::Storage _storage,
|
|
c10::impl::PyInterpreterStatus status,
|
|
bool allow_preexisting_pyobj = false);
|
|
extern PyTypeObject* THPStorageClass;
|
|
|
|
static inline bool THPStorage_CheckTypeExact(PyTypeObject* tp) {
|
|
return tp == THPStorageClass;
|
|
}
|
|
|
|
static inline bool THPStorage_CheckExact(PyObject* obj) {
|
|
return THPStorage_CheckTypeExact(Py_TYPE(obj));
|
|
}
|
|
|
|
inline bool THPStorage_Check(PyObject* obj) {
|
|
if (!THPStorageClass)
|
|
return false;
|
|
|
|
const auto result = PyObject_IsInstance(obj, (PyObject*)THPStorageClass);
|
|
if (result == -1)
|
|
throw python_error();
|
|
return result;
|
|
}
|
|
|
|
bool THPStorage_init(PyObject* module);
|
|
void THPStorage_postInit(PyObject* module);
|
|
|
|
void THPStorage_assertNotNull(THPStorage* storage);
|
|
void THPStorage_assertNotNull(PyObject* obj);
|
|
|
|
extern PyTypeObject THPStorageType;
|
|
|
|
inline const c10::Storage& THPStorage_Unpack(THPStorage* storage) {
|
|
return *storage->cdata;
|
|
}
|
|
|
|
inline const c10::Storage& THPStorage_Unpack(PyObject* obj) {
|
|
return THPStorage_Unpack(reinterpret_cast<THPStorage*>(obj));
|
|
}
|
|
|
|
#endif
|