diff options
author | Ludovic Courtès <ludo@gnu.org> | 2009-11-01 23:29:36 +0100 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2009-11-01 23:29:36 +0100 |
commit | 88cbb421895656c6d255610e32c2ae1addb2ea07 (patch) | |
tree | 693b83cd4142afeb572869b679f888acf337845f | |
parent | 731dd0ce191bf4f3ba8fedfe0e08c0e67a966ce4 (diff) | |
download | guile-88cbb421895656c6d255610e32c2ae1addb2ea07.tar.gz |
Restore signature of `scm_search_path ()' as found in 1.8.
The incompatibly was introduced by
22f4ee48822db5e30df3abf9a11b6066f2bab9d3 ("make primitive-load-path load
compiled files if available").
* doc/ref/api-options.texi (Build Config): Update `search-path'
documentation.
* libguile/load.c (scm_search_path): Change C prototype to expect only 3
arguments. Parse the rest argument accordingly. Update callers.
* libguile/load.h (scm_search_path): Update accordingly.
-rw-r--r-- | doc/ref/api-options.texi | 12 | ||||
-rw-r--r-- | libguile/load.c | 52 | ||||
-rw-r--r-- | libguile/load.h | 2 |
3 files changed, 54 insertions, 12 deletions
diff --git a/doc/ref/api-options.texi b/doc/ref/api-options.texi index f4caa8ac9..1b526a873 100644 --- a/doc/ref/api-options.texi +++ b/doc/ref/api-options.texi @@ -113,15 +113,21 @@ string, into a list and return the resulting list with is returned. @end deffn -@deffn {Scheme Procedure} search-path path filename [extensions] -@deffnx {C Function} scm_search_path (path, filename, extensions) +@deffn {Scheme Procedure} search-path path filename [extensions [require-exts?]] +@deffnx {C Function} scm_search_path (path, filename, rest) Search @var{path} for a directory containing a file named @var{filename}. The file must be readable, and not a directory. If we find one, return its full filename; otherwise, return @code{#f}. If @var{filename} is absolute, return it unchanged. If given, @var{extensions} is a list of strings; for each directory in @var{path}, we search for @var{filename} -concatenated with each @var{extension}. +concatenated with each @var{extension}. If @var{require-exts?} +is true, require that the returned file name have one of the +given extensions; if @var{require-exts?} is not given, it +defaults to @code{#f}. + +For compatibility with Guile 1.8 and earlier, the C function takes only +three arguments @end deffn @defvar %guile-build-info diff --git a/libguile/load.c b/libguile/load.c index 50af25643..c6fbf5f1b 100644 --- a/libguile/load.c +++ b/libguile/load.c @@ -391,8 +391,8 @@ scm_c_string_has_an_ext (char *str, size_t len, SCM extensions) If FILENAME is absolute, return it unchanged. If given, EXTENSIONS is a list of strings; for each directory in PATH, we search for FILENAME concatenated with each EXTENSION. */ -SCM_DEFINE (scm_search_path, "search-path", 2, 2, 0, - (SCM path, SCM filename, SCM extensions, SCM require_exts), +SCM_DEFINE (scm_search_path, "search-path", 2, 0, 1, + (SCM path, SCM filename, SCM rest), "Search @var{path} for a directory containing a file named\n" "@var{filename}. The file must be readable, and not a directory.\n" "If we find one, return its full filename; otherwise, return\n" @@ -405,11 +405,46 @@ SCM_DEFINE (scm_search_path, "search-path", 2, 2, 0, struct stringbuf buf; char *filename_chars; size_t filename_len; + SCM extensions, require_exts; SCM result = SCM_BOOL_F; + if (scm_is_null (rest)) + { + /* Called either by Scheme code that didn't provide the optional + arguments, or C code that used the Guile 1.8 signature (2 required, + 1 optional arg) and passed '() as the EXTENSIONS argument. */ + extensions = SCM_EOL; + require_exts = SCM_UNDEFINED; + } + else + { + if (scm_is_null (SCM_CAR (rest)) || scm_is_pair (SCM_CAR (rest))) + { + /* Called by Scheme code written for 1.9. */ + extensions = SCM_CAR (rest); + if (scm_is_null (SCM_CDR (rest))) + require_exts = SCM_UNDEFINED; + else + { + require_exts = SCM_CADR (rest); + if (SCM_UNLIKELY (!scm_is_null (SCM_CDDR (rest)))) + scm_wrong_num_args (scm_from_locale_string (FUNC_NAME)); + } + } + else + { + /* Called by C code that uses the 1.8 signature, i.e., which + expects the 3rd argument to be EXTENSIONS. */ + extensions = rest; + require_exts = SCM_UNDEFINED; + } + } + if (SCM_UNBNDP (extensions)) extensions = SCM_EOL; + SCM_VALIDATE_LIST (3, extensions); + if (SCM_UNBNDP (require_exts)) require_exts = SCM_BOOL_F; @@ -565,7 +600,7 @@ SCM_DEFINE (scm_sys_search_load_path, "%search-load-path", 1, 0, 0, SCM_MISC_ERROR ("%load-path is not a proper list", SCM_EOL); if (scm_ilength (exts) < 0) SCM_MISC_ERROR ("%load-extension list is not a proper list", SCM_EOL); - return scm_search_path (path, filename, exts, SCM_UNDEFINED); + return scm_search_path (path, filename, exts); } #undef FUNC_NAME @@ -726,11 +761,12 @@ SCM_DEFINE (scm_primitive_load_path, "primitive-load-path", 0, 0, 1, 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, - *scm_loc_load_compiled_extensions, - SCM_BOOL_T); - + compiled_filename = + scm_search_path (*scm_loc_load_compiled_path, + filename, + scm_list_2 (*scm_loc_load_compiled_extensions, + SCM_BOOL_T)); + if (scm_is_false (compiled_filename) && scm_is_true (full_filename) && scm_is_true (*scm_loc_compile_fallback_path) diff --git a/libguile/load.h b/libguile/load.h index cf825fc0f..81fbfbabd 100644 --- a/libguile/load.h +++ b/libguile/load.h @@ -32,7 +32,7 @@ SCM_API SCM scm_c_primitive_load (const char *filename); SCM_API SCM scm_sys_package_data_dir (void); 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_search_path (SCM path, SCM filename, SCM rest); SCM_API SCM scm_sys_search_load_path (SCM filename); 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); |