Skip to content

Commit 41f1695

Browse files
committed
Fix marshalling of pg tuples.
PullRequest: truffleruby/748
2 parents 9c40839 + 551bafb commit 41f1695

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed

lib/truffle/truffle/cext.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,23 @@ def rb_obj_instance_variables(object)
620620
object.instance_variables
621621
end
622622

623+
def rb_copy_generic_ivar(clone, original)
624+
Truffle.check_frozen(clone)
625+
original_ivars = original.instance_variables
626+
rb_free_generic_ivar(clone)
627+
original_ivars.each do |var|
628+
clone.instance_variable_set(var, original.instance_variable_get(var))
629+
end
630+
end
631+
632+
def rb_free_generic_ivar(original)
633+
Truffle.check_frozen(original)
634+
original_ivars = original.instance_variables
635+
original_ivars.each do |var|
636+
original.__send__ :remove_instance_variable, var
637+
end
638+
end
639+
623640
def rb_inspect(object)
624641
Truffle::Type.rb_inspect(object)
625642
end

spec/ruby/optional/capi/ext/object_spec.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,16 @@ static VALUE object_spec_rb_ivar_defined(VALUE self, VALUE obj, VALUE sym_name)
327327
return rb_ivar_defined(obj, SYM2ID(sym_name));
328328
}
329329

330+
static VALUE object_spec_rb_copy_generic_ivar(VALUE self, VALUE clone, VALUE obj) {
331+
rb_copy_generic_ivar(clone, obj);
332+
return self;
333+
}
334+
335+
static VALUE object_spec_rb_free_generic_ivar(VALUE self, VALUE obj) {
336+
rb_free_generic_ivar(obj);
337+
return self;
338+
}
339+
330340
static VALUE object_spec_rb_equal(VALUE self, VALUE a, VALUE b) {
331341
return rb_equal(a, b);
332342
}
@@ -400,6 +410,8 @@ void Init_object_spec(void) {
400410
rb_define_method(cls, "rb_ivar_get", object_spec_rb_ivar_get, 2);
401411
rb_define_method(cls, "rb_ivar_set", object_spec_rb_ivar_set, 3);
402412
rb_define_method(cls, "rb_ivar_defined", object_spec_rb_ivar_defined, 2);
413+
rb_define_method(cls, "rb_copy_generic_ivar", object_spec_rb_copy_generic_ivar, 2);
414+
rb_define_method(cls, "rb_free_generic_ivar", object_spec_rb_free_generic_ivar, 1);
403415
}
404416

405417
#ifdef __cplusplus

spec/ruby/optional/capi/object_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,5 +853,24 @@ def reach
853853
@o.rb_ivar_defined(@test, :bar).should == false
854854
end
855855
end
856+
857+
describe "rb_copy_generic_ivar" do
858+
it "copies the instance variables from one object to another" do
859+
original = Object.new
860+
original.instance_variable_set(:@foo, :bar)
861+
clone = Object.new
862+
@o.rb_copy_generic_ivar(clone, original)
863+
clone.instance_variable_get(:@foo).should == :bar
864+
end
865+
end
866+
867+
describe "rb_free_generic_ivar" do
868+
it "removes the instance variables from an object" do
869+
o = Object.new
870+
o.instance_variable_set(:@baz, :flibble)
871+
@o.rb_free_generic_ivar(o)
872+
o.instance_variables.should == []
873+
end
874+
end
856875
end
857876
end

src/main/c/cext/ruby.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,6 +1276,9 @@ int rb_tr_flags(VALUE value) {
12761276
if (OBJ_TAINTED(value)) {
12771277
flags |= RUBY_FL_TAINT;
12781278
}
1279+
if (RARRAY_LEN(rb_obj_instance_variables(value)) > 0) {
1280+
flags |= RUBY_FL_EXIVAR;
1281+
}
12791282
// TODO BJF Nov-11-2017 Implement more flags
12801283
return flags;
12811284
}
@@ -4403,11 +4406,11 @@ void rb_alias_variable(ID name1, ID name2) {
44034406
}
44044407

44054408
void rb_copy_generic_ivar(VALUE clone, VALUE obj) {
4406-
rb_tr_error("rb_copy_generic_ivar not implemented");
4409+
RUBY_CEXT_INVOKE_NO_WRAP("rb_copy_generic_ivar", clone, obj);
44074410
}
44084411

44094412
void rb_free_generic_ivar(VALUE obj) {
4410-
rb_tr_error("rb_free_generic_ivar not implemented");
4413+
RUBY_CEXT_INVOKE_NO_WRAP("rb_free_generic_ivar", obj);
44114414
}
44124415

44134416
void rb_ivar_foreach(VALUE obj, int (*func)(ANYARGS), st_data_t arg) {

0 commit comments

Comments
 (0)