summaryrefslogtreecommitdiffstats
path: root/Modules/_struct.c
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2006-07-30 06:55:48 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2006-07-30 06:55:48 (GMT)
commit07aadb14f39c585a463f19ec0496860a100051ad (patch)
tree633fcc0bb9fa8edbdae49bf761c3c3ec822319c6 /Modules/_struct.c
parent0d62a062066a4cbc8aabab9c305d60ebf7922c8c (diff)
downloadcpython-07aadb14f39c585a463f19ec0496860a100051ad.zip
cpython-07aadb14f39c585a463f19ec0496860a100051ad.tar.gz
cpython-07aadb14f39c585a463f19ec0496860a100051ad.tar.bz2
Add PyErr_WarnEx() so C code can pass the stacklevel to warnings.warn().
This provides the proper warning for struct.pack(). PyErr_Warn() is now deprecated in favor of PyErr_WarnEx(). As mentioned by Tim Peters on python-dev.
Diffstat (limited to 'Modules/_struct.c')
-rw-r--r--Modules/_struct.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/Modules/_struct.c b/Modules/_struct.c
index 7e30892..3774dfd 100644
--- a/Modules/_struct.c
+++ b/Modules/_struct.c
@@ -214,6 +214,8 @@ get_ulonglong(PyObject *v, unsigned PY_LONG_LONG *p)
/* Helper routine to get a Python integer and raise the appropriate error
if it isn't one */
+#define INT_OVERFLOW "struct integer overflow masking is deprecated"
+
static int
get_wrapped_long(PyObject *v, long *p)
{
@@ -223,7 +225,7 @@ get_wrapped_long(PyObject *v, long *p)
PyObject *wrapped;
long x;
PyErr_Clear();
- if (PyErr_Warn(PyExc_DeprecationWarning, "struct integer overflow masking is deprecated") < 0)
+ if (PyErr_WarnEx(PyExc_DeprecationWarning, INT_OVERFLOW, 2) < 0)
return -1;
wrapped = PyNumber_And(v, pylong_ulong_mask);
if (wrapped == NULL)
@@ -250,7 +252,7 @@ get_wrapped_ulong(PyObject *v, unsigned long *p)
wrapped = PyNumber_And(v, pylong_ulong_mask);
if (wrapped == NULL)
return -1;
- if (PyErr_Warn(PyExc_DeprecationWarning, "struct integer overflow masking is deprecated") < 0) {
+ if (PyErr_WarnEx(PyExc_DeprecationWarning, INT_OVERFLOW, 2) < 0) {
Py_DECREF(wrapped);
return -1;
}
@@ -345,8 +347,8 @@ _range_error(const formatdef *f, int is_unsigned)
Py_XDECREF(ptraceback);
if (msg == NULL)
return -1;
- rval = PyErr_Warn(PyExc_DeprecationWarning,
- PyString_AS_STRING(msg));
+ rval = PyErr_WarnEx(PyExc_DeprecationWarning,
+ PyString_AS_STRING(msg), 2);
Py_DECREF(msg);
if (rval == 0)
return 0;