~ubuntu-branches/ubuntu/hardy/sigscheme/hardy-proposed

« back to all changes in this revision

Viewing changes to src/module.c

  • Committer: Bazaar Package Importer
  • Author(s): NIIBE Yutaka
  • Date: 2007-01-29 15:31:24 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070129153124-j5fcqyrwcfbczma7
Tags: 0.7.4-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 *  Filename : module.c
3
3
 *  About    : Code module handlings
4
4
 *
5
 
 *  Copyright (C) 2005-2006 Kazuki Ohta <mover AT hct.zaq.ne.jp>
 
5
 *  Copyright (C) 2005      Kazuki Ohta <mover AT hct.zaq.ne.jp>
 
6
 *  Copyright (C) 2005      Jun Inoue <jun.lambda AT gmail.com>
 
7
 *  Copyright (C) 2005-2006 YAMAMOTO Kengo <yamaken AT bp.iij4u.or.jp>
 
8
 *  Copyright (c) 2007 SigScheme Project <uim AT freedesktop.org>
6
9
 *
7
10
 *  All rights reserved.
8
11
 *
59
62
SCM_GLOBAL_VARS_BEGIN(static_module);
60
63
#define static
61
64
static ScmObj l_features;
 
65
static ScmObj l_provided_modules;
62
66
#undef static
63
67
SCM_GLOBAL_VARS_END(static_module);
64
 
#define l_features SCM_GLOBAL_VAR(static_module, l_features)
 
68
#define l_features         SCM_GLOBAL_VAR(static_module, l_features)
 
69
#define l_provided_modules SCM_GLOBAL_VAR(static_module, l_provided_modules)
65
70
SCM_DEFINE_STATIC_VARS(static_module);
66
71
 
67
72
static const struct module_info module_info_table[] = {
108
113
  File Local Function Declarations
109
114
=======================================*/
110
115
static const struct module_info *lookup_module_info(const char *feature);
111
 
static scm_bool scm_use_internal(const char *feature);
 
116
static void *scm_use_internal(const char *feature);
112
117
 
113
118
/*=======================================
114
119
  Function Definitions
132
137
    SCM_GLOBAL_VARS_INIT(static_module);
133
138
 
134
139
    scm_gc_protect_with_init(&l_features, SCM_NULL);
 
140
    scm_gc_protect_with_init(&l_provided_modules, SCM_NULL);
135
141
}
136
142
 
137
143
SCM_EXPORT void
138
144
scm_fin_module(void)
139
145
{
140
 
#if 0
141
146
    const struct module_info *mod;
142
 
    ScmObj feature;
 
147
    const char *c_mod_name;
 
148
    ScmObj mod_name;
143
149
 
144
 
    /* FIXME: possible crash by a bogus provided string */
145
 
    FOR_EACH (feature, features) {
146
 
        ENSURE_STRING(feature);
147
 
        if (mod = lookup_module_info(STRING_STR(feature)) && mod->finalizer)
 
150
    FOR_EACH (mod_name, l_provided_modules) {
 
151
        SCM_ASSERT(STRINGP(mod_name));
 
152
        c_mod_name = SCM_STRING_STR(mod_name);
 
153
        if ((mod = lookup_module_info(c_mod_name)) && mod->finalizer)
148
154
            (*mod->finalizer)();
149
155
    }
150
 
#endif
 
156
 
151
157
    SCM_GLOBAL_VARS_FIN(static_module);
152
158
}
153
159
 
154
160
SCM_EXPORT void
155
161
scm_provide(ScmObj feature)
156
162
{
 
163
    SCM_ASSERT(STRINGP(feature));
 
164
 
157
165
    l_features = CONS(feature, l_features);
 
166
    l_provided_modules = CONS(feature, l_provided_modules);
158
167
}
159
168
 
160
169
SCM_EXPORT scm_bool
166
175
SCM_EXPORT scm_bool
167
176
scm_use(const char *feature)
168
177
{
169
 
    scm_bool ok;
170
 
 
171
 
    SCM_GC_PROTECTED_CALL(ok, scm_bool, scm_use_internal, (feature));
172
 
 
173
 
    return ok;
 
178
    return scm_call_with_gc_ready_stack((ScmGCGateFunc)scm_use_internal, (void *)feature) ? scm_true : scm_false;
174
179
}
175
180
 
176
 
static scm_bool
 
181
static void *
177
182
scm_use_internal(const char *feature)
178
183
{
179
184
    ScmObj ok;
181
186
    SCM_ASSERT(feature);
182
187
 
183
188
    ok = scm_s_use(scm_intern(feature), SCM_INTERACTION_ENV);
184
 
    return TRUEP(ok);
 
189
    return (void *)(uintptr_t)TRUEP(ok);
185
190
}
186
191
 
187
192
/*