summaryrefslogtreecommitdiff
path: root/transcode_data.h
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-03 14:12:06 (GMT)
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-03 14:12:06 (GMT)
commitf6441bf61cd4244aca5f465d262baf31b8872ac2 (patch)
tree57787744890d4ac6db62bbcf44b12e738f34eb62 /transcode_data.h
parentfce093432eadc191b3647f116a9c2f6748efda3e (diff)
* transcode_data.h (rb_transcoding): remove stateful field.
add state field. (TRANSCODING_STATE): defined. (rb_transcoder): add fields: state_size, state_init_func, state_fini_func. change rb_transcoding* argument to void*. * transcode.c (transcode_restartable0): use TRANSCODING_STATE for first arguments of transcoder functions. (rb_transcoding_open_by_transcoder): initialize state field. (rb_transcoding_close): finalize state field. * tool/transcode-tblgen.rb: provide state size/init/fini. * enc/trans/newline.trans (universal_newline_init): defined. (fun_so_universal_newline): take void* as a state pointer. (rb_universal_newline): provide state size/init/fini. (rb_crlf_newline): ditto. (rb_cr_newline): ditto. * enc/trans/iso2022.trans (iso2022jp_init): defined. (fun_si_iso2022jp_to_eucjp): take void* as a state pointer. (fun_so_iso2022jp_to_eucjp): ditto. (fun_so_eucjp_to_iso2022jp): ditto. (iso2022jp_reset_sequence_size): ditto. (finish_eucjp_to_iso2022jp): ditto. (rb_ISO_2022_JP_to_EUC_JP): provide state size/init/fini. (rb_EUC_JP_to_ISO_2022_JP): ditto. * enc/trans/utf_16_32.trans (fun_so_from_utf_16be): take void* as a state pointer. (fun_so_to_utf_16be): ditto. (fun_so_from_utf_16le): ditto. (fun_so_to_utf_16le): ditto. (fun_so_from_utf_32be): ditto. (fun_so_to_utf_32be): ditto. (fun_so_from_utf_32le): ditto. (fun_so_to_utf_32le): ditto. (rb_from_UTF_16BE): provide state size/init/fini. (rb_to_UTF_16BE): ditto. (rb_from_UTF_16LE): ditto. (rb_to_UTF_16LE): ditto. (rb_from_UTF_32BE): ditto. (rb_to_UTF_32BE): ditto. (rb_from_UTF_32LE): ditto. (rb_to_UTF_32LE): ditto. * enc/trans/japanese.trans (fun_so_eucjp2sjis): take void* as a state pointer. (fun_so_sjis2eucjp): ditto. (rb_eucjp2sjis): provide state size/init/fini. (rb_sjis2eucjp): provide state size/init/fini. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19096 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'transcode_data.h')
-rw-r--r--transcode_data.h24
1 files changed, 16 insertions, 8 deletions
diff --git a/transcode_data.h b/transcode_data.h
index 6081aec..a7f1db0 100644
--- a/transcode_data.h
+++ b/transcode_data.h
@@ -90,7 +90,7 @@ typedef struct rb_transcoding {
unsigned char *ptr; /* length: max_output */
} writebuf;
- unsigned char stateful[256]; /* opaque data for stateful encoding */
+ void *state; /* opaque data for stateful encoding */
} rb_transcoding;
#define TRANSCODING_READBUF(tc) \
((tc)->transcoder->max_input <= sizeof((tc)->readbuf.ary) ? \
@@ -100,6 +100,11 @@ typedef struct rb_transcoding {
((tc)->transcoder->max_output <= sizeof((tc)->writebuf.ary) ? \
(tc)->writebuf.ary : \
(tc)->writebuf.ptr)
+#define TRANSCODING_STATE_EMBED_MAX sizeof(void *)
+#define TRANSCODING_STATE(tc) \
+ ((tc)->transcoder->state_size <= sizeof((tc)->state) ? \
+ (void *)&(tc)->state : \
+ (tc)->state)
/* static structure, one per supported encoding pair */
struct rb_transcoder {
@@ -115,13 +120,16 @@ struct rb_transcoder {
int max_input;
int max_output;
rb_transcoder_stateful_type_t stateful_type;
- VALUE (*func_ii)(rb_transcoding*, VALUE); /* info -> info */
- VALUE (*func_si)(rb_transcoding*, const unsigned char*, size_t); /* start -> info */
- int (*func_io)(rb_transcoding*, VALUE, const unsigned char*); /* info -> output */
- int (*func_so)(rb_transcoding*, const unsigned char*, size_t, unsigned char*); /* start -> output */
- int (*finish_func)(rb_transcoding*, unsigned char*); /* -> output */
- int (*resetsize_func)(rb_transcoding*); /* -> len */
- int (*resetstate_func)(rb_transcoding*, unsigned char*); /* -> output */
+ size_t state_size;
+ int (*state_init_func)(void*); /* 0:success !=0:failure(errno) */
+ int (*state_fini_func)(void*); /* 0:success !=0:failure(errno) */
+ VALUE (*func_ii)(void*, VALUE); /* info -> info */
+ VALUE (*func_si)(void*, const unsigned char*, size_t); /* start -> info */
+ int (*func_io)(void*, VALUE, const unsigned char*); /* info -> output */
+ int (*func_so)(void*, const unsigned char*, size_t, unsigned char*); /* start -> output */
+ int (*finish_func)(void*, unsigned char*); /* -> output */
+ int (*resetsize_func)(void*); /* -> len */
+ int (*resetstate_func)(void*, unsigned char*); /* -> output */
};
void rb_declare_transcoder(const char *enc1, const char *enc2, const char *lib);