summaryrefslogtreecommitdiff
path: root/numpy/core/src/scalarmathmodule.c.src
diff options
context:
space:
mode:
authorPauli Virtanen <pav@iki.fi>2010-10-08 11:10:21 +0200
committerPauli Virtanen <pav@iki.fi>2010-10-08 23:28:58 +0200
commit024443026aa64db9b4884822aff1d6fd633ab8d8 (patch)
tree3e857930e85cc76baca037ede6ea718ea057b4ac /numpy/core/src/scalarmathmodule.c.src
parenta8441313359cd4ac0d4ce36f5a265304d25117b6 (diff)
downloadnumpy-024443026aa64db9b4884822aff1d6fd633ab8d8.tar.gz
BUG: core: handle errors from PyErr_Warn for ComplexWarning
Diffstat (limited to 'numpy/core/src/scalarmathmodule.c.src')
-rw-r--r--numpy/core/src/scalarmathmodule.c.src27
1 files changed, 18 insertions, 9 deletions
diff --git a/numpy/core/src/scalarmathmodule.c.src b/numpy/core/src/scalarmathmodule.c.src
index f3ee6724e..d76c8a975 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
}
@@ -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,7 +1024,10 @@ static PyObject *
x = ix;
#endif
#if @cmplx@
- emit_complexwarning();
+ ret = emit_complexwarning();
+ if (ret < 0) {
+ return NULL;
+ }
#endif
/*
@@ -1052,7 +1057,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@)));