MRI: {Rect,Color,Tone}#initialize_copy instead of #clone #3

Closed
cremno wants to merge 1 commits from mri-use-initialize_copy into master
2 changed files with 16 additions and 15 deletions
Showing only changes of commit 4604461514 - Show all commits

View File

@ -195,17 +195,6 @@ rb_bool_new(bool value)
return objectLoad<Typ>(argc, argv, self, Typ##Type); \ return objectLoad<Typ>(argc, argv, self, Typ##Type); \
} }
#define CLONE_FUNC(Klass) \
static mrb_value \
Klass##Clone(mrb_state *mrb, mrb_value self) \
{ \
Klass *k = getPrivateData<Klass>(mrb, self); \
mrb_value dupObj = mrb_obj_clone(mrb, self); \
Klass *dupK = new Klass(*k); \
setPrivateData(mrb, dupObj, dupK, Klass##Type); \
return dupObj; \
}
#define CLONE_FUN(Klass) \ #define CLONE_FUN(Klass) \
RB_METHOD(Klass##Clone) \ RB_METHOD(Klass##Clone) \
{ \ { \
@ -217,6 +206,18 @@ rb_bool_new(bool value)
return dupObj; \ return dupObj; \
} }
#define INITCOPY_FUN(Klass) \
RB_METHOD(Klass##InitCopy) \
{ \
VALUE original; \
rb_get_args(argc, argv, "o", &original); \
if (!OBJ_INIT_COPY(self, original)) \
return self; \
Klass *k = getPrivateData<Klass>(original); \
setPrivateData(self, new Klass(*k), Klass##Type); \
return self; \
}
/* If we're not binding a disposable class, /* If we're not binding a disposable class,
* we want to #undef DEF_PROP_CHK_DISP */ * we want to #undef DEF_PROP_CHK_DISP */
#define DEF_PROP_CHK_DISP \ #define DEF_PROP_CHK_DISP \

View File

@ -148,9 +148,9 @@ MARSH_LOAD_FUN(Color)
MARSH_LOAD_FUN(Tone) MARSH_LOAD_FUN(Tone)
MARSH_LOAD_FUN(Rect) MARSH_LOAD_FUN(Rect)
CLONE_FUN(Tone) INITCOPY_FUN(Tone)
CLONE_FUN(Color) INITCOPY_FUN(Color)
CLONE_FUN(Rect) INITCOPY_FUN(Rect)
#define INIT_BIND(Klass) \ #define INIT_BIND(Klass) \
{ \ { \
@ -159,8 +159,8 @@ CLONE_FUN(Rect)
rb_define_class_method(klass, "_load", Klass##Load); \ rb_define_class_method(klass, "_load", Klass##Load); \
serializableBindingInit<Klass>(klass); \ serializableBindingInit<Klass>(klass); \
_rb_define_method(klass, "initialize", Klass##Initialize); \ _rb_define_method(klass, "initialize", Klass##Initialize); \
_rb_define_method(klass, "initialize_copy", Klass##InitCopy); \
_rb_define_method(klass, "set", Klass##Set); \ _rb_define_method(klass, "set", Klass##Set); \
_rb_define_method(klass, "clone", Klass##Clone); \
_rb_define_method(klass, "==", Klass##Equal); \ _rb_define_method(klass, "==", Klass##Equal); \
_rb_define_method(klass, "to_s", Klass##Stringify); \ _rb_define_method(klass, "to_s", Klass##Stringify); \
_rb_define_method(klass, "inspect", Klass##Stringify); \ _rb_define_method(klass, "inspect", Klass##Stringify); \