On Tuesday 03 January 2006 18:45, Ralf Hautkappe wrote:
> i encountered a problem in trying to use the fflib.fs... maybe
> someone can help....
>
> this is the code i write to experiment with the curseslib
>
> require fflib.fs
> require forth/require/c-func.fs
> library curses /lib/libncurses.so.5.4
> curses initscr (void) initscr
> curses printw ptr (void) printw
> curses refresh (void) refresh
>
> : testp initscr s" timmy" ftoc printw refresh ;
>
> and here is the problem.... initscr it works but messed up the
> stack.. (see output)
>
> gforth curses.fs
> Gforth 0.6.2, Copyright (C) 1995-2003 Free Software Foundation, Inc.
> Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'
> Type `bye' to exit
> initscr
> ok
>    .s <-335773576>  ok
>
>
>
> as you see there are to much stack items... and i dont know why... i
> test various types between (void) (ptr) (int) and so on but the
> result is always the same.....

Yep, found it. ncurses messes around with the global variable SP, which 
we define and use to store the stack pointer while calling a C function 
(we need it be a global variable, since callbacks need to know the 
Forth stack pointer).

Renaming that global variable to SPg (for SP global) cures the problem.

SP is defined in engine/main.c, and used in prim and engine/engine.c. 
It's declaired in engine/forth.h. All these locations have to be 
changed.

libncurses brings its own SP, but since Gforth is compiled to export its 
own symbols (so you can create a library that calls back), the C linker 
is confused.

-- 
Bernd Paysan
"If you want it done right, you have to do it yourself"
http://www.jwdt.com/~paysan/

Attachment: pgpspn2gccwyO.pgp
Description: PGP signature

Reply via email to