summaryrefslogtreecommitdiff
path: root/libguile/load.c
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2009-06-03 09:48:16 +0200
committerAndy Wingo <wingo@pobox.com>2009-06-03 22:20:55 +0200
commit0fb81f95b0222c5ba49efd3e36cf797df54c0863 (patch)
tree4fa082789891713ede9e62ef209ff13cccf30231 /libguile/load.c
parent1d022387c8f2615cc94a27109db9b9e02d7d7831 (diff)
downloadguile-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.
Diffstat (limited to 'libguile/load.c')
-rw-r--r--libguile/load.c23
1 files changed, 17 insertions, 6 deletions
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);
}