X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fmodule-scheme.cc;h=58fc141f38c4675d7a8be002ef0036d2d7cb45b1;hb=9e781b7dc83b60a543ce218aa1a5f139f74c760f;hp=192fcf49664d0a08f2fdba8c09d1eead7db3d2c1;hpb=bc95f4434f760d41191341ab4508b2064eb19025;p=lilypond.git diff --git a/lily/module-scheme.cc b/lily/module-scheme.cc index 192fcf4966..58fc141f38 100644 --- a/lily/module-scheme.cc +++ b/lily/module-scheme.cc @@ -1,7 +1,7 @@ /* This file is part of LilyPond, the GNU music typesetter. - Copyright (C) 2005--2010 Han-Wen Nienhuys + Copyright (C) 2005--2014 Han-Wen Nienhuys LilyPond is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,13 +17,11 @@ along with LilyPond. If not, see . */ -#include "ly-module.hh" - +#include "ly-module.hh" // pulls in lily-guile.hh and guile-compatibility.hh #include "warn.hh" #include "main.hh" #include "std-string.hh" - /* If a variable is changed in SRC, then DEST doesn't see the definitions. @@ -31,9 +29,9 @@ static SCM module_define_closure_func (void *closure, - SCM key, - SCM val, - SCM /* result */) + SCM key, + SCM val, + SCM /* result */) { SCM module = (SCM) closure; if (scm_variable_bound_p (val) == SCM_BOOL_T) @@ -42,55 +40,60 @@ module_define_closure_func (void *closure, } LY_DEFINE (ly_module_copy, "ly:module-copy", - 2, 0, 0, (SCM dest, SCM src), - "Copy all bindings from module @var{src} into @var{dest}.") + 2, 0, 0, (SCM dest, SCM src), + "Copy all bindings from module @var{src} into @var{dest}.") { #define FUNC_NAME __FUNCTION__ SCM_VALIDATE_MODULE (1, src); - scm_internal_hash_fold ((Hash_closure_function) & module_define_closure_func, - (void *) dest, - SCM_EOL, SCM_MODULE_OBARRAY (src)); + scm_internal_hash_fold ((scm_t_hash_fold_fn) &module_define_closure_func, + (void *) dest, + SCM_EOL, SCM_MODULE_OBARRAY (src)); return SCM_UNSPECIFIED; } -LY_DEFINE (ly_clear_anonymous_modules, "ly:clear-anonymous-modules", - 0, 0, 0, (), - "Plug a GUILE 1.6 and 1.7 memory leak by breaking a weak" - " reference pointer cycle explicitly.") -{ -#ifdef MODULE_GC_KLUDGE - clear_anonymous_modules (); -#endif - return SCM_UNSPECIFIED; -} -/* Lookup SYM, but don't give error when it is not defined. */ +/* Lookup SYM, but don't give error when it is not defined. + N.B. this is only needed when running with Guile versions + prior to V2.0.3, when calls to ly_module_lookup can be replaced + with direct calls to the Guile API scm_module_variable in the + LilyPond codebase. +*/ SCM ly_module_lookup (SCM module, SCM sym) { #define FUNC_NAME __FUNCTION__ SCM_VALIDATE_MODULE (1, module); - +/* + Issue 2758: + Guile V2 onward has a scm_module_variable API module. + Guile V1.8.7 only has a (module-variable) REPL function, however + using ly_lily_module_constant ("module-variable") and calling + the memoized result is slow. + */ +#if GUILEV1 return scm_sym2var (sym, scm_module_lookup_closure (module), SCM_BOOL_F); +#else + return scm_module_variable (module, sym); +#endif #undef FUNC_NAME } /* Lookup SYM in a list of modules, which do not have to be related. Return the first instance. */ LY_DEFINE (ly_modules_lookup, "ly:modules-lookup", - 2, 1, 0, - (SCM modules, SCM sym, SCM def), - "Look up @var{sym} in the list @var{modules}," - " returning the first occurence. If not found, return" - " @var{def} or @code{#f} if @var{def} isn't specified.") + 2, 1, 0, + (SCM modules, SCM sym, SCM def), + "Look up @var{sym} in the list @var{modules}," + " returning the first occurence. If not found, return" + " @var{def} or @code{#f} if @var{def} isn't specified.") { for (SCM s = modules; scm_is_pair (s); s = scm_cdr (s)) { SCM mod = scm_car (s); SCM v = ly_module_lookup (mod, sym); if (SCM_VARIABLEP (v) && SCM_VARIABLE_REF (v) != SCM_UNDEFINED) - return scm_variable_ref (v); + return scm_variable_ref (v); } if (def != SCM_UNDEFINED)