newlisp and libcaca

Started by konrad, September 09, 2007, 05:02:25 PM

Previous topic - Next topic

konrad

Hi all



I'm trying to get libcaca (an Ascii  basically just the basic tutorial that can be found at:



http://linux.die.net/man/3/tutorial">//http://linux.die.net/man/3/tutorial



However i get a segfault at the line " caca_refresh_display(dp);"



running an strace shows : gettimeofday({1189337045, 203711}, NULL) = 0



I've tried running the program with and without the refresh line (not having a refresh means that there is not so much of the output but there are no significant differences in the strace before the failure point.



Note I tried compiling the example in C and it works fine on its own. Anyone have any ideas on what to try next in debugging this, I'd really like to get libcaca working with newLisp.



regards



Konrad

pjot

#1
It seems that the variable 'dp' is a pointer to some memory. If it is used wrongly your program may crash.



Therefore, could you show us your newLisp implementation?



Peter

konrad

#2
Here is my code:



(context 'CUCUL)
(set 'libcucul "/usr/lib/libcucul.so")
(set 'funcs '(
             "cucul_create_canvas"
             "cucul_set_color_ansi"
             "cucul_putstr"
             ))

(dolist (func funcs)
  (import libcucul func))

(set 'consts '(
              ("BLACK" 0x00)
              ("WHITE" 0x0f)))

(dolist (const consts)
  (constant (sym (const 0)) (const 1)))

(context 'CACA)
(set 'libcaca "/usr/lib/libcaca.so")
(set 'funcs '(
             "caca_create_display"
             "caca_set_display_title"
             "caca_refresh_display"
             ))

(dolist (func funcs)
  (import libcaca func))



(context 'MAIN)

(set 'cv (CUCUL:cucul_create_canvas 0 0))
(set 'db (CACA:caca_create_display cv))
(CACA:caca_set_display_title db "Hello!")
(CUCUL:cucul_set_color_ansi cv CUCUL:BLACK CUCUL:WHITE)
(CUCUL:cucul_putstr cv 0 0  "This is a message")
(CACA:caca_refresh_display dp)

pjot

#3
Hi,



Your last line shows:



(CACA:caca_refresh_display dp)


But where do you set the variable 'dp'? It has no value assigned and therefore the contents of 'dp' is nil.



According to the original C program at the link you provided above, the variable 'dp' should be set as follows:



dp = caca_create_display(cv);


However, in your program you use variablename 'db' instead of 'dp'.



Peter

konrad

#4
Yes Er that will be it.



I don't know how many times i've spend ages trying to debug a typo,



so here is another example. dp is what I had meant to xall the variable not db. Using longer names like display would have probably saved me on this one : )



regards



Konrad

konrad

#5
Well that works. The next trick is to capture events. Not to do this the C code



1) creates a variable based on a structure

2) passes the address of the structure into a function so it can be written too.



I assume that I need to



(set 'ev (pack ...))



to get a correct event symbol and then I need to unpack the results for reading?



would this be about the correct take on this ?



I have a feeling this is going to be a little clunky as the C definition contains a union.



regards



Konrad.

pjot

#6
To read C-structures in newLisp is explained here:



http://www.newlisp.org/CodePatterns.html#extending">http://www.newlisp.org/CodePatterns.html#extending





Maybe it helps.



Regards

Peter