mirror of https://github.com/KLayout/klayout.git
Ported enhancements for #33 fix (factory callbacks) to Ruby too.
This commit is contained in:
parent
1cea7dfd23
commit
6e14460334
|
|
@ -327,6 +327,14 @@ Proxy::call (int id, gsi::SerialArgs &args, gsi::SerialArgs &ret) const
|
|||
|
||||
push_arg (meth->ret_type (), ret, rb_ret, heap);
|
||||
|
||||
if (meth->ret_type ().pass_obj ()) {
|
||||
// In factory callbacks, make sure the returned object is not deleted by
|
||||
// anyone except the caller.
|
||||
Proxy *p = 0;
|
||||
Data_Get_Struct (rb_ret, Proxy, p);
|
||||
p->keep ();
|
||||
}
|
||||
|
||||
// a Ruby callback must not leave temporary objects
|
||||
tl_assert (heap.empty ());
|
||||
|
||||
|
|
|
|||
|
|
@ -53,6 +53,27 @@ class RBA::E
|
|||
@m = nil
|
||||
end
|
||||
|
||||
class RBAGObject < RBA::GObject
|
||||
def initialize(z)
|
||||
super()
|
||||
@z = z
|
||||
end
|
||||
# reimplementation of "virtual int g()"
|
||||
def g
|
||||
return @z*2
|
||||
end
|
||||
end
|
||||
|
||||
class RBAGFactory < RBA::GFactory
|
||||
def initialize
|
||||
super()
|
||||
end
|
||||
# reimplementation of "virtual GObject *f(int)"
|
||||
def f(z)
|
||||
return RBAGObject::new(z)
|
||||
end
|
||||
end
|
||||
|
||||
class Basic_TestClass < TestBase
|
||||
|
||||
def test_FIRST
|
||||
|
|
@ -2633,4 +2654,19 @@ class Basic_TestClass < TestBase
|
|||
|
||||
end
|
||||
|
||||
# Custom factory implemented in Ruby
|
||||
def test_80
|
||||
|
||||
gc = RBA::GObject.g_inst_count
|
||||
gf = RBAGFactory::new
|
||||
go = RBA::GFactory.create_f(gf, 17)
|
||||
assert_equal(go.g_virtual, 34)
|
||||
assert_equal(go.g_org, 0)
|
||||
assert_equal(RBA::GObject.g_inst_count, gc + 1)
|
||||
go = nil
|
||||
GC.start
|
||||
assert_equal(RBA::GObject.g_inst_count, gc)
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue