diff --git a/libguile/ChangeLog b/libguile/ChangeLog index c323294ff..58f662cf1 100644 --- a/libguile/ChangeLog +++ b/libguile/ChangeLog @@ -1,5 +1,8 @@ 2007-01-19 Han-Wen Nienhuys + * options.c (scm_options_try): new function. This allows error + reporting before changing options in a critical section. + * srcprop.c: use double cell for storing source-properties. Put filename in the plist, and share between srcprops if possible. Remove specialized storage. diff --git a/libguile/options.c b/libguile/options.c index 412192fb9..ae75e1318 100644 --- a/libguile/options.c +++ b/libguile/options.c @@ -164,9 +164,14 @@ options_length (scm_t_option options[]) * formed option setting, i. e. if for every non-boolean option a value is * given. For this reason, the function applies all changes to a copy of the * original setting in memory. Only if 'args' was successfully processed, - * the new setting will overwrite the old one. */ + * the new setting will overwrite the old one. + * + * If DRY_RUN is set, don't change anything. This is useful for trying out an option + * before entering a critical section. + */ static void -change_option_setting (SCM args, scm_t_option options[], const char *s) +change_option_setting (SCM args, scm_t_option options[], const char *s, + int dry_run) { unsigned int i; SCM locally_protected_args = args; @@ -214,6 +219,9 @@ change_option_setting (SCM args, scm_t_option options[], const char *s) args = SCM_CDR (args); } + if (dry_run) + return; + for (i = 0; options[i].name; ++i) { if (options[i].type == SCM_OPTION_SCM) @@ -234,6 +242,13 @@ change_option_setting (SCM args, scm_t_option options[], const char *s) SCM scm_options (SCM args, scm_t_option options[], const char *s) +{ + return scm_options_try (args, options, s, 0); +} + +SCM +scm_options_try (SCM args, scm_t_option options[], const char *s, + int dry_run) { if (SCM_UNBNDP (args)) return get_option_setting (options); @@ -247,7 +262,7 @@ scm_options (SCM args, scm_t_option options[], const char *s) SCM old_setting; SCM_ASSERT (scm_is_true (scm_list_p (args)), args, 1, s); old_setting = get_option_setting (options); - change_option_setting (args, options, s); + change_option_setting (args, options, s, dry_run); return old_setting; } } diff --git a/libguile/options.h b/libguile/options.h index 71761245e..5b9664958 100644 --- a/libguile/options.h +++ b/libguile/options.h @@ -40,6 +40,7 @@ typedef struct scm_t_option #define SCM_OPTION_SCM 2 +SCM_API SCM scm_options_try (SCM args, scm_t_option options[], const char *s, int dry_run); SCM_API SCM scm_options (SCM, scm_t_option [], const char*); SCM_API void scm_init_opts (SCM (*) (SCM), scm_t_option []); SCM_API void scm_init_options (void);