guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Web Development with Guile in HB


From: Gary Houston
Subject: Re: Web Development with Guile in HB
Date: 14 Nov 2000 22:17:07 -0000

> From: Alejandro Forero Cuervo <address@hidden>
> Date: Mon, 13 Nov 2000 17:00:16 -0500
> 
>    oldport = scm_current_output_port();
> 
>    scm_set_current_output_port(scm_mkstrport(SCM_INUM0,
>       scm_make_string(SCM_MAKINUM(0), SCM_UNDEFINED),
>       SCM_OPN | SCM_WRTNG, "hbguile_exec"));
> 
>    /* Execute the code */
> 
>    scm_set_current_output_port(oldport);
> 
> I guess that "hbguile_exec" (the name of the function where I have
> this code) is just the name of the caller and is used to report
> errors.  Am I wrong?  What am I supposed to pass as the caller?

You are correct, it's used when reporting errors.  However this
convention seems obsolete, we should remove the argument.  I suggest
passing "scm_mkstrport" for this parameter.

> I am also guessing that SCM_OPN means open and SCM_WRTNG means writing
> and those are the right flags I should pass to scm_mkstrport here.
> Right?

Right.

> An another thing I'm guessing is that Guile will take care of
> destroing the string and the string port when I set the current output
> port back to oldport.  Right?

Right, next time the garbage collector runs.

>     I'm not sure what the current status is, perhaps Guile can only be
>     used from one thread.  This could be a big problem for what you
>     are trying to do.
> 
> For the moment I'll just use a mutex around the code that calls Guile
> to avoid problems with this.  It means dead locks are possible
> (because, depending on the user's code, some of my C functions that
> are callable from Scheme might call others that might want to call
> Scheme again).

I'm not sure that a mutex is enough.  The problem as I understand it
is that if you call Guile from different threads, then the garbage
collector could be run from different threads and wouldn't necessarily
find all the Scheme references from the thread stacks.  If so, it
would free the data prematurely.  There may be other problems too.

Deadlocks don't seem like such a problem since the thread will already
hold the mutex.

>     In effect, you just create a new module, and import the bindings
>     you want to it.
> 
> Okay, I'm trying to do that.  I guess my code will have to:
> 
> 1. Create a new module and import the bindings into it.
> 2. Set it as the current module.
> 3. Execute the code.
> 4. Reset the current module to what it was initially.
> 
> Right?

This seems right, but I can't say more since I don't have a clue
about using the module system from C.  Sorry.

> How can I create a new module?  I can't figure out what the parameter
> to scm_make_module should be.  I figured I would ask, rather than try
> with some random values. :)
> 
> I am also assuming that scm_ensure_user_module imports some nice
> bindings into it.  Or how should I initialize the module?
> 
> Also, how can I get the current module (to be able to set it again in
> step 4)?
> 
> I am new to modules and haven't found any documentation on them.
> Could you please point me to some documents where I can find more
> information about them?
> 
> I am assuming `modules' means groups of bindings of names to values
> (such as "display" is bound to this procedure, "+" is bound to this
> procedure, "define" is bound to this procedure, stuff (define)d is
> bound to their values and so on).
> 
> Thank you very much. :)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]