1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-17 09:10:22 +02:00

Fix thread-unsafe lazy initializations.

* libguile/debug.c (scm_local_eval):
  libguile/ports.c (scm_current_warning_port):
  libguile/strports.c (scm_eval_string_in_module): Perform
  lazy-initialization while holding a mutex.  Use SCM_UNDEFINED as the
  uninitialized value.  Use 'scm_c_*_variable'.

* doc/ref/api-modules.texi (Accessing Modules from C): Fix
  'my_eval_string' example to be thread-safe.
This commit is contained in:
Mark H Weaver 2013-02-28 17:56:58 -05:00
parent 29ace173b1
commit f57ea23ac8
4 changed files with 29 additions and 14 deletions

View file

@ -945,14 +945,18 @@ the @var{name} is not bound in the module, signals an error. Returns a
variable, always.
@example
static SCM eval_string_var;
/* NOTE: It is important that the call to 'my_init'
happens-before all calls to 'my_eval_string'. */
void my_init (void)
@{
eval_string_var = scm_c_public_lookup ("ice-9 eval-string",
"eval-string");
@}
SCM my_eval_string (SCM str)
@{
static SCM eval_string_var = SCM_BOOL_F;
if (scm_is_false (eval_string_var))
eval_string_var =
scm_c_public_lookup ("ice-9 eval-string", "eval-string");
return scm_call_1 (scm_variable_ref (eval_string_var), str);
@}
@end example