mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Fix Python 2.7 compatibility
This commit is contained in:
@ -10,12 +10,20 @@ bool THPUtils_checkLong(PyObject *index) {
|
||||
return PyLong_Check(index) || PyInt_Check(index);
|
||||
}
|
||||
|
||||
int THPUtils_getLong(PyObject *index, long *result) {
|
||||
long THPUtils_unpackLong(PyObject *index) {
|
||||
if (PyLong_Check(index)) {
|
||||
*result = PyLong_AsLong(index);
|
||||
return PyLong_AsLong(index);
|
||||
} else if (PyInt_Check(index)) {
|
||||
*result = PyInt_AsLong(index);
|
||||
return PyInt_AsLong(index);
|
||||
} else {
|
||||
throw std::exception();
|
||||
}
|
||||
}
|
||||
|
||||
int THPUtils_getLong(PyObject *index, long *result) {
|
||||
try {
|
||||
*result = THPUtils_unpackLong(index);
|
||||
} catch(...) {
|
||||
char err_string[512];
|
||||
snprintf (err_string, 512, "%s %s",
|
||||
"getLong expected int or long, but got type: ",
|
||||
|
Reference in New Issue
Block a user