Revision: 6141
Author: iratqq
Date: Sat Jan 23 22:50:32 2010
Log: * uim/fileio.c (c_file_read_internal): New function.
(c_file_read):
- Call gc-guarded c_file_read_internal().
http://code.google.com/p/uim/source/detail?r=6141
Modified:
/trunk/uim/fileio.c
=======================================
--- /trunk/uim/fileio.c Tue Oct 20 09:48:29 2009
+++ /trunk/uim/fileio.c Sat Jan 23 22:50:32 2010
@@ -166,15 +166,34 @@
return MAKE_INT(close(C_INT(fd_)));
}
+struct c_file_read_args {
+ const unsigned char *buf;
+ int nr;
+};
+
+static uim_lisp
+c_file_read_internal(struct c_file_read_args *args)
+{
+ int i;
+ uim_lisp ret_ = uim_scm_null();
+ const unsigned char *p = args->buf;
+
+ ret_ = uim_scm_null();
+ for (i = 0; i < args->nr; i++) {
+ ret_ = CONS(MAKE_CHAR(*p), ret_);
+ p++;
+ }
+ return ret_;
+}
+
static uim_lisp
c_file_read(uim_lisp d_, uim_lisp nbytes_)
{
unsigned char *buf;
uim_lisp ret_;
int nbytes = C_INT(nbytes_);
- int i;
int nr;
- unsigned char *p;
+ struct c_file_read_args args;
buf = uim_malloc(nbytes);
if ((nr = read(C_INT(d_), buf, nbytes)) == 0)
@@ -182,12 +201,10 @@
if (nr < 0)
return uim_scm_f();
- p = buf;
- ret_ = uim_scm_null();
- for (i = 0; i < nr; i++) {
- ret_ = CONS(MAKE_CHAR(*p), ret_);
- p++;
- }
+ args.buf = buf;
+ args.nr = nr;
+ ret_ =
(uim_lisp)uim_scm_call_with_gc_ready_stack((uim_gc_gate_func_ptr)c_file_read_internal,
+ (void *)&args);
free(buf);
return uim_scm_callf("reverse", "o", ret_);
}