diff options
-rw-r--r-- | doc/ref/api-evaluation.texi | 11 | ||||
-rw-r--r-- | libguile/load.c | 31 | ||||
-rw-r--r-- | libguile/load.h | 4 |
3 files changed, 38 insertions, 8 deletions
diff --git a/doc/ref/api-evaluation.texi b/doc/ref/api-evaluation.texi index b245ab8b7..c4849529e 100644 --- a/doc/ref/api-evaluation.texi +++ b/doc/ref/api-evaluation.texi @@ -1,6 +1,6 @@ @c -*-texinfo-*- @c This is part of the GNU Guile Reference Manual. -@c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2005, 2006 +@c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009 @c Free Software Foundation, Inc. @c See the file guile.texi for copying conditions. @@ -538,13 +538,20 @@ documentation for @code{%load-hook} later in this section. @code{SCM}. @end deftypefn -@deffn {Scheme Procedure} primitive-load-path filename +@deffn {Scheme Procedure} primitive-load-path filename [exception-on-not-found] @deffnx {C Function} scm_primitive_load_path (filename) Search @code{%load-path} for the file named @var{filename} and load it into the top-level environment. If @var{filename} is a relative pathname and is not found in the list of search paths, an error is signalled. Preferentially loads a compiled version of the file, if it is available and up-to-date. + +By default or if @var{exception-on-not-found} is true, an exception is +raised if @var{filename} is not found. If @var{exception-on-not-found} +is @code{#f} and @var{filename} is not found, no exception is raised and +@code{#f} is returned. For compatibility with Guile 1.8 and earlier, +the C function takes only one argument, which can be either a string +(the file name) or an argument list. @end deffn @deffn {Scheme Procedure} %search-load-path filename diff --git a/libguile/load.c b/libguile/load.c index 10cbdb255..50af25643 100644 --- a/libguile/load.c +++ b/libguile/load.c @@ -685,8 +685,8 @@ scm_try_autocompile (SCM source) NULL, NULL); } -SCM_DEFINE (scm_primitive_load_path, "primitive-load-path", 1, 1, 0, - (SCM filename, SCM exception_on_not_found), +SCM_DEFINE (scm_primitive_load_path, "primitive-load-path", 0, 0, 1, + (SCM args), "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" @@ -695,9 +695,33 @@ SCM_DEFINE (scm_primitive_load_path, "primitive-load-path", 1, 1, 0, "@code{#f} is returned instead.") #define FUNC_NAME s_scm_primitive_load_path { + SCM filename, exception_on_not_found; SCM full_filename, compiled_filename; int compiled_is_fallback = 0; + if (scm_is_string (args)) + { + /* C code written for 1.8 and earlier expects this function to take a + single argument (the file name). */ + filename = args; + exception_on_not_found = SCM_UNDEFINED; + } + else + { + /* Starting from 1.9, this function takes 1 required and 1 optional + argument. */ + long len; + + SCM_VALIDATE_LIST_COPYLEN (SCM_ARG1, args, len); + if (len < 1 || len > 2) + scm_error_num_args_subr (FUNC_NAME); + + filename = SCM_CAR (args); + SCM_VALIDATE_STRING (SCM_ARG1, filename); + + exception_on_not_found = len > 1 ? SCM_CADR (args) : SCM_UNDEFINED; + } + if (SCM_UNBNDP (exception_on_not_found)) exception_on_not_found = SCM_BOOL_T; @@ -775,8 +799,7 @@ SCM_DEFINE (scm_primitive_load_path, "primitive-load-path", 1, 1, 0, SCM scm_c_primitive_load_path (const char *filename) { - return scm_primitive_load_path (scm_from_locale_string (filename), - SCM_BOOL_T); + return scm_primitive_load_path (scm_from_locale_string (filename)); } diff --git a/libguile/load.h b/libguile/load.h index 1a1a86528..cf825fc0f 100644 --- a/libguile/load.h +++ b/libguile/load.h @@ -3,7 +3,7 @@ #ifndef SCM_LOAD_H #define SCM_LOAD_H -/* Copyright (C) 1995,1996,1998,2000,2001, 2006, 2008 Free Software Foundation, Inc. +/* Copyright (C) 1995,1996,1998,2000,2001, 2006, 2008, 2009 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -34,7 +34,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 exception_on_not_found); +SCM_API SCM scm_primitive_load_path (SCM filename_and_exception_on_not_found); SCM_API SCM scm_c_primitive_load_path (const char *filename); SCM_INTERNAL SCM scm_sys_warn_autocompilation_enabled (void); SCM_INTERNAL void scm_init_load_path (void); |