Skip to content

new.code and new.function crashes Python iterpretter #59456

Closed

Description

@jeffdharper
BPO 15251
Nosy @loewis, @terryjreedy, @taleinat
Files
  • bug3.py
  • tem.py: Crashes 3.3.0b0 pythonw run from IDLE
  • repro.py
  • 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 2021-10-18.20:52:18.485>
    created_at = <Date 2012-07-04.17:29:13.207>
    labels = ['type-crash', 'docs']
    title = 'new.code and new.function crashes Python iterpretter'
    updated_at = <Date 2021-10-18.20:52:18.483>
    user = 'https://bugs.python.org/jeffdharper'

    bugs.python.org fields:

    activity = <Date 2021-10-18.20:52:18.483>
    actor = 'taleinat'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2021-10-18.20:52:18.485>
    closer = 'taleinat'
    components = ['Documentation']
    creation = <Date 2012-07-04.17:29:13.207>
    creator = 'jeffdharper'
    dependencies = []
    files = ['26257', '26279', '50368']
    hgrepos = []
    issue_num = 15251
    keywords = []
    message_count = 6.0
    messages = ['164652', '164653', '164654', '164663', '164775', '404219']
    nosy_count = 5.0
    nosy_names = ['loewis', 'terry.reedy', 'taleinat', 'docs@python', 'jeffdharper']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue15251'
    versions = ['Python 2.7']

    Activity

    1. jeffdharper commented on Jul 4, 2012

      jeffdharpermannequin
      MannequinAuthor

      I've attached a script that crashes the Python interpreter.

      I can get the crash to occur under Windows Vista with this version of Python:

      C:\tmp\remote>c:\Python27\python.exe
      Python 2.7.1 Stackless 3.1b3 060516 (release27-maint, Jan 1 2011, 13:04:37) [MSC v.1500 32 bit (Intel)] on win32

      Also, I got it to segfault under Ubuntu Linux:

      jharper@ubuntu:$ uname -a
      Linux ubuntu 2.6.35-27-generic #48-Ubuntu SMP Tue Feb 22 20:25:29 UTC 2011 i686 GNU/Linux
      jharper@ubuntu:
      $ python
      Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39)
      [GCC 4.4.5] on linux2

      Note, when I commented out the line, "pprint(code_args)", the script generated a SystemError exception instead of crashing.

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-crashA hard crash of the interpreter, possibly with a core dump
      on Jul 4, 2012
    3. jeffdharper commented on Jul 4, 2012

      jeffdharpermannequin
      MannequinAuthor

      The marshal loads and dumps don't seem to be necessary to reproduce the crash. On both the Windows Vista and Ubuntu Linux systems, the crash still occurred when I replaced:

      mcopy_code = loads(dumps(code))

      with:

      mcopy_code = code #loads(dumps(code))
    4. loewis commented on Jul 4, 2012

      loewismannequin
      Mannequin

      You need to pass co_freevars and co_cellvars as well for your example to work. It shouldn't crash, but I don't consider this particular crash as a bug, as it is a known limitation that new.code doesn't perform all consistency checks that are necessary to guarantee that the function execution doesn't crash the interpreter.

      It certainly can't be fixed in 2.6.

    5. jeffdharper commented on Jul 4, 2012

      jeffdharpermannequin
      MannequinAuthor

      Martin,

      Thanks for your response. I didn't know it was possible to pass freevars and cellvars to new.code. I think the documentation needs to be updated. The documentation for 2.7.3 located at http://docs.python.org/library/new.html?highlight=new#new.code is as follows:

      new.code(argcount, nlocals, stacksize, flags, codestring, constants, names, varnames, filename, name, firstlineno, lnotab)

      After I got your reply to this bug report I did help(new.code) and I see that it includes freevars and cellvars as optional arguments.

    6. added
      docsDocumentation in the Doc dir
      and removed
      stdlibStandard Library Python modules in the Lib/ directory
      on Jul 4, 2012
    7. terryjreedy commented on Jul 7, 2012

      @terryjreedy
      Member

      In Py3, new.code and new.function become types.CodeType and types.FunctionType. The 'documentation' of their signatures is only available with help(types.xxx). So the library doc issue is 2.7 only.

      Running with IDLE, 3.3b0, Win7, the converted example does crash after 5 seconds or so even with the missing arg and the pprint gone. The crash is in the new_fun(5) call. I might have gotten something wrong. Or maybe the the help is wrong.

    8. taleinat commented on Oct 18, 2021

      @taleinat
      Contributor

      I couldn't reproduce this on the latest main branch with an updated version of the code sample (see attached repro.py). I also couldn't get such a crash with some variations of this.

      I'm marking this as fixed for now. We can re-open this if anyone runs into an up-to-date case of this crash.

    9. 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

      docsDocumentation in the Doc dirtype-crashA hard crash of the interpreter, possibly with a core dump

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions