classification
Title: Curses segfaulting in FreeBSD/amd64
Type: crash Stage:
Components: Extension Modules Versions: Python 2.5
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: skrah, terry.reedy, themoken
Priority: normal Keywords:

Created on 2009-05-23 02:10 by themoken, last changed 2010-08-04 20:02 by terry.reedy. This issue is now closed.

Messages (4)
msg88220 - (view) Author: Jack Miller (themoken) Date: 2009-05-23 02:10
I have some code that gets a Pycurses window object, grabs the standard
ncurses WINDOW* out of it and proceeds to use that as usual. Works great
on Linux. Segfaults on FreeBSD/amd64.

static PyObject * mvw(PyObject *self, PyObject *args)
{
    PyObject *window;
    WINDOW *win;
    int y, x, width, rep_len, end_len, ret;
    char *message, *rep, *end;

    const char *m_enc, *r_enc, *e_enc;
    if(!PyArg_ParseTuple(args, "Oiiietetet", 
                &window, &y, &x, &width, &m_enc, &message,
                &r_enc, &rep, &e_enc, &end))
            return NULL;

    if (window != Py_None)
        win = ((PyCursesWindowObject *)window)->win;
    else
        win = NULL;
    ...

Very simple. After this runs, `win` should be a standard curses window.
As noted, this works just fine in Linux regardless of architecture and
I'm sure that I'm passing a correct object type. (Tangentially, the
window check macro in py_curses.h -- PyCursesWindow_Check(v) -- also
segfaults, but I haven't tested that on Linux).

The subsequent `win` is non-NULL, but when I attempt to actually use it,
even for a simple `mvwaddch(win, 0, 0, '?');`, the program segfaults on
FreeBSD.

Other Notes: If I just use curses from Python (i.e. without a C
extension), it works as expected. I've attached this basic, working
test. This leads me to believe that the ncurses library is ok, and that
the majority of the curses binding is probably ok.

Also, I'm not sure if there is a better (more pythonic) way to get to
the WINDOW object, I just looked at the struct in py_curses.h to grab it
and it worked, so I didn't give it a second thought until now. I also
don't know how to verify that the pointer points to a curses WINDOW, but
I do know that the pointer address looks ok.

I can whip up a non-working test case on request, but I'm not sure the
best way to include the extension. The full source for the extension and
the program using it at codezen.org/canto ( particularly: 
http://codezen.org/cgi-bin/gitweb.cgi?p=canto.git;a=blob;f=canto/widecurse.c;h=d8a259a66c85f5fa87d52045a643fc81beec8017;hb=HEAD
)

I'm running FreeBSD 8-CURRENT, but the code doesn't work on 7.2-STABLE
either. This is Python 2.5.4 and pyncurses 0.3 both built from source
out of ports as of May 20th.
msg104085 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2010-04-24 13:11
Can you check if the latest patch for issue 7384 fixes the problem?
The patch is against py3k, but it comes down to this:

  1) Build the readline module _only_ with -lreadline (instead of
     -lreadline -lncursesw)

  2) Build the curses and curses_panel modules with -lncurses (instead
     of -lncursesw)
msg104411 - (view) Author: Jack Miller (themoken) Date: 2010-04-28 05:04
The rest of my codebase is currently only 2.x compatible, but I saw identical symptoms about a month ago on Fedora/Mandriva when their 2.x packages were linked against non-widechar libraries so I imagine that is indeed the solution.

I'll close the bug when I can either wrap the code for 3.x or get a 2.x FreeBSD build with those changes.

Thanks!
msg112879 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2010-08-04 20:02
#7384 was closed two weeks ago with patches for 2.6 and 2.7 so this should be fixed in 2.6.6 (rc1 just out) and 2.7 svn (which will become 2.7.1. Only reopen if current/future 2.7.1 fails.
History
Date User Action Args
2010-08-04 20:02:41terry.reedysetstatus: open -> closed

nosy: + terry.reedy
messages: + msg112879

resolution: out of date
2010-04-28 05:04:45themokensetmessages: + msg104411
2010-04-24 13:11:12skrahsetnosy: + skrah
messages: + msg104085
2009-05-23 02:10:26themokencreate