Skip to content

Commit b97a656

Browse files
committed
Merge pull request #284 from johnhaddon/refCountBinding
Added python binding for RefCounted::refCount().
2 parents 06d08cb + 2b83a54 commit b97a656

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/IECorePython/RefCountedBinding.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ void bindRefCounted()
7878
.def( "__ne__", notEqual )
7979
.def( "__hash__", hash )
8080
.def( "isSame", &is )
81+
.def( "refCount", &RefCounted::refCount )
8182
.def( "numWrappedInstances", &WrapperGarbageCollector::numWrappedInstances ).staticmethod( "numWrappedInstances" )
8283
.add_static_property( "garbageCollectionThreshold", &WrapperGarbageCollector::getCollectThreshold, &WrapperGarbageCollector::setCollectThreshold )
8384
.def( "collectGarbage", &WrapperGarbageCollector::collect ).staticmethod( "collectGarbage" )

test/IECore/RefCountedTest.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,5 +151,18 @@ def testUseAsKey( self ) :
151151
self.assertEqual( d[p2], "p2" )
152152
self.assertEqual( d[c["p2"]], "p2" )
153153

154+
def testRefCount( self ) :
155+
156+
c = IECore.CompoundData()
157+
i = IECore.IntData( 10 )
158+
159+
r = i.refCount()
160+
161+
c["i"] = i
162+
self.assertEqual( i.refCount(), r + 1 )
163+
164+
del c["i"]
165+
self.assertEqual( i.refCount(), r )
166+
154167
if __name__ == "__main__":
155168
unittest.main()

0 commit comments

Comments
 (0)