Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

destructors of local variables are not traced #77627

Open
xdegaye mannequin opened this issue May 8, 2018 · 2 comments
Open

destructors of local variables are not traced #77627

xdegaye mannequin opened this issue May 8, 2018 · 2 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@xdegaye
Copy link
Mannequin

xdegaye mannequin commented May 8, 2018

BPO 33446
Nosy @xdegaye, @serhiy-storchaka
PRs
  • bpo-33446: destructors of local variables are now traced #6730
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2018-05-08.18:29:15.715>
    labels = ['interpreter-core', '3.8', 'type-bug', 'library', '3.7']
    title = 'destructors of local variables are not traced'
    updated_at = <Date 2018-05-08.19:00:03.664>
    user = 'https://github.com/xdegaye'

    bugs.python.org fields:

    activity = <Date 2018-05-08.19:00:03.664>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Interpreter Core', 'Library (Lib)']
    creation = <Date 2018-05-08.18:29:15.715>
    creator = 'xdegaye'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 33446
    keywords = ['patch']
    message_count = 2.0
    messages = ['316290', '316292']
    nosy_count = 2.0
    nosy_names = ['xdegaye', 'serhiy.storchaka']
    pr_nums = ['6730']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue33446'
    versions = ['Python 3.6', 'Python 3.7', 'Python 3.8']

    @xdegaye
    Copy link
    Mannequin Author

    xdegaye mannequin commented May 8, 2018

    In the following code, the destructors of objects referenced by the 'a' and 'b' local variables are not traced by the 'step' command of pdb.

    1 class C:
    2 def __init__(self, name):
    3 self.name = name
    4
    5 def __del__(self):
    6 print('"%s" destructor' % self.name)
    7
    8 def main():
    9 a = C('a')
    10 b = C('b')
    11 import pdb; pdb.set_trace()
    12 a = 1
    13
    14 main()

    @xdegaye xdegaye mannequin added 3.7 (EOL) end of life 3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels May 8, 2018
    @xdegaye
    Copy link
    Mannequin Author

    xdegaye mannequin commented May 8, 2018

    In both cases the destructor cannot be traced because it is invoked from functions called from [1] call_trace() where tracing is disabled:

    Case local variable 'a':
    On line 12, just before executing this line with a pdb step command, the object referenced by 'a' lives in frame->f_locals. The step command causes the ceval loop to execute the bytecodes corresponding to the statement on line 12 and to eventualy call [2] call_trampoline() with a 'return' trace event and to call PyFrame_FastToLocalsWithError() here. This last call causes the last reference to the previous 'a' object in frame->f_locals to be decremented and the object to be deallocated but without its destructor being traced as tracing has been disabled in call_trace().

    Case local variable 'b':
    Upon exiting the frame of the 'main' function, pdb keeps a reference to frame->f_locals through its own attribute curframe_locals. Next, after returning to the 'main' caller, this reference is decremented since pdb.curframe_locals references now another object and the dictionary referenced by the previous frame f_locals (the frame of 'main') is deallocated, but this happens within pdb where tracing is disabled and the destructor of the object that had been referenced by 'b' is therefore not traced.

    PR 6730 proposes a fix for both cases.

    [1] https://github.com/python/cpython/blob/master/Python/ceval.c#L4247
    [2] https://github.com/python/cpython/blob/master/Python/sysmodule.c#L462

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    0 participants