mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
make THPPointer have explicit constructors (#1636)
This commit is contained in:
committed by
Soumith Chintala
parent
6a7c56499c
commit
05bc877a05
@ -37,7 +37,7 @@ bool THPUtils_tryUnpackLongs(PyObject *arg, THLongStoragePtr& result) {
|
||||
bool list = PyList_Check(arg);
|
||||
if (tuple || list) {
|
||||
int nDim = tuple ? PyTuple_GET_SIZE(arg) : PyList_GET_SIZE(arg);
|
||||
THLongStoragePtr storage = THLongStorage_newWithSize(nDim);
|
||||
THLongStoragePtr storage(THLongStorage_newWithSize(nDim));
|
||||
for (int i = 0; i != nDim; ++i) {
|
||||
PyObject* item = tuple ? PyTuple_GET_ITEM(arg, i) : PyList_GET_ITEM(arg, i);
|
||||
if (!THPUtils_checkLong(item)) {
|
||||
@ -45,7 +45,7 @@ bool THPUtils_tryUnpackLongs(PyObject *arg, THLongStoragePtr& result) {
|
||||
}
|
||||
storage->data[i] = THPUtils_unpackLong(item);
|
||||
}
|
||||
result = storage.release();
|
||||
result = std::move(storage);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -136,14 +136,14 @@ static const char* classOrTypename(PyObject* obj) {
|
||||
PyObject * THPUtils_dispatchStateless(
|
||||
PyObject *tensor, const char *name, PyObject *args, PyObject *kwargs)
|
||||
{
|
||||
THPObjectPtr methods = PyObject_GetAttrString(tensor, THP_STATELESS_ATTRIBUTE_NAME);
|
||||
THPObjectPtr methods(PyObject_GetAttrString(tensor, THP_STATELESS_ATTRIBUTE_NAME));
|
||||
if (!methods) {
|
||||
return PyErr_Format(
|
||||
PyExc_TypeError,
|
||||
"Type %s doesn't implement stateless methods",
|
||||
classOrTypename(tensor));
|
||||
}
|
||||
THPObjectPtr method = PyObject_GetAttrString(methods, name);
|
||||
THPObjectPtr method(PyObject_GetAttrString(methods, name));
|
||||
if (!method) {
|
||||
return PyErr_Format(
|
||||
PyExc_TypeError,
|
||||
|
Reference in New Issue
Block a user