From bb8ddbe8471d4d1a66b79956b7697f947fb0a61d Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 13 Jan 2008 09:41:50 +0000 Subject: [PATCH] * encoding.c (Init_Encoding): moved initialization from encdb.h. * enc/make_encdb.rb (enc_name_list): constified. * enc/make_encdb.rb (enc_init_db): moved some functions to encoding.c. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15023 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 ++++++++ enc/make_encdb.rb | 22 ++++++---------------- encoding.c | 9 +++++++++ 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 421f4f3fb5..0e52f6becb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Sun Jan 13 18:41:48 2008 Nobuyoshi Nakada + + * encoding.c (Init_Encoding): moved initialization from encdb.h. + + * enc/make_encdb.rb (enc_name_list): constified. + + * enc/make_encdb.rb (enc_init_db): moved some functions to encoding.c. + Sun Jan 13 13:53:00 2008 Nobuyoshi Nakada * ruby.c (load_file): local variable was not initialized when -x flag diff --git a/enc/make_encdb.rb b/enc/make_encdb.rb index 32dacbc740..fe596769dc 100755 --- a/enc/make_encdb.rb +++ b/enc/make_encdb.rb @@ -35,26 +35,16 @@ Dir.open(encdir) {|d| d.grep(/.+\.c\z/)}.each do |fn| end p aliases open('encdb.h', 'wb') do |f| - f.puts 'static const char *enc_name_list[] = {' + f.puts 'static const char *const enc_name_list[] = {' encodings.each {|name| f.puts' "%s",' % name} replicas.each_key {|name| f.puts' "%s",' % name} aliases.each_key {|name| f.puts' "%s",' % name} - f.puts(<<"_TEXT_") -}; -#define enc_name_list_size (sizeof(enc_name_list)/sizeof(enc_name_list[0])) - -static void enc_init_db(void) -{ - if (!enc_table.replica_name) { - enc_table.replica_name = st_init_strcasetable(); - } - if (!enc_table.alias_name) { - enc_table.alias_name = st_init_strcasetable(); - } -_TEXT_ + f.puts('};', '', 'static void', 'enc_init_db(void)', '{') replicas.each_pair {|name, orig| - f.puts' st_insert(enc_table.replica_name, (st_data_t)"%s", (st_data_t)"%s");' % [name, orig]} + f.puts ' ENC_REPLICATE("%s", "%s");' % [name, orig] + } aliases.each_pair {|name, orig| - f.puts' st_insert(enc_table.alias_name, (st_data_t)"%s", (st_data_t)"%s");' % [name, orig]} + f.puts ' ENC_ALIAS("%s", "%s");' % [name, orig] + } f.puts '}' end diff --git a/encoding.c b/encoding.c index 62a4c87e22..9abfe2a833 100644 --- a/encoding.c +++ b/encoding.c @@ -34,6 +34,12 @@ static struct { st_table *alias_name; } enc_table; +#undef ENC_REPLICATE +#undef ENC_ALIAS +#define ENC_REPLICATE(name, orig) st_insert(enc_table.replica_name, (st_data_t)(name), (st_data_t)(orig)) +#define ENC_ALIAS(name, orig) st_insert(enc_table.alias_name, (st_data_t)(name), (st_data_t)(orig)) +#define enc_name_list_size (sizeof(enc_name_list)/sizeof(enc_name_list[0])) + #include "encdb.h" #define ENC_UNINITIALIZED (&rb_cEncoding) @@ -1033,6 +1039,9 @@ Init_Encoding(void) { id_base_encoding = rb_intern("#base_encoding"); + enc_table.replica_name = st_init_strcasetable(); + enc_table.alias_name = st_init_strcasetable(); + rb_cEncoding = rb_define_class("Encoding", rb_cObject); rb_undef_alloc_func(rb_cEncoding); rb_define_method(rb_cEncoding, "to_s", enc_name, 0);