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

_tkinter should use Python PyMem_Malloc() instead of Tcl ckalloc() #66532

Closed
vstinner opened this issue Sep 4, 2014 · 10 comments
Closed

_tkinter should use Python PyMem_Malloc() instead of Tcl ckalloc() #66532

vstinner opened this issue Sep 4, 2014 · 10 comments
Labels
topic-tkinter type-feature A feature request or enhancement

Comments

@vstinner
Copy link
Member

vstinner commented Sep 4, 2014

BPO 22336
Nosy @vstinner, @serhiy-storchaka
Files
  • pymem.patch
  • tkinter_pymem_2.patch
  • tkinter_pymem_3.patch
  • 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 2014-09-11.15:52:36.190>
    created_at = <Date 2014-09-04.15:46:10.949>
    labels = ['type-feature', 'expert-tkinter']
    title = '_tkinter should use Python PyMem_Malloc() instead of Tcl ckalloc()'
    updated_at = <Date 2014-09-11.15:53:44.381>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2014-09-11.15:53:44.381>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2014-09-11.15:52:36.190>
    closer = 'python-dev'
    components = ['Tkinter']
    creation = <Date 2014-09-04.15:46:10.949>
    creator = 'vstinner'
    dependencies = []
    files = ['36533', '36596', '36599']
    hgrepos = []
    issue_num = 22336
    keywords = ['patch']
    message_count = 10.0
    messages = ['226363', '226365', '226366', '226753', '226764', '226771', '226779', '226782', '226784', '226785']
    nosy_count = 4.0
    nosy_names = ['vstinner', 'python-dev', 'serhiy.storchaka', 'David.Edelsohn']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue22336'
    versions = ['Python 3.5']

    @vstinner
    Copy link
    Member Author

    vstinner commented Sep 4, 2014

    The PyMem_Malloc(size) function has a well defined behaviour: if size is 0, a pointer different than NULL is returned. It looks like ckalloc(size) returns NULL if the size is NULL: see issue bpo-21951 (bug on AIX).

    Moreover, memory allocated by ckalloc() is not traced by the new tracemalloc module!

    Attached patch replaces calls to ckalloc() and ckfree() with PyMem_Malloc() and PyMem_Free(). It may fix the issue bpo-21951 on AIX.

    There is still a call to ckfree() in Tkapp_SplitList(). This memory block is allocated internally by Tcl, not directly by _tkinter.c.

    @vstinner vstinner added type-feature A feature request or enhancement topic-tkinter labels Sep 4, 2014
    @vstinner
    Copy link
    Member Author

    vstinner commented Sep 4, 2014

       PyMem_Free(FREECAST argv);
    

    FREECAST can be dropped here, PyMem_Free() always takes a void* pointer.

    @serhiy-storchaka
    Copy link
    Member

    Event structs (Tkapp_CallEvent, VarEvent, CommandEvent) must have been allocated by the caller using Tcl_Alloc or ckalloc (see man Tcl_ThreadQueueEvent).

    @serhiy-storchaka
    Copy link
    Member

    Here is updated patch which is synchronized with the tip after changes made in bpo-21951 and addresses my comments.

    @vstinner
    Copy link
    Member Author

    I read tkinter_pymem_2.patch.

    Remaining calls to ckalloc():

    • they are only used to allocate events passed later to Tcl_ThreadQueueEvent(). Tcl_ThreadQueueEvent doc explicitly says that the memory must be allocated by Tcl_Alloc or ckalloc, so it's correct (PyMem cannot be used).

    Remaining calls to ckfree():

    • Tkapp_SplitList() calls ckfree() on memory allocated by Tcl_SplitList(), it's correct.

    • Tkapp_CallDeallocArgs() ckfree() on memory allocated by PyMem_Malloc() => wrong (see my review on Rietveld).

    @serhiy-storchaka
    Copy link
    Member

    • Tkapp_CallDeallocArgs() ckfree() on memory allocated by PyMem_Malloc() =>
      wrong

    Oh, you are right, thanks.

    (see my review on Rietveld).

    Perhaps you forgot to press the "Publish" button.

    @vstinner
    Copy link
    Member Author

    tkinter_pymem_3.patch looks good to me.

    @serhiy-storchaka
    Copy link
    Member

    And to me too. Please commit it, this is mainly your patch.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Sep 11, 2014

    New changeset 9f1d3e6e6ce6 by Victor Stinner in branch 'default':
    Closes bpo-22336: attemptckalloc() with PyMem_Malloc() in _tkinter
    http://hg.python.org/cpython/rev/9f1d3e6e6ce6

    @python-dev python-dev mannequin closed this as completed Sep 11, 2014
    @vstinner
    Copy link
    Member Author

    And to me too. Please commit it, this is mainly your patch.

    Ok, thanks, done.

    @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
    topic-tkinter type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants