diff --git a/ChangeLog b/ChangeLog index 36cf859c34..ff25df39ff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Sun Oct 21 18:29:17 2007 Nobuyoshi Nakada + + * encoding.c (rb_enc_default, rb_enc_primary): return pointers to + rb_encoding of default and primary respectively. [ruby-core:12795] + + * encoding.c (set_primary_encoding): removed primary_encoding setter. + Sat Oct 20 11:49:20 2007 Nobuyoshi Nakada * file.c (rb_get_path): returns frozen string. diff --git a/encoding.c b/encoding.c index a67e49fefb..3de7fcf3d3 100644 --- a/encoding.c +++ b/encoding.c @@ -48,6 +48,7 @@ VALUE rb_enc_from_encoding(rb_encoding *encoding) { VALUE enc; + if (!encoding) return 0; if (enc_initialized_p(encoding)) return ENC_FROM_ENCODING(encoding); enc = enc_new(encoding); @@ -524,12 +525,27 @@ enc_load(VALUE klass, VALUE str) return enc_find(klass, str); } -static VALUE rb_primary_encoding; +static int primary_encoding_index; + +rb_encoding * +rb_enc_default(void) +{ + if (!enc_table) { + rb_enc_init(); + } + return enc_table[0].enc; +} + +rb_encoding * +rb_enc_primary(void) +{ + return rb_enc_from_index(primary_encoding_index); +} VALUE rb_get_primary_encoding(void) { - return rb_primary_encoding; + return rb_enc_from_encoding(rb_enc_primary()); } static VALUE @@ -542,14 +558,7 @@ void rb_set_primary_encoding(VALUE encoding) { rb_to_encoding(encoding); - rb_primary_encoding = encoding; -} - -static VALUE -set_primary_encoding(VALUE klass, VALUE enc) -{ - rb_set_primary_encoding(enc); - return rb_primary_encoding; + primary_encoding_index = ENCODING_GET(encoding); } static void @@ -616,9 +625,7 @@ Init_Encoding(void) rb_define_method(rb_cEncoding, "_dump", enc_dump, -1); rb_define_singleton_method(rb_cEncoding, "_load", enc_load, 1); - rb_primary_encoding = rb_enc_from_encoding(rb_enc_from_index(0)); rb_define_singleton_method(rb_cEncoding, "primary_encoding", get_primary_encoding, 0); - rb_define_singleton_method(rb_cEncoding, "primary_encoding=", set_primary_encoding, 1); for (i = 0; i < enc_table_size; ++i) { rb_encoding *enc = enc_table[i].enc; diff --git a/include/ruby/encoding.h b/include/ruby/encoding.h index 08371cc141..0d02c88459 100644 --- a/include/ruby/encoding.h +++ b/include/ruby/encoding.h @@ -100,6 +100,8 @@ ID rb_intern3(const char*, long, rb_encoding*); int rb_enc_symname_p(const char*, rb_encoding*); int rb_enc_str_coderange(VALUE); VALUE rb_enc_from_encoding(rb_encoding *enc); +rb_encoding *rb_enc_primary(void); +rb_encoding *rb_enc_default(void); VALUE rb_get_primary_encoding(void); void rb_set_primary_encoding(VALUE encoding); diff --git a/version.h b/version.h index 0e6e369f49..995c667ce3 100644 --- a/version.h +++ b/version.h @@ -1,7 +1,7 @@ #define RUBY_VERSION "1.9.0" -#define RUBY_RELEASE_DATE "2007-10-20" +#define RUBY_RELEASE_DATE "2007-10-21" #define RUBY_VERSION_CODE 190 -#define RUBY_RELEASE_CODE 20071020 +#define RUBY_RELEASE_CODE 20071021 #define RUBY_PATCHLEVEL 0 #define RUBY_VERSION_MAJOR 1 @@ -9,7 +9,7 @@ #define RUBY_VERSION_TEENY 0 #define RUBY_RELEASE_YEAR 2007 #define RUBY_RELEASE_MONTH 10 -#define RUBY_RELEASE_DAY 20 +#define RUBY_RELEASE_DAY 21 #ifdef RUBY_EXTERN RUBY_EXTERN const char ruby_version[];