Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6d63adf

Browse files
committed
Improve the exceptions raised by PyErr_BadInternalCall(); adding the
filename and line number of the call site to allow esier debugging. This closes SourceForge patch #101214.
1 parent 9ed49e9 commit 6d63adf

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

Include/pyerrors.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,12 @@ extern DL_IMPORT(PyObject *) PyErr_SetFromWindowsErrWithFilename(int, const char
8282
extern DL_IMPORT(PyObject *) PyErr_SetFromWindowsErr(int);
8383
#endif
8484

85+
/* Export the old function so that the existing API remains available: */
8586
extern DL_IMPORT(void) PyErr_BadInternalCall(void);
87+
extern DL_IMPORT(void) _PyErr_BadInternalCall(char *filename, int lineno);
88+
/* Mask the old API with a call to the new API for code compiled under
89+
Python 2.0: */
90+
#define PyErr_BadInternalCall() _PyErr_BadInternalCall(__FILE__, __LINE__)
8691

8792
/* Function to create a new exception */
8893
DL_IMPORT(PyObject *) PyErr_NewException(char *name, PyObject *base,

Python/errors.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,12 +368,25 @@ PyObject *PyErr_SetFromWindowsErr(int ierr)
368368
}
369369
#endif /* MS_WINDOWS */
370370

371+
void
372+
_PyErr_BadInternalCall(char *filename, int lineno)
373+
{
374+
PyErr_Format(PyExc_SystemError,
375+
"%s:%d: bad argument to internal function",
376+
filename, lineno);
377+
}
378+
379+
/* Remove the preprocessor macro for PyErr_BadInternalCall() so that we can
380+
export the entry point for existing object code: */
381+
#undef PyErr_BadInternalCall
371382
void
372383
PyErr_BadInternalCall(void)
373384
{
374-
PyErr_SetString(PyExc_SystemError,
375-
"bad argument to internal function");
385+
PyErr_Format(PyExc_SystemError,
386+
"bad argument to internal function");
376387
}
388+
#define PyErr_BadInternalCall() _PyErr_BadInternalCall(__FILE__, __LINE__)
389+
377390

378391

379392
PyObject *

0 commit comments

Comments
 (0)