Skip to content

Commit

Permalink
bpo-33818: PyExceptionClass_Name() will now return "const char *". (G…
Browse files Browse the repository at this point in the history
  • Loading branch information
serhiy-storchaka authored Jun 15, 2018
1 parent 08f127a commit ceeef10
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 9 deletions.
4 changes: 4 additions & 0 deletions Doc/whatsnew/3.8.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions Include/pyerrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:c:func:`PyExceptionClass_Name` will now return ``const char *`` instead of
``char *``.
4 changes: 2 additions & 2 deletions Objects/exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = {
Expand Down
4 changes: 2 additions & 2 deletions Python/errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions Python/pythonrun.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit ceeef10

Please sign in to comment.