0002-use-rb_constant_entry_t-as-entry-of-RCLASS_CONST_TBL.patch
| b/class.c | ||
|---|---|---|
| 26 | 26 |
#include "ruby/ruby.h" |
| 27 | 27 |
#include "ruby/st.h" |
| 28 | 28 |
#include "method.h" |
| 29 |
#include "constant.h" |
|
| 29 | 30 |
#include "vm_core.h" |
| 30 | 31 |
#include <ctype.h> |
| 31 | 32 | |
| ... | ... | |
| 140 | 141 |
return ST_CONTINUE; |
| 141 | 142 |
} |
| 142 | 143 | |
| 144 |
static int |
|
| 145 |
clone_const(ID key, const rb_const_entry_t *ce, st_table *tbl) |
|
| 146 |
{
|
|
| 147 |
rb_const_entry_t *nce = ALLOC(rb_const_entry_t); |
|
| 148 |
*nce = *ce; |
|
| 149 |
st_insert(tbl, key, (st_data_t)nce); |
|
| 150 |
} |
|
| 151 | ||
| 143 | 152 |
/* :nodoc: */ |
| 144 | 153 |
VALUE |
| 145 | 154 |
rb_mod_init_copy(VALUE clone, VALUE orig) |
| ... | ... | |
| 164 | 173 |
} |
| 165 | 174 |
if (RCLASS_CONST_TBL(orig)) {
|
| 166 | 175 |
if (RCLASS_CONST_TBL(clone)) {
|
| 167 |
st_free_table(RCLASS_CONST_TBL(clone));
|
|
| 176 |
rb_free_const_table(RCLASS_CONST_TBL(clone));
|
|
| 168 | 177 |
} |
| 169 |
RCLASS_CONST_TBL(clone) = st_copy(RCLASS_CONST_TBL(orig)); |
|
| 178 |
RCLASS_CONST_TBL(clone) = st_init_numtable(); |
|
| 179 |
st_foreach(RCLASS_CONST_TBL(orig), clone_const, (st_data_t)RCLASS_CONST_TBL(clone)); |
|
| 170 | 180 |
} |
| 171 | 181 |
if (RCLASS_M_TBL(orig)) {
|
| 172 | 182 |
struct clone_method_data data; |
| 173 | 183 | |
| 174 | 184 |
if (RCLASS_M_TBL(clone)) {
|
| 175 |
extern void rb_free_m_table(st_table *tbl); |
|
| 176 | 185 |
rb_free_m_table(RCLASS_M_TBL(clone)); |
| 177 | 186 |
} |
| 178 | 187 |
data.tbl = RCLASS_M_TBL(clone) = st_init_numtable(); |
| ... | ... | |
| 224 | 233 |
RCLASS_IV_TBL(clone) = st_copy(RCLASS_IV_TBL(klass)); |
| 225 | 234 |
} |
| 226 | 235 |
if (RCLASS_CONST_TBL(klass)) {
|
| 227 |
RCLASS_CONST_TBL(clone) = st_copy(RCLASS_CONST_TBL(klass)); |
|
| 236 |
RCLASS_CONST_TBL(clone) = st_init_numtable(); |
|
| 237 |
st_foreach(RCLASS_CONST_TBL(klass), clone_const, (st_data_t)RCLASS_CONST_TBL(clone)); |
|
| 228 | 238 |
} |
| 229 | 239 |
RCLASS_M_TBL(clone) = st_init_numtable(); |
| 230 | 240 |
data.tbl = RCLASS_M_TBL(clone); |
| b/gc.c | ||
|---|---|---|
| 19 | 19 |
#include "eval_intern.h" |
| 20 | 20 |
#include "vm_core.h" |
| 21 | 21 |
#include "gc.h" |
| 22 |
#include "constant.h" |
|
| 22 | 23 |
#include <stdio.h> |
| 23 | 24 |
#include <setjmp.h> |
| 24 | 25 |
#include <sys/types.h> |
| ... | ... | |
| 1503 | 1504 |
st_free_table(tbl); |
| 1504 | 1505 |
} |
| 1505 | 1506 | |
| 1507 |
static int |
|
| 1508 |
mark_const_entry_i(ID key, const rb_const_entry_t *ce, st_data_t data) |
|
| 1509 |
{
|
|
| 1510 |
struct mark_tbl_arg *arg = (void*)data; |
|
| 1511 |
gc_mark(arg->objspace, ce->value, arg->lev); |
|
| 1512 |
return ST_CONTINUE; |
|
| 1513 |
} |
|
| 1514 | ||
| 1515 |
static void |
|
| 1516 |
mark_const_tbl(rb_objspace_t *objspace, st_table *tbl, int lev) |
|
| 1517 |
{
|
|
| 1518 |
struct mark_tbl_arg arg; |
|
| 1519 |
if (!tbl) return; |
|
| 1520 |
arg.objspace = objspace; |
|
| 1521 |
arg.lev = lev; |
|
| 1522 |
st_foreach(tbl, mark_const_entry_i, (st_data_t)&arg); |
|
| 1523 |
} |
|
| 1524 | ||
| 1525 |
static int |
|
| 1526 |
free_const_entry_i(ID key, rb_const_entry_t *ce, st_data_t data) |
|
| 1527 |
{
|
|
| 1528 |
xfree(ce); |
|
| 1529 |
return ST_CONTINUE; |
|
| 1530 |
} |
|
| 1531 | ||
| 1532 |
void |
|
| 1533 |
rb_free_const_table(st_table *tbl) |
|
| 1534 |
{
|
|
| 1535 |
st_foreach(tbl, free_const_entry_i, 0); |
|
| 1536 |
st_free_table(tbl); |
|
| 1537 |
} |
|
| 1538 | ||
| 1506 | 1539 |
void |
| 1507 | 1540 |
rb_mark_tbl(st_table *tbl) |
| 1508 | 1541 |
{
|
| ... | ... | |
| 1717 | 1750 |
case T_MODULE: |
| 1718 | 1751 |
mark_m_tbl(objspace, RCLASS_M_TBL(obj), lev); |
| 1719 | 1752 |
mark_tbl(objspace, RCLASS_IV_TBL(obj), lev); |
| 1720 |
mark_tbl(objspace, RCLASS_CONST_TBL(obj), lev); |
|
| 1753 |
mark_const_tbl(objspace, RCLASS_CONST_TBL(obj), lev);
|
|
| 1721 | 1754 |
ptr = RCLASS_SUPER(obj); |
| 1722 | 1755 |
goto again; |
| 1723 | 1756 | |
| ... | ... | |
| 2166 | 2199 |
st_free_table(RCLASS_IV_TBL(obj)); |
| 2167 | 2200 |
} |
| 2168 | 2201 |
if (RCLASS_CONST_TBL(obj)) {
|
| 2169 |
st_free_table(RCLASS_CONST_TBL(obj));
|
|
| 2202 |
rb_free_const_table(RCLASS_CONST_TBL(obj));
|
|
| 2170 | 2203 |
} |
| 2171 | 2204 |
if (RCLASS_IV_INDEX_TBL(obj)) {
|
| 2172 | 2205 |
st_free_table(RCLASS_IV_INDEX_TBL(obj)); |
| b/method.h | ||
|---|---|---|
| 99 | 99 |
void rb_mark_method_entry(const rb_method_entry_t *me); |
| 100 | 100 |
void rb_free_method_entry(rb_method_entry_t *me); |
| 101 | 101 |
void rb_sweep_method_entry(void *vm); |
| 102 |
void rb_free_m_table(st_table *tbl); |
|
| 102 | 103 | |
| 103 | 104 |
#endif /* METHOD_H */ |
| b/object.c | ||
|---|---|---|
| 19 | 19 |
#include <ctype.h> |
| 20 | 20 |
#include <math.h> |
| 21 | 21 |
#include <float.h> |
| 22 |
#include "constant.h" |
|
| 22 | 23 | |
| 23 | 24 |
VALUE rb_cBasicObject; |
| 24 | 25 |
VALUE rb_mKernel; |
| ... | ... | |
| 222 | 223 |
RCLASS_IV_TBL(dest) = 0; |
| 223 | 224 |
} |
| 224 | 225 |
if (RCLASS_CONST_TBL(dest)) {
|
| 225 |
st_free_table(RCLASS_CONST_TBL(dest));
|
|
| 226 |
rb_free_const_table(RCLASS_CONST_TBL(dest));
|
|
| 226 | 227 |
RCLASS_CONST_TBL(dest) = 0; |
| 227 | 228 |
} |
| 228 | 229 |
if (RCLASS_IV_TBL(obj)) {
|
| b/variable.c | ||
|---|---|---|
| 16 | 16 |
#include "ruby/util.h" |
| 17 | 17 |
#include "ruby/encoding.h" |
| 18 | 18 |
#include "node.h" |
| 19 |
#include "constant.h" |
|
| 19 | 20 | |
| 20 | 21 |
void rb_vm_change_state(void); |
| 21 | 22 |
void rb_vm_inc_const_missing_count(void); |
| ... | ... | |
| 71 | 72 |
} |
| 72 | 73 | |
| 73 | 74 |
static int |
| 74 |
fc_i(ID key, VALUE value, struct fc_result *res)
|
|
| 75 |
fc_i(ID key, rb_const_entry_t *ce, struct fc_result *res)
|
|
| 75 | 76 |
{
|
| 77 |
VALUE value = ce->value; |
|
| 76 | 78 |
if (!rb_is_const_id(key)) return ST_CONTINUE; |
| 77 | 79 | |
| 78 | 80 |
if (value == res->klass) {
|
| ... | ... | |
| 1438 | 1440 |
rb_raise(rb_eArgError, "empty file name"); |
| 1439 | 1441 |
} |
| 1440 | 1442 | |
| 1441 |
if ((tbl = RCLASS_CONST_TBL(mod)) && st_lookup(tbl, (st_data_t)id, &av) && (VALUE)av != Qundef)
|
|
| 1443 |
if ((tbl = RCLASS_CONST_TBL(mod)) && st_lookup(tbl, (st_data_t)id, &av) && ((rb_const_entry_t*)av)->value != Qundef)
|
|
| 1442 | 1444 |
return; |
| 1443 | 1445 | |
| 1444 | 1446 |
rb_const_set(mod, id, Qundef); |
| 1445 | 1447 |
tbl = RCLASS_IV_TBL(mod); |
| 1446 |
if (st_lookup(tbl, (st_data_t)autoload, &av)) {
|
|
| 1448 |
if (tbl && st_lookup(tbl, (st_data_t)autoload, &av)) {
|
|
| 1447 | 1449 |
tbl = check_autoload_table((VALUE)av); |
| 1448 | 1450 |
} |
| 1449 | 1451 |
else {
|
| 1452 |
if (!tbl) tbl = RCLASS_IV_TBL(mod) = st_init_numtable(); |
|
| 1450 | 1453 |
av = (st_data_t)TypedData_Wrap_Struct(0, &autoload_data_type, 0); |
| 1451 | 1454 |
st_add_direct(tbl, (st_data_t)autoload, av); |
| 1452 | 1455 |
DATA_PTR(av) = tbl = st_init_numtable(); |
| ... | ... | |
| 1461 | 1464 |
autoload_delete(VALUE mod, ID id) |
| 1462 | 1465 |
{
|
| 1463 | 1466 |
st_data_t val, load = 0, n = id; |
| 1467 |
rb_const_entry_t *ce; |
|
| 1464 | 1468 | |
| 1465 |
st_delete(RCLASS_CONST_TBL(mod), &n, 0); |
|
| 1469 |
st_delete(RCLASS_CONST_TBL(mod), &n, &val); |
|
| 1470 |
ce = (rb_const_entry_t*)val; |
|
| 1471 |
if (ce) xfree(ce); |
|
| 1466 | 1472 |
if (st_lookup(RCLASS_IV_TBL(mod), (st_data_t)autoload, &val)) {
|
| 1467 | 1473 |
struct st_table *tbl = check_autoload_table((VALUE)val); |
| 1468 | 1474 | |
| ... | ... | |
| 1471 | 1477 |
if (tbl->num_entries == 0) {
|
| 1472 | 1478 |
n = autoload; |
| 1473 | 1479 |
st_delete(RCLASS_CONST_TBL(mod), &n, &val); |
| 1480 |
ce = (rb_const_entry_t*)val; |
|
| 1481 |
if (ce) xfree(ce); |
|
| 1474 | 1482 |
} |
| 1475 | 1483 |
} |
| 1476 | 1484 | |
| ... | ... | |
| 1530 | 1538 |
struct st_table *tbl = RCLASS_CONST_TBL(mod); |
| 1531 | 1539 |
st_data_t val; |
| 1532 | 1540 | |
| 1533 |
if (!tbl || !st_lookup(tbl, (st_data_t)id, &val) || (VALUE)val != Qundef) {
|
|
| 1541 |
if (!tbl || !st_lookup(tbl, (st_data_t)id, &val) || ((rb_const_entry_t*)val)->value != Qundef) {
|
|
| 1534 | 1542 |
return 0; |
| 1535 | 1543 |
} |
| 1536 | 1544 |
return 1; |
| ... | ... | |
| 1568 | 1576 |
static VALUE |
| 1569 | 1577 |
rb_const_get_0(VALUE klass, ID id, int exclude, int recurse) |
| 1570 | 1578 |
{
|
| 1579 |
st_data_t v; |
|
| 1571 | 1580 |
VALUE value, tmp; |
| 1572 | 1581 |
int mod_retry = 0; |
| 1573 | 1582 | |
| ... | ... | |
| 1575 | 1584 |
retry: |
| 1576 | 1585 |
while (RTEST(tmp)) {
|
| 1577 | 1586 |
VALUE am = 0; |
| 1578 |
while (RCLASS_CONST_TBL(tmp) && st_lookup(RCLASS_CONST_TBL(tmp), (st_data_t)id, &value)) {
|
|
| 1587 |
while (RCLASS_CONST_TBL(tmp) && st_lookup(RCLASS_CONST_TBL(tmp), (st_data_t)id, &v)) {
|
|
| 1588 |
value = ((rb_const_entry_t*)v)->value; |
|
| 1579 | 1589 |
if (value == Qundef) {
|
| 1580 | 1590 |
if (am == tmp) break; |
| 1581 | 1591 |
am = tmp; |
| ... | ... | |
| 1661 | 1671 | |
| 1662 | 1672 |
rb_vm_change_state(); |
| 1663 | 1673 | |
| 1664 |
val = (VALUE)v;
|
|
| 1674 |
val = ((rb_const_entry_t*)v)->value;
|
|
| 1665 | 1675 |
if (val == Qundef) {
|
| 1666 | 1676 |
autoload_delete(mod, id); |
| 1667 | 1677 |
val = Qnil; |
| 1668 | 1678 |
} |
| 1679 |
xfree((rb_const_entry_t*)v); |
|
| 1669 | 1680 |
return val; |
| 1670 | 1681 |
} |
| 1671 | 1682 | |
| 1672 | 1683 |
static int |
| 1673 |
sv_i(ID key, VALUE value, st_table *tbl)
|
|
| 1684 |
sv_i(ID key, rb_const_entry_t *ce, st_table *tbl)
|
|
| 1674 | 1685 |
{
|
| 1675 | 1686 |
if (rb_is_const_id(key)) {
|
| 1676 | 1687 |
if (!st_lookup(tbl, (st_data_t)key, 0)) {
|
| ... | ... | |
| 1774 | 1785 |
retry: |
| 1775 | 1786 |
while (tmp) {
|
| 1776 | 1787 |
if (RCLASS_CONST_TBL(tmp) && st_lookup(RCLASS_CONST_TBL(tmp), (st_data_t)id, &value)) {
|
| 1777 |
if ((VALUE)value == Qundef && !autoload_node((VALUE)klass, id, 0))
|
|
| 1788 |
if (((rb_const_entry_t*)value)->value == Qundef && !autoload_node((VALUE)klass, id, 0))
|
|
| 1778 | 1789 |
return (int)Qfalse; |
| 1779 | 1790 |
return (int)Qtrue; |
| 1780 | 1791 |
} |
| ... | ... | |
| 1825 | 1836 |
void |
| 1826 | 1837 |
rb_const_set(VALUE klass, ID id, VALUE val) |
| 1827 | 1838 |
{
|
| 1839 |
rb_const_entry_t *ce; |
|
| 1840 | ||
| 1828 | 1841 |
if (NIL_P(klass)) {
|
| 1829 | 1842 |
rb_raise(rb_eTypeError, "no class/module to define constant %s", |
| 1830 | 1843 |
rb_id2name(id)); |
| ... | ... | |
| 1838 | 1851 |
st_data_t value; |
| 1839 | 1852 | |
| 1840 | 1853 |
if (st_lookup(RCLASS_CONST_TBL(klass), (st_data_t)id, &value)) {
|
| 1841 |
if ((VALUE)value == Qundef)
|
|
| 1854 |
if (((rb_const_entry_t*)value)->value == Qundef)
|
|
| 1842 | 1855 |
autoload_delete(klass, id); |
| 1843 | 1856 |
else |
| 1844 | 1857 |
rb_warn("already initialized constant %s", rb_id2name(id));
|
| ... | ... | |
| 1846 | 1859 |
} |
| 1847 | 1860 | |
| 1848 | 1861 |
rb_vm_change_state(); |
| 1849 |
st_insert(RCLASS_CONST_TBL(klass), (st_data_t)id, (st_data_t)val); |
|
| 1862 | ||
| 1863 |
ce = ALLOC(rb_const_entry_t); |
|
| 1864 |
ce->flag = CONST_PUBLIC; |
|
| 1865 |
ce->value = val; |
|
| 1866 | ||
| 1867 |
st_insert(RCLASS_CONST_TBL(klass), (st_data_t)id, (st_data_t)ce); |
|
| 1850 | 1868 |
} |
| 1851 | 1869 | |
| 1852 | 1870 |
void |
| b/vm_insnhelper.c | ||
|---|---|---|
| 11 | 11 |
/* finish iseq array */ |
| 12 | 12 |
#include "insns.inc" |
| 13 | 13 |
#include <math.h> |
| 14 |
#include "constant.h" |
|
| 14 | 15 | |
| 15 | 16 |
/* control stack frame */ |
| 16 | 17 | |
| ... | ... | |
| 1166 | 1167 |
cref = cref->nd_next; |
| 1167 | 1168 | |
| 1168 | 1169 |
if (!NIL_P(klass)) {
|
| 1170 |
st_data_t v; |
|
| 1169 | 1171 |
VALUE am = 0; |
| 1170 | 1172 |
search_continue: |
| 1171 | 1173 |
if (RCLASS_CONST_TBL(klass) && |
| 1172 |
st_lookup(RCLASS_CONST_TBL(klass), id, &val)) {
|
|
| 1174 |
st_lookup(RCLASS_CONST_TBL(klass), id, &v)) {
|
|
| 1175 |
val = ((rb_const_entry_t*)v)->value; |
|
| 1173 | 1176 |
if (val == Qundef) {
|
| 1174 | 1177 |
if (am == klass) break; |
| 1175 | 1178 |
am = klass; |
| 1176 |
- |
|