mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
symbol.c: wrap global_symbols tables
* symbol.c (register_symid_direct, unregister_sym): extract to wrap global_symbols tables. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46972 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b2aee6f45b
commit
42425c89a4
1 changed files with 40 additions and 22 deletions
62
symbol.c
62
symbol.c
|
@ -308,6 +308,38 @@ rb_str_symname_type(VALUE name, unsigned int allowed_attrset)
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
register_symid_direct(VALUE str, ID id)
|
||||||
|
{
|
||||||
|
st_add_direct(global_symbols.str_id, (st_data_t)str, (st_data_t)id);
|
||||||
|
st_add_direct(global_symbols.id_str, (st_data_t)id, (st_data_t)str);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
unregister_sym_str(VALUE str)
|
||||||
|
{
|
||||||
|
st_data_t str_data = (st_data_t)str;
|
||||||
|
return st_delete(global_symbols.str_id, &str_data, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
unregister_sym_id(VALUE sym)
|
||||||
|
{
|
||||||
|
st_data_t sym_data = (st_data_t)sym;
|
||||||
|
return st_delete(global_symbols.id_str, &sym_data, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
unregister_sym(VALUE str, VALUE sym)
|
||||||
|
{
|
||||||
|
if (!unregister_sym_str(str)) {
|
||||||
|
rb_bug("%p can't remove str from str_id (%s)", (void *)sym, RSTRING_PTR(str));
|
||||||
|
}
|
||||||
|
if (!unregister_sym_id(sym)) {
|
||||||
|
rb_bug("%p can't remove sym from id_str (%s)", (void *)sym, RSTRING_PTR(str));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static ID
|
static ID
|
||||||
register_static_symid(ID id, const char *name, long len, rb_encoding *enc)
|
register_static_symid(ID id, const char *name, long len, rb_encoding *enc)
|
||||||
{
|
{
|
||||||
|
@ -325,8 +357,7 @@ register_static_symid_str(ID id, VALUE str)
|
||||||
RUBY_DTRACE_SYMBOL_CREATE(RSTRING_PTR(str), rb_sourcefile(), rb_sourceline());
|
RUBY_DTRACE_SYMBOL_CREATE(RSTRING_PTR(str), rb_sourcefile(), rb_sourceline());
|
||||||
}
|
}
|
||||||
|
|
||||||
st_add_direct(global_symbols.str_id, (st_data_t)str, (st_data_t)id);
|
register_symid_direct(str, id);
|
||||||
st_add_direct(global_symbols.id_str, (st_data_t)id, (st_data_t)str);
|
|
||||||
rb_gc_register_mark_object(str);
|
rb_gc_register_mark_object(str);
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
|
@ -394,8 +425,7 @@ dsymbol_alloc(const VALUE klass, const VALUE str, rb_encoding * const enc)
|
||||||
RB_OBJ_WRITE(dsym, &RSYMBOL(dsym)->fstr, str);
|
RB_OBJ_WRITE(dsym, &RSYMBOL(dsym)->fstr, str);
|
||||||
RSYMBOL(dsym)->type = type;
|
RSYMBOL(dsym)->type = type;
|
||||||
|
|
||||||
st_add_direct(global_symbols.str_id, (st_data_t)str, (st_data_t)dsym);
|
register_symid_direct(str, (ID)dsym);
|
||||||
st_add_direct(global_symbols.id_str, (st_data_t)dsym, (st_data_t)str);
|
|
||||||
rb_hash_aset(global_symbols.dsymbol_fstr_hash, str, Qtrue);
|
rb_hash_aset(global_symbols.dsymbol_fstr_hash, str, Qtrue);
|
||||||
|
|
||||||
if (RUBY_DTRACE_SYMBOL_CREATE_ENABLED()) {
|
if (RUBY_DTRACE_SYMBOL_CREATE_ENABLED()) {
|
||||||
|
@ -412,12 +442,7 @@ dsymbol_check(const VALUE sym)
|
||||||
const VALUE fstr = RSYMBOL(sym)->fstr;
|
const VALUE fstr = RSYMBOL(sym)->fstr;
|
||||||
RSYMBOL(sym)->fstr = 0;
|
RSYMBOL(sym)->fstr = 0;
|
||||||
|
|
||||||
if (st_delete(global_symbols.str_id, (st_data_t *)&fstr, NULL) == 0) {
|
unregister_sym(fstr, sym);
|
||||||
rb_bug("can't remove fstr from str_id (%s)", RSTRING_PTR(fstr));
|
|
||||||
}
|
|
||||||
if (st_delete(global_symbols.id_str, (st_data_t *)&sym, NULL) == 0) {
|
|
||||||
rb_bug("can't remove sym from id_sym (%s)", RSTRING_PTR(fstr));
|
|
||||||
}
|
|
||||||
return dsymbol_alloc(rb_cSymbol, fstr, rb_enc_get(fstr));
|
return dsymbol_alloc(rb_cSymbol, fstr, rb_enc_get(fstr));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -675,17 +700,11 @@ rb_intern_str(VALUE str)
|
||||||
void
|
void
|
||||||
rb_gc_free_dsymbol(VALUE sym)
|
rb_gc_free_dsymbol(VALUE sym)
|
||||||
{
|
{
|
||||||
st_data_t str_data = (st_data_t)RSYMBOL(sym)->fstr;
|
VALUE str = RSYMBOL(sym)->fstr;
|
||||||
st_data_t sym_data = (st_data_t)sym;
|
|
||||||
|
|
||||||
if (str_data) {
|
if (str) {
|
||||||
if (st_delete(global_symbols.str_id, &str_data, 0) == 0) {
|
RSYMBOL(sym)->fstr = 0;
|
||||||
rb_bug("rb_gc_free_dsymbol: %p can't remove str from str_id (%s)", (void *)sym, RSTRING_PTR(RSYMBOL(sym)->fstr));
|
unregister_sym(str, sym);
|
||||||
}
|
|
||||||
if (st_delete(global_symbols.id_str, &sym_data, 0) == 0) {
|
|
||||||
rb_bug("rb_gc_free_dsymbol: %p can't remove sym from id_str (%s)", (void *)sym, RSTRING_PTR(RSYMBOL(sym)->fstr));
|
|
||||||
}
|
|
||||||
RSYMBOL(sym)->fstr = (VALUE)NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -847,9 +866,8 @@ symbols_i(st_data_t key, st_data_t value, st_data_t arg)
|
||||||
VALUE sym = ID2SYM((ID)value);
|
VALUE sym = ID2SYM((ID)value);
|
||||||
|
|
||||||
if (DYNAMIC_SYM_P(sym) && !SYMBOL_PINNED_P(sym) && rb_objspace_garbage_object_p(sym)) {
|
if (DYNAMIC_SYM_P(sym) && !SYMBOL_PINNED_P(sym) && rb_objspace_garbage_object_p(sym)) {
|
||||||
st_data_t sym_data = (st_data_t)sym;
|
|
||||||
st_delete(global_symbols.id_str, &sym_data, NULL);
|
|
||||||
RSYMBOL(sym)->fstr = 0;
|
RSYMBOL(sym)->fstr = 0;
|
||||||
|
unregister_sym_id(sym);
|
||||||
return ST_DELETE;
|
return ST_DELETE;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue