summaryrefslogtreecommitdiff
path: root/numpy/core/src/scalarmathmodule.c.src
diff options
context:
space:
mode:
authorArink Verma <arinkverma@gmail.com>2013-08-27 22:05:38 +0530
committerArink Verma <arinkverma@gmail.com>2013-08-30 02:14:29 +0530
commit7b415b26f4a1d58164a69ef44fb501fbd93e666f (patch)
tree674f77f9046efab147a83cc961151e18094bafed /numpy/core/src/scalarmathmodule.c.src
parent9c7ef03df6ae9553149d26ba5d367bd94b0489fd (diff)
downloadnumpy-7b415b26f4a1d58164a69ef44fb501fbd93e666f.tar.gz
Added PyInt_CheckExact for python < 3 and error check for PyLong_AsLong
Diffstat (limited to 'numpy/core/src/scalarmathmodule.c.src')
-rw-r--r--numpy/core/src/scalarmathmodule.c.src55
1 files changed, 34 insertions, 21 deletions
diff --git a/numpy/core/src/scalarmathmodule.c.src b/numpy/core/src/scalarmathmodule.c.src
index c379b4698..3fa1deb35 100644
--- a/numpy/core/src/scalarmathmodule.c.src
+++ b/numpy/core/src/scalarmathmodule.c.src
@@ -781,18 +781,22 @@ _@name@_convert_to_ctype(PyObject *a, @type@ *arg1)
{
PyObject *temp;
-#if PY_VERSION_HEX >= 0x03000000
- if(PyLong_CheckExact(a)){
- *arg1 = PyLong_AsUnsignedLong(a);
- return 0;
- }
-#else
- if (PyInt_CheckExact(a)){
+#if PY_VERSION_HEX < 0x03000000
+ if (PyInt_CheckExact(a)) {
*arg1 = PyInt_AS_LONG(a);
return 0;
}
#endif
+ if(PyLong_CheckExact(a)) {
+ if ((*arg1 = PyLong_AsUnsignedLong(a)) == -1 && PyErr_Occurred()) {
+ return -1;
+ }
+ else {
+ return 0;
+ }
+ }
+
if (PyArray_IsScalar(a, @Name@)) {
*arg1 = PyArrayScalar_VAL(a, @Name@);
return 0;
@@ -841,18 +845,22 @@ _@name@_convert_to_ctype(PyObject *a, @type@ *arg1)
{
PyObject *temp;
-#if PY_VERSION_HEX >= 0x03000000
- if(PyLong_CheckExact(a)){
- *arg1 = PyLong_AsLong(a);
- return 0;
- }
-#else
- if (PyInt_CheckExact(a)){
+#if PY_VERSION_HEX < 0x03000000
+ if (PyInt_CheckExact(a)) {
*arg1 = PyInt_AS_LONG(a);
return 0;
}
#endif
+ if(PyLong_CheckExact(a)) {
+ if ((*arg1 = PyLong_AsLong(a)) == -1 && PyErr_Occurred()) {
+ return -1;
+ }
+ else {
+ return 0;
+ }
+ }
+
if (PyArray_IsScalar(a, @Name@)) {
*arg1 = PyArrayScalar_VAL(a, @Name@);
return 0;
@@ -901,18 +909,23 @@ _@name@_convert_to_ctype(PyObject *a, @type@ *arg1)
{
PyObject *temp;
-#if PY_VERSION_HEX >= 0x03000000
- if(PyLong_CheckExact(a)){
- *arg1 = @PYEXTRACTCTYPE@(a);
- return 0;
- }
-#else
- if (PyInt_CheckExact(a)){
+
+#if PY_VERSION_HEX < 0x03000000
+ if (PyInt_CheckExact(a)) {
*arg1 = PyInt_AS_LONG(a);
return 0;
}
#endif
+ if (PyLong_CheckExact(a)) {
+ if ((*arg1 = @PYEXTRACTCTYPE@(a)) == -1 && PyErr_Occurred()) {
+ return -1;
+ }
+ else {
+ return 0;
+ }
+ }
+
if (PyArray_IsScalar(a, @Name@)) {
*arg1 = PyArrayScalar_VAL(a, @Name@);
return 0;