]> granicus.if.org Git - python/commitdiff
bpo-33818: PyExceptionClass_Name() will now return "const char *". (GH-7581)
authorSerhiy Storchaka <storchaka@gmail.com>
Fri, 15 Jun 2018 08:09:43 +0000 (11:09 +0300)
committerGitHub <noreply@github.com>
Fri, 15 Jun 2018 08:09:43 +0000 (11:09 +0300)
Doc/whatsnew/3.8.rst
Include/pyerrors.h
Misc/NEWS.d/next/C API/2018-06-10-09-42-31.bpo-33818.50nlf3.rst [new file with mode: 0644]
Objects/exceptions.c
Python/errors.c
Python/pythonrun.c

index 9ae52c241f11e82347d46c32d838048c0012fef8..10fa182faeb3bfccbf8aaf6dc389c9459157e7de 100644 (file)
@@ -115,9 +115,13 @@ Optimizations
   first introduced in Python 3.4.  It offers better performance and smaller
   size compared to Protocol 3 available since Python 3.0.
 
+
 Build and C API Changes
 =======================
 
+* The result of :c:func:`PyExceptionClass_Name` is now of type
+  ``const char *`` rather of ``char *``.
+  (Contributed by Serhiy Storchaka in :issue:`33818`.)
 
 
 Deprecated
index 5b626584bb25eebfd699f6c31397fdf9e1f3c71f..416d750d9b1f0f836828655eb13561eb983aaa5f 100644 (file)
@@ -140,10 +140,9 @@ PyAPI_FUNC(void) _PyErr_ChainExceptions(PyObject *, PyObject *, PyObject *);
 #define PyExceptionInstance_Check(x)                    \
     PyType_FastSubclass((x)->ob_type, Py_TPFLAGS_BASE_EXC_SUBCLASS)
 
-PyAPI_FUNC(char *) PyExceptionClass_Name(PyObject *);
+PyAPI_FUNC(const char *) PyExceptionClass_Name(PyObject *);
 #ifndef Py_LIMITED_API
-#define PyExceptionClass_Name(x) \
-     ((char *)(((PyTypeObject *)(x))->tp_name))
+#define PyExceptionClass_Name(x)  (((PyTypeObject*)(x))->tp_name)
 #endif
 
 #define PyExceptionInstance_Class(x) ((PyObject*)((x)->ob_type))
diff --git a/Misc/NEWS.d/next/C API/2018-06-10-09-42-31.bpo-33818.50nlf3.rst b/Misc/NEWS.d/next/C API/2018-06-10-09-42-31.bpo-33818.50nlf3.rst
new file mode 100644 (file)
index 0000000..0f30a6e
--- /dev/null
@@ -0,0 +1,2 @@
+:c:func:`PyExceptionClass_Name` will now return ``const char *`` instead of
+``char *``.
index e1615b2a8f3a9e8b37fa7f138e378a4f62c91de0..bb50c1c36964d9889d3e6862fac4b136baeeff30 100644 (file)
@@ -344,10 +344,10 @@ PyException_SetContext(PyObject *self, PyObject *context)
 
 #undef PyExceptionClass_Name
 
-char *
+const char *
 PyExceptionClass_Name(PyObject *ob)
 {
-    return (char *)((PyTypeObject*)ob)->tp_name;
+    return ((PyTypeObject*)ob)->tp_name;
 }
 
 static struct PyMemberDef BaseException_members[] = {
index 15e6ba057143371ff08ba07120ee5b76384ae688..98910b44908764a8caf7127f589c9f083c3d0266 100644 (file)
@@ -947,7 +947,7 @@ PyErr_WriteUnraisable(PyObject *obj)
     _Py_IDENTIFIER(__module__);
     PyObject *f, *t, *v, *tb;
     PyObject *moduleName = NULL;
-    char* className;
+    const char *className;
 
     PyErr_Fetch(&t, &v, &tb);
 
@@ -977,7 +977,7 @@ PyErr_WriteUnraisable(PyObject *obj)
     assert(PyExceptionClass_Check(t));
     className = PyExceptionClass_Name(t);
     if (className != NULL) {
-        char *dot = strrchr(className, '.');
+        const char *dot = strrchr(className, '.');
         if (dot != NULL)
             className = dot+1;
     }
index 26f74c80d032708bd33e542c1395edfc4bb18d5c..3d40c79bc1bec14d1fd8df6c3f9f5b91472e2ffb 100644 (file)
@@ -774,12 +774,12 @@ print_exception(PyObject *f, PyObject *value)
     }
     else {
         PyObject* moduleName;
-        char* className;
+        const char *className;
         _Py_IDENTIFIER(__module__);
         assert(PyExceptionClass_Check(type));
         className = PyExceptionClass_Name(type);
         if (className != NULL) {
-            char *dot = strrchr(className, '.');
+            const char *dot = strrchr(className, '.');
             if (dot != NULL)
                 className = dot+1;
         }