commit 01e390acccf336e0e6f4141a4f0d739e64aa3b22
parent e1f93041d47235fcb4a605ed60eaf47f746e4a3c
Author: Andres Navarro <canavarro82@gmail.com>
Date: Sat, 16 Apr 2011 14:26:10 -0300
Changed kmakeport interface to not take NAME or SI. Added GC assumtion: filename rooted.
Diffstat:
3 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/src/kgports.c b/src/kgports.c
@@ -65,7 +65,7 @@ void with_file(klisp_State *K, TValue *xparams, TValue ptree,
bind_2tp(K, name, ptree, "string", ttisstring, filename,
"combiner", ttiscombiner, comb);
- TValue new_port = kmake_port(K, filename, writep, KNIL, KNIL);
+ TValue new_port = kmake_port(K, filename, writep);
krooted_tvs_push(K, new_port);
/* make the continuation to close the file before returning */
TValue new_cont = kmake_continuation(K, kget_cc(K), KNIL, KNIL,
@@ -113,7 +113,7 @@ void open_file(klisp_State *K, TValue *xparams, TValue ptree, TValue denv)
bind_1tp(K, name, ptree, "string", ttisstring, filename);
- TValue new_port = kmake_port(K, filename, writep, KNIL, KNIL);
+ TValue new_port = kmake_port(K, filename, writep);
kapply_cc(K, new_port);
}
@@ -356,7 +356,7 @@ void call_with_file(klisp_State *K, TValue *xparams, TValue ptree,
bind_2tp(K, name, ptree, "string", ttisstring, filename,
"combiner", ttiscombiner, comb);
- TValue new_port = kmake_port(K, filename, writep, KNIL, KNIL);
+ TValue new_port = kmake_port(K, filename, writep);
krooted_tvs_push(K, new_port);
/* make the continuation to close the file before returning */
TValue new_cont = kmake_continuation(K, kget_cc(K), KNIL, KNIL,
@@ -471,7 +471,7 @@ void load(klisp_State *K, TValue *xparams, TValue ptree, TValue denv)
/* the reads must be guarded to close the file if there is some error
this continuation also will return inert after the evaluation of the
last expression is done */
- TValue port = kmake_port(K, filename, false, KNIL, KNIL);
+ TValue port = kmake_port(K, filename, false);
krooted_tvs_push(K, port);
TValue inert_cont = make_return_value_cont(K, kget_cc(K), KINERT);
@@ -515,7 +515,7 @@ void get_module(klisp_State *K, TValue *xparams, TValue ptree, TValue denv)
bind_al1tp(K, "get-module", ptree, "string", ttisstring, filename,
maybe_env);
- TValue port = kmake_port(K, filename, false, KNIL, KNIL);
+ TValue port = kmake_port(K, filename, false);
krooted_tvs_push(K, port);
TValue env = kmake_environment(K, K->ground_env);
diff --git a/src/kport.c b/src/kport.c
@@ -20,8 +20,9 @@
file-exists? and a mechanism to truncate or append to a file, or
throw error if it exists.
Should use open, but it is non standard (fcntl.h, POSIX only) */
-TValue kmake_port(klisp_State *K, TValue filename, bool writep, TValue name,
- TValue si)
+
+/* GC: Assumes filename is rooted */
+TValue kmake_port(klisp_State *K, TValue filename, bool writep)
{
/* for now always use text mode */
FILE *f = fopen(kstring_buf(filename), writep? "w": "r");
@@ -29,22 +30,18 @@ TValue kmake_port(klisp_State *K, TValue filename, bool writep, TValue name,
klispE_throw(K, "Create port: could't open file");
return KINERT;
} else {
- return kmake_std_port(K, filename, writep, name, si, f);
+ return kmake_std_port(K, filename, writep, KNIL, KNIL, f);
}
}
/* this is for creating ports for stdin/stdout/stderr &
also a helper for the above */
+
+/* GC: Assumes filename, name & si are rooted */
TValue kmake_std_port(klisp_State *K, TValue filename, bool writep,
TValue name, TValue si, FILE *file)
{
- krooted_tvs_push(K, filename);
- krooted_tvs_push(K, name);
- krooted_tvs_push(K, si);
Port *new_port = klispM_new(K, Port);
- krooted_tvs_pop(K);
- krooted_tvs_pop(K);
- krooted_tvs_pop(K);
/* header + gc_fields */
klispC_link(K, (GCObject *) new_port, K_TPORT,
diff --git a/src/kport.h b/src/kport.h
@@ -12,10 +12,12 @@
#include "kobject.h"
#include "kstate.h"
-TValue kmake_port(klisp_State *K, TValue filename, bool writep, TValue name,
- TValue si);
+/* GC: Assumes filename is rooted */
+TValue kmake_port(klisp_State *K, TValue filename, bool writep);
-/* this is for creating ports for stdin/stdout/stderr */
+/* this is for creating ports for stdin/stdout/stderr &
+ helper for the one above */
+/* GC: Assumes filename, name & si are rooted */
TValue kmake_std_port(klisp_State *K, TValue filename, bool writep,
TValue name, TValue si, FILE *file);