unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Invoking guile procs from C in an efficient way
@ 2004-10-25 11:12 Victor Morilla
  2004-10-25 14:18 ` Andreas Rottmann
  0 siblings, 1 reply; 5+ messages in thread
From: Victor Morilla @ 2004-10-25 11:12 UTC (permalink / raw)



[-- Attachment #1.1: Type: text/plain, Size: 434 bytes --]

Hello,
 
I would like to know the best way to resolve a proc symbol from its name and call it from c. Right now, I'm using:
 
SCM proc = scm_c_eval_string("my_proc");
scm_apply(proc, argslist, SCM_EOL);
 
Is there an alternative to scm_c_eval_string ? I have used scm_c_lookup
 
SCM proc = scm_c_lookup("my_proc");
scm_apply(proc, argslist, SCM_EOL);
 
, but I get an error
 
Thanks in advance


		
---------------------------------


[-- Attachment #1.2: Type: text/html, Size: 889 bytes --]

[-- Attachment #2: Type: text/plain, Size: 140 bytes --]

_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Invoking guile procs from C in an efficient way
  2004-10-25 11:12 Invoking guile procs from C in an efficient way Victor Morilla
@ 2004-10-25 14:18 ` Andreas Rottmann
  2004-10-25 16:51   ` Rob Browning
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas Rottmann @ 2004-10-25 14:18 UTC (permalink / raw)


Victor Morilla <victormorilla@yahoo.es> writes:

> Hello,
>  
> I would like to know the best way to resolve a proc symbol from its
> name and call it from c. Right now, I'm using:
>  
> SCM proc = scm_c_eval_string("my_proc");
> scm_apply(proc, argslist, SCM_EOL);
>  
> Is there an alternative to scm_c_eval_string ? I have used scm_c_lookup
>  
> SCM proc = scm_c_lookup("my_proc");
> scm_apply(proc, argslist, SCM_EOL);
>  
I think it's:

scm_apply(SCM_VARIABLE_REF(scm_c_lookup("my-proc")), argslist, SCM_EOL);


HTH, Rotty
-- 
Andreas Rottmann         | Rotty@ICQ      | 118634484@ICQ | a.rottmann@gmx.at
http://yi.org/rotty      | GnuPG Key: http://yi.org/rotty/gpg.asc
Fingerprint              | DFB4 4EB4 78A4 5EEE 6219  F228 F92F CFC5 01FD 5B62

Software Patents: Where do you want to stifle inovation today?



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Invoking guile procs from C in an efficient way
  2004-10-25 14:18 ` Andreas Rottmann
@ 2004-10-25 16:51   ` Rob Browning
  0 siblings, 0 replies; 5+ messages in thread
From: Rob Browning @ 2004-10-25 16:51 UTC (permalink / raw)
  Cc: guile-user

Andreas Rottmann <a.rottmann@gmx.at> writes:

>> SCM proc = scm_c_lookup("my_proc");
>> scm_apply(proc, argslist, SCM_EOL);
>>  
> I think it's:
>
> scm_apply(SCM_VARIABLE_REF(scm_c_lookup("my-proc")), argslist, SCM_EOL);

In some cases you can also cache the binding if you want to avoid
repeated lookups (using 1.6 interfaces):

  foo()
  {
    static SCM my_proc = SCM_BOOL_F;
    if(SCM_FALSEP(my_proc))
    {
      my_proc = scm_c_lookup("my-proc");  /* or scm_c_module_lookup */
      /* check for failure here */
      scm_permanent_object(my_proc); /* presumes you always need my_proc */
    }

    scm_apply(scm_variable_ref(my_proc), argslist, SCM_EOL);
  }

Caveats apply -- i.e. don't call this before guile is initialized,
consider synchronization issues (if we ever let multiple posix threads
call guile at the same time), etc.

-- 
Rob Browning
rlb @defaultvalue.org and @debian.org; previously @cs.utexas.edu
GPG starting 2002-11-03 = 14DD 432F AE39 534D B592  F9A0 25C8 D377 8C7E 73A4


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Invoking guile procs from C in an efficient way
@ 2004-10-26 20:58 Victor Morilla
  2004-10-27  3:12 ` Rob Browning
  0 siblings, 1 reply; 5+ messages in thread
From: Victor Morilla @ 2004-10-26 20:58 UTC (permalink / raw)


Rob Browning wrote:
>
>In some cases you can also cache the binding if you
want to avoid
>repeated lookups (using 1.6 interfaces):
>
> foo()
>  {
>    static SCM my_proc = SCM_BOOL_F;
>    if(SCM_FALSEP(my_proc))
>    {
>      my_proc = scm_c_lookup("my-proc");  /* or
scm_c_module_lookup */
>      /* check for failure here */
>      scm_permanent_object(my_proc); /* presumes you
always need my_proc */
>    }

>    scm_apply(scm_variable_ref(my_proc), argslist,
SCM_EOL);
>  }

Thank you, Rob.

Why scm_permanent_object is used ? Would it be
equivalent something like:

foo()
{
  static SCM my_proc =
scm_variable_ref(scm_c_lookup("my-proc"));
  scm_apply(my_proc, argslist, SCM_EOL);
}




	
		
__________________________________
Do you Yahoo!?
Yahoo! Mail - You care about security. So do we.
http://promotions.yahoo.com/new_mail


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Invoking guile procs from C in an efficient way
  2004-10-26 20:58 Victor Morilla
@ 2004-10-27  3:12 ` Rob Browning
  0 siblings, 0 replies; 5+ messages in thread
From: Rob Browning @ 2004-10-27  3:12 UTC (permalink / raw)
  Cc: guile-user

Victor Morilla <victormorilla@yahoo.es> writes:

> Why scm_permanent_object is used ? Would it be
> equivalent something like:
>
> foo()
> {
>   static SCM my_proc =
> scm_variable_ref(scm_c_lookup("my-proc"));
>   scm_apply(my_proc, argslist, SCM_EOL);
> }

It's only OK to cache the result of scm_variable_ref if you know
you'll never change the value of the variable (via set!) and want to
track that change on the C side.

Also, the scm_permanent_object (or something equivalent) is necessary
because the GC can't see static varibles.  However, if you know for
sure that the value you're storing in my_proc is bound to something on
the Scheme side that will outlast your usage of the C code above, then
you can do without the call to scm_permanent_object.

Also, as previously mentioned, you can use
scm_gc_protect/unprotect_object if you only need the object for a
limited period of time.

-- 
Rob Browning
rlb @defaultvalue.org and @debian.org; previously @cs.utexas.edu
GPG starting 2002-11-03 = 14DD 432F AE39 534D B592  F9A0 25C8 D377 8C7E 73A4


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-10-27  3:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-10-25 11:12 Invoking guile procs from C in an efficient way Victor Morilla
2004-10-25 14:18 ` Andreas Rottmann
2004-10-25 16:51   ` Rob Browning
  -- strict thread matches above, loose matches on Subject: below --
2004-10-26 20:58 Victor Morilla
2004-10-27  3:12 ` Rob Browning

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).