* python/lilylib.py (setup_temp): temporary directories are mode 700.
[lilypond.git] / lily / ly-module.cc
blob821e95ec851338917168b8debec566009feaf9e2
1 /*
2 ly-module.cc -- implement guile module stuff.
4 source file of the GNU LilyPond music typesetter
6 (c) 2002--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
10 #include "string.hh"
11 #include "lily-guile.hh"
12 #include "ly-modules.hh"
13 #include "protected-scm.hh"
15 #define FUNC_NAME __FUNCTION__
17 static int module_count;
19 void
20 ly_init_anonymous_module (void * data)
22 scm_c_use_module ("lily");
25 Protected_scm anon_modules;
27 SCM
28 ly_make_anonymous_module ()
30 String s = "*anonymous-ly-" + to_string (module_count++) + "*";
31 SCM mod = scm_c_define_module (s.to_str0(), ly_init_anonymous_module, 0);
33 anon_modules = scm_cons (mod, anon_modules);
34 return mod;
37 void
38 ly_clear_anonymous_modules ()
40 SCM s = anon_modules;
41 anon_modules = SCM_EOL;
43 for (; gh_pair_p (s) ; s = gh_cdr (s))
45 SCM tab= scm_c_make_hash_table (2);
47 UGH.
50 SCM_STRUCT_DATA(gh_car(s))[scm_module_index_obarray] = (long unsigned int) tab;
54 #define FUNC_NAME __FUNCTION__
56 SCM
57 define_one_var (void * closure, SCM key, SCM val, SCM result)
59 SCM dest = (SCM) closure;
60 scm_module_define (dest, key, scm_variable_ref (val));
61 return SCM_EOL;
65 Ugh signature of scm_internal_hash_fold () is inaccurate.
67 typedef SCM (*Hash_cl_func)();
69 void
70 ly_copy_module_variables (SCM dest, SCM src)
72 SCM_VALIDATE_MODULE (1, src);
74 SCM obarr= SCM_MODULE_OBARRAY(src);
75 scm_internal_hash_fold ((Hash_cl_func) &define_one_var, (void*) dest, SCM_EOL, obarr);
78 SCM
79 accumulate_symbol (void * closure, SCM key, SCM val, SCM result)
81 return scm_cons (key, result);
84 SCM
85 ly_module_symbols (SCM mod)
87 SCM_VALIDATE_MODULE (1, mod);
89 SCM obarr= SCM_MODULE_OBARRAY(mod);
90 return scm_internal_hash_fold ((Hash_cl_func) &accumulate_symbol, NULL, SCM_EOL, obarr);
93 SCM
94 entry_to_alist (void * closure, SCM key, SCM val, SCM result)
96 return scm_cons (scm_cons (key, scm_variable_ref (val)), result);
99 SCM
100 ly_module_to_alist (SCM mod)
102 SCM_VALIDATE_MODULE (1, mod);
105 SCM obarr= SCM_MODULE_OBARRAY(mod);
107 return scm_internal_hash_fold ((Hash_cl_func) &entry_to_alist, NULL, SCM_EOL, obarr);
111 Lookup SYM, but don't give error when it is not defined.
114 ly_module_lookup (SCM module, SCM sym)
116 #define FUNC_NAME __FUNCTION__
117 SCM_VALIDATE_MODULE (1, module);
119 return scm_sym2var (sym, scm_module_lookup_closure (module), SCM_BOOL_F);
122 SCM export_function ;
124 void
125 ly_export (SCM module, SCM namelist)
127 if (!export_function)
129 export_function = scm_permanent_object (scm_c_lookup ("module-export!"));
132 scm_call_2 (SCM_VARIABLE_REF (export_function),
133 module, namelist);
136 void
137 ly_reexport_module (SCM mod)
139 ly_export (mod, ly_module_symbols (mod));