summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarius Vollmer <mvo@zagadka.de>2004-08-12 17:03:36 +0000
committerMarius Vollmer <mvo@zagadka.de>2004-08-12 17:03:36 +0000
commitd617ee1895503e4b85da9fa72fcafb7a3b79951d (patch)
tree990d36145c8894014b6088d752d87e9deae47ac7
parentffa747a6ead5e8ba3c6af1fc26c4bbaa72e2d72b (diff)
downloadguile-d617ee1895503e4b85da9fa72fcafb7a3b79951d.tar.gz
* fports.h, fports.c (scm_i_fdes_to_port): New, like
scm_fdes_to_port, but take mode bits directly instead of as a C string. (scm_i_fdes_to_port): Implement using above. (scm_open_file): Use scm_i_fdes_to_port together with scm_i_mode_bits to avoid accessing internals of SCM string from C. * vports.c (scm_make_soft_port): Use scm_i_fdes_to_port together with scm_i_mode_bits to avoid accessing internals of SCM string from C. * ports.h (scm_i_mode_bits): New, same as scm_mode_bits but with a SCM string as argument. * ports.c (scm_i_void_port): New, like scm_void_port but take mode bits directly instead of C string. (scm_void_port): Implement using above. (scm_sys_make_void_port): Use scm_i_void_port together with scm_i_mode_bits to avoid accessing internals of SCM string. * convert.i.c, backtrace.c, strop.c, strorder.c, strports.c, struct.c, unif.c, ports.c: Use SCM_I_STRING_CHARS, SCM_I_STRING_UCHARS, and SCM_I_STRING_LENGTH instead of SCM_STRING_CHARS, SCM_STRING_UCHARS, and SCM_STRING_LENGTH, respectively. Also, replaced scm_return_first with more explicit scm_remember_upto_here_1, etc, or introduced them in the first place.
-rw-r--r--libguile/fports.c11
-rw-r--r--libguile/fports.h4
-rw-r--r--libguile/ports.c30
-rw-r--r--libguile/ports.h5
-rw-r--r--libguile/vports.c2
5 files changed, 41 insertions, 11 deletions
diff --git a/libguile/fports.c b/libguile/fports.c
index 6b462e03e..769474952 100644
--- a/libguile/fports.c
+++ b/libguile/fports.c
@@ -342,7 +342,7 @@ SCM_DEFINE (scm_open_file, "open-file", 2, 0, 0,
scm_cons (scm_strerror (scm_from_int (en)),
scm_cons (filename, SCM_EOL)), en);
}
- port = scm_fdes_to_port (fdes, md, filename);
+ port = scm_i_fdes_to_port (fdes, scm_i_mode_bits (mode), filename);
scm_frame_end ();
@@ -401,10 +401,9 @@ static int getflags (int fdes)
NAME is a string to be used as the port's filename.
*/
SCM
-scm_fdes_to_port (int fdes, char *mode, SCM name)
+scm_i_fdes_to_port (int fdes, long mode_bits, SCM name)
#define FUNC_NAME "scm_fdes_to_port"
{
- long mode_bits = scm_mode_bits (mode);
SCM port;
scm_t_port *pt;
int flags;
@@ -448,6 +447,12 @@ scm_fdes_to_port (int fdes, char *mode, SCM name)
}
#undef FUNC_NAME
+SCM
+scm_fdes_to_port (int fdes, char *mode, SCM name)
+{
+ return scm_i_fdes_to_port (fdes, scm_mode_bits (mode), name);
+}
+
/* Return a lower bound on the number of bytes available for input. */
static int
fport_input_waiting (SCM port)
diff --git a/libguile/fports.h b/libguile/fports.h
index 9ce23f546..3d88c2fb4 100644
--- a/libguile/fports.h
+++ b/libguile/fports.h
@@ -55,6 +55,10 @@ SCM_API SCM scm_fdes_to_port (int fdes, char *mode, SCM name);
SCM_API SCM scm_file_port_p (SCM obj);
SCM_API void scm_init_fports (void);
+/* internal functions */
+
+SCM_API SCM scm_i_fdes_to_port (int fdes, long mode_bits, SCM name);
+
#endif /* SCM_FPORTS_H */
/*
diff --git a/libguile/ports.c b/libguile/ports.c
index 02d72b448..d0931ed71 100644
--- a/libguile/ports.c
+++ b/libguile/ports.c
@@ -330,7 +330,7 @@ SCM_DEFINE (scm_drain_input, "drain-input", 1, 0, 0,
count += pt->saved_read_end - pt->saved_read_pos;
result = scm_allocate_string (count);
- scm_take_from_input_buffers (port, SCM_STRING_CHARS (result), count);
+ scm_take_from_input_buffers (port, SCM_I_STRING_CHARS (result), count);
return result;
}
@@ -680,6 +680,18 @@ scm_mode_bits (char *modes)
| (strchr (modes, 'l') ? SCM_BUFLINE : 0));
}
+long
+scm_i_mode_bits (SCM modes)
+{
+ long bits;
+
+ if (!scm_is_string (modes))
+ scm_wrong_type_arg_msg (NULL, 0, modes, "string");
+
+ bits = scm_mode_bits (SCM_I_STRING_CHARS (modes));
+ scm_remember_upto_here_1 (modes);
+ return bits;
+}
/* Return the mode flags from an open port.
* Some modes such as "append" are only used when opening
@@ -1310,7 +1322,7 @@ SCM_DEFINE (scm_unread_string, "unread-string", 2, 0, 0,
else
SCM_VALIDATE_OPINPORT (2, port);
- scm_ungets (SCM_STRING_CHARS (str), SCM_STRING_LENGTH (str), port);
+ scm_ungets (SCM_I_STRING_CHARS (str), SCM_I_STRING_LENGTH (str), port);
return str;
}
@@ -1599,12 +1611,11 @@ write_void_port (SCM port SCM_UNUSED,
{
}
-SCM
-scm_void_port (char *mode_str)
+static SCM
+scm_i_void_port (long mode_bits)
{
scm_mutex_lock (&scm_i_port_table_mutex);
{
- int mode_bits = scm_mode_bits (mode_str);
SCM answer = scm_new_port_table_entry (scm_tc16_void_port);
scm_t_port * pt = SCM_PTAB_ENTRY(answer);
@@ -1617,6 +1628,12 @@ scm_void_port (char *mode_str)
}
}
+SCM
+scm_void_port (char *mode_str)
+{
+ return scm_i_void_port (scm_mode_bits (mode_str));
+}
+
SCM_DEFINE (scm_sys_make_void_port, "%make-void-port", 1, 0, 0,
(SCM mode),
"Create and return a new void port. A void port acts like\n"
@@ -1625,8 +1642,7 @@ SCM_DEFINE (scm_sys_make_void_port, "%make-void-port", 1, 0, 0,
"documentation for @code{open-file} in @ref{File Ports}.")
#define FUNC_NAME s_scm_sys_make_void_port
{
- SCM_VALIDATE_STRING (1, mode);
- return scm_void_port (SCM_STRING_CHARS (mode));
+ return scm_i_void_port (scm_i_mode_bits (mode));
}
#undef FUNC_NAME
diff --git a/libguile/ports.h b/libguile/ports.h
index ee53d3773..93f3344cc 100644
--- a/libguile/ports.h
+++ b/libguile/ports.h
@@ -301,6 +301,11 @@ SCM_API SCM scm_pt_size (void);
SCM_API SCM scm_pt_member (SCM member);
#endif /* GUILE_DEBUG */
+/* internal */
+
+SCM_API long scm_i_mode_bits (SCM modes);
+
+
#endif /* SCM_PORTS_H */
/*
diff --git a/libguile/vports.c b/libguile/vports.c
index 096b26c7f..e99d7961c 100644
--- a/libguile/vports.c
+++ b/libguile/vports.c
@@ -196,7 +196,7 @@ SCM_DEFINE (scm_make_soft_port, "make-soft-port", 2, 0, 0,
z = scm_new_port_table_entry (scm_tc16_sfport);
pt = SCM_PTAB_ENTRY (z);
scm_port_non_buffer (pt);
- SCM_SET_CELL_TYPE (z, scm_tc16_sfport | scm_mode_bits (SCM_STRING_CHARS (modes)));
+ SCM_SET_CELL_TYPE (z, scm_tc16_sfport | scm_i_mode_bits (modes));
SCM_SETSTREAM (z, SCM_UNPACK (pv));
scm_mutex_unlock (&scm_i_port_table_mutex);