ruby: use placement-new instead of hack

develop
jj 2014-04-01 15:05:39 +02:00
parent a09e132107
commit eac126c884
1 changed files with 3 additions and 7 deletions

@ -778,9 +778,7 @@ static VALUE rb_dfmemory_stlstring_delete(VALUE self, VALUE addr)
} }
static VALUE rb_dfmemory_stlstring_init(VALUE self, VALUE addr) static VALUE rb_dfmemory_stlstring_init(VALUE self, VALUE addr)
{ {
// XXX THIS IS TERRIBLE new((void*)rb_num2ulong(addr)) std::string();
std::string *ptr = new std::string;
memcpy((void*)rb_num2ulong(addr), (void*)ptr, sizeof(*ptr));
return Qtrue; return Qtrue;
} }
static VALUE rb_dfmemory_read_stlstring(VALUE self, VALUE addr) static VALUE rb_dfmemory_read_stlstring(VALUE self, VALUE addr)
@ -812,8 +810,7 @@ static VALUE rb_dfmemory_vec_delete(VALUE self, VALUE addr)
} }
static VALUE rb_dfmemory_vec_init(VALUE self, VALUE addr) static VALUE rb_dfmemory_vec_init(VALUE self, VALUE addr)
{ {
std::vector<uint8_t> *ptr = new std::vector<uint8_t>; new((void*)rb_num2ulong(addr)) std::vector<uint8_t>();
memcpy((void*)rb_num2ulong(addr), (void*)ptr, sizeof(*ptr));
return Qtrue; return Qtrue;
} }
// vector<uint8> // vector<uint8>
@ -903,8 +900,7 @@ static VALUE rb_dfmemory_vecbool_delete(VALUE self, VALUE addr)
} }
static VALUE rb_dfmemory_vecbool_init(VALUE self, VALUE addr) static VALUE rb_dfmemory_vecbool_init(VALUE self, VALUE addr)
{ {
std::vector<bool> *ptr = new std::vector<bool>; new((void*)rb_num2ulong(addr)) std::vector<bool>();
memcpy((void*)rb_num2ulong(addr), (void*)ptr, sizeof(*ptr));
return Qtrue; return Qtrue;
} }
static VALUE rb_dfmemory_vecbool_length(VALUE self, VALUE addr) static VALUE rb_dfmemory_vecbool_length(VALUE self, VALUE addr)