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

PythonCmd in Modules/_tkinter.c should use the given "interp" parameter #49042

Closed
gpolo mannequin opened this issue Dec 31, 2008 · 5 comments
Closed

PythonCmd in Modules/_tkinter.c should use the given "interp" parameter #49042

gpolo mannequin opened this issue Dec 31, 2008 · 5 comments

Comments

@gpolo
Copy link
Mannequin

gpolo mannequin commented Dec 31, 2008

BPO 4792
Files
  • use_given_interp.diff
  • 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 = <Date 2009-03-07.01:59:03.456>
    created_at = <Date 2008-12-31.15:29:57.482>
    labels = ['expert-tkinter']
    title = 'PythonCmd in Modules/_tkinter.c should use the given "interp" parameter'
    updated_at = <Date 2009-03-07.01:59:03.441>
    user = 'https://bugs.python.org/gpolo'

    bugs.python.org fields:

    activity = <Date 2009-03-07.01:59:03.441>
    actor = 'gpolo'
    assignee = 'none'
    closed = True
    closed_date = <Date 2009-03-07.01:59:03.456>
    closer = 'gpolo'
    components = ['Tkinter']
    creation = <Date 2008-12-31.15:29:57.482>
    creator = 'gpolo'
    dependencies = []
    files = ['12505']
    hgrepos = []
    issue_num = 4792
    keywords = ['patch']
    message_count = 5.0
    messages = ['78613', '81329', '83266', '83267', '83269']
    nosy_count = 1.0
    nosy_names = ['gpolo']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue4792'
    versions = ['Python 2.6', 'Python 3.0', 'Python 3.1', 'Python 2.7']

    @gpolo
    Copy link
    Mannequin Author

    gpolo mannequin commented Dec 31, 2008

    Right now PythonCmd is using the Tcl interpreter stored in self->interp,
    but this is unsafe and since it is a Tcl_CmdProc it already receives the
    Tcl interpreter as a parameter. Using the interpreter in self->interp is
    unsafe because Python might deallocate this TkappObject and then
    PythonCmd could be invoked later, and using the interpreter given to the
    Tcl_CmdProc is guaranteed to be safe by Tcl.

    To reproduce this I needed a debug build and also needed to run the
    example below in the interpreter:

    >> import tkFileDialog
    >> tkFileDialog.askdirectory() # here I both windows, then:
    >> Segmentation fault

    There are other ways to reproduce this but I can't remember them
    offhand, I know there are other ways because I've hit this same problem
    in another python <-> tcl bridge by doing something else.

    The patch could be expanded to remove the use of "self" in
    PythonCmd_Clientdata, but given another wish I have -- to move to
    Tcl_CreateObjCommand -- self would be needed again.

    @gpolo gpolo mannequin added the topic-tkinter label Dec 31, 2008
    @gpolo
    Copy link
    Mannequin Author

    gpolo mannequin commented Feb 7, 2009

    Another way to reproduce it (tested using debug build):

    Python 2.7a0 (trunk:69375:69376M, Feb  6 2009, 20:27:09) 
    [GCC 4.3.2] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import Tkinter
    >>> Tkinter.Tk()
    <Tkinter.Tk instance at 0xb79c8edc>
    >>> Tkinter.Tk()
    <Tkinter.Tk instance at 0xb79cb06c>

    # close both windows now, get a segfault

    @gpolo
    Copy link
    Mannequin Author

    gpolo mannequin commented Mar 7, 2009

    I will be committing this but I'm afraid a test won't be added for it.
    Several people told me that creating multiple tcl interpreters (even if
    only one is active at some point) is problematic, specially in older tcl
    versions.

    So if someone can find another way to reproduce the problem you are
    welcome to add a test. Ideally it would let the only tcl interpreter
    created still alive (although as I see this bug you will only hit it if
    a Tkapp is dealloced and then a callback created through Python is
    invoked), otherwise the other existing tests will suffer.

    @gpolo
    Copy link
    Mannequin Author

    gpolo mannequin commented Mar 7, 2009

    Fixed in r70219.

    @gpolo
    Copy link
    Mannequin Author

    gpolo mannequin commented Mar 7, 2009

    Merges: r70220, r70221, r70222

    @gpolo gpolo mannequin closed this as completed Mar 7, 2009
    @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
    Projects
    None yet
    Development

    No branches or pull requests

    0 participants