1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18454 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2008-08-09 07:35:28 +00:00
parent ca3dd2d89e
commit 4bceda1125
3 changed files with 33 additions and 10 deletions

View file

@ -1,3 +1,11 @@
Sat Aug 9 16:33:21 2008 Tanaka Akira <akr@fsij.org>
* 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@fsij.org> Sat Aug 9 15:10:15 2008 Tanaka Akira <akr@fsij.org>
* transcode.c (transcode_restartable): my_transcoder argument removed. * transcode.c (transcode_restartable): my_transcoder argument removed.

View file

@ -368,6 +368,8 @@ transcode_restartable(const unsigned char **in_pos, unsigned char **out_pos,
unsigned char *out_p; unsigned char *out_p;
int readlen; int readlen;
const BYTE_LOOKUP *next_table; const BYTE_LOOKUP *next_table;
VALUE next_info;
unsigned char next_byte;
unsigned char empty_buf; unsigned char empty_buf;
unsigned char *empty_ptr = &empty_buf; unsigned char *empty_ptr = &empty_buf;
@ -386,6 +388,8 @@ transcode_restartable(const unsigned char **in_pos, unsigned char **out_pos,
out_p = *out_pos; out_p = *out_pos;
readlen = my_transcoding->readlen; readlen = my_transcoding->readlen;
next_table = my_transcoding->next_table; next_table = my_transcoding->next_table;
next_info = my_transcoding->next_info;
next_byte = my_transcoding->next_byte;
#define SUSPEND(ret, num) \ #define SUSPEND(ret, num) \
do { \ do { \
@ -399,6 +403,8 @@ transcode_restartable(const unsigned char **in_pos, unsigned char **out_pos,
*out_pos = out_p; \ *out_pos = out_p; \
my_transcoding->readlen = readlen; \ my_transcoding->readlen = readlen; \
my_transcoding->next_table = next_table; \ my_transcoding->next_table = next_table; \
my_transcoding->next_info = next_info; \
my_transcoding->next_byte = next_byte; \
return ret; \ return ret; \
resume_label ## num:; \ resume_label ## num:; \
} while (0) } while (0)
@ -422,9 +428,6 @@ transcode_restartable(const unsigned char **in_pos, unsigned char **out_pos,
} }
while (1) { while (1) {
unsigned char next_byte;
VALUE next_info;
if (in_stop <= in_p) { if (in_stop <= in_p) {
if (!(opt & PARTIAL_INPUT)) if (!(opt & PARTIAL_INPUT))
break; break;
@ -460,7 +463,6 @@ transcode_restartable(const unsigned char **in_pos, unsigned char **out_pos,
readlen++; readlen++;
next_table = (const BYTE_LOOKUP *)next_info; next_table = (const BYTE_LOOKUP *)next_info;
goto follow_byte; goto follow_byte;
/* maybe rewrite the following cases to use fallthrough???? */
case ZERObt: /* drop input */ case ZERObt: /* drop input */
continue; continue;
case ONEbt: case ONEbt:
@ -509,21 +511,32 @@ transcode_restartable(const unsigned char **in_pos, unsigned char **out_pos,
} }
case INVALID: case INVALID:
{ {
int step;
if (readlen <= unitlen) { if (readlen <= unitlen) {
while ((opt & PARTIAL_INPUT) && readlen + (in_stop - in_p) < 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; in_p = in_stop;
SUSPEND(transcode_ibuf_empty, 8); 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; in_p = in_stop;
else
in_p += unitlen - readlen;
} }
else { else {
/* xxx: possibly in_p is lesser than *in_pos step = unitlen - readlen;
readlen = unitlen;
in_p += step;
}
}
else {
/* xxx: step may be negative.
* possibly in_p is lesser than *in_pos.
* caller may want to access readbuf. */ * 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; goto invalid;
} }

View file

@ -66,6 +66,8 @@ typedef struct rb_transcoding {
int resume_position; int resume_position;
const BYTE_LOOKUP *next_table; const BYTE_LOOKUP *next_table;
VALUE next_info;
unsigned char next_byte;
int readlen; int readlen;
union { union {
unsigned char ary[8]; /* max_input <= sizeof(ary) */ unsigned char ary[8]; /* max_input <= sizeof(ary) */