[Chicken-users] Easyffi
Hi again, I'm still trying to get back into run m ode with Xubuntu and now I'm finding a problem with easyffi. I use gtk+ in my user interface and access it through easyffi.This is an old program that's worked for a long time - including in Chicken-4.0.0 on Gentoo. It compiles fine, but now I get the following runtime error: Error: unbound variable: foreign-parse Call history: foreign-parse-- The offending lines are only in the c code - I don't use 'foreign-parse' anywhere in the scheme code. Any ideas on what could be wrong? I rather like the Xubuntu distribution and would hate to go back to Gentoo. Bill ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
[Chicken-users] Easyffi question
Hi again, Can anyone explain to me how I convert a string to a null terminated c-pointer that points to a list of strings. For example the c function I need to use looks like: foo (char **str, int cnt, c-struct result) In other words I'm passing a list of cnt strings into the function to get back a structure that contains the strings. The problem is with the first parameter.In most cases I will pass only one string, but the function still expects it to be a list of strings - in this case a list of one string. Bill ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Easyffi question
Jim Ursetto scripsit: The `sx` egg does something similar -- transforming a list of strings into a null-terminated array of C strings. I derived a quick example from it and attached the code. BTW, there is a bug in this code: if it's passed an improper list, it goes off into hyperspace. It's never a good idea to test for () as a list terminator in either C or Scheme: you should use something like this: (define (end? x) (cond ((pair? x) #f) ((eq? x '()) #t) (else (error A proper list should not end with x (This is based on the Common Lisp predicate ENDP.) -- But you, Wormtongue, you have done what you could for your true master. Some reward you have earned at least. Yet Saruman is apt to overlook his bargains. I should advise you to go quickly and remind him, lest he forget your faithful service. --Gandalf John Cowan co...@ccil.org ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] easyffi usage
On Tue, Jul 8, 2008 at 1:46 PM, William Xu [EMAIL PROTECTED] wrote: Also, the first example at http://chicken.wiki.br/easyffi#usage seems not very good: 1) Both math.h and csi have defined sin function, one can't verify that he'd call sin from which. 2) It defined #define my_pi 3.14 first, but the call (print (sin 3.14)) doesn't use my_pi at all. So i doubt the following clam that it'll generated this equivalent code: (define-foreign-variable my_pi float my_pi) Thanks, William. I'll fix the examples. cheers, felix ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
[Chicken-users] easyffi usage
Hi, I'm learning how to use the easyffi.egg. With the following code: (foreign-declare double my_pi; ) (foreign-parse double my_pi = 3.14; ) (print (sin my_pi)) Built with `csc -X easyffi foo.scm', when I try to run it, i got: , | Error: (sin) bad argument type - not a number: #procedure (my_pi . g12) ` What's the problem here? Also, the first example at http://chicken.wiki.br/easyffi#usage seems not very good: 1) Both math.h and csi have defined sin function, one can't verify that he'd call sin from which. 2) It defined #define my_pi 3.14 first, but the call (print (sin 3.14)) doesn't use my_pi at all. So i doubt the following clam that it'll generated this equivalent code: (define-foreign-variable my_pi float my_pi) -- William http://williamxu.net9.org You can fool all the people all of the time if the advertising is right and the budget is big enough. -- Joseph E. Levine ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] easyffi usage
William Xu wrote: [...] (foreign-declare double my_pi; ) (foreign-parse double my_pi = 3.14; ) (print (sin my_pi)) [...] Hello, if I'm not mistaken, easyffi generates parameter style procedures to acces global C variables, probably because it is impossible in CHICKEN to create magic Scheme variables that map directly to C variables. Therefore the correct way to use my_pi in your example would be (print (sin (my_pi))) As my_pi isn't declared constant you could also modify its value using a call like (my_pi 3.1415) cu, Thomas ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] easyffi missing foreign-parse
On 4/30/07, John Cowan [EMAIL PROTECTED] wrote: -- We are lost, lost. No name, no business, no Precious, nothing. Only empty. Only hungry: yes, we are hungry. A few little fishes, nassty bony little fishes, for a poor creature, and they say death. So wise they are; so just, so very just. --Gollum[EMAIL PROTECTED] http://ccil.org/~cowan Oh boy, I feel like that sometimes... cheers, felix ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
[Chicken-users] easyffi missing foreign-parse
Hi, I'm a n00b to scheme, and I thought I'd check out Chicken. I tried to get the readline egg installed, which is dependent on easyffi. I installed the easyffi egg, but if I type foreign-parse I get the response Error: unbound variable: foreign-parse All the other easyffi procedures seem to exist, as evidenced by the following transcript: #;3 register-ffi-macro #procedure #;4 check-c-syntax #procedure #;5 foreign-parse Error: unbound variable: foreign-parse #;5 Error: unbound variable: foreign-parse So, what gives? ___ Yahoo! Answers - Got a question? Someone out there knows the answer. Try it now. http://uk.answers.yahoo.com/ ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] easyFFI and GTK
On Apr 7, 2007, at 7:11 AM, William Ramsay wrote: Hi, I'm trying to create a menu with Gtk.Everything seems to be working fine, but I can't seem to figure out how to use menu-append. My code looks like this: (define create-menu-item (lambda (menu text cmd image) (let ((item #f)) (if image (let ((source (sprintf icons/~A.png image))) (set! item (gtk_image_menu_item_new_with_label (sutils-get- text text))) (gtk_image_menu_item_set_image item source)) (set! item (gtk_image_menu_item_new_with_label(sutils-get- text text (if (not (= cmd NO_ACTION))(g_signal_connect window button_press_event #$cmd #f)) (foreign-code gtk_menu_append(menu, item);) The problem is the foreign-code bit. There isn't any automatic connection between user defined Scheme variables C variables. Not sure what menu item are but guessing they would be passed as pointers so: ((foreign-lambda void gtk_menu_append pointer pointer) menu item) #t))) -- I'm fairly new to Scheme, so forgive my code if it doesn't meet expectations -- Anyway, when I compile this it tells me menu and item are not declared.What is the secret for getting this to work? Thanks in advance. I think Chicken is the greatest and easyFFI is beyond praise. You guys have done a fantastic job in creating the perfect computing system! Bill Ramsay ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users Best Wishes, Kon ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] easyffi virtual=0 methods
On 3/12/07, Carlos Pita [EMAIL PROTECTED] wrote: Specifically, the problematic line is: ScmStkFrames( unsigned int nFrames, unsigned int nChannels, bool interleaved ) : StkFrames(nFrames, nChannels, interleaved) {} And the reported error is: Error: during expansion of (foreign-parse ...) - unexpected tokens: ((op :) (id StkFrames) open-paren (id nFrames) comma (id nChannels) comma (id interleaved) close-paren (scope)) I have added a fix to easyffi, which should be updated in a couple hours. cheers, felix ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] easyffi virtual=0 methods
On 3/12/07, Carlos Pita [EMAIL PROTECTED] wrote: fmscm.scm -- Ah, yes. I can reproduce it. Thanks, I'll fix this. cheers, felix ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] easyffi virtual=0 methods
On 3/12/07, Carlos Pita [EMAIL PROTECTED] wrote: I was thinking a bit more about this and concluded that it wouldn't be possible to derive from an abstract C++ class in tinyclos anyway (because of the impossibility of constructing an instance of that class from anywhere but a subclass C++ constructor). So I decided to subclass the problematic class from C++ providing default dummy implementations for the abstract methods. Now I must call the (non-default) constructor of the subclass and I'm having trouble with the easyffi parser for the syntax: ctor(...) : base-ctor(..) {}. One thing I can do to solve this is to put the definition inside a # # block and the declaration inside a #? # block (instead of putting the definition once in-between #! #). But in any case, the easyffi documentation in http://galinha.ucpel.tche.br:8080//easyffi#foreign-include-path states that the grammar supports calling base constructors: CONSTRUCTOR = [___callback | ___safe] [explicit] ID ( ARGTYPE , ... ) [BASECONSTRUCTORS] [CODE] Specifically, the problematic line is: ScmStkFrames( unsigned int nFrames, unsigned int nChannels, bool interleaved ) : StkFrames(nFrames, nChannels, interleaved) {} And the reported error is: Error: during expansion of (foreign-parse ...) - unexpected tokens: ((op :) (id StkFrames) open-paren (id nFrames) comma (id nChannels) comma (id interleaved) close-paren (scope)) This works for me: #? class ScmStkFrames { ScmStkFrames( unsigned int nFrames, unsigned int nChannels, bool interleaved ) : StkFrames(nFrames, nChannels, interleaved) {} }; # Can you provide a complete example? cheers, felix ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
[Chicken-users] easyffi virtual=0 methods
Hi all, suppose I have a C++ class FM with some pure/abstract/virtual=0 (you choose) methods that I want to expose to chicken via easyffi. This class has a constructor, to be used by its concrete subclasses (and I'm not the owner of the code, so avoiding ctors in abstract classes is a nono). The trouble is that even if I mark the class as ___abstract, easyffi is trying to instantiate it someway, so I get an error report from the g++ compiler, something like: /site/install/stk-4.2.1/include/FM.h:36: note: because the following virtual functions are pure within ‘FM’: /site/install/stk-4.2.1/include/Instrmnt.h:27: note:virtual void Instrmnt::noteOn(StkFloat, StkFloat) /site/install/stk-4.2.1/include/FM.h:88: note: virtual StkFloat FM::computeSample() *** Shell command terminated with exit status 1: g++ fmscm.cpp -o fmscm.o -c -DHAVE_CHICKEN_CONFIG_H -Os -fomit-frame-pointer -fno-strict-aliasing -Wall -Wno-unused -Wno-uninitialized -DC_ENABLE_PTABLES -DC_NO_PIC_NO_DLL -I /data1/install/chicken-2.518/include/ -I/site/install/stk-4.2.1/include I could comment out the ctor and then things go fine, but I lose the chance to invoke this ctor from tinyclos concrete subclasses... don't I? Can you help me? Thank you in advance. Regards, Carlos __ Pregunt�. Respond�. Descubr�. Todo lo que quer�as saber, y lo que ni imaginabas, est� en Yahoo! Respuestas (Beta). �Probalo ya! http://www.yahoo.com.ar/respuestas ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] easyffi virtual=0 methods
I was thinking a bit more about this and concluded that it wouldn't be possible to derive from an abstract C++ class in tinyclos anyway (because of the impossibility of constructing an instance of that class from anywhere but a subclass C++ constructor). So I decided to subclass the problematic class from C++ providing default dummy implementations for the abstract methods. Now I must call the (non-default) constructor of the subclass and I'm having trouble with the easyffi parser for the syntax: ctor(...) : base-ctor(..) {}. One thing I can do to solve this is to put the definition inside a # # block and the declaration inside a #? # block (instead of putting the definition once in-between #! #). But in any case, the easyffi documentation in http://galinha.ucpel.tche.br:8080//easyffi#foreign-include-path states that the grammar supports calling base constructors: CONSTRUCTOR = [___callback | ___safe] [explicit] ID ( ARGTYPE , ... ) [BASECONSTRUCTORS] [CODE] Specifically, the problematic line is: ScmStkFrames( unsigned int nFrames, unsigned int nChannels, bool interleaved ) : StkFrames(nFrames, nChannels, interleaved) {} And the reported error is: Error: during expansion of (foreign-parse ...) - unexpected tokens: ((op :) (id StkFrames) open-paren (id nFrames) comma (id nChannels) comma (id interleaved) close-paren (scope)) Cheers!, Carlos On Sun, 2007-03-11 at 17:11 -0300, Carlos Pita wrote: Hi all, suppose I have a C++ class FM with some pure/abstract/virtual=0 (you choose) methods that I want to expose to chicken via easyffi. This class has a constructor, to be used by its concrete subclasses (and I'm not the owner of the code, so avoiding ctors in abstract classes is a nono). The trouble is that even if I mark the class as ___abstract, easyffi is trying to instantiate it someway, so I get an error report from the g++ compiler, something like: /site/install/stk-4.2.1/include/FM.h:36: note: because the following virtual functions are pure within ‘FM’: /site/install/stk-4.2.1/include/Instrmnt.h:27: note:virtual void Instrmnt::noteOn(StkFloat, StkFloat) /site/install/stk-4.2.1/include/FM.h:88: note: virtual StkFloat FM::computeSample() *** Shell command terminated with exit status 1: g++ fmscm.cpp -o fmscm.o -c -DHAVE_CHICKEN_CONFIG_H -Os -fomit-frame-pointer -fno-strict-aliasing -Wall -Wno-unused -Wno-uninitialized -DC_ENABLE_PTABLES -DC_NO_PIC_NO_DLL -I /data1/install/chicken-2.518/include/ -I/site/install/stk-4.2.1/include I could comment out the ctor and then things go fine, but I lose the chance to invoke this ctor from tinyclos concrete subclasses... don't I? Can you help me? Thank you in advance. Regards, Carlos __ Pregunt. Respond. Descubr. Todo lo que queras saber, y lo que ni imaginabas, est en Yahoo! Respuestas (Beta). Probalo ya! http://www.yahoo.com.ar/respuestas ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users __ Pregunt�. Respond�. Descubr�. Todo lo que quer�as saber, y lo que ni imaginabas, est� en Yahoo! Respuestas (Beta). �Probalo ya! http://www.yahoo.com.ar/respuestas ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
[Chicken-users] easyffi default arguments
Hi, continuing with the easyffi saga :) I would like to hear your suggestions about the best way to get c++ default args. One alternative would be to rename the original method using ___declare(rename...) directive, and then define a tinyclos method with an #!optional clause that just delegates to the renamed method. I think it would be better to directly invoke the underlying foreign-lambda to avoid the generic-generic-foreign-lambda invocation chain which would incur into possibly expensive method resolution twice. But I don't know how to reference this hipotetical foreign-lambda (maybe an stub with a criptic name that keeps no resemblance to the original one). Btw, is there any way to inspect the macroexpanded ffi-level output of the # # sections so I can tweak with more confidence? Cheers, Carlos __ Preguntá. Respondé. Descubrí. Todo lo que querías saber, y lo que ni imaginabas, está en Yahoo! Respuestas (Beta). ¡Probalo ya! http://www.yahoo.com.ar/respuestas ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] easyffi default arguments
On 3/12/07, Carlos Pita [EMAIL PROTECTED] wrote: Hi, continuing with the easyffi saga :) I would like to hear your suggestions about the best way to get c++ default args. One alternative would be to rename the original method using ___declare(rename...) directive, and then define a tinyclos method with an #!optional clause that just delegates to the renamed method. I think it would be better to directly invoke the underlying foreign-lambda to avoid the generic-generic-foreign-lambda invocation chain which would incur into possibly expensive method resolution twice. But I don't know how to reference this hipotetical foreign-lambda (maybe an stub with a criptic name that keeps no resemblance to the original one). Btw, is there any way to inspect the macroexpanded ffi-level output of the # # sections so I can tweak with more confidence? Compile with -debug F to see the generated code. cheers, felix ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] easyffi include path
I have added a macro (foreign-include-path) to easyffi. The new version (1.5) should be available now. Thank you Felix! How should I get this patched version? I have tried doing a chicken-setup from svn repo but the macro isn't included. Indeed, the version of easyffi in the repo is still 1.4. Am I missing something? Btw, what is the recommended way to do bulk-bindings now: easyffi or swig? cheers, Carlos - Preguntá. Respondé. Descubrí. Todo lo que querías saber, y lo que ni imaginabas, está en Yahoo! Respuestas (Beta). Probalo ya! ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] easyffi include path
On 3/6/07, Carlos Pita [EMAIL PROTECTED] wrote: I have added a macro (foreign-include-path) to easyffi. The new version (1.5) should be available now. Thank you Felix! How should I get this patched version? I have tried doing a chicken-setup from svn repo but the macro isn't included. Indeed, the version of easyffi in the repo is still 1.4. Am I missing something? It's available by downloading via chicken-setup. I'll commit the new version in a few minutes. Btw, what is the recommended way to do bulk-bindings now: easyffi or swig? SWIG is much more powerful, but for simple interfaces, easyffi might be easier to use. It really depends on what you are more familiar with. cheers, felix ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
[Chicken-users] easyffi include path
Hi all, what is the include path that easyffi parser uses, if any? When just declaring #includes (between # #) everything goes fine, if I pass the right -I option to the csc compiler. But when parse/declare is asked (between #! #), so that easyffi has to effectively include the file to parse it, I get a can not open include file error. For example: /X/foo/bar.h int incr(int x); /X/test.scm --- #! #include bar.h # cd /X csc -X easyffi test.scm -I /X/foo = Error: during expansion of (foreign-parse ...) - can not open include file: bar.h Best regards, Carlos __ Preguntá. Respondé. Descubrí. Todo lo que querías saber, y lo que ni imaginabas, está en Yahoo! Respuestas (Beta). ¡Probalo ya! http://www.yahoo.com.ar/respuestas ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] easyffi include path
On 3/4/07, Carlos Pita [EMAIL PROTECTED] wrote: Hi all, what is the include path that easyffi parser uses, if any? When just declaring #includes (between # #) everything goes fine, if I pass the right -I option to the csc compiler. But when parse/declare is asked (between #! #), so that easyffi has to effectively include the file to parse it, I get a can not open include file error. For example: Yes, when easyffi was integrated into the base chicken, there was a command line option. I have added a macro (foreign-include-path) to easyffi. The new version (1.5) should be available now. cheers, felix ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] easyffi and gtk
On 1/29/07, Tony Sidaway [EMAIL PROTECTED] wrote: I'm trying to do basic stuff with easyffi and gtk. Just some basic sanity checks. A very simple program that instantiates a toplevel window and terminates. This is indeed a bug in easyffi (a new version is available in a few minutes). But note that your example will not work. You will just slurp in huge amounts of definitions (many of which will not be parsable by easyffi) and generating gobs of code. Easyffi is not strong enough to do that sort of bulk wrapping. For such things, you should look into SWIG, for example (http://www.swig.org). Easyffi can handle straight C and C++, when it is clean and simple and has relatively obvious semantics. For more advanced things, one has to massage the input anyway. cheers, felix ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
[Chicken-users] easyffi and gtk
I'm trying to do basic stuff with easyffi and gtk. Just some basic sanity checks. A very simple program that instantiates a toplevel window and terminates. $ cat window.c #! #include gtk/gtk.h # (g_type_init) (gtk_window_new GTK_WINDOW_TOPLEVEL) Compilation: $ csc -v -X easyffi window.scm -C `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0` /usr/local/bin/chicken window.scm -output-file window.c -quiet -extend easyffi gcc window.c -o window.o -c -DHAVE_CHICKEN_CONFIG_H -Os -fno-strict-aliasing -Wall -Wno-unused -Wno-uninitialized -fomit-frame-pointer -DC_ENABLE_PTABLES -I /usr/local/include -I/usr/local/include/cairo -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include rm window.c gcc window.o -lchicken -o window -L/usr/local/lib -Wl,-R/usr/local/lib -L/usr/local/lib -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lm -lpangocairo-1.0 -lfontconfig -lXext -lXrender -lXinerama -lXi -lXrandr -lXcursor -lXfixes -lpango-1.0 -lcairo -lX11 -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0 -ldl -lm -lchicken rm window.o Run it: $ ./window Error: unbound variable: g_type_init Call history: window.scm: 4g_type_init-- Hmm, what am I doing wrong, here? ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users