diff --git a/src/rba/rba/rbaInternal.cc b/src/rba/rba/rbaInternal.cc index 8227a8bd4..7cc10964e 100644 --- a/src/rba/rba/rbaInternal.cc +++ b/src/rba/rba/rbaInternal.cc @@ -257,7 +257,7 @@ 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 ()) { + if (meth->ret_type ().pass_obj () && rb_ret != Qnil) { // In factory callbacks, make sure the returned object is not deleted by // anyone except the caller. Proxy *p = 0; diff --git a/testdata/python/basic.py b/testdata/python/basic.py index fc988880b..234528431 100644 --- a/testdata/python/basic.py +++ b/testdata/python/basic.py @@ -146,6 +146,13 @@ class PyGFactory(pya.GFactory): def f(self, z): return PyGObject(z) +class PyNilGFactory(pya.GFactory): + def __init__(self): + super(PyNilGFactory, self).__init__() + # reimplementation of "virtual GObject *f(int)" + def f(self, z): + return None + class BasicTest(unittest.TestCase): def test_00(self): @@ -3255,6 +3262,10 @@ class BasicTest(unittest.TestCase): go = None self.assertEqual(pya.GObject.g_inst_count(), gc) + gf = PyNilGFactory() + go = pya.GFactory.create_f(gf, 17) + self.assertEqual(go is None, True) + # fallback to __rmul__ for not implemented __mul__ def test_90(self): diff --git a/testdata/ruby/basic_testcore.rb b/testdata/ruby/basic_testcore.rb index b19e22b95..caef54edf 100644 --- a/testdata/ruby/basic_testcore.rb +++ b/testdata/ruby/basic_testcore.rb @@ -3252,6 +3252,10 @@ class Basic_TestClass < TestBase GC.start assert_equal(RBA::GObject.g_inst_count, gc) + gf = RBANilGFactory::new + go = RBA::GFactory.create_f(gf, 17) + assert_equal(go, nil) + end # keyword arguments, enums and error messages diff --git a/testdata/ruby/basic_testcore_defs.rb b/testdata/ruby/basic_testcore_defs.rb index fb896a71c..b6ff5502f 100644 --- a/testdata/ruby/basic_testcore_defs.rb +++ b/testdata/ruby/basic_testcore_defs.rb @@ -76,3 +76,13 @@ class RBAGFactory < RBA::GFactory end end +class RBANilGFactory < RBA::GFactory + def initialize + super() + end + # reimplementation of "virtual GObject *f(int)" + def f(z) + return nil + end +end +