Skip to content

pyexpat.c calls trace function incorrectly for exceptions #50608

Closed

Description

@nedbat
BPO 6359
Nosy @loewis, @freddrake, @birkenfeld, @nedbat, @ezio-melotti, @jeremyhylton
Superseder
  • bpo-22462: Modules/pyexpat.c violates PEP 384
  • Files
  • domshow.py: Demonstration code.
  • 6539.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-10-06.13:08:08.240>
    created_at = <Date 2009-06-28.22:43:21.910>
    labels = ['expert-XML', 'type-bug']
    title = 'pyexpat.c calls trace function incorrectly for exceptions'
    updated_at = <Date 2014-10-06.13:08:08.238>
    user = 'https://github.com/nedbat'

    bugs.python.org fields:

    activity = <Date 2014-10-06.13:08:08.238>
    actor = 'georg.brandl'
    assignee = 'none'
    closed = True
    closed_date = <Date 2014-10-06.13:08:08.240>
    closer = 'georg.brandl'
    components = ['XML']
    creation = <Date 2009-06-28.22:43:21.910>
    creator = 'nedbat'
    dependencies = []
    files = ['14379', '29951']
    hgrepos = []
    issue_num = 6359
    keywords = ['patch']
    message_count = 6.0
    messages = ['89798', '175234', '175246', '182723', '187426', '228679']
    nosy_count = 6.0
    nosy_names = ['loewis', 'fdrake', 'georg.brandl', 'nedbat', 'ezio.melotti', 'Jeremy.Hylton']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'test needed'
    status = 'closed'
    superseder = '22462'
    type = 'behavior'
    url = 'https://bugs.python.org/issue6359'
    versions = ['Python 2.7', 'Python 3.2', 'Python 3.3', 'Python 3.4']

    Activity

    1. nedbat commented on Jun 28, 2009

      @nedbat
      MemberAuthor

      Pyexpat.c calls the tracing function explicitly (not sure why). When it
      intercepts an exception, it calls the function with PyTrace_EXCEPTION,
      but then leaves the scope without calling PyTrace_RETURN. This is
      incorrect. There should always be a PyTrace_RETURN for every PyTrace_CALL.

      I've attached domshow.py to demonstrate the problem.

      Running it produces many lines of output, including:

                       line expatbuilder.py 222
                       line expatbuilder.py 223
                       call pyexpat.c 905
                          call expatbuilder.py 892
                             line expatbuilder.py 894
                             line expatbuilder.py 900
                             exception expatbuilder.py 900
                             return expatbuilder.py 900
                          exception pyexpat.c 905
                          exception expatbuilder.py 223
                          line expatbuilder.py 225
                          line expatbuilder.py 226
      

      The exception at line 905 in pyexpat.c should be followed with a return
      from line 905 in pyexpat.c, but is not. After that exception, the
      nesting is off by one because the Calls and Returns don't match.

    2. ezio-melotti commented on Nov 9, 2012

      @ezio-melotti
      Member

      Can you provide a patch?

    3. nedbat commented on Nov 9, 2012

      @nedbat
      MemberAuthor

      I have no idea why pyexpat.c invokes the trace function in the first place. Unless someone can explain why it does that when no other C extension does, my inclination would be to make it stop calling the trace function at all, not to fix how it calls it.

    4. ezio-melotti commented on Feb 23, 2013

      @ezio-melotti
      Member

      The relevant changesets are 1c26eb768293 and e43126c470a7. See also bpo-534864.

    5. nedbat commented on Apr 20, 2013

      @nedbat
      MemberAuthor

      Attached a patch which simply removes the code that invokes the trace function.

    6. birkenfeld commented on Oct 6, 2014

      @birkenfeld
      Member

      A more complete patch that also fixes up pyexpat's frame trickery is tracked in bpo-22462.

    7. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      topic-XMLtype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions