summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2020-10-24 20:59:11 +0300
committerGitHub <noreply@github.com>2020-10-24 20:59:11 +0300
commitd483de0f32baec73b0856230dd35f08373ecbb85 (patch)
treeb3c2c8c6c25ab83f1eb59adfc2a4d0939a6712f0
parentba1fdc94b0d7358c993361bdd73feca09d38171c (diff)
parentcf06cd41ba8bd49b3ada8aa333df8e562829247b (diff)
downloadnumpy-d483de0f32baec73b0856230dd35f08373ecbb85.tar.gz
Merge pull request #17580 from charris/cleanup-swig-for-python3
MAINT: Cleanup swig for Python 3.
-rw-r--r--doc/release/upcoming_changes/17580.compatibility.rst4
-rw-r--r--tools/swig/numpy.i12
-rw-r--r--tools/swig/pyfragments.swg11
3 files changed, 15 insertions, 12 deletions
diff --git a/doc/release/upcoming_changes/17580.compatibility.rst b/doc/release/upcoming_changes/17580.compatibility.rst
new file mode 100644
index 000000000..b8e1849af
--- /dev/null
+++ b/doc/release/upcoming_changes/17580.compatibility.rst
@@ -0,0 +1,4 @@
+The numpy.i file for swig is Python 3 only.
+-------------------------------------------
+Uses of Python 2.7 C-API functions have been updated to Python 3 only. Users
+who need the old version should take it from an older version of NumPy.
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 {