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

* transcode_data.h: output function takes output buffer size.

* transcode.c: give output buffer size for output functions.

* enc/trans/newline.trans: follow the type change.

* enc/trans/escape.trans: ditto.

* enc/trans/utf_16_32.trans: ditto.

* enc/trans/iso2022.trans: ditto.

* enc/trans/japanese.trans: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19350 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2008-09-14 18:06:20 +00:00
parent 2f67b43aec
commit a3c8c0adec
8 changed files with 59 additions and 29 deletions

View file

@ -1,3 +1,19 @@
Mon Sep 15 03:04:29 2008 Tanaka Akira <akr@fsij.org>
* transcode_data.h: output function takes output buffer size.
* transcode.c: give output buffer size for output functions.
* enc/trans/newline.trans: follow the type change.
* enc/trans/escape.trans: ditto.
* enc/trans/utf_16_32.trans: ditto.
* enc/trans/iso2022.trans: ditto.
* enc/trans/japanese.trans: ditto.
Mon Sep 15 02:37:19 2008 Nobuyoshi Nakada <nobu@ruby-lang.org> Mon Sep 15 02:37:19 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* transcode.c (str_encode): returns duplicated string if nothing * transcode.c (str_encode): returns duplicated string if nothing

View file

@ -44,7 +44,7 @@ escape_xml_attr_quote_init(void *statep)
} }
static int static int
fun_so_escape_xml_attr_quote(void *statep, const unsigned char *s, size_t l, unsigned char *o) fun_so_escape_xml_attr_quote(void *statep, const unsigned char *s, size_t l, unsigned char *o, size_t osize)
{ {
unsigned char *sp = statep; unsigned char *sp = statep;
int n = 0; int n = 0;
@ -57,7 +57,7 @@ fun_so_escape_xml_attr_quote(void *statep, const unsigned char *s, size_t l, uns
} }
static int static int
escape_xml_attr_quote_finish(void *statep, unsigned char *o) escape_xml_attr_quote_finish(void *statep, unsigned char *o, size_t osize)
{ {
unsigned char *sp = statep; unsigned char *sp = statep;
int n = 0; int n = 0;

View file

@ -71,7 +71,7 @@ fun_si_iso2022jp_decoder(void *statep, const unsigned char *s, size_t l)
} }
static int static int
fun_so_iso2022jp_decoder(void *statep, const unsigned char *s, size_t l, unsigned char* o) fun_so_iso2022jp_decoder(void *statep, const unsigned char *s, size_t l, unsigned char* o, size_t osize)
{ {
unsigned char *sp = statep; unsigned char *sp = statep;
if (s[0] == 0x1b) { if (s[0] == 0x1b) {
@ -120,7 +120,7 @@ rb_iso2022jp_decoder = {
}; };
static int static int
fun_so_iso2022jp_encoder(void *statep, const unsigned char *s, size_t l, unsigned char *o) fun_so_iso2022jp_encoder(void *statep, const unsigned char *s, size_t l, unsigned char *o, size_t osize)
{ {
unsigned char *sp = statep; unsigned char *sp = statep;
unsigned char *output0 = o; unsigned char *output0 = o;
@ -173,7 +173,7 @@ iso2022jp_encoder_reset_sequence_size(void *statep)
} }
static int static int
finish_iso2022jp_encoder(void *statep, unsigned char *o) finish_iso2022jp_encoder(void *statep, unsigned char *o, size_t osize)
{ {
unsigned char *sp = statep; unsigned char *sp = statep;
unsigned char *output0 = o; unsigned char *output0 = o;
@ -204,7 +204,7 @@ rb_iso2022jp_encoder = {
}; };
static int static int
fun_so_stateless_iso2022jp_to_eucjp(void *statep, const unsigned char *s, size_t l, unsigned char *o) fun_so_stateless_iso2022jp_to_eucjp(void *statep, const unsigned char *s, size_t l, unsigned char *o, size_t osize)
{ {
o[0] = s[1]; o[0] = s[1];
o[1] = s[2]; o[1] = s[2];
@ -224,7 +224,7 @@ rb_stateless_iso2022jp_to_eucjp = {
}; };
static int static int
fun_so_eucjp_to_stateless_iso2022jp(void *statep, const unsigned char *s, size_t l, unsigned char *o) fun_so_eucjp_to_stateless_iso2022jp(void *statep, const unsigned char *s, size_t l, unsigned char *o, size_t osize)
{ {
o[0] = EMACS_MULE_LEADING_CODE_JISX0208_1983; o[0] = EMACS_MULE_LEADING_CODE_JISX0208_1983;
o[1] = s[0]; o[1] = s[0];

View file

@ -20,7 +20,7 @@
<%= transcode_generated_code %> <%= transcode_generated_code %>
static int static int
fun_so_eucjp2sjis(void *statep, const unsigned char *s, size_t l, unsigned char *o) fun_so_eucjp2sjis(void *statep, const unsigned char *s, size_t l, unsigned char *o, size_t osize)
{ {
if (s[0] == 0x8e) { if (s[0] == 0x8e) {
o[0] = s[1]; o[0] = s[1];
@ -41,7 +41,7 @@ fun_so_eucjp2sjis(void *statep, const unsigned char *s, size_t l, unsigned char
} }
static int static int
fun_so_sjis2eucjp(void *statep, const unsigned char *s, size_t l, unsigned char *o) fun_so_sjis2eucjp(void *statep, const unsigned char *s, size_t l, unsigned char *o, size_t osize)
{ {
if (l == 1) { if (l == 1) {
o[0] = '\x8e'; o[0] = '\x8e';

View file

@ -41,7 +41,7 @@ universal_newline_init(void *statep)
} }
static int static int
fun_so_universal_newline(void *statep, const unsigned char *s, size_t l, unsigned char *o) fun_so_universal_newline(void *statep, const unsigned char *s, size_t l, unsigned char *o, size_t osize)
{ {
unsigned char *sp = statep; unsigned char *sp = statep;
int len; int len;
@ -76,7 +76,7 @@ fun_so_universal_newline(void *statep, const unsigned char *s, size_t l, unsigne
} }
static int static int
universal_newline_finish(void *statep, unsigned char *o) universal_newline_finish(void *statep, unsigned char *o, size_t osize)
{ {
unsigned char *sp = statep; unsigned char *sp = statep;
if (STATE == JUST_AFTER_CR) if (STATE == JUST_AFTER_CR)

View file

@ -38,7 +38,7 @@
<%= transcode_generated_code %> <%= transcode_generated_code %>
static int static int
fun_so_from_utf_16be(void *statep, const unsigned char *s, size_t l, unsigned char *o) fun_so_from_utf_16be(void *statep, const unsigned char *s, size_t l, unsigned char *o, size_t osize)
{ {
if (!s[0] && s[1]<0x80) { if (!s[0] && s[1]<0x80) {
o[0] = s[1]; o[0] = s[1];
@ -66,7 +66,7 @@ fun_so_from_utf_16be(void *statep, const unsigned char *s, size_t l, unsigned ch
} }
static int static int
fun_so_to_utf_16be(void *statep, const unsigned char *s, size_t l, unsigned char *o) fun_so_to_utf_16be(void *statep, const unsigned char *s, size_t l, unsigned char *o, size_t osize)
{ {
if (!(s[0]&0x80)) { if (!(s[0]&0x80)) {
o[0] = 0x00; o[0] = 0x00;
@ -94,7 +94,7 @@ fun_so_to_utf_16be(void *statep, const unsigned char *s, size_t l, unsigned char
} }
static int static int
fun_so_from_utf_16le(void *statep, const unsigned char *s, size_t l, unsigned char *o) fun_so_from_utf_16le(void *statep, const unsigned char *s, size_t l, unsigned char *o, size_t osize)
{ {
if (!s[1] && s[0]<0x80) { if (!s[1] && s[0]<0x80) {
o[0] = s[0]; o[0] = s[0];
@ -122,7 +122,7 @@ fun_so_from_utf_16le(void *statep, const unsigned char *s, size_t l, unsigned ch
} }
static int static int
fun_so_to_utf_16le(void *statep, const unsigned char *s, size_t l, unsigned char *o) fun_so_to_utf_16le(void *statep, const unsigned char *s, size_t l, unsigned char *o, size_t osize)
{ {
if (!(s[0]&0x80)) { if (!(s[0]&0x80)) {
o[1] = 0x00; o[1] = 0x00;
@ -150,7 +150,7 @@ fun_so_to_utf_16le(void *statep, const unsigned char *s, size_t l, unsigned char
} }
static int static int
fun_so_from_utf_32be(void *statep, const unsigned char *s, size_t l, unsigned char *o) fun_so_from_utf_32be(void *statep, const unsigned char *s, size_t l, unsigned char *o, size_t osize)
{ {
if (!s[1]) { if (!s[1]) {
if (s[2]==0 && s[3]<0x80) { if (s[2]==0 && s[3]<0x80) {
@ -179,7 +179,7 @@ fun_so_from_utf_32be(void *statep, const unsigned char *s, size_t l, unsigned ch
} }
static int static int
fun_so_to_utf_32be(void *statep, const unsigned char *s, size_t l, unsigned char *o) fun_so_to_utf_32be(void *statep, const unsigned char *s, size_t l, unsigned char *o, size_t osize)
{ {
o[0] = 0; o[0] = 0;
if (!(s[0]&0x80)) { if (!(s[0]&0x80)) {
@ -205,7 +205,7 @@ fun_so_to_utf_32be(void *statep, const unsigned char *s, size_t l, unsigned char
} }
static int static int
fun_so_from_utf_32le(void *statep, const unsigned char *s, size_t l, unsigned char *o) fun_so_from_utf_32le(void *statep, const unsigned char *s, size_t l, unsigned char *o, size_t osize)
{ {
if (!s[2]) { if (!s[2]) {
if (s[1]==0 && s[0]<0x80) { if (s[1]==0 && s[0]<0x80) {
@ -234,7 +234,7 @@ fun_so_from_utf_32le(void *statep, const unsigned char *s, size_t l, unsigned ch
} }
static int static int
fun_so_to_utf_32le(void *statep, const unsigned char *s, size_t l, unsigned char *o) fun_so_to_utf_32le(void *statep, const unsigned char *s, size_t l, unsigned char *o, size_t osize)
{ {
o[3] = 0; o[3] = 0;
if (!(s[0]&0x80)) { if (!(s[0]&0x80)) {

View file

@ -80,6 +80,10 @@ typedef struct rb_transcoding {
((tc)->transcoder->max_output <= sizeof((tc)->writebuf.ary) ? \ ((tc)->transcoder->max_output <= sizeof((tc)->writebuf.ary) ? \
(tc)->writebuf.ary : \ (tc)->writebuf.ary : \
(tc)->writebuf.ptr) (tc)->writebuf.ptr)
#define TRANSCODING_WRITEBUF_SIZE(tc) \
((tc)->transcoder->max_output <= sizeof((tc)->writebuf.ary) ? \
sizeof((tc)->writebuf.ary) : \
(tc)->transcoder->max_output)
#define TRANSCODING_STATE_EMBED_MAX sizeof(union rb_transcoding_state_t) #define TRANSCODING_STATE_EMBED_MAX sizeof(union rb_transcoding_state_t)
#define TRANSCODING_STATE(tc) \ #define TRANSCODING_STATE(tc) \
((tc)->transcoder->state_size <= sizeof((tc)->state) ? \ ((tc)->transcoder->state_size <= sizeof((tc)->state) ? \
@ -600,9 +604,13 @@ transcode_restartable0(const unsigned char **in_pos, unsigned char **out_pos,
case FUNio: case FUNio:
SUSPEND_OBUF(13); SUSPEND_OBUF(13);
if (tr->max_output <= out_stop - out_p) if (tr->max_output <= out_stop - out_p)
out_p += (VALUE)(*tr->func_io)(TRANSCODING_STATE(tc), next_info, out_p); out_p += (VALUE)(*tr->func_io)(TRANSCODING_STATE(tc),
next_info,
out_p, out_stop - out_p);
else { else {
writebuf_len = (VALUE)(*tr->func_io)(TRANSCODING_STATE(tc), next_info, TRANSCODING_WRITEBUF(tc)); writebuf_len = (VALUE)(*tr->func_io)(TRANSCODING_STATE(tc),
next_info,
TRANSCODING_WRITEBUF(tc), TRANSCODING_WRITEBUF_SIZE(tc));
writebuf_off = 0; writebuf_off = 0;
while (writebuf_off < writebuf_len) { while (writebuf_off < writebuf_len) {
SUSPEND_OBUF(20); SUSPEND_OBUF(20);
@ -617,11 +625,15 @@ transcode_restartable0(const unsigned char **in_pos, unsigned char **out_pos,
SUSPEND_OBUF(14); SUSPEND_OBUF(14);
if (tr->max_output <= out_stop - out_p) { if (tr->max_output <= out_stop - out_p) {
char_start = transcode_char_start(tc, *in_pos, inchar_start, in_p, &char_len); char_start = transcode_char_start(tc, *in_pos, inchar_start, in_p, &char_len);
out_p += (VALUE)(*tr->func_so)(TRANSCODING_STATE(tc), char_start, (size_t)char_len, out_p); out_p += (VALUE)(*tr->func_so)(TRANSCODING_STATE(tc),
char_start, (size_t)char_len,
out_p, out_stop - out_p);
} }
else { else {
char_start = transcode_char_start(tc, *in_pos, inchar_start, in_p, &char_len); char_start = transcode_char_start(tc, *in_pos, inchar_start, in_p, &char_len);
writebuf_len = (VALUE)(*tr->func_so)(TRANSCODING_STATE(tc), char_start, (size_t)char_len, TRANSCODING_WRITEBUF(tc)); writebuf_len = (VALUE)(*tr->func_so)(TRANSCODING_STATE(tc),
char_start, (size_t)char_len,
TRANSCODING_WRITEBUF(tc), TRANSCODING_WRITEBUF_SIZE(tc));
writebuf_off = 0; writebuf_off = 0;
while (writebuf_off < writebuf_len) { while (writebuf_off < writebuf_len) {
SUSPEND_OBUF(22); SUSPEND_OBUF(22);
@ -675,10 +687,12 @@ transcode_restartable0(const unsigned char **in_pos, unsigned char **out_pos,
if (tr->finish_func) { if (tr->finish_func) {
SUSPEND_OBUF(4); SUSPEND_OBUF(4);
if (tr->max_output <= out_stop - out_p) { if (tr->max_output <= out_stop - out_p) {
out_p += tr->finish_func(TRANSCODING_STATE(tc), out_p); out_p += tr->finish_func(TRANSCODING_STATE(tc),
out_p, out_stop - out_p);
} }
else { else {
writebuf_len = tr->finish_func(TRANSCODING_STATE(tc), TRANSCODING_WRITEBUF(tc)); writebuf_len = tr->finish_func(TRANSCODING_STATE(tc),
TRANSCODING_WRITEBUF(tc), TRANSCODING_WRITEBUF_SIZE(tc));
writebuf_off = 0; writebuf_off = 0;
while (writebuf_off < writebuf_len) { while (writebuf_off < writebuf_len) {
SUSPEND_OBUF(23); SUSPEND_OBUF(23);

View file

@ -84,11 +84,11 @@ struct rb_transcoder {
int (*state_fini_func)(void*); /* ret==0:success ret!=0:failure(errno) */ int (*state_fini_func)(void*); /* ret==0:success ret!=0:failure(errno) */
VALUE (*func_ii)(void*, VALUE); /* info -> info */ VALUE (*func_ii)(void*, VALUE); /* info -> info */
VALUE (*func_si)(void*, const unsigned char*, size_t); /* start -> info */ VALUE (*func_si)(void*, const unsigned char*, size_t); /* start -> info */
int (*func_io)(void*, VALUE, const unsigned char*); /* info -> output */ int (*func_io)(void*, VALUE, const unsigned char*, size_t); /* info -> output */
int (*func_so)(void*, const unsigned char*, size_t, unsigned char*); /* start -> output */ int (*func_so)(void*, const unsigned char*, size_t, unsigned char*, size_t); /* start -> output */
int (*finish_func)(void*, unsigned char*); /* -> output */ int (*finish_func)(void*, unsigned char*, size_t); /* -> output */
int (*resetsize_func)(void*); /* -> len */ int (*resetsize_func)(void*); /* -> len */
int (*resetstate_func)(void*, unsigned char*); /* -> output */ int (*resetstate_func)(void*, unsigned char*, size_t); /* -> output */
}; };
void rb_declare_transcoder(const char *enc1, const char *enc2, const char *lib); void rb_declare_transcoder(const char *enc1, const char *enc2, const char *lib);