mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
bpo-39882: Add _Py_FatalErrorFormat() function (GH-19157)
This commit is contained in:
parent
ace018ca47
commit
87d3b9db4a
15 changed files with 158 additions and 110 deletions
|
@ -46,7 +46,8 @@ _Py_CheckFunctionResult(PyThreadState *tstate, PyObject *callable,
|
|||
"%s returned NULL without setting an error",
|
||||
where);
|
||||
#ifdef Py_DEBUG
|
||||
/* Ensure that the bug is caught in debug mode */
|
||||
/* Ensure that the bug is caught in debug mode.
|
||||
Py_FatalError() logs the SystemError exception raised above. */
|
||||
Py_FatalError("a function returned NULL without setting an error");
|
||||
#endif
|
||||
return NULL;
|
||||
|
@ -67,7 +68,8 @@ _Py_CheckFunctionResult(PyThreadState *tstate, PyObject *callable,
|
|||
"%s returned a result with an error set", where);
|
||||
}
|
||||
#ifdef Py_DEBUG
|
||||
/* Ensure that the bug is caught in debug mode */
|
||||
/* Ensure that the bug is caught in debug mode.
|
||||
Py_FatalError() logs the SystemError exception raised above. */
|
||||
Py_FatalError("a function returned a result with an error set");
|
||||
#endif
|
||||
return NULL;
|
||||
|
|
|
@ -957,8 +957,9 @@ void
|
|||
PyFrame_BlockSetup(PyFrameObject *f, int type, int handler, int level)
|
||||
{
|
||||
PyTryBlock *b;
|
||||
if (f->f_iblock >= CO_MAXBLOCKS)
|
||||
Py_FatalError("XXX block stack overflow");
|
||||
if (f->f_iblock >= CO_MAXBLOCKS) {
|
||||
Py_FatalError("block stack overflow");
|
||||
}
|
||||
b = &f->f_blockstack[f->f_iblock++];
|
||||
b->b_type = type;
|
||||
b->b_level = level;
|
||||
|
@ -969,8 +970,9 @@ PyTryBlock *
|
|||
PyFrame_BlockPop(PyFrameObject *f)
|
||||
{
|
||||
PyTryBlock *b;
|
||||
if (f->f_iblock <= 0)
|
||||
Py_FatalError("XXX block stack underflow");
|
||||
if (f->f_iblock <= 0) {
|
||||
Py_FatalError("block stack underflow");
|
||||
}
|
||||
b = &f->f_blockstack[--f->f_iblock];
|
||||
return b;
|
||||
}
|
||||
|
|
|
@ -2361,26 +2361,22 @@ _PyMem_DebugRealloc(void *ctx, void *ptr, size_t nbytes)
|
|||
static void
|
||||
_PyMem_DebugCheckAddress(const char *func, char api, const void *p)
|
||||
{
|
||||
assert(p != NULL);
|
||||
|
||||
const uint8_t *q = (const uint8_t *)p;
|
||||
char msgbuf[64];
|
||||
const char *msg;
|
||||
size_t nbytes;
|
||||
const uint8_t *tail;
|
||||
int i;
|
||||
char id;
|
||||
|
||||
if (p == NULL) {
|
||||
msg = "didn't expect a NULL pointer";
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Check the API id */
|
||||
id = (char)q[-SST];
|
||||
if (id != api) {
|
||||
msg = msgbuf;
|
||||
snprintf(msgbuf, sizeof(msgbuf), "bad ID: Allocated using API '%c', verified using API '%c'", id, api);
|
||||
msgbuf[sizeof(msgbuf)-1] = 0;
|
||||
goto error;
|
||||
_PyObject_DebugDumpAddress(p);
|
||||
_Py_FatalErrorFormat(func,
|
||||
"bad ID: Allocated using API '%c', "
|
||||
"verified using API '%c'",
|
||||
id, api);
|
||||
}
|
||||
|
||||
/* Check the stuff at the start of p first: if there's underwrite
|
||||
|
@ -2389,8 +2385,8 @@ _PyMem_DebugCheckAddress(const char *func, char api, const void *p)
|
|||
*/
|
||||
for (i = SST-1; i >= 1; --i) {
|
||||
if (*(q-i) != PYMEM_FORBIDDENBYTE) {
|
||||
msg = "bad leading pad byte";
|
||||
goto error;
|
||||
_PyObject_DebugDumpAddress(p);
|
||||
_Py_FatalErrorFunc(func, "bad leading pad byte");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2398,16 +2394,10 @@ _PyMem_DebugCheckAddress(const char *func, char api, const void *p)
|
|||
tail = q + nbytes;
|
||||
for (i = 0; i < SST; ++i) {
|
||||
if (tail[i] != PYMEM_FORBIDDENBYTE) {
|
||||
msg = "bad trailing pad byte";
|
||||
goto error;
|
||||
_PyObject_DebugDumpAddress(p);
|
||||
_Py_FatalErrorFunc(func, "bad trailing pad byte");
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
error:
|
||||
_PyObject_DebugDumpAddress(p);
|
||||
_Py_FatalErrorFunc(func, msg);
|
||||
}
|
||||
|
||||
/* Display info to stderr about the memory block at p. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue