Re: Curses-perl that doesn't live up to it's name?




"Fred Stone" <fstone69@xxxxxxxxxxxxx> wrote in message
news:Xns987857FEBF574fstone69@xxxxxxxxxxxxxxxx
"Sisyphus" <sisyphus1@xxxxxxxxxxxxxxxxx> wrote in
..
..

So I wrote the following demo:

-------------------------
use warnings;
use Inline C => Config =>
BUILD_NOISY => 1, # verbose build
LIBS => '-LF:/pdcurses_mingw -lpdcurses',
INC => '-IF:/pdcurses_mingw';

use Inline C => <<'EOC';

#include <curses.h>

int wrap_baudrate() {
return baudrate();
}

int wrap_beep() {
return beep();
}

int get_sizeof_chtype() {
return sizeof(chtype);
}


EOC

$ret1 = wrap_baudrate();
$ret2 = wrap_beep();
$size = get_sizeof_chtype();

print $ret1, " ", $ret2, "\n";
-------------------------
..
..


In my C++ programs I wrap curses.h into objects so that the old C
structures become private to those objects.

And I think that's approximately what the Curses-1.15 installation
Makefile.pl is doing, though the automated process is not at all
transparent to a perl n00b like me. He's doing some weird hack to
generate compiler calls to detect each of the routines in curses.h and
then generates C macros to interface them, and then *that* gets compiled
to make the Curses.pm module.


But both perl.h (and hence embed.h) and curses.h are being included in perl
Curses, so perl Curses must be doing something to resolve the 'instr'
conflict. Indeed, I find in perl curses.c the following:

-------------------------
/* c-config.h above includes Ncurses header files that define macro
'instr'. Unfortunately, perl.h (below) also defines 'instr'.
Fortunately, we don't need the Curses version -- we use
winstr(stdscr, ...) instead. So we undef instr here to avoid a compiler
warning about the redeclaration.
*/
------------------------

(Aside: I note that they refer to the redeclaration as a "warning" only.
With Visual Studio perhaps that all it is - in which case it's not such a
big deal anyway. But with MinGW it's a fatal error.)

So, for the purpose of the proof-of-concept of the above script, I
commented out the 'int instr(char *)' and '#define instr ...' lines in
curses.h and ran again.

With those changes in place, the Inline::C wrappers I tested produce the
same results as running a C program - ie the sizeof chtype is reported as 4,
baudrate() returns 2147483647, and beep() segfaults when called. Either
there's something wrong with the pre-compiled library, or one simply can't
just call beep() indiscriminately as I did. I didn't expect baudrate to
return such a large number, either - looks more like a memory location ....
like I said, I know nothing about PDCurses.

I think that if *I* wanted a perl interface to PDCurses, I would probably be
writing a Win32::PDCurses module, that wraps the individual PDCurses
functions, instead of trying to get perl Curses to work with it .... but
that's possibly just me :-)

There are quite a few Win32 users who would like to see a workable curses
module for Win32 - so Win32::PDCurses would probably be a useful addition to
CPAN.

Did you see the (minimal) PDCurses notes at the bottom of the perl Curses
'INSTALL' file ? Didn't mean much to me - though, having taken a look at
c-MSWin32.visualc.h in the Curses-1.15 source, they start to make better
sense.

Cheers,
Rob


.



Relevant Pages

  • Re: Curses-perl that doesnt live up to its name?
    ... int wrap_baudrate{ ... transparent to a perl n00b like me. ... perl Curses, so perl Curses must be doing something to resolve the ... compiler warning about the redeclaration. ...
    (comp.lang.perl.modules)
  • Re: Evaluation of ++ different in C and perl?
    ... In the C language what the debate is about is clearly: ... I think in Perl, the outcome is also UNDEFINED. ... int main ... test.c:6: warning: operation on `x' may be undefined ...
    (perl.beginners)
  • Re: Why is java considered a language for "web" or "internet" programming?
    ... I don't remember reading exact things about Perl interpreter, ... load and parse bytecodes. ... I think, integer in Perl or Python or other scripting languages is some structure, with at the least field for type and value, and pointer to this structure you hold in 'i' variable. ... const int NNUM = 1000000; ...
    (comp.lang.java.help)
  • Re: ANNOUNCE: DBD:Oracle 1.18
    ... Well a warning in one compiler is better than and error in an other so I ... This might be a problem more with the older oracle OCI in your client. ... perl -Mblib t/26exe_array.t ...
    (perl.dbi.users)
  • AW: Problems building DBD-Oracle-1.16 on HP
    ... Looks as if gcc gets some parameters it does not understand. ... I have tried all the various incantations listed in the READMEs (perl ... Oracle version 10.2.0.2 ... Oracle.c:24: warning: 'RETVAL' might be used uninitialized in this ...
    (perl.dbi.users)