Fix Python 2.7 compatibility

This commit is contained in:
Adam Paszke
2016-08-12 18:24:36 -07:00
parent 3d80b1371a
commit ef7364b80e
154 changed files with 607 additions and 454 deletions

View File

@ -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: ",