From db70ec38800e56da9b03c60767739c6b4ba38318 Mon Sep 17 00:00:00 2001 From: hanwen Date: Mon, 1 Aug 2005 20:15:09 +0000 Subject: [PATCH] (LY_DEFINE): new file. --- ChangeLog | 2 + lily/GNUmakefile | 3 +- lily/include/ly-module.hh | 3 ++ lily/ly-module.cc | 108 +++++++++++++------------------------- lily/module-scheme.cc | 87 ++++++++++++++++++++++++++++++ lily/spacing-spanner.cc | 14 +++-- 6 files changed, 140 insertions(+), 77 deletions(-) create mode 100644 lily/module-scheme.cc diff --git a/ChangeLog b/ChangeLog index fb3f719678..52cd078d3f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2005-08-01 Han-Wen Nienhuys + * lily/module-scheme.cc (LY_DEFINE): new file. + * Documentation/user/advanced-notation.itely (Font selection): add doco for make-pango-font-tree. diff --git a/lily/GNUmakefile b/lily/GNUmakefile index 0dadf1f71f..04ad56acf4 100644 --- a/lily/GNUmakefile +++ b/lily/GNUmakefile @@ -54,7 +54,8 @@ ETAGS_FLAGS += --regex='{c++}/^LY_DEFINE *([^"]*"\([^"]+\)"/\1/' default: -$(outdir)/libstdc++.a: +$(outdir)/libstdc++.a: + rm -f $@ ln -s `$(CXX) -print-file-name=libstdc++.a` $(outdir)/ ifeq ($(LINK_GXX_STATICALLY),yes) diff --git a/lily/include/ly-module.hh b/lily/include/ly-module.hh index a45fad64c8..bc1ba2125a 100644 --- a/lily/include/ly-module.hh +++ b/lily/include/ly-module.hh @@ -21,5 +21,8 @@ inline bool ly_is_module (SCM x) { return SCM_MODULEP (x); } SCM ly_clear_anonymous_modules (); SCM ly_use_module (SCM mod, SCM used); +/* Ugh signature of scm_internal_hash_fold () is inaccurate. */ +typedef SCM (*Hash_closure_function) (); + #endif /* LY_MODULE_HH */ diff --git a/lily/ly-module.cc b/lily/ly-module.cc index b14a222b49..ba99e64f74 100644 --- a/lily/ly-module.cc +++ b/lily/ly-module.cc @@ -18,16 +18,10 @@ Protected_scm anonymous_modules = SCM_EOL; #endif -#define FUNC_NAME __FUNCTION__ - -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." - ) +void +clear_anonymous_modules () { -#ifdef MODULE_GC_KLUDGE for (SCM s = anonymous_modules; scm_is_pair (s); s = scm_cdr (s)) @@ -44,9 +38,6 @@ LY_DEFINE(ly_clear_anonymous_modules, "ly:clear-anonymous-modules", } anonymous_modules = SCM_EOL; -#endif - - return SCM_UNSPECIFIED; } SCM @@ -93,33 +84,7 @@ ly_use_module (SCM mod, SCM used) #define FUNC_NAME __FUNCTION__ -static SCM -module_define_closure_func (void *closure, SCM key, SCM val, SCM result) -{ - (void) result; - SCM module = (SCM) closure; - if (scm_variable_bound_p (val) == SCM_BOOL_T) - scm_module_define (module, key, scm_variable_ref (val)); - return SCM_EOL; -} - -/* Ugh signature of scm_internal_hash_fold () is inaccurate. */ -typedef SCM (*Hash_cl_func) (); -/* - If a variable in changed in SRC, we DEST doesn't see the - definitions. -*/ -LY_DEFINE (ly_module_copy, "ly:module-copy", - 2, 0, 0, (SCM dest, SCM src), - "Copy all bindings from module SRC into DEST.") -{ - SCM_VALIDATE_MODULE (1, src); - scm_internal_hash_fold ((Hash_cl_func) & module_define_closure_func, - (void *) dest, - SCM_EOL, SCM_MODULE_OBARRAY (src)); - return SCM_UNSPECIFIED; -} static SCM accumulate_symbol (void *closure, SCM key, SCM val, SCM result) @@ -135,7 +100,7 @@ ly_module_symbols (SCM mod) SCM_VALIDATE_MODULE (1, mod); SCM obarr = SCM_MODULE_OBARRAY (mod); - return scm_internal_hash_fold ((Hash_cl_func) & accumulate_symbol, + return scm_internal_hash_fold ((Hash_closure_function) & accumulate_symbol, NULL, SCM_EOL, obarr); } @@ -156,40 +121,7 @@ LY_DEFINE (ly_module2alist, "ly:module->alist", SCM_VALIDATE_MODULE (1, mod); SCM obarr = SCM_MODULE_OBARRAY (mod); - return scm_internal_hash_fold ((Hash_cl_func) & entry_to_alist, NULL, SCM_EOL, obarr); -} - -/* Lookup SYM, but don't give error when it is not defined. */ -SCM -ly_module_lookup (SCM module, SCM sym) -{ -#define FUNC_NAME __FUNCTION__ - SCM_VALIDATE_MODULE (1, module); - - return scm_sym2var (sym, scm_module_lookup_closure (module), SCM_BOOL_F); -#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), - "Lookup @var{sym} in the list @var{modules}, " - "returning the first occurence. " - "If not found, return @var{default}, or @code{#f}.") -{ - 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); - } - - if (def != SCM_UNDEFINED) - return def; - return SCM_BOOL_F; + return scm_internal_hash_fold ((Hash_closure_function) & entry_to_alist, NULL, SCM_EOL, obarr); } void @@ -207,3 +139,35 @@ ly_reexport_module (SCM mod) { ly_export (mod, ly_module_symbols (mod)); } + + + +#ifdef MODULE_GC_KLUDGE +static SCM +redefine_keyval (void *closure, SCM key, SCM val, SCM result) +{ + (void)closure; + SCM new_tab = result; + scm_hashq_set_x (new_tab, key, val); + return new_tab; +} + +/* + UGH UGH. + Kludge for older GUILE 1.6 versions. + */ +void +make_stand_in_procs_weak () +{ + SCM old_tab = scm_stand_in_procs; + SCM new_tab = scm_make_weak_key_hash_table (scm_from_int (257)); + + new_tab = scm_internal_hash_fold ((Hash_closure_function) & redefine_keyval, + NULL, + new_tab, old_tab); + + scm_stand_in_procs = new_tab; +} + +ADD_SCM_INIT_FUNC(make_stand_in_procs_weak, make_stand_in_procs_weak); +#endif diff --git a/lily/module-scheme.cc b/lily/module-scheme.cc new file mode 100644 index 0000000000..0e3d98c612 --- /dev/null +++ b/lily/module-scheme.cc @@ -0,0 +1,87 @@ +/* + lily/module-scheme.cc -- implement module bindings + + source file of the GNU LilyPond music typesetter + + (c) 2005 Han-Wen Nienhuys + +*/ + +#include "lily-guile.hh" +#include "warn.hh" +#include "main.hh" +#include "string.hh" + +/* + If a variable in changed in SRC, we DEST doesn't see the + definitions. +*/ + +static SCM +module_define_closure_func (void *closure, SCM key, SCM val, SCM result) +{ + (void) result; + SCM module = (SCM) closure; + if (scm_variable_bound_p (val) == SCM_BOOL_T) + scm_module_define (module, key, scm_variable_ref (val)); + return SCM_EOL; +} + +LY_DEFINE (ly_module_copy, "ly:module-copy", + 2, 0, 0, (SCM dest, SCM src), + "Copy all bindings from module SRC into 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)); + 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. */ +SCM +ly_module_lookup (SCM module, SCM sym) +{ +#define FUNC_NAME __FUNCTION__ + SCM_VALIDATE_MODULE (1, module); + + return scm_sym2var (sym, scm_module_lookup_closure (module), SCM_BOOL_F); +#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), + "Lookup @var{sym} in the list @var{modules}, " + "returning the first occurence. " + "If not found, return @var{default}, or @code{#f}.") +{ + 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); + } + + if (def != SCM_UNDEFINED) + return def; + return SCM_BOOL_F; +} diff --git a/lily/spacing-spanner.cc b/lily/spacing-spanner.cc index b8513cec0a..64eecf0758 100644 --- a/lily/spacing-spanner.cc +++ b/lily/spacing-spanner.cc @@ -895,8 +895,9 @@ Spacing_spanner::note_spacing (Grob *me, Grob *lc, Grob *rc, shortest_playing_len = max (shortest_playing_len, delta_t); if (delta_t.main_part_ && !lwhen.grace_part_) { - dist = get_duration_space (me, shortest_playing_len, shortest.main_part_, expand_only); - dist *= (double) (delta_t.main_part_ / shortest_playing_len.main_part_); + dist = get_duration_space (me, shortest_playing_len, + shortest.main_part_, expand_only); + dist *= double (delta_t.main_part_ / shortest_playing_len.main_part_); } else if (delta_t.grace_part_) { @@ -925,9 +926,14 @@ ADD_INTERFACE (Spacing_spanner, "spacing-spanner-interface", "gets 2 note heads width (i.e. the space following a note is 1 note\n" "head width) A 16th note is followed by 0.5 note head width. The\n" "quarter note is followed by 3 NHW, the half by 4 NHW, etc.\n", - "grace-space-factor spacing-increment base-shortest-duration shortest-duration-space common-shortest-duration"); + + "grace-space-factor spacing-increment base-shortest-duration " + "shortest-duration-space common-shortest-duration" + + ); ADD_INTERFACE (Spacing_interface, "spacing-interface", - "Something to do with line breaking and spacing. Kill this one after determining line breaks.", + "Something to do with line breaking and spacing. " + "Kill this one after determining line breaks.", ""); -- 2.39.5