* encoding.c (enc_alias_internal): free the copied key and
return NULL when given key is already regisitered. * encoding.c (enc_alias): call set_encoding_const only when the alias is not registered yet. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30052 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
51da92ea12
commit
260e8ce637
@ -1,3 +1,11 @@
|
|||||||
|
Thu Dec 2 21:22:05 2010 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
|
* encoding.c (enc_alias_internal): free the copied key and
|
||||||
|
return NULL when given key is already regisitered.
|
||||||
|
|
||||||
|
* encoding.c (enc_alias): call set_encoding_const only when the
|
||||||
|
alias is not registered yet.
|
||||||
|
|
||||||
Thu Dec 2 19:58:24 2010 URABE Shyouhei <shyouhei@ruby-lang.org>
|
Thu Dec 2 19:58:24 2010 URABE Shyouhei <shyouhei@ruby-lang.org>
|
||||||
|
|
||||||
* vm.c (ruby_vm_at_exit): new API. This enables extension libs to
|
* vm.c (ruby_vm_at_exit): new API. This enables extension libs to
|
||||||
|
15
encoding.c
15
encoding.c
@ -436,12 +436,19 @@ rb_enc_unicode_p(rb_encoding *enc)
|
|||||||
return name[0] == 'U' && name[1] == 'T' && name[2] == 'F' && name[4] != '7';
|
return name[0] == 'U' && name[1] == 'T' && name[2] == 'F' && name[4] != '7';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns copied alias name when the key is added for st_table,
|
||||||
|
* else returns NULL.
|
||||||
|
*/
|
||||||
static const char *
|
static const char *
|
||||||
enc_alias_internal(const char *alias, int idx)
|
enc_alias_internal(const char *alias, int idx)
|
||||||
{
|
{
|
||||||
alias = strdup(alias);
|
char *name = strdup(alias);
|
||||||
st_insert(enc_table.names, (st_data_t)alias, (st_data_t)idx);
|
if (st_insert(enc_table.names, (st_data_t)name, (st_data_t)idx)) {
|
||||||
return alias;
|
free(name);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -449,7 +456,7 @@ enc_alias(const char *alias, int idx)
|
|||||||
{
|
{
|
||||||
if (!valid_encoding_name_p(alias)) return -1;
|
if (!valid_encoding_name_p(alias)) return -1;
|
||||||
alias = enc_alias_internal(alias, idx);
|
alias = enc_alias_internal(alias, idx);
|
||||||
set_encoding_const(alias, rb_enc_from_index(idx));
|
if (alias) set_encoding_const(alias, rb_enc_from_index(idx));
|
||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user