summaryrefslogtreecommitdiff
path: root/tools/swig
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2020-10-18 14:18:10 -0600
committerCharles Harris <charlesr.harris@gmail.com>2020-10-18 15:05:25 -0600
commitcf06cd41ba8bd49b3ada8aa333df8e562829247b (patch)
tree85fae9ed78814a08ff5c64a2ac5afae4147f60ae /tools/swig
parenta5aae4f4cd852b64f5f36e8c225895b3a2113c48 (diff)
downloadnumpy-cf06cd41ba8bd49b3ada8aa333df8e562829247b.tar.gz
MAINT: Cleanup swig for Python 3.
Replaces ``PyInt_Check`` and ``PyInt_AsLong`` in a few places.
Diffstat (limited to 'tools/swig')
-rw-r--r--tools/swig/numpy.i12
-rw-r--r--tools/swig/pyfragments.swg11
2 files changed, 11 insertions, 12 deletions
diff --git a/tools/swig/numpy.i b/tools/swig/numpy.i
index a2e7a335f..60930c098 100644
--- a/tools/swig/numpy.i
+++ b/tools/swig/numpy.i
@@ -115,7 +115,7 @@
if (py_obj == Py_None ) return "Python None" ;
if (PyCallable_Check(py_obj)) return "callable" ;
if (PyBytes_Check( py_obj)) return "string" ;
- if (PyInt_Check( py_obj)) return "int" ;
+ if (PyLong_Check( py_obj)) return "int" ;
if (PyFloat_Check( py_obj)) return "float" ;
if (PyDict_Check( py_obj)) return "dict" ;
if (PyList_Check( py_obj)) return "list" ;
@@ -2002,7 +2002,7 @@
(PyObject* array = NULL)
{
npy_intp dims[1];
- if (!PyInt_Check($input))
+ if (!PyLong_Check($input))
{
const char* typestring = pytype_string($input);
PyErr_Format(PyExc_TypeError,
@@ -2010,7 +2010,8 @@
typestring);
SWIG_fail;
}
- $2 = (DIM_TYPE) PyInt_AsLong($input);
+ $2 = (DIM_TYPE) PyLong_AsSsize_t($input);
+ if ($2 == -1 && PyErr_Occurred()) SWIG_fail;
dims[0] = (npy_intp) $2;
array = PyArray_SimpleNew(1, dims, DATA_TYPECODE);
if (!array) SWIG_fail;
@@ -2030,7 +2031,7 @@
(PyObject* array = NULL)
{
npy_intp dims[1];
- if (!PyInt_Check($input))
+ if (!PyLong_Check($input))
{
const char* typestring = pytype_string($input);
PyErr_Format(PyExc_TypeError,
@@ -2038,7 +2039,8 @@
typestring);
SWIG_fail;
}
- $1 = (DIM_TYPE) PyInt_AsLong($input);
+ $1 = (DIM_TYPE) PyLong_AsSsize_t($input);
+ if ($1 == -1 && PyErr_Occurred()) SWIG_fail;
dims[0] = (npy_intp) $1;
array = PyArray_SimpleNew(1, dims, DATA_TYPECODE);
if (!array) SWIG_fail;
diff --git a/tools/swig/pyfragments.swg b/tools/swig/pyfragments.swg
index ce2452f80..558633733 100644
--- a/tools/swig/pyfragments.swg
+++ b/tools/swig/pyfragments.swg
@@ -22,12 +22,9 @@
SWIGINTERN int
SWIG_AsVal_dec(long)(PyObject * obj, long * val)
{
- if (PyInt_Check(obj)) {
- if (val) *val = PyInt_AsLong(obj);
- return SWIG_OK;
- } else if (PyLong_Check(obj)) {
+ if (PyLong_Check(obj)) {
long v = PyLong_AsLong(obj);
- if (!PyErr_Occurred()) {
+ if (v != -1 || !PyErr_Occurred()) {
if (val) *val = v;
return SWIG_OK;
} else {
@@ -37,8 +34,8 @@
%#ifdef SWIG_PYTHON_CAST_MODE
{
int dispatch = 0;
- long v = PyInt_AsLong(obj);
- if (!PyErr_Occurred()) {
+ long v = PyLong_AsLong(obj);
+ if (v != -1 || !PyErr_Occurred()) {
if (val) *val = v;
return SWIG_AddCast(SWIG_OK);
} else {