From eac126c8844c87c8cff294912194a6d7916beba6 Mon Sep 17 00:00:00 2001 From: jj Date: Tue, 1 Apr 2014 15:05:39 +0200 Subject: [PATCH] ruby: use placement-new instead of hack --- plugins/ruby/ruby.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/plugins/ruby/ruby.cpp b/plugins/ruby/ruby.cpp index 33477d56e..17db1eb21 100644 --- a/plugins/ruby/ruby.cpp +++ b/plugins/ruby/ruby.cpp @@ -778,9 +778,7 @@ static VALUE rb_dfmemory_stlstring_delete(VALUE self, VALUE addr) } static VALUE rb_dfmemory_stlstring_init(VALUE self, VALUE addr) { - // XXX THIS IS TERRIBLE - std::string *ptr = new std::string; - memcpy((void*)rb_num2ulong(addr), (void*)ptr, sizeof(*ptr)); + new((void*)rb_num2ulong(addr)) std::string(); return Qtrue; } 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) { - std::vector *ptr = new std::vector; - memcpy((void*)rb_num2ulong(addr), (void*)ptr, sizeof(*ptr)); + new((void*)rb_num2ulong(addr)) std::vector(); return Qtrue; } // vector @@ -903,8 +900,7 @@ static VALUE rb_dfmemory_vecbool_delete(VALUE self, VALUE addr) } static VALUE rb_dfmemory_vecbool_init(VALUE self, VALUE addr) { - std::vector *ptr = new std::vector; - memcpy((void*)rb_num2ulong(addr), (void*)ptr, sizeof(*ptr)); + new((void*)rb_num2ulong(addr)) std::vector(); return Qtrue; } static VALUE rb_dfmemory_vecbool_length(VALUE self, VALUE addr)