Bug Summary

File:build/../torch/csrc/Device.cpp
Warning:line 148, column 27
PyObject ownership leak with reference count of 1

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name Device.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -analyzer-output=html -analyzer-checker=python -analyzer-disable-checker=deadcode -analyzer-config prune-paths=true,suppress-c++-stdlib=true,suppress-inlined-defensive-checks=false,suppress-null-return-paths=false,crosscheck-with-z3=true,model-path=/opt/pyrefcon/lib/pyrefcon/models/models -analyzer-config experimental-enable-naive-ctu-analysis=true,ctu-dir=/tmp/pyrefcon/pytorch/csa-scan,ctu-index-name=/tmp/pyrefcon/pytorch/csa-scan/externalDefMap.txt,ctu-invocation-list=/tmp/pyrefcon/pytorch/csa-scan/invocations.yaml,display-ctu-progress=false -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=none -relaxed-aliasing -fno-rounding-math -ffp-exception-behavior=ignore -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/tmp/pyrefcon/pytorch/build -resource-dir /opt/pyrefcon/lib/clang/13.0.0 -isystem third_party/gloo -isystem ../cmake/../third_party/gloo -isystem ../cmake/../third_party/googletest/googlemock/include -isystem ../cmake/../third_party/googletest/googletest/include -isystem ../third_party/protobuf/src -isystem ../third_party/gemmlowp -isystem ../third_party/neon2sse -isystem ../third_party/XNNPACK/include -isystem ../third_party -isystem ../cmake/../third_party/eigen -isystem /opt/pyrefcon/lib/pyrefcon/models/python3.8 -isystem /usr/lib/python3/dist-packages/numpy/core/include -isystem ../cmake/../third_party/pybind11/include -isystem /usr/lib/x86_64-linux-gnu/openmpi/include/openmpi -isystem /usr/lib/x86_64-linux-gnu/openmpi/include -isystem ../third_party/ideep/mkl-dnn/include -isystem ../third_party/ideep/include -D BUILDING_TESTS -D FMT_HEADER_ONLY=1 -D HAVE_MALLOC_USABLE_SIZE=1 -D HAVE_MMAP=1 -D HAVE_SHM_OPEN=1 -D HAVE_SHM_UNLINK=1 -D MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS -D ONNXIFI_ENABLE_EXT=1 -D ONNX_ML=1 -D ONNX_NAMESPACE=onnx_torch -D THP_BUILD_MAIN_LIB -D USE_C10D -D USE_C10D_GLOO -D USE_C10D_MPI -D USE_DISTRIBUTED -D USE_EXTERNAL_MZCRC -D USE_NUMPY -D USE_RPC -D USE_TENSORPIPE -D USE_VALGRIND -D _FILE_OFFSET_BITS=64 -D torch_python_EXPORTS -I aten/src -I ../aten/src -I . -I ../ -I ../cmake/../third_party/benchmark/include -I caffe2/contrib/aten -I ../third_party/onnx -I third_party/onnx -I ../third_party/foxi -I third_party/foxi -I ../torch/.. -I ../torch/../aten/src -I ../torch/../aten/src/TH -I caffe2/aten/src -I third_party -I ../torch/../third_party/valgrind-headers -I ../torch/../third_party/gloo -I ../torch/../third_party/onnx -I ../torch/csrc -I ../torch/csrc/api/include -I ../torch/lib -I ../torch/lib/libshm -I ../torch/csrc/distributed -I ../torch/csrc/api -I ../c10/.. -I third_party/ideep/mkl-dnn/include -I ../third_party/ideep/mkl-dnn/src/../include -I ../torch/lib/libshm/../../../torch/lib -I ../third_party/fmt/include -D USE_PTHREADPOOL -D NDEBUG -D USE_KINETO -D LIBKINETO_NOCUPTI -D USE_FBGEMM -D USE_QNNPACK -D USE_PYTORCH_QNNPACK -D USE_XNNPACK -D SYMBOLICATE_MOBILE_DEBUG_HANDLE -D HAVE_AVX_CPU_DEFINITION -D HAVE_AVX2_CPU_DEFINITION -D NDEBUG -D NDEBUG -D CAFFE2_USE_GLOO -D HAVE_GCC_GET_CPUID -D USE_AVX -D USE_AVX2 -D TH_HAVE_THREAD -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/x86_64-linux-gnu/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/backward -internal-isystem /opt/pyrefcon/lib/clang/13.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -Wno-narrowing -Wall -Wextra -Werror=return-type -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-result -Wno-unused-local-typedefs -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-psabi -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -Wno-unused-but-set-variable -Wno-maybe-uninitialized -Werror=format -Werror=cast-function-type -Wno-stringop-overflow -Wno-write-strings -Wno-strict-aliasing -w -std=gnu++14 -fdeprecated-macro -fdebug-compilation-dir=/tmp/pyrefcon/pytorch/build -ferror-limit 19 -fvisibility-inlines-hidden -fopenmp -fopenmp-cuda-parallel-target-regions -pthread -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -faligned-allocation -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/pyrefcon/pytorch/csa-scan/reports -x c++ ../torch/csrc/Device.cpp

../torch/csrc/Device.cpp

1#include <torch/csrc/Device.h>
2
3#include <torch/csrc/Exceptions.h>
4#include <torch/csrc/utils/object_ptr.h>
5#include <torch/csrc/utils/python_arg_parser.h>
6#include <torch/csrc/utils/python_strings.h>
7#include <torch/csrc/utils/python_numbers.h>
8#include <torch/csrc/utils/pybind.h>
9
10#include <ATen/Device.h>
11#include <c10/util/Exception.h>
12
13#include <cstring>
14#include <limits>
15#include <structmember.h>
16#include <sstream>
17
18PyObject *THPDevice_New(const at::Device& device)
19{
20 auto type = (PyTypeObject*)&THPDeviceType;
21 auto self = THPObjectPtr{type->tp_alloc(type, 0)};
22 if (!self) throw python_error();
23 auto self_ = reinterpret_cast<THPDevice*>(self.get());
24 self_->device = device;
25 return self.release();
26}
27
28PyObject *THPDevice_repr(THPDevice *self)
29{
30 std::ostringstream oss;
31 oss << "device(type=\'" << self->device.type() << "\'";
32 if (self->device.has_index()) {
33 // `self->device.index()` returns uint8_t which is treated as ascii while printing,
34 // hence casting it to uint16_t.
35 // https://stackoverflow.com/questions/19562103/uint8-t-cant-be-printed-with-cout
36 oss << ", index=" << static_cast<uint16_t>(self->device.index());
37 }
38 oss << ")";
39 return THPUtils_packString(oss.str().c_str());
40}
41
42PyObject *THPDevice_str(THPDevice *self)
43{
44 std::ostringstream oss;
45 oss << self->device;
46 return THPUtils_packString(oss.str().c_str());
47}
48
49PyObject *THPDevice_pynew(PyTypeObject *type, PyObject *args, PyObject *kwargs)
50{
51 HANDLE_TH_ERRORStry { torch::PyWarningHandler __enforce_warning_buffer; try {
52 static torch::PythonArgParser parser({
53 "Device(Device device)",
54 "Device(c10::string_view type, int64_t? index=-1)"
55 });
56 torch::ParsedArgs<2> parsed_args;
57 auto r = parser.parse(args, kwargs, parsed_args);
58 if (r.idx == 0) {
59 auto device = r.device(0);
60 return THPDevice_New(device);
61 } else if (r.idx == 1) {
62 auto as_device = r.device(0); // this works, because device can take strings
63 auto device_type = r.string(0);
64 if (as_device.has_index()) {
65 throw std::runtime_error("type (string) must not include an index because index "
66 "was passed explicitly: " + device_type);
67 }
68 int32_t device_index = -1;
69 if (!r.isNone(1)) {
70 device_index = r.toInt64(1);
71 // -1 is allowed in ATen/C++, to mean the default device, but not in
72 // Python.
73 TORCH_CHECK(device_index >= 0, "Device index must not be negative")if ((__builtin_expect(static_cast<bool>(!(device_index >=
0)), 0))) { ::c10::detail::torchCheckFail( __func__, "../torch/csrc/Device.cpp"
, static_cast<uint32_t>(73), (::c10::detail::torchCheckMsgImpl
( "Expected " "device_index >= 0" " to be true, but got false. "
"(Could this error message be improved? If so, " "please report an enhancement request to PyTorch.)"
, "Device index must not be negative"))); }
;
74 }
75 at::Device device(as_device.type(), device_index);
76 return THPDevice_New(device);
77 }
78 Py_RETURN_NONEreturn _Py_INCREF(((PyObject*)((&_Py_NoneStruct)))), (&
_Py_NoneStruct)
;
79 END_HANDLE_TH_ERRORS} catch(...) { __enforce_warning_buffer.set_in_exception(); throw
; } } catch (python_error & e) { e.restore(); return nullptr
; } catch (const c10::IndexError& e) { auto msg = torch::
get_cpp_stacktraces_enabled() ? e.what() : e.what_without_backtrace
(); PyErr_SetString(PyExc_IndexError, torch::processErrorMsg(
msg)); return nullptr; } catch (const c10::ValueError& e)
{ auto msg = torch::get_cpp_stacktraces_enabled() ? e.what()
: e.what_without_backtrace(); PyErr_SetString(PyExc_ValueError
, torch::processErrorMsg(msg)); return nullptr; } catch (const
c10::TypeError& e) { auto msg = torch::get_cpp_stacktraces_enabled
() ? e.what() : e.what_without_backtrace(); PyErr_SetString(PyExc_TypeError
, torch::processErrorMsg(msg)); return nullptr; } catch (const
c10::NotImplementedError& e) { auto msg = torch::get_cpp_stacktraces_enabled
() ? e.what() : e.what_without_backtrace(); PyErr_SetString(PyExc_NotImplementedError
, torch::processErrorMsg(msg)); return nullptr; } catch (const
c10::Error& e) { auto msg = torch::get_cpp_stacktraces_enabled
() ? e.what() : e.what_without_backtrace(); PyErr_SetString(PyExc_RuntimeError
, torch::processErrorMsg(msg)); return nullptr; } catch (torch
::PyTorchError & e) { auto msg = torch::processErrorMsg(e
.what()); PyErr_SetString(e.python_type(), msg); return nullptr
; } catch (const std::exception& e) { auto msg = torch::processErrorMsg
(e.what()); PyErr_SetString(PyExc_RuntimeError, msg); return nullptr
; }
80}
81
82PyObject *THPDevice_type(THPDevice *self, PyObject *noargs)
83{
84 HANDLE_TH_ERRORStry { torch::PyWarningHandler __enforce_warning_buffer; try {
85 std::ostringstream oss;
86 oss << self->device.type();
87 return THPUtils_packString(oss.str().c_str());
88 Py_RETURN_NONEreturn _Py_INCREF(((PyObject*)((&_Py_NoneStruct)))), (&
_Py_NoneStruct)
;
89 END_HANDLE_TH_ERRORS} catch(...) { __enforce_warning_buffer.set_in_exception(); throw
; } } catch (python_error & e) { e.restore(); return nullptr
; } catch (const c10::IndexError& e) { auto msg = torch::
get_cpp_stacktraces_enabled() ? e.what() : e.what_without_backtrace
(); PyErr_SetString(PyExc_IndexError, torch::processErrorMsg(
msg)); return nullptr; } catch (const c10::ValueError& e)
{ auto msg = torch::get_cpp_stacktraces_enabled() ? e.what()
: e.what_without_backtrace(); PyErr_SetString(PyExc_ValueError
, torch::processErrorMsg(msg)); return nullptr; } catch (const
c10::TypeError& e) { auto msg = torch::get_cpp_stacktraces_enabled
() ? e.what() : e.what_without_backtrace(); PyErr_SetString(PyExc_TypeError
, torch::processErrorMsg(msg)); return nullptr; } catch (const
c10::NotImplementedError& e) { auto msg = torch::get_cpp_stacktraces_enabled
() ? e.what() : e.what_without_backtrace(); PyErr_SetString(PyExc_NotImplementedError
, torch::processErrorMsg(msg)); return nullptr; } catch (const
c10::Error& e) { auto msg = torch::get_cpp_stacktraces_enabled
() ? e.what() : e.what_without_backtrace(); PyErr_SetString(PyExc_RuntimeError
, torch::processErrorMsg(msg)); return nullptr; } catch (torch
::PyTorchError & e) { auto msg = torch::processErrorMsg(e
.what()); PyErr_SetString(e.python_type(), msg); return nullptr
; } catch (const std::exception& e) { auto msg = torch::processErrorMsg
(e.what()); PyErr_SetString(PyExc_RuntimeError, msg); return nullptr
; }
90}
91
92PyObject *THPDevice_index(THPDevice *self, PyObject *noargs)
93{
94 HANDLE_TH_ERRORStry { torch::PyWarningHandler __enforce_warning_buffer; try {
95 if (self->device.has_index()) {
96 return THPUtils_packInt64(self->device.index());
97 } else {
98 Py_RETURN_NONEreturn _Py_INCREF(((PyObject*)((&_Py_NoneStruct)))), (&
_Py_NoneStruct)
;
99 }
100 END_HANDLE_TH_ERRORS} catch(...) { __enforce_warning_buffer.set_in_exception(); throw
; } } catch (python_error & e) { e.restore(); return nullptr
; } catch (const c10::IndexError& e) { auto msg = torch::
get_cpp_stacktraces_enabled() ? e.what() : e.what_without_backtrace
(); PyErr_SetString(PyExc_IndexError, torch::processErrorMsg(
msg)); return nullptr; } catch (const c10::ValueError& e)
{ auto msg = torch::get_cpp_stacktraces_enabled() ? e.what()
: e.what_without_backtrace(); PyErr_SetString(PyExc_ValueError
, torch::processErrorMsg(msg)); return nullptr; } catch (const
c10::TypeError& e) { auto msg = torch::get_cpp_stacktraces_enabled
() ? e.what() : e.what_without_backtrace(); PyErr_SetString(PyExc_TypeError
, torch::processErrorMsg(msg)); return nullptr; } catch (const
c10::NotImplementedError& e) { auto msg = torch::get_cpp_stacktraces_enabled
() ? e.what() : e.what_without_backtrace(); PyErr_SetString(PyExc_NotImplementedError
, torch::processErrorMsg(msg)); return nullptr; } catch (const
c10::Error& e) { auto msg = torch::get_cpp_stacktraces_enabled
() ? e.what() : e.what_without_backtrace(); PyErr_SetString(PyExc_RuntimeError
, torch::processErrorMsg(msg)); return nullptr; } catch (torch
::PyTorchError & e) { auto msg = torch::processErrorMsg(e
.what()); PyErr_SetString(e.python_type(), msg); return nullptr
; } catch (const std::exception& e) { auto msg = torch::processErrorMsg
(e.what()); PyErr_SetString(PyExc_RuntimeError, msg); return nullptr
; }
101}
102
103static Py_ssize_t THPDevice_hash(THPDevice *self)
104{
105 HANDLE_TH_ERRORStry { torch::PyWarningHandler __enforce_warning_buffer; try {
106 return static_cast<Py_ssize_t>(std::hash<at::Device>{}(self->device) % std::numeric_limits<Py_ssize_t>::max());
107 END_HANDLE_TH_ERRORS_RET(-1)} catch(...) { __enforce_warning_buffer.set_in_exception(); throw
; } } catch (python_error & e) { e.restore(); return -1; }
catch (const c10::IndexError& e) { auto msg = torch::get_cpp_stacktraces_enabled
() ? e.what() : e.what_without_backtrace(); PyErr_SetString(PyExc_IndexError
, torch::processErrorMsg(msg)); return -1; } catch (const c10
::ValueError& e) { auto msg = torch::get_cpp_stacktraces_enabled
() ? e.what() : e.what_without_backtrace(); PyErr_SetString(PyExc_ValueError
, torch::processErrorMsg(msg)); return -1; } catch (const c10
::TypeError& e) { auto msg = torch::get_cpp_stacktraces_enabled
() ? e.what() : e.what_without_backtrace(); PyErr_SetString(PyExc_TypeError
, torch::processErrorMsg(msg)); return -1; } catch (const c10
::NotImplementedError& e) { auto msg = torch::get_cpp_stacktraces_enabled
() ? e.what() : e.what_without_backtrace(); PyErr_SetString(PyExc_NotImplementedError
, torch::processErrorMsg(msg)); return -1; } catch (const c10
::Error& e) { auto msg = torch::get_cpp_stacktraces_enabled
() ? e.what() : e.what_without_backtrace(); PyErr_SetString(PyExc_RuntimeError
, torch::processErrorMsg(msg)); return -1; } catch (torch::PyTorchError
& e) { auto msg = torch::processErrorMsg(e.what()); PyErr_SetString
(e.python_type(), msg); return -1; } catch (const std::exception
& e) { auto msg = torch::processErrorMsg(e.what()); PyErr_SetString
(PyExc_RuntimeError, msg); return -1; }
108}
109
110PyObject *THPDevice_rc(PyObject *a, PyObject *b, int op) {
111 HANDLE_TH_ERRORStry { torch::PyWarningHandler __enforce_warning_buffer; try {
112 if (!THPDevice_Check(a) || !THPDevice_Check(b)) {
113 // Py_RETURN_NOTIMPLEMENTED not in python 2.
114 Py_INCREF(Py_NotImplemented)_Py_INCREF(((PyObject*)((&_Py_NotImplementedStruct))));
115 return Py_NotImplemented(&_Py_NotImplementedStruct);
116 }
117 THPDevice *da = reinterpret_cast<THPDevice*>(a);
118 THPDevice *db = reinterpret_cast<THPDevice*>(b);
119
120 switch(op) {
121 case Py_EQ2:
122 if (da->device == db->device) {
123 Py_RETURN_TRUEreturn _Py_INCREF(((PyObject*)(((PyObject *) &_Py_TrueStruct
)))), ((PyObject *) &_Py_TrueStruct)
;
124 } else {
125 Py_RETURN_FALSEreturn _Py_INCREF(((PyObject*)(((PyObject *) &_Py_FalseStruct
)))), ((PyObject *) &_Py_FalseStruct)
;
126 }
127 case Py_NE3:
128 if (da->device == db->device) {
129 Py_RETURN_FALSEreturn _Py_INCREF(((PyObject*)(((PyObject *) &_Py_FalseStruct
)))), ((PyObject *) &_Py_FalseStruct)
;
130 } else {
131 Py_RETURN_TRUEreturn _Py_INCREF(((PyObject*)(((PyObject *) &_Py_TrueStruct
)))), ((PyObject *) &_Py_TrueStruct)
;
132 }
133 case Py_LT0:
134 case Py_LE1:
135 case Py_GT4:
136 case Py_GE5:
137 throw torch::TypeError("comparison not implemented");
138 default:
139 throw torch::TypeError("unexpected comparison op");
140 }
141 END_HANDLE_TH_ERRORS} catch(...) { __enforce_warning_buffer.set_in_exception(); throw
; } } catch (python_error & e) { e.restore(); return nullptr
; } catch (const c10::IndexError& e) { auto msg = torch::
get_cpp_stacktraces_enabled() ? e.what() : e.what_without_backtrace
(); PyErr_SetString(PyExc_IndexError, torch::processErrorMsg(
msg)); return nullptr; } catch (const c10::ValueError& e)
{ auto msg = torch::get_cpp_stacktraces_enabled() ? e.what()
: e.what_without_backtrace(); PyErr_SetString(PyExc_ValueError
, torch::processErrorMsg(msg)); return nullptr; } catch (const
c10::TypeError& e) { auto msg = torch::get_cpp_stacktraces_enabled
() ? e.what() : e.what_without_backtrace(); PyErr_SetString(PyExc_TypeError
, torch::processErrorMsg(msg)); return nullptr; } catch (const
c10::NotImplementedError& e) { auto msg = torch::get_cpp_stacktraces_enabled
() ? e.what() : e.what_without_backtrace(); PyErr_SetString(PyExc_NotImplementedError
, torch::processErrorMsg(msg)); return nullptr; } catch (const
c10::Error& e) { auto msg = torch::get_cpp_stacktraces_enabled
() ? e.what() : e.what_without_backtrace(); PyErr_SetString(PyExc_RuntimeError
, torch::processErrorMsg(msg)); return nullptr; } catch (torch
::PyTorchError & e) { auto msg = torch::processErrorMsg(e
.what()); PyErr_SetString(e.python_type(), msg); return nullptr
; } catch (const std::exception& e) { auto msg = torch::processErrorMsg
(e.what()); PyErr_SetString(PyExc_RuntimeError, msg); return nullptr
; }
142}
143
144PyObject *THPDevice_reduce(PyObject *_self, PyObject *noargs)
145{
146 HANDLE_TH_ERRORStry { torch::PyWarningHandler __enforce_warning_buffer; try {
147 auto self = (THPDevice*)_self;
148 auto ret = THPObjectPtr{PyTuple_New(2)};
1
Calling 'PyTuple_New'
3
Returning from 'PyTuple_New'
9
PyObject ownership leak with reference count of 1
149 if (!ret) throw python_error();
4
Assuming the condition is false
5
Taking false branch
150
151 py::object torch_module = py::module::import("torch");
152 py::object torch_device = torch_module.attr("device");
153 PyTuple_SET_ITEM(ret.get(), 0, torch_device.release().ptr())PyTuple_SetItem(ret.get(), 0, torch_device.release().ptr());
154
155 THPObjectPtr args;
156 std::ostringstream oss;
157 oss << self->device.type();
158 if (self->device.has_index()) {
6
Taking false branch
159 args = THPObjectPtr{Py_BuildValue("(si)", oss.str().c_str(), self->device.index())};
160 } else {
161 args = THPObjectPtr{Py_BuildValue("(s)", oss.str().c_str())};
162 }
163 if (!args) throw python_error();
7
Assuming the condition is true
8
Taking true branch
164 PyTuple_SET_ITEM(ret.get(), 1, args.release())PyTuple_SetItem(ret.get(), 1, args.release());
165
166 return ret.release();
167 END_HANDLE_TH_ERRORS} catch(...) { __enforce_warning_buffer.set_in_exception(); throw
; } } catch (python_error & e) { e.restore(); return nullptr
; } catch (const c10::IndexError& e) { auto msg = torch::
get_cpp_stacktraces_enabled() ? e.what() : e.what_without_backtrace
(); PyErr_SetString(PyExc_IndexError, torch::processErrorMsg(
msg)); return nullptr; } catch (const c10::ValueError& e)
{ auto msg = torch::get_cpp_stacktraces_enabled() ? e.what()
: e.what_without_backtrace(); PyErr_SetString(PyExc_ValueError
, torch::processErrorMsg(msg)); return nullptr; } catch (const
c10::TypeError& e) { auto msg = torch::get_cpp_stacktraces_enabled
() ? e.what() : e.what_without_backtrace(); PyErr_SetString(PyExc_TypeError
, torch::processErrorMsg(msg)); return nullptr; } catch (const
c10::NotImplementedError& e) { auto msg = torch::get_cpp_stacktraces_enabled
() ? e.what() : e.what_without_backtrace(); PyErr_SetString(PyExc_NotImplementedError
, torch::processErrorMsg(msg)); return nullptr; } catch (const
c10::Error& e) { auto msg = torch::get_cpp_stacktraces_enabled
() ? e.what() : e.what_without_backtrace(); PyErr_SetString(PyExc_RuntimeError
, torch::processErrorMsg(msg)); return nullptr; } catch (torch
::PyTorchError & e) { auto msg = torch::processErrorMsg(e
.what()); PyErr_SetString(e.python_type(), msg); return nullptr
; } catch (const std::exception& e) { auto msg = torch::processErrorMsg
(e.what()); PyErr_SetString(PyExc_RuntimeError, msg); return nullptr
; }
168}
169
170typedef PyObject *(*getter)(PyObject *, void *);
171
172// NB: If you edit these properties/methods, update torch/_C/__init__.pyi.in
173
174// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,cppcoreguidelines-avoid-non-const-global-variables,modernize-avoid-c-arrays)
175static struct PyGetSetDef THPDevice_properties[] = {
176 {"type", (getter)THPDevice_type, nullptr, nullptr, nullptr},
177 {"index", (getter)THPDevice_index, nullptr, nullptr, nullptr},
178 {nullptr}
179};
180
181// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,cppcoreguidelines-avoid-non-const-global-variables,modernize-avoid-c-arrays)
182static PyMethodDef THPDevice_methods[] = {
183 {"__reduce__", THPDevice_reduce, METH_NOARGS0x0004, nullptr},
184 {nullptr} /* Sentinel */
185};
186
187// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
188PyTypeObject THPDeviceType = {
189 PyVarObject_HEAD_INIT(nullptr, 0){ { 1, nullptr }, 0 },
190 "torch.device", /* tp_name */
191 sizeof(THPDevice), /* tp_basicsize */
192 0, /* tp_itemsize */
193 nullptr, /* tp_dealloc */
194 // NOLINTNEXTLINE(modernize-use-nullptr)
195 0, /* tp_vectorcall_offset */
196 nullptr, /* tp_getattr */
197 nullptr, /* tp_setattr */
198 nullptr, /* tp_reserved */
199 (reprfunc)THPDevice_repr, /* tp_repr */
200 nullptr, /* tp_as_number */
201 nullptr, /* tp_as_sequence */
202 nullptr, /* tp_as_mapping */
203 (hashfunc)THPDevice_hash, /* tp_hash */
204 nullptr, /* tp_call */
205 (reprfunc)THPDevice_str, /* tp_str */
206 nullptr, /* tp_getattro */
207 nullptr, /* tp_setattro */
208 nullptr, /* tp_as_buffer */
209 Py_TPFLAGS_DEFAULT( 0 | (1UL << 18) | 0), /* tp_flags */
210 nullptr, /* tp_doc */
211 nullptr, /* tp_traverse */
212 nullptr, /* tp_clear */
213 (richcmpfunc)THPDevice_rc, /* tp_richcompare */
214 0, /* tp_weaklistoffset */
215 nullptr, /* tp_iter */
216 nullptr, /* tp_iternext */
217 THPDevice_methods, /* tp_methods */
218 nullptr, /* tp_members */
219 THPDevice_properties, /* tp_getset */
220 nullptr, /* tp_base */
221 nullptr, /* tp_dict */
222 nullptr, /* tp_descr_get */
223 nullptr, /* tp_descr_set */
224 0, /* tp_dictoffset */
225 nullptr, /* tp_init */
226 nullptr, /* tp_alloc */
227 THPDevice_pynew, /* tp_new */
228};
229
230void THPDevice_init(PyObject *module)
231{
232 if (PyType_Ready(&THPDeviceType) < 0) {
233 throw python_error();
234 }
235 Py_INCREF(&THPDeviceType)_Py_INCREF(((PyObject*)(&THPDeviceType)));
236 if (PyModule_AddObject(module, "device", (PyObject *)&THPDeviceType) != 0) {
237 throw python_error();
238 }
239}

/opt/pyrefcon/lib/pyrefcon/models/models/PyTuple_New.model

1#ifndef PyTuple_New
2struct _object;
3typedef struct _object PyObject;
4PyObject* clang_analyzer_PyObject_New_Reference();
5PyObject* PyTuple_New(Py_ssize_t len) {
6 return clang_analyzer_PyObject_New_Reference();
2
Setting reference count to 1
7}
8#else
9#warning "API PyTuple_New is defined as a macro."
10#endif