Feature #3908 » 0002-use-rb_constant_entry_t-as-entry-of-RCLASS_CONST_TBL.patch
class.c | ||
---|---|---|
#include "ruby/ruby.h"
|
||
#include "ruby/st.h"
|
||
#include "method.h"
|
||
#include "constant.h"
|
||
#include "vm_core.h"
|
||
#include <ctype.h>
|
||
... | ... | |
return ST_CONTINUE;
|
||
}
|
||
static int
|
||
clone_const(ID key, const rb_const_entry_t *ce, st_table *tbl)
|
||
{
|
||
rb_const_entry_t *nce = ALLOC(rb_const_entry_t);
|
||
*nce = *ce;
|
||
st_insert(tbl, key, (st_data_t)nce);
|
||
}
|
||
/* :nodoc: */
|
||
VALUE
|
||
rb_mod_init_copy(VALUE clone, VALUE orig)
|
||
... | ... | |
}
|
||
if (RCLASS_CONST_TBL(orig)) {
|
||
if (RCLASS_CONST_TBL(clone)) {
|
||
st_free_table(RCLASS_CONST_TBL(clone));
|
||
rb_free_const_table(RCLASS_CONST_TBL(clone));
|
||
}
|
||
RCLASS_CONST_TBL(clone) = st_copy(RCLASS_CONST_TBL(orig));
|
||
RCLASS_CONST_TBL(clone) = st_init_numtable();
|
||
st_foreach(RCLASS_CONST_TBL(orig), clone_const, (st_data_t)RCLASS_CONST_TBL(clone));
|
||
}
|
||
if (RCLASS_M_TBL(orig)) {
|
||
struct clone_method_data data;
|
||
if (RCLASS_M_TBL(clone)) {
|
||
extern void rb_free_m_table(st_table *tbl);
|
||
rb_free_m_table(RCLASS_M_TBL(clone));
|
||
}
|
||
data.tbl = RCLASS_M_TBL(clone) = st_init_numtable();
|
||
... | ... | |
RCLASS_IV_TBL(clone) = st_copy(RCLASS_IV_TBL(klass));
|
||
}
|
||
if (RCLASS_CONST_TBL(klass)) {
|
||
RCLASS_CONST_TBL(clone) = st_copy(RCLASS_CONST_TBL(klass));
|
||
RCLASS_CONST_TBL(clone) = st_init_numtable();
|
||
st_foreach(RCLASS_CONST_TBL(klass), clone_const, (st_data_t)RCLASS_CONST_TBL(clone));
|
||
}
|
||
RCLASS_M_TBL(clone) = st_init_numtable();
|
||
data.tbl = RCLASS_M_TBL(clone);
|
gc.c | ||
---|---|---|
#include "eval_intern.h"
|
||
#include "vm_core.h"
|
||
#include "gc.h"
|
||
#include "constant.h"
|
||
#include <stdio.h>
|
||
#include <setjmp.h>
|
||
#include <sys/types.h>
|
||
... | ... | |
st_free_table(tbl);
|
||
}
|
||
static int
|
||
mark_const_entry_i(ID key, const rb_const_entry_t *ce, st_data_t data)
|
||
{
|
||
struct mark_tbl_arg *arg = (void*)data;
|
||
gc_mark(arg->objspace, ce->value, arg->lev);
|
||
return ST_CONTINUE;
|
||
}
|
||
static void
|
||
mark_const_tbl(rb_objspace_t *objspace, st_table *tbl, int lev)
|
||
{
|
||
struct mark_tbl_arg arg;
|
||
if (!tbl) return;
|
||
arg.objspace = objspace;
|
||
arg.lev = lev;
|
||
st_foreach(tbl, mark_const_entry_i, (st_data_t)&arg);
|
||
}
|
||
static int
|
||
free_const_entry_i(ID key, rb_const_entry_t *ce, st_data_t data)
|
||
{
|
||
xfree(ce);
|
||
return ST_CONTINUE;
|
||
}
|
||
void
|
||
rb_free_const_table(st_table *tbl)
|
||
{
|
||
st_foreach(tbl, free_const_entry_i, 0);
|
||
st_free_table(tbl);
|
||
}
|
||
void
|
||
rb_mark_tbl(st_table *tbl)
|
||
{
|
||
... | ... | |
case T_MODULE:
|
||
mark_m_tbl(objspace, RCLASS_M_TBL(obj), lev);
|
||
mark_tbl(objspace, RCLASS_IV_TBL(obj), lev);
|
||
mark_tbl(objspace, RCLASS_CONST_TBL(obj), lev);
|
||
mark_const_tbl(objspace, RCLASS_CONST_TBL(obj), lev);
|
||
ptr = RCLASS_SUPER(obj);
|
||
goto again;
|
||
... | ... | |
st_free_table(RCLASS_IV_TBL(obj));
|
||
}
|
||
if (RCLASS_CONST_TBL(obj)) {
|
||
st_free_table(RCLASS_CONST_TBL(obj));
|
||
rb_free_const_table(RCLASS_CONST_TBL(obj));
|
||
}
|
||
if (RCLASS_IV_INDEX_TBL(obj)) {
|
||
st_free_table(RCLASS_IV_INDEX_TBL(obj));
|
method.h | ||
---|---|---|
void rb_mark_method_entry(const rb_method_entry_t *me);
|
||
void rb_free_method_entry(rb_method_entry_t *me);
|
||
void rb_sweep_method_entry(void *vm);
|
||
void rb_free_m_table(st_table *tbl);
|
||
#endif /* METHOD_H */
|
object.c | ||
---|---|---|
#include <ctype.h>
|
||
#include <math.h>
|
||
#include <float.h>
|
||
#include "constant.h"
|
||
VALUE rb_cBasicObject;
|
||
VALUE rb_mKernel;
|
||
... | ... | |
RCLASS_IV_TBL(dest) = 0;
|
||
}
|
||
if (RCLASS_CONST_TBL(dest)) {
|
||
st_free_table(RCLASS_CONST_TBL(dest));
|
||
rb_free_const_table(RCLASS_CONST_TBL(dest));
|
||
RCLASS_CONST_TBL(dest) = 0;
|
||
}
|
||
if (RCLASS_IV_TBL(obj)) {
|
variable.c | ||
---|---|---|
#include "ruby/util.h"
|
||
#include "ruby/encoding.h"
|
||
#include "node.h"
|
||
#include "constant.h"
|
||
void rb_vm_change_state(void);
|
||
void rb_vm_inc_const_missing_count(void);
|
||
... | ... | |
}
|
||
static int
|
||
fc_i(ID key, VALUE value, struct fc_result *res)
|
||
fc_i(ID key, rb_const_entry_t *ce, struct fc_result *res)
|
||
{
|
||
VALUE value = ce->value;
|
||
if (!rb_is_const_id(key)) return ST_CONTINUE;
|
||
if (value == res->klass) {
|
||
... | ... | |
rb_raise(rb_eArgError, "empty file name");
|
||
}
|
||
if ((tbl = RCLASS_CONST_TBL(mod)) && st_lookup(tbl, (st_data_t)id, &av) && (VALUE)av != Qundef)
|
||
if ((tbl = RCLASS_CONST_TBL(mod)) && st_lookup(tbl, (st_data_t)id, &av) && ((rb_const_entry_t*)av)->value != Qundef)
|
||
return;
|
||
rb_const_set(mod, id, Qundef);
|
||
tbl = RCLASS_IV_TBL(mod);
|
||
if (st_lookup(tbl, (st_data_t)autoload, &av)) {
|
||
if (tbl && st_lookup(tbl, (st_data_t)autoload, &av)) {
|
||
tbl = check_autoload_table((VALUE)av);
|
||
}
|
||
else {
|
||
if (!tbl) tbl = RCLASS_IV_TBL(mod) = st_init_numtable();
|
||
av = (st_data_t)TypedData_Wrap_Struct(0, &autoload_data_type, 0);
|
||
st_add_direct(tbl, (st_data_t)autoload, av);
|
||
DATA_PTR(av) = tbl = st_init_numtable();
|
||
... | ... | |
autoload_delete(VALUE mod, ID id)
|
||
{
|
||
st_data_t val, load = 0, n = id;
|
||
rb_const_entry_t *ce;
|
||
st_delete(RCLASS_CONST_TBL(mod), &n, 0);
|
||
st_delete(RCLASS_CONST_TBL(mod), &n, &val);
|
||
ce = (rb_const_entry_t*)val;
|
||
if (ce) xfree(ce);
|
||
if (st_lookup(RCLASS_IV_TBL(mod), (st_data_t)autoload, &val)) {
|
||
struct st_table *tbl = check_autoload_table((VALUE)val);
|
||
... | ... | |
if (tbl->num_entries == 0) {
|
||
n = autoload;
|
||
st_delete(RCLASS_CONST_TBL(mod), &n, &val);
|
||
ce = (rb_const_entry_t*)val;
|
||
if (ce) xfree(ce);
|
||
}
|
||
}
|
||
... | ... | |
struct st_table *tbl = RCLASS_CONST_TBL(mod);
|
||
st_data_t val;
|
||
if (!tbl || !st_lookup(tbl, (st_data_t)id, &val) || (VALUE)val != Qundef) {
|
||
if (!tbl || !st_lookup(tbl, (st_data_t)id, &val) || ((rb_const_entry_t*)val)->value != Qundef) {
|
||
return 0;
|
||
}
|
||
return 1;
|
||
... | ... | |
static VALUE
|
||
rb_const_get_0(VALUE klass, ID id, int exclude, int recurse)
|
||
{
|
||
st_data_t v;
|
||
VALUE value, tmp;
|
||
int mod_retry = 0;
|
||
... | ... | |
retry:
|
||
while (RTEST(tmp)) {
|
||
VALUE am = 0;
|
||
while (RCLASS_CONST_TBL(tmp) && st_lookup(RCLASS_CONST_TBL(tmp), (st_data_t)id, &value)) {
|
||
while (RCLASS_CONST_TBL(tmp) && st_lookup(RCLASS_CONST_TBL(tmp), (st_data_t)id, &v)) {
|
||
value = ((rb_const_entry_t*)v)->value;
|
||
if (value == Qundef) {
|
||
if (am == tmp) break;
|
||
am = tmp;
|
||
... | ... | |
rb_vm_change_state();
|
||
val = (VALUE)v;
|
||
val = ((rb_const_entry_t*)v)->value;
|
||
if (val == Qundef) {
|
||
autoload_delete(mod, id);
|
||
val = Qnil;
|
||
}
|
||
xfree((rb_const_entry_t*)v);
|
||
return val;
|
||
}
|
||
static int
|
||
sv_i(ID key, VALUE value, st_table *tbl)
|
||
sv_i(ID key, rb_const_entry_t *ce, st_table *tbl)
|
||
{
|
||
if (rb_is_const_id(key)) {
|
||
if (!st_lookup(tbl, (st_data_t)key, 0)) {
|
||
... | ... | |
retry:
|
||
while (tmp) {
|
||
if (RCLASS_CONST_TBL(tmp) && st_lookup(RCLASS_CONST_TBL(tmp), (st_data_t)id, &value)) {
|
||
if ((VALUE)value == Qundef && !autoload_node((VALUE)klass, id, 0))
|
||
if (((rb_const_entry_t*)value)->value == Qundef && !autoload_node((VALUE)klass, id, 0))
|
||
return (int)Qfalse;
|
||
return (int)Qtrue;
|
||
}
|
||
... | ... | |
void
|
||
rb_const_set(VALUE klass, ID id, VALUE val)
|
||
{
|
||
rb_const_entry_t *ce;
|
||
if (NIL_P(klass)) {
|
||
rb_raise(rb_eTypeError, "no class/module to define constant %s",
|
||
rb_id2name(id));
|
||
... | ... | |
st_data_t value;
|
||
if (st_lookup(RCLASS_CONST_TBL(klass), (st_data_t)id, &value)) {
|
||
if ((VALUE)value == Qundef)
|
||
if (((rb_const_entry_t*)value)->value == Qundef)
|
||
autoload_delete(klass, id);
|
||
else
|
||
rb_warn("already initialized constant %s", rb_id2name(id));
|
||
... | ... | |
}
|
||
rb_vm_change_state();
|
||
st_insert(RCLASS_CONST_TBL(klass), (st_data_t)id, (st_data_t)val);
|
||
ce = ALLOC(rb_const_entry_t);
|
||
ce->flag = CONST_PUBLIC;
|
||
ce->value = val;
|
||
st_insert(RCLASS_CONST_TBL(klass), (st_data_t)id, (st_data_t)ce);
|
||
}
|
||
void
|
vm_insnhelper.c | ||
---|---|---|
/* finish iseq array */
|
||
#include "insns.inc"
|
||
#include <math.h>
|
||
#include "constant.h"
|
||
/* control stack frame */
|
||
... | ... | |
cref = cref->nd_next;
|
||
if (!NIL_P(klass)) {
|
||
st_data_t v;
|
||
VALUE am = 0;
|
||
search_continue:
|
||
if (RCLASS_CONST_TBL(klass) &&
|
||
st_lookup(RCLASS_CONST_TBL(klass), id, &val)) {
|
||
st_lookup(RCLASS_CONST_TBL(klass), id, &v)) {
|
||
val = ((rb_const_entry_t*)v)->value;
|
||
if (val == Qundef) {
|
||
if (am == klass) break;
|
||
am = klass;
|