summaryrefslogtreecommitdiff
path: root/vm_method.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-09-08 09:52:26 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-09-08 09:52:26 +0000
commit5fbfc21b67f4bd68502e186024636f5bf4350f90 (patch)
tree3ff79b074c314852173be275c081b16483b1f3ac /vm_method.c
parentea005c47faf3563b7fc9a3f92525a05e745df033 (diff)
internal.h: allocator function in rb_classext_t
* internal.h (struct rb_classext_struct): move allocator function into rb_classext_t from ordinary method table. [ruby-dev:46121] [Feature #6993] * object.c (rb_obj_alloc): call allocator function directly. * vm_method.c (rb_define_alloc_func, rb_undef_alloc_func) (rb_get_alloc_func): use allocator function in rb_classext_t. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36925 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_method.c')
-rw-r--r--vm_method.c29
1 files changed, 10 insertions, 19 deletions
diff --git a/vm_method.c b/vm_method.c
index 6582bd1716..43b9ddb107 100644
--- a/vm_method.c
+++ b/vm_method.c
@@ -190,13 +190,6 @@ rb_method_entry_make(VALUE klass, ID mid, rb_method_type_t type,
(mid == rb_intern("initialize") || mid == rb_intern("initialize_copy"))) {
noex = NOEX_PRIVATE | noex;
}
- else if (FL_TEST(klass, FL_SINGLETON) &&
- type == VM_METHOD_TYPE_CFUNC &&
- mid == rb_intern("allocate")) {
- rb_warn("defining %s.allocate is deprecated; use rb_define_alloc_func()",
- rb_class2name(rb_ivar_get(klass, attached)));
- mid = ID_ALLOCATOR;
- }
rb_check_frozen(klass);
#if NOEX_NOREDEF
@@ -289,7 +282,7 @@ rb_method_entry_make(VALUE klass, ID mid, rb_method_type_t type,
static void
method_added(VALUE klass, ID mid)
{
- if (mid != ID_ALLOCATOR && ruby_running) {
+ if (ruby_running) {
CALL_METHOD_HOOK(klass, added, mid);
}
}
@@ -355,34 +348,32 @@ rb_method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *me, rb_method_
return newme;
}
+#define UNDEF_ALLOC_FUNC ((rb_alloc_func_t)-1)
+
void
rb_define_alloc_func(VALUE klass, VALUE (*func)(VALUE))
{
Check_Type(klass, T_CLASS);
- rb_add_method_cfunc(rb_singleton_class(klass), ID_ALLOCATOR,
- func, 0, NOEX_PRIVATE);
+ RCLASS_EXT(klass)->allocator = func;
}
void
rb_undef_alloc_func(VALUE klass)
{
- Check_Type(klass, T_CLASS);
- rb_add_method(rb_singleton_class(klass), ID_ALLOCATOR, VM_METHOD_TYPE_UNDEF, 0, NOEX_UNDEF);
+ rb_define_alloc_func(klass, UNDEF_ALLOC_FUNC);
}
rb_alloc_func_t
rb_get_alloc_func(VALUE klass)
{
- rb_method_entry_t *me;
Check_Type(klass, T_CLASS);
- me = rb_method_entry(CLASS_OF(klass), ID_ALLOCATOR, 0);
- if (me && me->def && me->def->type == VM_METHOD_TYPE_CFUNC) {
- return (rb_alloc_func_t)me->def->body.cfunc.func;
- }
- else {
- return 0;
+ for (; klass; klass = RCLASS_SUPER(klass)) {
+ rb_alloc_func_t allocator = RCLASS_EXT(klass)->allocator;
+ if (allocator == UNDEF_ALLOC_FUNC) break;
+ if (allocator) return allocator;
}
+ return 0;
}
static rb_method_entry_t*