diff Modules/_struct.c @ 39301:7dc5f3ede4cd legacy-trunk

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.
author Neal Norwitz <nnorwitz@gmail.com>
date Sun, 30 Jul 2006 06:55:48 +0000
parents e80097bf73b6
children 9cb4565e60ca
line wrap: on
line diff
--- a/Modules/_struct.c	Sun Jul 30 06:53:31 2006 +0000
+++ b/Modules/_struct.c	Sun Jul 30 06:55:48 2006 +0000
@@ -214,6 +214,8 @@
 /* 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 @@
 			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 @@
 		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 @@
 		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;