Skip to content

curses crash on FreeBSD #51633

Closed
Closed

Description

@mdickinson
BPO 7384
Nosy @akuchling, @mdickinson, @vstinner, @ashemedai, @bitdancer, @skrah
Files
  • freebsd-curses.diff: Possible fix
  • issue7384.patch
  • issue7384-2.patch
  • issue7384-3-py3k.patch
  • issue7384-4-py3k.patch
  • issue7384-5-py3k.patch
  • issue7384-5-trunk.patch
  • ldd-retval-py3k.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 2010-07-17.12:41:55.048>
    created_at = <Date 2009-11-23.20:03:46.996>
    labels = ['extension-modules', 'type-bug']
    title = 'curses crash on FreeBSD'
    updated_at = <Date 2010-07-17.12:41:55.047>
    user = 'https://github.com/mdickinson'

    bugs.python.org fields:

    activity = <Date 2010-07-17.12:41:55.047>
    actor = 'skrah'
    assignee = 'none'
    closed = True
    closed_date = <Date 2010-07-17.12:41:55.048>
    closer = 'skrah'
    components = ['Extension Modules']
    creation = <Date 2009-11-23.20:03:46.996>
    creator = 'mark.dickinson'
    dependencies = []
    files = ['16935', '16963', '16973', '17023', '17050', '17064', '17528', '17997']
    hgrepos = []
    issue_num = 7384
    keywords = ['patch', 'buildbot']
    message_count = 52.0
    messages = ['95652', '97709', '97722', '99657', '99658', '99659', '103231', '103256', '103261', '103263', '103264', '103265', '103267', '103295', '103307', '103308', '103393', '103394', '103395', '103429', '103432', '103497', '103503', '103828', '103838', '103980', '103996', '103997', '104000', '104002', '104054', '104057', '104070', '104071', '104074', '104283', '104302', '104311', '104315', '106199', '106939', '106940', '106948', '107323', '107999', '110222', '110224', '110225', '110238', '110271', '110378', '110550']
    nosy_count = 8.0
    nosy_names = ['akuchling', 'mark.dickinson', 'vstinner', 'asmodai', 'rpetrov', 'Arfrever', 'r.david.murray', 'skrah']
    pr_nums = []
    priority = 'normal'
    resolution = 'accepted'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue7384'
    versions = ['Python 2.6', 'Python 3.1', 'Python 2.7', 'Python 3.2']

    Activity

    1. mdickinson commented on Nov 23, 2009

      @mdickinson
      MemberAuthor

      test_curses is currently causing the test runs to abort on the FreeBSD 6.4
      and 7.2 buildbots.

      I can reproduce this on a FreeBSD 7.2 /amd64 machine by doing

      ./python Lib/test/regrtest.py -uall test___all__ test_curses

      This dumps core, and the traceback points at the call to delwin() in
      PyCursesWindow_Dealloc, but it's far from obvious (to me) what's going
      wrong. wo->win is not NULL here, and appears to point to a valid WINDOW.
      However, stdscr is NULL! As far as I can tell, this shouldn't happen.

      test_curses by itself doesn't crash, unless I add an 'import readline' or
      'import rlcompleter' to the top of test_curses.py.

      I expect to have access to the FreeBSD machine for a few more days. Any
      hints about what to try next would be appreciated.

    2. mdickinson commented on Jan 13, 2010

      @mdickinson
      MemberAuthor

      I've not had any success tracking the cause of this failure down, and no longer have the resources to do so. It does appear that curses itself is broken on FreeBSD: it's not just a problem with the tests.

      Adding Andrew Kuchling to the nosy in case he has any ideas what's wrong here.

      Since the test_curses crash is currently aborting the test run, and so preventing us from getting feedback from the other tests on the FreeBSD buildbots, I propose that test_curses be skipped with a "the curses module is broken on FreeBSD" message.

    3. self-assigned this
      on Jan 13, 2010
    4. changed the title [-]test_curses crash on FreeBSD buildbots[/-] [+]curses crash on FreeBSD[/+] on Jan 13, 2010
    5. bitdancer commented on Jan 13, 2010

      @bitdancer
      Member

      Given your diagnosis so far, +1 on the skip.

    6. mdickinson commented on Feb 21, 2010

      @mdickinson
      MemberAuthor

      It does appear that curses itself is broken on FreeBSD

      Rereading this, it doesn't say what I meant it to say: I meant that the Python curses module seems to be broken, not that the system-level curses library is broken (though that seems possible too).

    7. mdickinson commented on Feb 21, 2010

      @mdickinson
      MemberAuthor

      Applied the test_curses skip in r78281 (trunk); will merge to the other branches.

      Leaving this issue open, since the root cause isn't fixed.

    8. removed their assignment
      on Feb 21, 2010
    9. mdickinson commented on Feb 21, 2010

      @mdickinson
      MemberAuthor

      Merged to the other 3 branches in revisions r78282 (release26-maint), r78283 (py3k), r78284 (release31-maint).

    10. mdickinson commented on Apr 15, 2010

      @mdickinson
      MemberAuthor

      I'm looking at this again, after installing FreeBSD 8.0/amd64 in a VM.

      I've reduced Lib/test/test_curses.py to the following 9 lines:

      import rlcompleter
      import curses
      f = open('mytempfile', 'w+b')
      stdscr = curses.initscr()
      stdscr.putwin(f)
      f.seek(0)
      curses.getwin(f)
      f.close()
      curses.endwin()

      I then get:

      $ ./python Lib/test/regrtest.py test_curses
      test_curses
      Bus error (core dumped)

      From looking at the core dump, and tracing through with gdb, the core dump occurs when delwin is called (from PyCursesWindow_Dealloc) on the result of curses.getwin(f), as a result of garbage collection.

      The 'import rlcompleter' line appears to be necessary to cause this; I've no idea why.

    11. mdickinson commented on Apr 15, 2010

      @mdickinson
      MemberAuthor

      Here's the top of the backtrace. (Thanks asmodai for helping me out with working out how to build a FreeBSD system ncurses with debugging information.)

      #0 0x0000000801460714 in cannot_delete (win=0x80116b1d0)
      at /usr/src/lib/ncurses/ncursesw/../../../contrib/ncurses/ncurses/base/lib_delwin.c:54
      p = (struct _win_list *) 0xdbdbdbdbdbdbdbdb
      result = false
      #1 0x0000000801460773 in delwin (win=0x80116b1d0)
      at /usr/src/lib/ncurses/ncursesw/../../../contrib/ncurses/ncurses/base/lib_delwin.c:71
      result = -1
      #2 0x000000080170d140 in PyCursesWindow_Dealloc (wo=0x800eb74c0)
      at /usr/home/dickinsm/python/svn/trunk/Modules/cursesmodule.c:357
      No locals.
      #3 0x000000000046325f in _Py_Dealloc (op=0x800eb74c0) at Objects/object.c:2211
      dealloc = 0x80170d110 <PyCursesWindow_Dealloc>
      #4 0x00000000004578d8 in PyDict_DelItem (op=0x800f121b0, key=0x8011062e0)
      at Objects/dictobject.c:829
      mp = (PyDictObject *) 0x800f121b0
      hash = -3668919459648339544
      ep = (PyDictEntry *) 0x8010cb5a8
      old_value = (PyObject *) 0x800eb74c0
      old_key = (PyObject *) 0x8011062e0
      __func
      _ = "PyDict_DelItem"
      #5 0x0000000000458a48 in dict_ass_sub (mp=0x800f121b0, v=0x8011062e0, w=0x0)
      ---Type <return> to continue, or q <return> to quit---
      at Objects/dictobject.c:1184
      No locals.
      #6 0x000000000041aadd in PyObject_DelItem (o=0x800f121b0, key=0x8011062e0)
      at Objects/abstract.c:205
      m = (PyMappingMethods *) 0x6c2960

    12. akuchling commented on Apr 15, 2010

      @akuchling
      Contributor

      Could I get a login on the buildbot to make a fix?

      I bet the problem is with the stdscr object. PyCurses_InitScr()
      does 'return (PyObject *)PyCursesWindow_New(stdscr);'.

      PyCursesWindow_Dealloc() does:
      if (wo->win != stdscr) delwin(wo->win);

      I bet FreeBSD is clearing contents of the stdscr global variable. The condition in PyCursesWindow_Dealloc() is then true, and it tries to delwin() the old value, which is in wo->win.

      One fix might be to keep a reference to that PyCursesWindow object holding stdscr, and change dealloc to 'if (wo != saved_stdscr_object)'. Or maybe, since multiple calls to initscr() will create multiple window objects holding the value of stdscr, window objects should have a 'do_not_delwin' flag.

    13. akuchling commented on Apr 15, 2010

      @akuchling
      Contributor

      Here's a possible patch; it at least doesn't seem to break the module on MacOS, though MacOS doesn't crash with the current code either.

    14. 29 remaining items

    15. vstinner commented on May 20, 2010

      @vstinner
      Member

      I tested bpo-7384-5-py3k.patch on FreeBSD 8.0: it fixes the crash.

    16. skrah commented on Jun 3, 2010

      skrahmannequin
      Mannequin

      I think it would be nice to get this into 2.7. I don't expect buildbot
      failures, since the 2.7 patch is essentially the same as the py3k version,
      which has been tested extensively.

    17. mdickinson commented on Jun 3, 2010

      @mdickinson
      MemberAuthor

      I think it would be nice to get this into 2.7.

      Agreed. I think you should go ahead and commit it.

    18. skrah commented on Jun 3, 2010

      skrahmannequin
      Mannequin

      Mark, thanks. Committed in r81669; I'll keep an eye on the buildbots.

    19. skrah commented on Jun 8, 2010

      skrahmannequin
      Mannequin

      Committed in r81669,r81672,r81683 (trunk) and r81830,81831 (py3k).

      What to do with the releases? To recap, the fix is:

      1. Detect if readline is already linked against ncurses and
        if so, skip any further selection. This must be done.

      2. Use the same version of ncurses for readline.so and _curses.so.

      3. should be done in any case. 2) could change the behavior for
        users who previously had readline/ncurses, cursesmodule/ncursesw,
        but only use the cursesmodule in an application.

    20. skrah commented on Jun 17, 2010

      skrahmannequin
      Mannequin

      Committed a conservative version implementing part 1) in r82017 (2.6) and
      r82019 (3.1). Part 2) can be enabled by uncommenting a couple of lines in
      setup.py.

      The buildbots look good, but I'm setting this to 'pending' in case
      someone would like part 2) of the fix in the releases.

    21. Arfrever commented on Jul 13, 2010

      Arfrevermannequin
      Mannequin

      These changes break building of Python 3.* in some locales in Gentoo.

      running build
      running build_ext
      Traceback (most recent call last):
        File "./setup.py", line 1812, in <module>
          main()
        File "./setup.py", line 1807, in main
          "Tools/scripts/2to3"]
        File "/var/tmp/portage/dev-lang/python-3.2_pre20100711/work/Python-3.2_pre20100711/Lib/distutils/core.py", line 152, in setup
          dist.run_commands()
        File "/var/tmp/portage/dev-lang/python-3.2_pre20100711/work/Python-3.2_pre20100711/Lib/distutils/dist.py", line 946, in run_commands
          self.run_command(cmd)
        File "/var/tmp/portage/dev-lang/python-3.2_pre20100711/work/Python-3.2_pre20100711/Lib/distutils/dist.py", line 965, in run_command
          cmd_obj.run()
        File "/var/tmp/portage/dev-lang/python-3.2_pre20100711/work/Python-3.2_pre20100711/Lib/distutils/command/build.py", line 127, in run
          self.run_command(cmd_name)
        File "/var/tmp/portage/dev-lang/python-3.2_pre20100711/work/Python-3.2_pre20100711/Lib/distutils/cmd.py", line 315, in run_command
          self.distribution.run_command(command)
        File "/var/tmp/portage/dev-lang/python-3.2_pre20100711/work/Python-3.2_pre20100711/Lib/distutils/dist.py", line 965, in run_command
          cmd_obj.run()
        File "/var/tmp/portage/dev-lang/python-3.2_pre20100711/work/Python-3.2_pre20100711/Lib/distutils/command/build_ext.py", line 393, in run
          self.build_extensions()
        File "./setup.py", line 151, in build_extensions
          missing = self.detect_modules()
        File "./setup.py", line 539, in detect_modules
          for ln in fp:
        File "/var/tmp/portage/dev-lang/python-3.2_pre20100711/work/Python-3.2_pre20100711/Lib/encodings/ascii.py", line 26, in decode
          return codecs.ascii_decode(input, self.errors)[0]
      UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 20: ordinal not in range(128)
      make: *** [sharedmods] Error 1

      In lt_LT.UTF-8 locale, readline_termcap_lib file contains:
      ne dinaminis paleidžiamasis failas

      In en_US.UTF-8 locale, this file would contain:
      not a dynamic executable

      do_readline is "/usr/lib64/libreadline.so".

      /usr/lib64/libreadline.so is a linker script with the following content:
      /* GNU ld script
      Since Gentoo has critical dynamic libraries in /lib, and the static versions
      in /usr/lib, we need to have a "fake" dynamic lib in /usr/lib, otherwise we
      run into linking problems. This "fake" dynamic lib is a linker script that
      redirects the linker to the real lib. And yes, this works in the cross-
      compiling scenario as the sysroot-ed linker will prepend the real path.

      See bug http://bugs.gentoo.org/4411 for more info.
      */
      OUTPUT_FORMAT ( elf64-x86-64 )
      GROUP ( /lib64/libreadline.so.6 )

      I think that using ldd is a wrong idea.

    22. skrah commented on Jul 13, 2010

      skrahmannequin
      Mannequin

      In Ubuntu I can build just fine with lt_LT.UTF-8. So perhaps this problem
      should be addressed in Gentoo.

    23. Arfrever commented on Jul 13, 2010

      Arfrevermannequin
      Mannequin

      You shouldn't use ldd. I suggest that setup.py try to link a small executable, which would use a function from libcurses and would be linked against libreadline, but not libcurses. If linking succeeds, then you libreadline is linked against libcurses. If linking fails, then repeat this procedure with libcursesw, libncurses, libncursesw, libtinfo.

    24. vstinner commented on Jul 13, 2010

      @vstinner
      Member

      "In lt_LT.UTF-8 locale, readline_termcap_lib file contains:
      ne dinaminis paleidžiamasis failas"

      You can run ldd without LANG variable to get the original (english, ascii only) message.

    25. skrah commented on Jul 14, 2010

      skrahmannequin
      Mannequin

      So you have garbage from stderr in readline_termcap_lib. Since that's
      useless anyway (no matter what locale is set), let's check the return
      value of os.system().

      The attached patch skips readline linkage detection if ldd fails. In
      that case, linking will be done in the same manner as before r81830.

      Please report if the patch allows you to build py3k in the problematic
      locale.

      Your method of detecting readline linkage looks interesting, but I
      doubt that I'm going to implement it: These cross platform issues
      take an *immense* amount of time, since you have to test on all
      buildbot platforms (+ OpenBSD and OpenSolaris), with different
      compilers (icc, suncc).

      If you want that done, the best way is to open another issue, submit a
      patch (probably for configure.in) _and_ do all the testing.

    26. Arfrever commented on Jul 15, 2010

      Arfrevermannequin
      Mannequin

      This patch allows to build Python 3.* in this locale.

      It might be safer to open tmpfile in binary mode to avoid potential problems with non-ASCII characters in paths to libraries.

    27. skrah commented on Jul 17, 2010

      skrahmannequin
      Mannequin

      ldd return value check committed in r82927, r82928, r82929 and r82930.

      Thanks for reporting this!

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

      extension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions