BUU has asked for the wisdom of the Perl Monks concerning the following question:

I've been amusing myself recently playing with Curses in perl and now I want to play with multiple terminals (ala screen). If I'm reading the documentation for curses correctly, I want to use the newterm function to facilitate this. The problem is, newterm() either errors with complaints about my arguments or segfaults.

My latest segfault looks like this:
my $o = IO::File->new("/dev/tty", "w"); my $i = IO::File->new("/dev/tty", "r"); newterm(undef, $o, $i); endwin()

I should note that roughly the same code in C works:
#include <curses.h> #include <stdlib.h> int main() { FILE *i, *o; i = fopen( "/dev/tty", "r" ); o = fopen( "/dev/tty", "w" ); SCREEN *s = newterm(0, o, i); addch('a'); addch('b'); addch('c'); refresh(); endwin(); }
I'll reproduce the XS code for newterm for your viewing pleasure:
XS(XS_Curses_newterm) { dXSARGS; #ifdef C_NEWTERM c_exactargs("newterm", items, 3); { char * type = ST(0) != &PL_sv_undef ? (char *)SvPV(ST(0),PL_na) : +NULL; FILE * outfd = IoIFP(sv_2io(ST(1))); FILE * infd = IoIFP(sv_2io(ST(2))); SCREEN * ret = newterm(type, outfd, infd); ST(0) = sv_newmortal(); c_screen2sv(ST(0), ret); } XSRETURN(1); #else c_fun_not_there("newterm"); XSRETURN(0); #endif }

Replies are listed 'Best First'.
Re: Curses.pm and newterm
by BrowserUk (Patriarch) on Dec 12, 2005 at 09:42 UTC

    *guesswork alert*

    The first parameter you are passing to newterm(), zero in the C version and undef in the perl version aren't exactly equivalent.

    Did you try passing zero from the perl version?


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Well, that's interesting. Now it doesn't segfault, but none of the display functions seem to do anything, even if I call refresh().

        I cannot even try any of this stuff here, but I did lookup newwin() on the net, and every reference I found lists 4 parameters for the call?

        The thing that intrigues me about your C version in the OP, is that you get a SCREEN *s returned from newwin(), but you make no use of it in your calls to addch() and the rest.

        If you had created two SCREENs, how would those other calls know which of them they were supposed to be affecting?


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.