Opened 3 years ago

Closed 3 years ago

#27093 closed enhancement (fixed)

type_debug: support subtype_dealloc, subtype_clear, subtype_traverse

Reported by: jdemeyer Owned by:
Priority: major Milestone: sage-8.7
Component: misc Keywords:
Cc: tscrim Merged in:
Authors: Jeroen Demeyer Reviewers: Travis Scrimshaw
Report Upstream: N/A Work issues:
Branch: 7f3d84d (Commits, GitHub, GitLab) Commit: 7f3d84d07c5728850df4ef1b679e86869b8ac478
Dependencies: Stopgaps:

Status badges

Description (last modified by jdemeyer)

Support the default tp_dealloc, tp_clear, tp_traverse functions for heap types (a.k.a. Python classes). This is not exported by Python, but we can dynamically determine it.

With this patch, one has for example

sage: class X(object): pass
sage: type_debug(X)
<class '__main__.X'> (0x7fe42bfc3a80)
  ob_refcnt: 5
  ob_type: <type 'type'>
  tp_name: X
  tp_basicsize: 32
  tp_itemsize: 0
  tp_dictoffset: 16
  tp_weaklistoffset: 24
  tp_base (__base__): <type 'object'>
  tp_bases (__bases__): tuple:
    <type 'object'>
  tp_mro (__mro__): tuple:
    <class '__main__.X'>
    <type 'object'>
  tp_dict (__dict__): dict:
    '__dict__': <attribute '__dict__' of 'X' objects>
    '__module__': '__main__'
    '__weakref__': <attribute '__weakref__' of 'X' objects>
    '__doc__': None
  tp_alloc: PyType_GenericAlloc
  tp_new (__new__): == object
  tp_init (__init__): == object
  tp_dealloc (__dealloc__): subtype_dealloc
  tp_del (__del__): NULL
  tp_free: PyObject_GC_Del
  tp_repr (__repr__): == object
  tp_print: NULL
  tp_hash (__hash__): _Py_HashPointer
  tp_call (__call__): NULL
  tp_str (__str__): == object
  tp_compare (cmp): NULL
  tp_richcompare (__richcmp__): NULL
  tp_getattr (__getattribute__): NULL
  tp_setattr (__setattribute__): NULL
  tp_getattro (__getattribute__): PyObject_GenericGetAttr
  tp_setattro (__setattribute__): PyObject_GenericSetAttr
  tp_iter (__iter__): NULL
  tp_iternext (__next__): 0x7fe426a40150
  tp_descr_get (__get__): NULL
  tp_descr_set (__set__): NULL
  tp_cache: NULL
  tp_weaklist: <weakref at 0x7fe36b81e050; to 'type' at 0x7fe42bfc3a80 (X)>
  tp_traverse: subtype_traverse
  tp_clear: subtype_clear
  tp_is_gc: NULL
  tp_as_number: 0x7fe42bfc3c08
    nb_add (__add__): NULL
    nb_subtract (__sub__): NULL
    nb_multiply (__mul__): NULL
    nb_divide (__div__): NULL
    nb_floor_divide (__floordiv__): NULL
    nb_true_divide (__truediv__): NULL
    nb_remainder (__mod__): NULL
    nb_divmod (__divmod__): NULL
    nb_power (__pow__): NULL
    nb_negative (__neg__): NULL
    nb_positive (__pos__): NULL
    nb_absolute (__abs__): NULL
    nb_nonzero (__nonzero__): NULL
    nb_invert (__invert__): NULL
    nb_lshift (__lshift__): NULL
    nb_rshift (__rshift__): NULL
    nb_and (__and__): NULL
    nb_or (__or__): NULL
    nb_xor (__xor__): NULL
    nb_int (__int__): NULL
    nb_long (__long__): NULL
    nb_index (__index__): NULL
    nb_float (__float__): NULL
    nb_oct (__oct__): NULL
    nb_hex (__hex__): NULL
    nb_coerce: NULL
    nb_inplace_add (__iadd__): NULL
    nb_inplace_subtract (__isub__): NULL
    nb_inplace_multiply (__imul__): NULL
    nb_inplace_divide (__idiv__): NULL
    nb_inplace_floor_divide (__ifloordiv__): NULL
    nb_inplace_true_divide (__itruediv__): NULL
    nb_inplace_remainder (__imod__): NULL
    nb_inplace_power (__ipow__): NULL
    nb_inplace_lshift (__ilshift__): NULL
    nb_inplace_rshift (__irshift__): NULL
    nb_inplace_and (__iand__): NULL
    nb_inplace_or (__ior__): NULL
    nb_inplace_xor (__ixor__): NULL
  tp_as_sequence: 0x7fe42bfc3d58
    sq_length (__len__): NULL
    sq_concat (__add__): NULL
    sq_inplace_concat (__iadd__): NULL
    sq_repeat (__mul__): NULL
    sq_inplace_repeat (__imul__): NULL
    sq_item (__getitem__): NULL
    sq_ass_item (__setitem__): NULL
    sq_contains (__contains__): NULL
  tp_as_mapping: 0x7fe42bfc3d40
    mp_length (__len__): NULL
    mp_subscript (__getitem__): NULL
    mp_ass_subscript (__setitem__): NULL
  tp_as_buffer: 0x7fe42bfc3da8
    bf_getreadbuffer: NULL
    bf_getwritebuffer: NULL
    bf_getsegcount: NULL
    bf_getcharbuffer: NULL
  tp_version_tag: 10759

Note the lines tp_dealloc, tp_traverse and tp_clear which are more interesting than the hexadecimal constants before this patch.

Change History (6)

comment:1 Changed 3 years ago by jdemeyer

  • Description modified (diff)
  • Summary changed from type_debug: support subtype_dealloc() to type_debug: support subtype_dealloc, subtype_clear, subtype_traverse

comment:2 Changed 3 years ago by jdemeyer

  • Branch set to u/jdemeyer/type_debug__support_subtype_dealloc__

comment:3 Changed 3 years ago by jdemeyer

  • Cc tscrim added
  • Commit set to 7f3d84d07c5728850df4ef1b679e86869b8ac478
  • Status changed from new to needs_review

New commits:

7f3d84dtype_debug: support subtype_traverse, subtype_clear, subtype_dealloc

comment:4 Changed 3 years ago by jdemeyer

  • Description modified (diff)

comment:5 Changed 3 years ago by tscrim

  • Reviewers set to Travis Scrimshaw
  • Status changed from needs_review to positive_review


comment:6 Changed 3 years ago by vbraun

  • Branch changed from u/jdemeyer/type_debug__support_subtype_dealloc__ to 7f3d84d07c5728850df4ef1b679e86869b8ac478
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.