summaryrefslogtreecommitdiff
path: root/numpy/core/src/scalarmathmodule.c.src
diff options
context:
space:
mode:
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;