Revision: 6143
Author: iratqq
Date: Sat Jan 23 23:32:29 2010
Log: * uim/openssl.c (c_SSL_read_internal):
  - New function.
  (c_SSL_read):
  - Call gc-guarded c_SSL_read_internal().

http://code.google.com/p/uim/source/detail?r=6143

Modified:
 /trunk/uim/openssl.c

=======================================
--- /trunk/uim/openssl.c        Fri Dec 25 08:58:38 2009
+++ /trunk/uim/openssl.c        Sat Jan 23 23:32:29 2010
@@ -143,15 +143,33 @@
   return MAKE_INT(SSL_connect(C_PTR(s_)));
 }

+struct c_SSL_read_args {
+  const unsigned char *buf;
+  int nr;
+};
+
+static uim_lisp
+c_SSL_read_internal(struct c_SSL_read_args *args)
+{
+  int i;
+  uim_lisp ret_ = uim_scm_null();
+  const unsigned char *p = args->buf;
+
+  for (i = 0; i < args->nr; i++) {
+    ret_ = CONS(MAKE_CHAR(*p), ret_);
+    p++;
+  }
+  return ret_;
+}
+
 static uim_lisp
 c_SSL_read(uim_lisp s_, uim_lisp nbytes_)
 {
   unsigned char *buf;
   uim_lisp ret_;
   int nbytes = C_INT(nbytes_);
-  int i;
   int nr;
-  unsigned char *p;
+  struct c_SSL_read_args args;

   buf = uim_malloc(nbytes);
   if ((nr = SSL_read(C_PTR(s_), buf, nbytes)) == 0)
@@ -159,12 +177,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_SSL_read_internal,
+                                                   (void *)&args);
   free(buf);
   return uim_scm_callf("reverse", "o", ret_);
 }

Reply via email to