[前][次][番号順一覧][スレッド一覧]

ruby-changes:6936

From: akr <ko1@a...>
Date: Sat, 9 Aug 2008 16:35:48 +0900 (JST)
Subject: [ruby-changes:6936] Ruby:r18454 (trunk): * transcode_data.h (rb_transcoding): new fields: next_info and next_byte.

akr	2008-08-09 16:35:28 +0900 (Sat, 09 Aug 2008)

  New Revision: 18454

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=18454

  Log:
    * transcode_data.h (rb_transcoding): new fields: next_info and next_byte.
    
    * transcode.c (transcode_restartable): save/restore next_info and
      next_byte.
      sync readlen and in_p when invalid.

  Modified files:
    trunk/ChangeLog
    trunk/transcode.c
    trunk/transcode_data.h

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 18453)
+++ ChangeLog	(revision 18454)
@@ -1,3 +1,11 @@
+Sat Aug  9 16:33:21 2008  Tanaka Akira  <akr@f...>
+
+	* transcode_data.h (rb_transcoding): new fields: next_info and next_byte.
+
+	* transcode.c (transcode_restartable): save/restore next_info and
+	  next_byte.
+	  sync readlen and in_p when invalid.
+
 Sat Aug  9 15:10:15 2008  Tanaka Akira  <akr@f...>
 
 	* transcode.c (transcode_restartable): my_transcoder argument removed.
Index: transcode_data.h
===================================================================
--- transcode_data.h	(revision 18453)
+++ transcode_data.h	(revision 18454)
@@ -66,6 +66,8 @@
 
     int resume_position;
     const BYTE_LOOKUP *next_table;
+    VALUE next_info;
+    unsigned char next_byte;
     int readlen;
     union {
         unsigned char ary[8]; /* max_input <= sizeof(ary) */
Index: transcode.c
===================================================================
--- transcode.c	(revision 18453)
+++ transcode.c	(revision 18454)
@@ -368,6 +368,8 @@
     unsigned char *out_p;
     int readlen;
     const BYTE_LOOKUP *next_table;
+    VALUE next_info;
+    unsigned char next_byte;
 
     unsigned char empty_buf;
     unsigned char *empty_ptr = &empty_buf;
@@ -386,6 +388,8 @@
     out_p = *out_pos;
     readlen = my_transcoding->readlen;
     next_table = my_transcoding->next_table;
+    next_info = my_transcoding->next_info;
+    next_byte = my_transcoding->next_byte;
 
 #define SUSPEND(ret, num) \
     do { \
@@ -399,6 +403,8 @@
         *out_pos = out_p; \
         my_transcoding->readlen = readlen; \
         my_transcoding->next_table = next_table; \
+        my_transcoding->next_info = next_info; \
+        my_transcoding->next_byte = next_byte; \
         return ret; \
         resume_label ## num:; \
     } while (0)
@@ -422,9 +428,6 @@
     }
 
     while (1) {
-        unsigned char next_byte;
-        VALUE next_info;
-
         if (in_stop <= in_p) {
             if (!(opt & PARTIAL_INPUT))
                 break;
@@ -460,7 +463,6 @@
             readlen++;
 	    next_table = (const BYTE_LOOKUP *)next_info;
 	    goto follow_byte;
-	    /* maybe rewrite the following cases to use fallthrough???? */
 	  case ZERObt: /* drop input */
 	    continue;
 	  case ONEbt:
@@ -509,21 +511,32 @@
             }
 	  case INVALID:
             {
+                int step;
                 if (readlen <= unitlen) {
                     while ((opt & PARTIAL_INPUT) && readlen + (in_stop - in_p) < unitlen) {
-                        readlen += in_stop - in_p;
+                        step = in_stop - in_p;
+                        readlen += step;
                         in_p = in_stop;
                         SUSPEND(transcode_ibuf_empty, 8);
                     }
-                    if (readlen + (in_stop - in_p) <= unitlen)
+                    if (readlen + (in_stop - in_p) <= unitlen) {
+                        step = in_stop - in_p;
+                        readlen += step;
                         in_p = in_stop;
-                    else
-                        in_p += unitlen - readlen;
+                    }
+                    else {
+                        step = unitlen - readlen;
+                        readlen = unitlen;
+                        in_p += step;
+                    }
                 }
                 else {
-                    /* xxx: possibly in_p is lesser than *in_pos
+                    /* xxx: step may be negative.
+                     * possibly in_p is lesser than *in_pos.
                      * caller may want to access readbuf.  */
-                    in_p += ((readlen - 1) / unitlen) * unitlen - readlen;
+                    step = ((readlen - 1) / unitlen) * unitlen - readlen;
+                    in_p += step;
+                    readlen += step;
                 }
                 goto invalid;
             }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]