mirror of
https://github.com/KLayout/klayout.git
synced 2026-09-07 03:21:34 +02:00
Ported enhancements for #33 fix (factory callbacks) to Ruby too.
This commit is contained in:
@@ -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 ());
|
||||
|
||||
|
||||
Vendored
+36
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user