mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
A few miscellaneous helpers.
PyObject_Dump(): New function that is useful when debugging Python's C runtime. In something like gdb it can be a pain to get some useful information out of PyObject*'s. This function prints the str() of the object to stderr, along with the object's refcount and hex address. PyGC_Dump(): Similar to PyObject_Dump() but knows how to cast from the garbage collector prefix back to the PyObject* structure. [See Misc/gdbinit for some useful gdb hooks] none_dealloc(): Rather than SEGV if we accidentally decref None out of existance, we assign None's and NotImplemented's destructor slot to this function, which just calls abort().
This commit is contained in:
parent
9667ed23c5
commit
9bf16440f4
1 changed files with 26 additions and 2 deletions
|
|
@ -220,6 +220,19 @@ PyObject_Print(PyObject *op, FILE *fp, int flags)
|
|||
return ret;
|
||||
}
|
||||
|
||||
/* For debugging convenience. See Misc/gdbinit for some useful gdb hooks */
|
||||
void PyObject_Dump(PyObject* op)
|
||||
{
|
||||
(void)PyObject_Print(op, stderr, 0);
|
||||
fprintf(stderr, "\nrefcounts: %d\n", op->ob_refcnt);
|
||||
fprintf(stderr, "address : %x\n", op);
|
||||
}
|
||||
void PyGC_Dump(PyGC_Head* op)
|
||||
{
|
||||
PyObject_Dump(PyObject_FROM_GC(op));
|
||||
}
|
||||
|
||||
|
||||
PyObject *
|
||||
PyObject_Repr(PyObject *v)
|
||||
{
|
||||
|
|
@ -1213,13 +1226,24 @@ none_repr(PyObject *op)
|
|||
return PyString_FromString("None");
|
||||
}
|
||||
|
||||
/* ARGUSED */
|
||||
static void
|
||||
none_dealloc(PyObject* ignore)
|
||||
{
|
||||
/* This should never get called, but we also don't want to SEGV if
|
||||
* we accidently decref None out of existance.
|
||||
*/
|
||||
abort();
|
||||
}
|
||||
|
||||
|
||||
static PyTypeObject PyNothing_Type = {
|
||||
PyObject_HEAD_INIT(&PyType_Type)
|
||||
0,
|
||||
"None",
|
||||
0,
|
||||
0,
|
||||
0, /*tp_dealloc*/ /*never called*/
|
||||
(destructor)none_dealloc, /*tp_dealloc*/ /*never called*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
|
|
@ -1250,7 +1274,7 @@ static PyTypeObject PyNotImplemented_Type = {
|
|||
"NotImplemented",
|
||||
0,
|
||||
0,
|
||||
0, /*tp_dealloc*/ /*never called*/
|
||||
(destructor)none_dealloc, /*tp_dealloc*/ /*never called*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue