diff options
author | Andy Wingo <wingo@pobox.com> | 2009-06-03 09:48:16 +0200 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2009-06-03 22:20:55 +0200 |
commit | 0fb81f95b0222c5ba49efd3e36cf797df54c0863 (patch) | |
tree | 4fa082789891713ede9e62ef209ff13cccf30231 | |
parent | 1d022387c8f2615cc94a27109db9b9e02d7d7831 (diff) | |
download | guile-0fb81f95b0222c5ba49efd3e36cf797df54c0863.tar.gz |
add exception_on_error optional arg to primitive-load-path
* libguile/init.c (scm_load_startup_files): Use
scm_c_primitive_load_path.
* libguile/load.c (scm_primitive_load_path): Add an optional arg,
exception_on_error, which if #f will cause primitive-load-path to just
return #f if no file is found. This is to help out the semantics of
try-module-autoload. We can't just catch misc-error, because loading
the file could raise any exception.
(scm_c_primitive_load_path): Add the extra arg to
scm_primitive_load_path.
* libguile/load.h: Adapt scm_primitive_load_path prototype.
* module/ice-9/boot-9.scm (try-module-autoload): Refactor slightly to be
clearer.
-rw-r--r-- | libguile/init.c | 2 | ||||
-rw-r--r-- | libguile/load.c | 23 | ||||
-rw-r--r-- | libguile/load.h | 2 | ||||
-rw-r--r-- | module/ice-9/boot-9.scm | 9 |
4 files changed, 23 insertions, 13 deletions
diff --git a/libguile/init.c b/libguile/init.c index dbc7f8706..c72aeff4c 100644 --- a/libguile/init.c +++ b/libguile/init.c @@ -282,7 +282,7 @@ scm_load_startup_files () /* Load Ice-9. */ if (!scm_ice_9_already_loaded) { - scm_primitive_load_path (scm_from_locale_string ("ice-9/boot-9")); + scm_c_primitive_load_path ("ice-9/boot-9"); /* Load the init.scm file. */ if (scm_is_true (init_path)) diff --git a/libguile/load.c b/libguile/load.c index 5dcbe9cbb..6b5d1a528 100644 --- a/libguile/load.c +++ b/libguile/load.c @@ -586,16 +586,21 @@ scm_try_autocompile (SCM source) return SCM_BOOL_F; } -SCM_DEFINE (scm_primitive_load_path, "primitive-load-path", 1, 0, 0, - (SCM filename), +SCM_DEFINE (scm_primitive_load_path, "primitive-load-path", 1, 1, 0, + (SCM filename, SCM exception_on_not_found), "Search @var{%load-path} for the file named @var{filename} and\n" "load it into the top-level environment. If @var{filename} is a\n" "relative pathname and is not found in the list of search paths,\n" - "an error is signalled.") + "an error is signalled, unless the optional argument\n" + "@var{exception_on_not_found} is @code{#f}, in which case\n" + "@code{#f} is returned instead.") #define FUNC_NAME s_scm_primitive_load_path { SCM full_filename, compiled_filename; + if (SCM_UNBNDP (exception_on_not_found)) + exception_on_not_found = SCM_BOOL_T; + full_filename = scm_sys_search_load_path (filename); compiled_filename = scm_search_path (*scm_loc_load_compiled_path, filename, @@ -603,8 +608,13 @@ SCM_DEFINE (scm_primitive_load_path, "primitive-load-path", 1, 0, 0, SCM_BOOL_T); if (scm_is_false (full_filename) && scm_is_false (compiled_filename)) - SCM_MISC_ERROR ("Unable to find file ~S in load path", - scm_list_1 (filename)); + { + if (scm_is_true (exception_on_not_found)) + SCM_MISC_ERROR ("Unable to find file ~S in load path", + scm_list_1 (filename)); + else + return SCM_BOOL_F; + } if (scm_is_false (full_filename) || (scm_is_true (compiled_filename) @@ -622,7 +632,8 @@ SCM_DEFINE (scm_primitive_load_path, "primitive-load-path", 1, 0, 0, SCM scm_c_primitive_load_path (const char *filename) { - return scm_primitive_load_path (scm_from_locale_string (filename)); + return scm_primitive_load_path (scm_from_locale_string (filename), + SCM_BOOL_T); } diff --git a/libguile/load.h b/libguile/load.h index 87f336e1e..021987329 100644 --- a/libguile/load.h +++ b/libguile/load.h @@ -33,7 +33,7 @@ SCM_API SCM scm_sys_library_dir (void); SCM_API SCM scm_sys_site_dir (void); SCM_API SCM scm_search_path (SCM path, SCM filename, SCM exts, SCM require_exts); SCM_API SCM scm_sys_search_load_path (SCM filename); -SCM_API SCM scm_primitive_load_path (SCM filename); +SCM_API SCM scm_primitive_load_path (SCM filename, SCM exception_on_not_found); SCM_API SCM scm_c_primitive_load_path (const char *filename); SCM_INTERNAL void scm_init_load_path (void); SCM_INTERNAL void scm_init_load (void); diff --git a/module/ice-9/boot-9.scm b/module/ice-9/boot-9.scm index 5f365b484..bb66ccfb6 100644 --- a/module/ice-9/boot-9.scm +++ b/module/ice-9/boot-9.scm @@ -2270,16 +2270,15 @@ module '(ice-9 q) '(make-q q-length))}." (resolve-module dir-hint-module-name #f) (and (not (autoload-done-or-in-progress? dir-hint name)) (let ((didit #f)) - (define (load-file proc file) - (save-module-excursion (lambda () (proc file))) - (set! didit #t)) (dynamic-wind (lambda () (autoload-in-progress! dir-hint name)) (lambda () (with-fluid* current-reader #f (lambda () - (load-file primitive-load-path - (in-vicinity dir-hint name))))) + (save-module-excursion + (lambda () + (primitive-load-path (in-vicinity dir-hint name) #f) + (set! didit #t)))))) (lambda () (set-autoloaded! dir-hint name didit))) didit)))) |