summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikael Djurfeldt <djurfeldt@nada.kth.se>1998-06-18 21:53:45 +0000
committerMikael Djurfeldt <djurfeldt@nada.kth.se>1998-06-18 21:53:45 +0000
commitd7834b915babbd877a08169bf04066785af67bbb (patch)
treed91f2b78c683eb0b06c7ca62e11ca08eaacfa444
parent1a64191ee695f6337a469e35da0ff0e5375b6f25 (diff)
downloadguile-d7834b915babbd877a08169bf04066785af67bbb.tar.gz
* load.c: #include "dynwind.h";
(scm_primitive_load): Use scm_inner_dynamic_wind to update scm_cur_loadp.
-rw-r--r--libguile/load.c38
1 files changed, 30 insertions, 8 deletions
diff --git a/libguile/load.c b/libguile/load.c
index f1da0547e..066556f94 100644
--- a/libguile/load.c
+++ b/libguile/load.c
@@ -48,6 +48,7 @@
#include "eval.h"
#include "throw.h"
#include "alist.h"
+#include "dynwind.h"
#include "load.h"
@@ -69,6 +70,28 @@
Applied to the full name of the file. */
static SCM *scm_loc_load_hook;
+void
+swap_port (void *data)
+{
+ SCM *save_port = data, tmp = scm_cur_loadp;
+ scm_cur_loadp = *save_port;
+ *save_port = tmp;
+}
+
+static SCM
+load (void *data)
+{
+ SCM port = (SCM) data, form;
+ while (1)
+ {
+ form = scm_read (port);
+ if (SCM_EOF_OBJECT_P (form))
+ break;
+ scm_eval_x (form);
+ }
+ return SCM_UNSPECIFIED;
+}
+
SCM_PROC(s_primitive_load, "primitive-load", 1, 0, 0, scm_primitive_load);
SCM
scm_primitive_load (filename)
@@ -86,16 +109,15 @@ scm_primitive_load (filename)
scm_apply (hook, scm_listify (filename, SCM_UNDEFINED), SCM_EOL);
{
- SCM form, port;
+ SCM port, save_port;
port = scm_open_file (filename,
scm_makfromstr ("r", (scm_sizet) sizeof (char), 0));
- while (1)
- {
- form = scm_read (port);
- if (SCM_EOF_OBJECT_P (form))
- break;
- scm_eval_x (form);
- }
+ save_port = port;
+ scm_internal_dynamic_wind (swap_port,
+ load,
+ swap_port,
+ (void *) port,
+ &save_port);
scm_close_port (port);
}
return SCM_UNSPECIFIED;