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.src35
1 files changed, 20 insertions, 15 deletions
diff --git a/numpy/core/src/scalarmathmodule.c.src b/numpy/core/src/scalarmathmodule.c.src
index f3ee6724e..6261c4c73 100644
--- a/numpy/core/src/scalarmathmodule.c.src
+++ b/numpy/core/src/scalarmathmodule.c.src
@@ -974,10 +974,11 @@ NONZERO_NAME(@name@_,)(PyObject *a)
/**end repeat**/
-static void
+static int
emit_complexwarning()
{
static PyObject *cls = NULL;
+ int ret;
if (cls == NULL) {
PyObject *mod;
mod = PyImport_ImportModule("numpy.core");
@@ -987,13 +988,13 @@ emit_complexwarning()
Py_DECREF(mod);
}
#if PY_VERSION_HEX >= 0x02050000
- PyErr_WarnEx(cls,
- "Casting complex values to real discards the imaginary "
- "part", 0);
+ return PyErr_WarnEx(cls,
+ "Casting complex values to real discards the imaginary "
+ "part", 0);
#else
- PyErr_Warn(cls,
- "Casting complex values to real discards the imaginary "
- "part");
+ return PyErr_Warn(cls,
+ "Casting complex values to real discards the imaginary "
+ "part");
#endif
}
@@ -1003,7 +1004,7 @@ emit_complexwarning()
* #Name=Byte,UByte,Short,UShort,Int,UInt,Long,ULong,LongLong,ULongLong,Float,Double,LongDouble,CFloat,CDouble,CLongDouble#
* #cmplx=0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1#
* #sign=(signed,unsigned)*5,,,,,,#
- * #unsigntyp=0,1,0,1,0,1,0,1,0,1,1*6#
+ * #unsigntyp=0,1,0,1,0,1,0,1,0,1,0*6#
* #ctype=long*8,PY_LONG_LONG*2,double*6#
* #realtyp=0*10,1*6#
* #func=(PyLong_FromLong,PyLong_FromUnsignedLong)*4,PyLong_FromLongLong,PyLong_FromUnsignedLongLong,PyLong_FromDouble*6#
@@ -1013,6 +1014,7 @@ static PyObject *
{
#if @cmplx@
@sign@ @ctype@ x= PyArrayScalar_VAL(obj, @Name@).real;
+ int ret;
#else
@sign@ @ctype@ x= PyArrayScalar_VAL(obj, @Name@);
#endif
@@ -1022,15 +1024,14 @@ static PyObject *
x = ix;
#endif
#if @cmplx@
- emit_complexwarning();
+ ret = emit_complexwarning();
+ if (ret < 0) {
+ return NULL;
+ }
#endif
-/*
- * For unsigned type, the (@ctype@) cast just does what is implicitely done by
- * the compiler.
- */
#if @unsigntyp@
- if(LONG_MIN < (@ctype@)x && (@ctype@)x < LONG_MAX)
+ if(x < LONG_MAX)
return PyInt_FromLong(x);
#else
if(LONG_MIN < x && x < LONG_MAX)
@@ -1052,7 +1053,11 @@ static PyObject *
@name@_@which@(PyObject *obj)
{
#if @cmplx@
- emit_complexwarning();
+ int ret;
+ ret = emit_complexwarning();
+ if (ret < 0) {
+ return NULL;
+ }
return @func@((PyArrayScalar_VAL(obj, @Name@)).real);
#else
return @func@((PyArrayScalar_VAL(obj, @Name@)));