From 752e053a1df0446b6ca20815b1976dd322d736bd Mon Sep 17 00:00:00 2001 From: akr Date: Mon, 1 Sep 2008 16:22:49 +0000 Subject: * transcode_data.h (BYTE_LOOKUP): change to uintptr_t array. (BYTE_LOOKUP_BASE): follow the type change. (BYTE_LOOKUP_INFO): ditto. (PType): ditto. (rb_transcoding): ditto. * tool/transcode-tblgen.rb: follow the type change. * transcode.c: ditto. * enc/trans/newline.trans: ditto. * enc/trans/iso2022.trans: ditto. * enc/trans/utf_16_32.trans: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19038 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 18 ++++++++++++++++++ enc/trans/iso2022.trans | 6 +++--- enc/trans/newline.trans | 6 +++--- enc/trans/utf_16_32.trans | 32 ++++++++++++++++---------------- tool/transcode-tblgen.rb | 12 +++++++----- transcode.c | 2 +- transcode_data.h | 15 ++++++--------- 7 files changed, 54 insertions(+), 37 deletions(-) diff --git a/ChangeLog b/ChangeLog index a26dff77ec..508daae436 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +Tue Sep 2 01:19:15 2008 Tanaka Akira + + * transcode_data.h (BYTE_LOOKUP): change to uintptr_t array. + (BYTE_LOOKUP_BASE): follow the type change. + (BYTE_LOOKUP_INFO): ditto. + (PType): ditto. + (rb_transcoding): ditto. + + * tool/transcode-tblgen.rb: follow the type change. + + * transcode.c: ditto. + + * enc/trans/newline.trans: ditto. + + * enc/trans/iso2022.trans: ditto. + + * enc/trans/utf_16_32.trans: ditto. + Mon Sep 1 23:32:46 2008 Tanaka Akira * transcode_data.h (BYTE_LOOKUP_BASE): abstract accessor for diff --git a/enc/trans/iso2022.trans b/enc/trans/iso2022.trans index 4340fa9b27..8a94d70040 100644 --- a/enc/trans/iso2022.trans +++ b/enc/trans/iso2022.trans @@ -33,7 +33,7 @@ fun_si_iso2022jp_to_eucjp(rb_transcoding* t, const unsigned char* s, size_t l) if (t->stateful[0] == 0) return (VALUE)NOMAP; else if (0x21 <= s[0] && s[0] <= 0x7e) - return (VALUE)&iso2022jp_to_eucjp_jisx0208_rest; + return (VALUE)iso2022jp_to_eucjp_jisx0208_rest; else return (VALUE)INVALID; } @@ -69,7 +69,7 @@ fun_so_iso2022jp_to_eucjp(rb_transcoding* t, const unsigned char* s, size_t l, u static const rb_transcoder rb_ISO_2022_JP_to_EUC_JP = { - "ISO-2022-JP", "EUC-JP", &iso2022jp_to_eucjp, + "ISO-2022-JP", "EUC-JP", iso2022jp_to_eucjp, 1, /* input_unit_length */ 3, /* max_input */ 3, /* max_output */ @@ -141,7 +141,7 @@ finish_eucjp_to_iso2022jp(rb_transcoding *t, unsigned char *o) static const rb_transcoder rb_EUC_JP_to_ISO_2022_JP = { - "EUC-JP", "ISO-2022-JP", &eucjp_to_iso2022jp, + "EUC-JP", "ISO-2022-JP", eucjp_to_iso2022jp, 1, /* input_unit_length */ 3, /* max_input */ 5, /* max_output */ diff --git a/enc/trans/newline.trans b/enc/trans/newline.trans index 5d6c9bf054..536cba108c 100644 --- a/enc/trans/newline.trans +++ b/enc/trans/newline.trans @@ -54,7 +54,7 @@ fun_so_universal_newline(rb_transcoding* t, const unsigned char* s, size_t l, un static const rb_transcoder rb_universal_newline = { - "universal_newline", "", &universal_newline, + "universal_newline", "", universal_newline, 1, /* input_unit_length */ 1, /* max_input */ 1, /* max_output */ @@ -64,7 +64,7 @@ rb_universal_newline = { static const rb_transcoder rb_crlf_newline = { - "", "crlf_newline", &crlf_newline, + "", "crlf_newline", crlf_newline, 1, /* input_unit_length */ 1, /* max_input */ 2, /* max_output */ @@ -74,7 +74,7 @@ rb_crlf_newline = { static const rb_transcoder rb_cr_newline = { - "", "cr_newline", &cr_newline, + "", "cr_newline", cr_newline, 1, /* input_unit_length */ 1, /* max_input */ 1, /* max_output */ diff --git a/enc/trans/utf_16_32.trans b/enc/trans/utf_16_32.trans index b71c289bae..2bbee65b7f 100644 --- a/enc/trans/utf_16_32.trans +++ b/enc/trans/utf_16_32.trans @@ -261,82 +261,82 @@ fun_so_to_utf_32le(rb_transcoding* t, const unsigned char* s, size_t l, unsigned static const rb_transcoder rb_from_UTF_16BE = { - "UTF-16BE", "UTF-8", &from_UTF_16BE, + "UTF-16BE", "UTF-8", from_UTF_16BE, 2, /* input_unit_length */ 4, /* max_input */ 4, /* max_output */ stateless_converter, /* stateful_type */ - NULL, NULL, NULL, &fun_so_from_utf_16be + NULL, NULL, NULL, fun_so_from_utf_16be }; static const rb_transcoder rb_to_UTF_16BE = { - "UTF-8", "UTF-16BE", &to_UTF_16BE, + "UTF-8", "UTF-16BE", to_UTF_16BE, 1, /* input_unit_length */ 4, /* max_input */ 4, /* max_output */ stateless_converter, /* stateful_type */ - NULL, NULL, NULL, &fun_so_to_utf_16be + NULL, NULL, NULL, fun_so_to_utf_16be }; static const rb_transcoder rb_from_UTF_16LE = { - "UTF-16LE", "UTF-8", &from_UTF_16LE, + "UTF-16LE", "UTF-8", from_UTF_16LE, 2, /* input_unit_length */ 4, /* max_input */ 4, /* max_output */ stateless_converter, /* stateful_type */ - NULL, NULL, NULL, &fun_so_from_utf_16le + NULL, NULL, NULL, fun_so_from_utf_16le }; static const rb_transcoder rb_to_UTF_16LE = { - "UTF-8", "UTF-16LE", &to_UTF_16BE, + "UTF-8", "UTF-16LE", to_UTF_16BE, 1, /* input_unit_length */ 4, /* max_input */ 4, /* max_output */ stateless_converter, /* stateful_type */ - NULL, NULL, NULL, &fun_so_to_utf_16le + NULL, NULL, NULL, fun_so_to_utf_16le }; static const rb_transcoder rb_from_UTF_32BE = { - "UTF-32BE", "UTF-8", &from_UTF_32BE, + "UTF-32BE", "UTF-8", from_UTF_32BE, 4, /* input_unit_length */ 4, /* max_input */ 4, /* max_output */ stateless_converter, /* stateful_type */ - NULL, NULL, NULL, &fun_so_from_utf_32be + NULL, NULL, NULL, fun_so_from_utf_32be }; static const rb_transcoder rb_to_UTF_32BE = { - "UTF-8", "UTF-32BE", &to_UTF_16BE, + "UTF-8", "UTF-32BE", to_UTF_16BE, 1, /* input_unit_length */ 4, /* max_input */ 4, /* max_output */ stateless_converter, /* stateful_type */ - NULL, NULL, NULL, &fun_so_to_utf_32be + NULL, NULL, NULL, fun_so_to_utf_32be }; static const rb_transcoder rb_from_UTF_32LE = { - "UTF-32LE", "UTF-8", &from_UTF_32LE, + "UTF-32LE", "UTF-8", from_UTF_32LE, 4, /* input_unit_length */ 4, /* max_input */ 4, /* max_output */ stateless_converter, /* stateful_type */ - NULL, NULL, NULL, &fun_so_from_utf_32le + NULL, NULL, NULL, fun_so_from_utf_32le }; static const rb_transcoder rb_to_UTF_32LE = { - "UTF-8", "UTF-32LE", &to_UTF_16BE, + "UTF-8", "UTF-32LE", to_UTF_16BE, 1, /* input_unit_length */ 4, /* max_input */ 4, /* max_output */ stateless_converter, /* stateful_type */ - NULL, NULL, NULL, &fun_so_to_utf_32le + NULL, NULL, NULL, fun_so_to_utf_32le }; void diff --git a/tool/transcode-tblgen.rb b/tool/transcode-tblgen.rb index 22587ac4f3..cdeb27f0fd 100644 --- a/tool/transcode-tblgen.rb +++ b/tool/transcode-tblgen.rb @@ -273,7 +273,7 @@ class ActionMap "o3(0x#$1,0x#$2,0x#$3)" when /\A([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])\z/i "o4(0x#$1,0x#$2,0x#$3,0x#$4)" - when /\A&/ # pointer to BYTE_LOOKUP structure + when /\A\/\*BYTE_LOOKUP\*\// # pointer to BYTE_LOOKUP structure info.to_s else raise "unexpected action: #{info.inspect}" @@ -347,8 +347,9 @@ End else infos_name = "#{name}_infos" infos_code = <<"End" -static const struct byte_lookup* const +static const uintptr_t #{infos_name}[#{infos.length}] = #{format_infos(infos)}; +\#define #{infos_name} ((uintptr_t)#{infos_name}) End InfosMemo[infos] = infos_name end @@ -356,9 +357,10 @@ End r = infos_code + <<"End" static const BYTE_LOOKUP #{name} = { - #{offsets_name}, + (uintptr_t)#{offsets_name}, #{infos_name} }; +\#define #{name} ((uintptr_t)#{name}) End words_code << r @@ -380,7 +382,7 @@ End else name_hint2 = nil name_hint2 = "#{name_hint}_#{'%02X' % byte}" if name_hint - table[byte] = "&" + rest.generate_node(bytes_code, words_code, name_hint2, rest_valid_encoding) + table[byte] = "/*BYTE_LOOKUP*/" + rest.generate_node(bytes_code, words_code, name_hint2, rest_valid_encoding) end } @@ -572,7 +574,7 @@ def transcode_tblgen(from, to, map) transcoder_code = <<"End" static const rb_transcoder #{transcoder_name} = { - #{c_esc from}, #{c_esc to}, &#{real_tree_name}, + #{c_esc from}, #{c_esc to}, #{real_tree_name}, #{input_unit_length}, /* input_unit_length */ #{max_input}, /* max_input */ #{max_output}, /* max_output */ diff --git a/transcode.c b/transcode.c index a67565e3e4..f4409a39ab 100644 --- a/transcode.c +++ b/transcode.c @@ -513,7 +513,7 @@ transcode_restartable0(const unsigned char **in_pos, unsigned char **out_pos, SUSPEND(econv_source_buffer_empty, 5); } next_byte = (unsigned char)*in_p++; - next_table = (const BYTE_LOOKUP *)next_info; + next_table = next_info; goto follow_byte; case ZERObt: /* drop input */ continue; diff --git a/transcode_data.h b/transcode_data.h index b705760273..8287cf66e0 100644 --- a/transcode_data.h +++ b/transcode_data.h @@ -16,17 +16,14 @@ typedef unsigned char base_element; -typedef struct byte_lookup { - const base_element *base; - const struct byte_lookup *const *info; -} BYTE_LOOKUP; +typedef uintptr_t BYTE_LOOKUP[2]; -#define BYTE_LOOKUP_BASE(bl) ((bl)->base) -#define BYTE_LOOKUP_INFO(bl) ((bl)->info) +#define BYTE_LOOKUP_BASE(bl) ((const base_element *)(((uintptr_t *)(bl))[0])) +#define BYTE_LOOKUP_INFO(bl) ((const struct byte_lookup *const *)(((uintptr_t *)(bl))[1])) #ifndef PType /* data file needs to treat this as a pointer, to remove warnings */ -#define PType (const BYTE_LOOKUP *) +#define PType (uintptr_t) #endif #define NOMAP (PType 0x01) /* single byte direct map */ @@ -76,7 +73,7 @@ typedef struct rb_transcoding { int flags; int resume_position; - const BYTE_LOOKUP *next_table; + uintptr_t next_table; VALUE next_info; unsigned char next_byte; @@ -109,7 +106,7 @@ typedef struct rb_transcoding { struct rb_transcoder { const char *from_encoding; const char *to_encoding; - const BYTE_LOOKUP *conv_tree_start; + uintptr_t conv_tree_start; int input_unit_length; int max_input; int max_output; -- cgit v1.2.3