We were warned that lots of modules would need modification to build for threads and PerlIO. Curses has proved to be one. I did a little source diving, and came up with patches for Curses.c and CursesFun.c which work for me. I built for Linux-2.4, gcc3, glibc-2.2.5, libncurses.so.5.2, perl-5.8.0(i686-linux-thread-multi)

The first patch is needed for ithreads. The Perl_sv_isa() function of perl has a wrapper macro, sv_isa(), which takes care of adding the interpreter state argument to the function call, if needed. Curses.c nearly always uses the macro, but it was omitted in one place it is needed.

The other patch is to repair 'incompatible pointer type' warnings in CursesFun.c. Those are related to PerlIO. To get a native FILE * pointer from a handle (transparent to the IO model), the PerlIO_findFILE() wrapper must be called. There are four locations in CursesFun.c which need this applied.

I don't know very much about maintaining backward compatibility so I'll welcome comments on whether these patches are the most correct way to update Curses. I'll send them on to the author once I'm satisfied that they're correct.

Threading patch:

--- Curses-1.06/Curses.c.orig Tue Jul 30 02:42:30 2002 +++ Curses-1.06/Curses.c Tue Jul 30 03:09:25 2002 @@ -272,7 +272,7 @@ SV *sv; int argnum; { - if (Perl_sv_isa(sv, "Curses::Window")) { + if (sv_isa( sv, "Curses::Window")) { WINDOW *ret = (WINDOW *)SvIV((SV*)SvRV(sv)); return ret; }

PerlIO patch:

--- Curses-1.06/CursesFun.c.orig Tue Jul 30 04:04:30 2002 +++ Curses-1.06/CursesFun.c Tue Jul 30 07:23:06 2002 @@ -1276,8 +1276,8 @@ 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))); + FILE * outfd = PerlIO_findFILE(IoIFP(sv_2io(ST(1)))); + FILE * infd = PerlIO_findFILE(IoIFP(sv_2io(ST(2)))); SCREEN * ret = newterm(type, outfd, infd); ST(0) = sv_newmortal(); @@ -3450,7 +3450,7 @@ c_exactargs("putwin", items, 2); { WINDOW *win = c_sv2window(ST(0), 0); - FILE * filep = IoIFP(sv_2io(ST(1))); + FILE * filep = PerlIO_findFILE(IoIFP(sv_2io(ST(1)))); int ret = putwin(win, filep); ST(0) = sv_newmortal(); @@ -3469,7 +3469,7 @@ #ifdef C_GETWIN c_exactargs("getwin", items, 1); { - FILE * filep = IoIFP(sv_2io(ST(0))); + FILE * filep = PerlIO_findFILE(IoIFP(sv_2io(ST(0)))); WINDOW * ret = getwin(filep); ST(0) = sv_newmortal();

After Compline,
Zaxo

Replies are listed 'Best First'.
(win32) Re: Build Curses for Perl 5.8.0
by PodMaster (Abbot) on Jul 31, 2002 at 07:40 UTC
    That's cool zaxo.

    All my attempts to build Curses.pm on win32 have failed (win2k).

    I have contacted the author, but he's not win32 knowledgable, and says that the win32 support that had existed, he got in the form of a patch. He also thought there was a PPM at the ActiveState repository of Curses. I couldn't find one for win32.

    So I call upon anyone who knows how to build Curses.pm on win32, to go ahead and please do so, or help me do it, on Perl 5.6.1 or 5.7 or 5.8 or any perl.

    ____________________________________________________
    ** The Third rule of perl club is a statement of fact: pod is sexy.

      Hi, I was wondering if you tried the perl that comes with CYGWIN as well as ActivePerl. If you haven't tried CYGWIN, it's worth a shot. Let me know if it works, because if I ever get a Windows box I'd like my programs to work on it :)


      Rohit
Re: Build Curses for Perl 5.8.0
by Cmdr_Tofu (Scribe) on Dec 01, 2002 at 15:41 UTC
    Thank you SO much for creating this node! I've been trying to do figger this out for three days.
Re: Build Curses for Perl 5.8.0
by warren (Initiate) on Apr 14, 2003 at 22:57 UTC
    Hi,

    After implementing your suggested changes I still am unable to install curses. Whether or not it is the same problem I am not sure, I no longer recieve the "incompatible pointer type". Bellow in a readmore is all the gory details.

Thanks
by Anonymous Monk on Mar 13, 2004 at 00:11 UTC
    Thank you for posting this fix for building Curses.PM on Perl 5.8. I'm surprised it hasn't been incorporated yet. I downloaded Curses 1.06 from CPAN today, and had great difficulty getting it to build on Mac OS X 10.3 until I found this article. I patched the two files as shown, and made some minor changes to the c-darwin.h file and the build went smoothly. Thanks again!
Re: Build Curses for Perl 5.8.0
by cheval_bleu (Initiate) on Sep 07, 2004 at 02:00 UTC
    Merci Zaxo! This was way beyond my reach.