From 4ef8e5228e3011acea61f7ad1d29d3273e883f0c Mon Sep 17 00:00:00 2001 From: rdb Date: Sat, 22 Feb 2020 12:08:03 +0100 Subject: [PATCH] interrogate: fix ability to return ReferenceCount-like classes Classes with virtual ref(), unref() and get_ref_count() methods, like RecorderBase, could not be returned by PT() from methods because they didn't inherit from ReferenceCount. However, classes do not need to inherit ReferenceCount to be able to be tracked by a PointerTo, and defining an abstract base class with pure virtual ref()/unref()/get_ref_count() is a way to avoid dual inheritance of ReferenceCount. --- dtool/src/interrogate/typeManager.cxx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/dtool/src/interrogate/typeManager.cxx b/dtool/src/interrogate/typeManager.cxx index ab1fbffce3..dba10f4520 100644 --- a/dtool/src/interrogate/typeManager.cxx +++ b/dtool/src/interrogate/typeManager.cxx @@ -1442,7 +1442,7 @@ is_void(CPPType *type) { /** * Returns true if the indicated type is some class that derives from - * ReferenceCount, or false otherwise. + * ReferenceCount, or defines ref and unref(), or false otherwise. */ bool TypeManager:: is_reference_count(CPPType *type) { @@ -1459,6 +1459,14 @@ is_reference_count(CPPType *type) { case CPPDeclaration::ST_struct: { CPPStructType *stype = type->as_struct_type(); + + // If we have methods named ref() and unref(), this is good enough. + if (stype->_scope->_functions.count("ref") && + stype->_scope->_functions.count("unref") && + stype->_scope->_functions.count("get_ref_count")) { + return true; + } + CPPStructType::Derivation::const_iterator di; for (di = stype->_derivation.begin(); di != stype->_derivation.end();