diff --git a/lily/dispatcher.cc b/lily/dispatcher.cc index 9fd2a5da1c07e696664029e33cceb23a3f7e5c93..5138fff4ff78df87252e4165c20009afb2a4672a 100644 --- a/lily/dispatcher.cc +++ b/lily/dispatcher.cc @@ -174,22 +174,20 @@ Dispatcher::is_listened_class (SCM cl) return false; } -static SCM -accumulate_types (void * /* closure */, - SCM key, - SCM val, - SCM result) -{ - if (scm_is_pair (val)) - return scm_cons (key, result); - return result; -} - SCM Dispatcher::listened_types () { - return scm_internal_hash_fold ((scm_t_hash_fold_fn) &accumulate_types, - NULL, SCM_EOL, listeners_); + auto accumulate_types = [] (void * /* closure */, + SCM key, + SCM val, + SCM result) + { + if (scm_is_pair (val)) + return scm_cons (key, result); + return result; + }; + + return ly_scm_hash_fold (accumulate_types, nullptr, SCM_EOL, listeners_); } void diff --git a/lily/general-scheme.cc b/lily/general-scheme.cc index dbafdc25bf0969f9c3bfc919b344ac12070a262f..6358d8f42fc526d1585ef06468dd7a5499ef279d 100644 --- a/lily/general-scheme.cc +++ b/lily/general-scheme.cc @@ -416,21 +416,19 @@ LY_DEFINE (ly_stderr_redirect, "ly:stderr-redirect", return SCM_UNSPECIFIED; } -static SCM -accumulate_symbol (void * /* closure */, - SCM key, - SCM /* val */, - SCM result) -{ - return scm_cons (key, result); -} - LY_DEFINE (ly_hash_table_keys, "ly:hash-table-keys", 1, 0, 0, (SCM tab), "Return a list of keys in @var{tab}.") { - return scm_internal_hash_fold ((scm_t_hash_fold_fn) &accumulate_symbol, - NULL, SCM_EOL, tab); + auto accumulate_symbol = [] (void * /* closure */, + SCM key, + SCM /* val */, + SCM result) + { + return scm_cons (key, result); + }; + + return ly_scm_hash_fold (accumulate_symbol, nullptr, SCM_EOL, tab); } LY_DEFINE (ly_camel_case_2_lisp_identifier, "ly:camel-case->lisp-identifier", diff --git a/lily/include/lily-guile.hh b/lily/include/lily-guile.hh index 491596c40ebc53241aafad4a802e94b0ab0a1065..eb18f3775fa2cedbec66dba3f5c3f36509a72e34 100644 --- a/lily/include/lily-guile.hh +++ b/lily/include/lily-guile.hh @@ -158,11 +158,21 @@ inline SCM ly_car (SCM x) { return SCM_CAR (x); } inline SCM ly_cdr (SCM x) { return SCM_CDR (x); } inline bool ly_is_pair (SCM x) { return SCM_I_CONSP (x); } -/* For backward compatability with Guile 1.8 */ +// Wrap scm_internal_hash_fold() to reduce the number of places we need to use +// reinterpret_cast. +inline SCM +ly_scm_hash_fold (SCM (*fn) (void *closure, SCM key, SCM val, SCM result), + void *closure, SCM init, SCM table) +{ #if !HAVE_GUILE_HASH_FUNC -typedef SCM (*scm_t_hash_fold_fn) (GUILE_ELLIPSIS); + // For backward compatibility with Guile 1.8 + typedef SCM (*scm_t_hash_fold_fn) (GUILE_ELLIPSIS); #endif + return scm_internal_hash_fold (reinterpret_cast (fn), + closure, init, table); +} + // These are patterns for conversion functions. We currently use them to // predict the return types of overloaded functions before they are defined, // but other things could be added here, if necessary. diff --git a/lily/ly-module.cc b/lily/ly-module.cc index e5e8f94962112db3c3c90c7206737b4b9a714c9a..a0a398cb90ac5e949734eb7becf9e7b33f1058f7 100644 --- a/lily/ly-module.cc +++ b/lily/ly-module.cc @@ -107,18 +107,6 @@ ly_module_symbols (SCM mod) return filtered; } -static SCM -entry_to_alist (void * /* closure */, - SCM key, - SCM val, - SCM result) -{ - if (from_scm (scm_variable_bound_p (val))) - return scm_cons (scm_cons (key, scm_variable_ref (val)), result); - programming_error ("unbound variable in module"); - return result; -} - LY_DEFINE (ly_module_2_alist, "ly:module->alist", 1, 0, 0, (SCM mod), "Dump the contents of module @var{mod} as an alist.") @@ -126,8 +114,18 @@ LY_DEFINE (ly_module_2_alist, "ly:module->alist", SCM_VALIDATE_MODULE (1, mod); SCM obarr = SCM_MODULE_OBARRAY (mod); - return scm_internal_hash_fold ((scm_t_hash_fold_fn) &entry_to_alist, - NULL, SCM_EOL, obarr); + auto entry_to_alist = [] (void * /* closure */, + SCM key, + SCM val, + SCM result) + { + if (from_scm (scm_variable_bound_p (val))) + return scm_cons (scm_cons (key, scm_variable_ref (val)), result); + programming_error ("unbound variable in module"); + return result; + }; + + return ly_scm_hash_fold (entry_to_alist, nullptr, SCM_EOL, obarr); } void diff --git a/lily/module-scheme.cc b/lily/module-scheme.cc index ab4fa1d201d0d02a12fdf014b3b2505c15574655..81b34f019e9d43384bba2234adfc175d8ccd384e 100644 --- a/lily/module-scheme.cc +++ b/lily/module-scheme.cc @@ -26,28 +26,27 @@ definitions. */ -static SCM -module_define_closure_func (void *closure, - SCM key, - SCM val, - SCM /* result */) -{ - SCM module = *static_cast (closure); - if (from_scm (scm_variable_bound_p (val)) - && !is_module_internal_symbol (key)) - 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 @var{src} into @var{dest}.") { #define FUNC_NAME __FUNCTION__ SCM_VALIDATE_MODULE (1, src); - scm_internal_hash_fold ((scm_t_hash_fold_fn) &module_define_closure_func, - static_cast (&dest), - SCM_EOL, SCM_MODULE_OBARRAY (src)); + + auto module_define_closure_func = [] (void *closure, + SCM key, + SCM val, + SCM /* result */) + { + SCM module = *static_cast (closure); + if (from_scm (scm_variable_bound_p (val)) + && !is_module_internal_symbol (key)) + scm_module_define (module, key, scm_variable_ref (val)); + return SCM_EOL; + }; + + ly_scm_hash_fold (module_define_closure_func, static_cast (&dest), + SCM_EOL, SCM_MODULE_OBARRAY (src)); return SCM_UNSPECIFIED; } diff --git a/lily/scm-hash.cc b/lily/scm-hash.cc index 95482f617796d4d3c2f22afe5657a74a217bbf55..aae5e377468b7162a050006704004ad3d2400d1c 100644 --- a/lily/scm-hash.cc +++ b/lily/scm-hash.cc @@ -73,18 +73,16 @@ Scheme_hash_table::remove (SCM k) scm_hashq_remove_x (hash_tab (), k); } -static SCM -collect_handles (void * /* closure */, - SCM key, - SCM value, - SCM result) -{ - return scm_acons (key, value, result); -} - SCM Scheme_hash_table::to_alist () const { - return scm_internal_hash_fold ((scm_t_hash_fold_fn) &collect_handles, - NULL, SCM_EOL, hash_tab ()); + auto collect_handles = [] (void * /* closure */, + SCM key, + SCM value, + SCM result) + { + return scm_acons (key, value, result); + }; + + return ly_scm_hash_fold (collect_handles, nullptr, SCM_EOL, hash_tab ()); }