aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog13
-rw-r--r--transcode.c31
-rw-r--r--transcode_data.h3
3 files changed, 30 insertions, 17 deletions
diff --git a/ChangeLog b/ChangeLog
index e9835f94c3..21158917d6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+Sat Aug 9 22:05:29 2008 Tanaka Akira <akr@fsij.org>
+
+ * transcode.c (transcode_loop): take destination and resize function
+ as parameters.
+ (more_output_buffer): ditto.
+ (str_transcoding_resize): argument changed from rb_transcoding* to
+ VALUE.
+ (str_transcode): call transcode_loop with destination string and its
+ resize function.
+
+ * transcode_data.h (rb_transcoding): move ruby_string_dest and
+ flush_func to transcode_loop parameters.
+
Sat Aug 9 21:29:45 2008 NARUSE, Yui <naruse@ruby-lang.org>
* common.mk: encs depend on transdb.h
diff --git a/transcode.c b/transcode.c
index 3b47534d5f..369f04a625 100644
--- a/transcode.c
+++ b/transcode.c
@@ -559,6 +559,8 @@ transcode_restartable(rb_transcoding *tc,
static void
more_output_buffer(
+ VALUE destination,
+ unsigned char *(*resize_destination)(VALUE, int, int),
rb_transcoding *my_transcoding,
unsigned char **out_start_ptr,
unsigned char **out_pos,
@@ -566,7 +568,7 @@ more_output_buffer(
{
size_t len = (*out_pos - *out_start_ptr);
size_t new_len = (len + my_transcoding->transcoder->max_output) * 2;
- *out_start_ptr = (*my_transcoding->flush_func)(my_transcoding, len, new_len);
+ *out_start_ptr = resize_destination(destination, len, new_len);
*out_pos = *out_start_ptr + len;
*out_stop_ptr = *out_start_ptr + new_len;
}
@@ -575,6 +577,8 @@ more_output_buffer(
static void
transcode_loop(const unsigned char **in_pos, unsigned char **out_pos,
const unsigned char *in_stop, unsigned char *out_stop,
+ VALUE destination,
+ unsigned char *(*resize_destination)(VALUE, int, int),
rb_transcoding *my_transcoding,
const int opt)
{
@@ -606,7 +610,7 @@ resume:
}
else if (opt&INVALID_REPLACE) {
if (out_stop - *out_pos < my_transcoder->max_output)
- more_output_buffer(my_transcoding, &out_start, out_pos, &out_stop);
+ more_output_buffer(destination, resize_destination, my_transcoding, &out_start, out_pos, &out_stop);
output_replacement_character(out_pos, rb_enc_find(my_transcoder->to_encoding));
goto resume;
}
@@ -622,7 +626,7 @@ resume:
}
else if (opt&UNDEF_REPLACE) {
if (out_stop - *out_pos < my_transcoder->max_output)
- more_output_buffer(my_transcoding, &out_start, out_pos, &out_stop);
+ more_output_buffer(destination, resize_destination, my_transcoding, &out_start, out_pos, &out_stop);
output_replacement_character(out_pos, rb_enc_find(my_transcoder->to_encoding));
goto resume;
}
@@ -630,7 +634,7 @@ resume:
rb_raise(TRANSCODE_ERROR, "conversion undefined for byte sequence (maybe invalid byte sequence)");
}
if (ret == transcode_obuf_full) {
- more_output_buffer(my_transcoding, &out_start, out_pos, &out_stop);
+ more_output_buffer(destination, resize_destination, my_transcoding, &out_start, out_pos, &out_stop);
goto resume;
}
@@ -643,6 +647,8 @@ resume:
static void
transcode_loop(const unsigned char **in_pos, unsigned char **out_pos,
const unsigned char *in_stop, unsigned char *out_stop,
+ VALUE destination,
+ unsigned char *(*resize_destination)(VALUE, struct rb_transcoding*, int, int),
rb_transcoding *my_transcoding,
const int opt)
{
@@ -694,7 +700,7 @@ transcode_loop(const unsigned char **in_pos, unsigned char **out_pos,
}
else if (opt&INVALID_REPLACE) {
if (out_stop - *out_pos < my_transcoder->max_output)
- more_output_buffer(my_transcoding, &out_start, out_pos, &out_stop);
+ more_output_buffer(destination, resize_destination, my_transcoding, &out_start, out_pos, &out_stop);
output_replacement_character(out_pos, rb_enc_find(my_transcoder->to_encoding));
break;
}
@@ -711,7 +717,7 @@ transcode_loop(const unsigned char **in_pos, unsigned char **out_pos,
}
else if (opt&UNDEF_REPLACE) {
if (out_stop - *out_pos < my_transcoder->max_output)
- more_output_buffer(my_transcoding, &out_start, out_pos, &out_stop);
+ more_output_buffer(destination, resize_destination, my_transcoding, &out_start, out_pos, &out_stop);
output_replacement_character(out_pos, rb_enc_find(my_transcoder->to_encoding));
break;
}
@@ -720,7 +726,7 @@ transcode_loop(const unsigned char **in_pos, unsigned char **out_pos,
break;
case transcode_obuf_full:
- more_output_buffer(my_transcoding, &out_start, out_pos, &out_stop);
+ more_output_buffer(destination, resize_destination, my_transcoding, &out_start, out_pos, &out_stop);
break;
case transcode_ibuf_empty:
@@ -743,11 +749,10 @@ transcode_loop(const unsigned char **in_pos, unsigned char **out_pos,
*/
static unsigned char *
-str_transcoding_resize(rb_transcoding *my_transcoding, int len, int new_len)
+str_transcoding_resize(VALUE destination, int len, int new_len)
{
- VALUE dest_string = my_transcoding->ruby_string_dest;
- rb_str_resize(dest_string, new_len);
- return (unsigned char *)RSTRING_PTR(dest_string);
+ rb_str_resize(destination, new_len);
+ return (unsigned char *)RSTRING_PTR(destination);
}
static int
@@ -851,10 +856,8 @@ str_transcode(int argc, VALUE *argv, VALUE *self)
blen = slen + 30; /* len + margin */
dest = rb_str_tmp_new(blen);
bp = (unsigned char *)RSTRING_PTR(dest);
- my_transcoding.ruby_string_dest = dest;
- my_transcoding.flush_func = str_transcoding_resize;
- transcode_loop(&fromp, &bp, (sp+slen), (bp+blen), &my_transcoding, options);
+ transcode_loop(&fromp, &bp, (sp+slen), (bp+blen), dest, str_transcoding_resize, &my_transcoding, options);
if (fromp != sp+slen) {
rb_raise(rb_eArgError, "not fully converted, %"PRIdPTRDIFF" bytes left", sp+slen-fromp);
}
diff --git a/transcode_data.h b/transcode_data.h
index 12e24e71eb..ad20a0b9df 100644
--- a/transcode_data.h
+++ b/transcode_data.h
@@ -60,9 +60,6 @@ typedef struct byte_lookup {
/* may carry conversion state (e.g. for iso-2022-jp) */
typedef struct rb_transcoding {
const struct rb_transcoder *transcoder;
- VALUE ruby_string_dest; /* the String used as the conversion destination,
- or NULL if something else is being converted */
- unsigned char *(*flush_func)(struct rb_transcoding*, int, int);
int resume_position;
const BYTE_LOOKUP *next_table;