aboutsummaryrefslogtreecommitdiffstats
path: root/transcode.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-10 13:37:44 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-10 13:37:44 +0000
commitbadd9f1efca296be0f1dce0491f8c7662434da5f (patch)
treea3714b04da9625a105c359d348c083a60f3f75a7 /transcode.c
parent4d763fb8eedb279cb8ccd1e6757ca94f9ac2d7f2 (diff)
downloadruby-badd9f1efca296be0f1dce0491f8c7662434da5f.tar.gz
* transcode.c (transcode_restartable0): invalid handling simplified.
(transcode_restartable): use PARTIAL_INPUT for converting buffered input. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18476 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'transcode.c')
-rw-r--r--transcode.c48
1 files changed, 17 insertions, 31 deletions
diff --git a/transcode.c b/transcode.c
index 3c1858d67d..317781b2ac 100644
--- a/transcode.c
+++ b/transcode.c
@@ -533,40 +533,26 @@ transcode_restartable0(const unsigned char **in_pos, unsigned char **out_pos,
break;
}
case INVALID:
- {
- if (tc->readlen + (in_p - inchar_start) <= unitlen) {
- while ((opt & PARTIAL_INPUT) && tc->readlen + (in_stop - inchar_start) < unitlen) {
- in_p = in_stop;
- SUSPEND(transcode_ibuf_empty, 8);
- }
- if (tc->readlen + (in_stop - inchar_start) <= unitlen) {
- in_p = in_stop;
- }
- else {
- in_p = inchar_start + (unitlen - tc->readlen);
- }
+ if (tc->readlen + (in_p - inchar_start) <= unitlen) {
+ while ((opt & PARTIAL_INPUT) && tc->readlen + (in_stop - inchar_start) < unitlen) {
+ in_p = in_stop;
+ SUSPEND(transcode_ibuf_empty, 8);
+ }
+ if (tc->readlen + (in_stop - inchar_start) <= unitlen) {
+ in_p = in_stop;
}
else {
- int found_len; /* including the last byte which cuases invalid */
- int invalid_len;
- int step;
- found_len = tc->readlen + (in_p - inchar_start);
- invalid_len = ((found_len - 1) / unitlen) * unitlen;
- step = invalid_len - found_len;
- if (step < -1) {
- if (-step <= in_p - *in_pos) {
- in_p += step;
- }
- else {
- feedlen = -step;
- }
- }
- else {
- in_p += step;
- }
+ in_p = inchar_start + (unitlen - tc->readlen);
}
- goto invalid;
}
+ else {
+ int invalid_len; /* including the last byte which causes invalid */
+ int discard_len;
+ invalid_len = tc->readlen + (in_p - inchar_start);
+ discard_len = ((invalid_len - 1) / unitlen) * unitlen;
+ feedlen = invalid_len - discard_len;
+ }
+ goto invalid;
case UNDEF:
goto undef;
}
@@ -608,7 +594,7 @@ transcode_restartable(const unsigned char **in_pos, unsigned char **out_pos,
MEMCPY(feed_buf, TRANSCODING_READBUF(tc) + tc->readlen,
unsigned char, tc->feedlen);
tc->feedlen = 0;
- res = transcode_restartable0(&feed_pos, out_pos, feed_stop, out_stop, tc, opt);
+ res = transcode_restartable0(&feed_pos, out_pos, feed_stop, out_stop, tc, opt|PARTIAL_INPUT);
if (res != transcode_ibuf_empty) {
MEMCPY(TRANSCODING_READBUF(tc) + tc->readlen + tc->feedlen,
feed_pos, unsigned char, feed_stop - feed_pos);