From 0f67a3bb3171c98770c7a5de8559636d2551a3b8 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 17 Oct 2014 08:00:42 +0000 Subject: [PATCH] symbol.c (register_sym): debug code git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47995 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- symbol.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/symbol.c b/symbol.c index 6cc0e3eba9..b9d41efda9 100644 --- a/symbol.c +++ b/symbol.c @@ -18,6 +18,10 @@ #include "gc.h" #include "probes.h" +#ifndef SYMBOL_DEBUG +# define SYMBOL_DEBUG 0 +#endif + #define SYMBOL_PINNED_P(sym) (RSYMBOL(sym)->id&~ID_SCOPE_MASK) #define DYNAMIC_ID_P(id) (!(id&ID_STATIC_SYM)&&id>tLAST_OP_ID) @@ -396,10 +400,28 @@ get_id_entry(ID num, const enum id_entry_type t) return 0; } +#if SYMBOL_DEBUG +static int +register_sym_update_callback(st_data_t *key, st_data_t *value, st_data_t arg, int existing) +{ + if (existing) { + rb_fatal("symbol :% "PRIsVALUE" is already registered with %"PRIxVALUE, + (VALUE)*key, (VALUE)*value); + } + *value = arg; + return ST_CONTINUE; +} +#endif + static void register_sym(VALUE str, VALUE sym) { +#if SYMBOL_DEBUG + st_update(global_symbols.str_sym, (st_data_t)str, + register_sym_update_callback, (st_data_t)sym); +#else st_add_direct(global_symbols.str_sym, (st_data_t)str, (st_data_t)sym); +#endif } static void