Skip to content

Commit 38230d2

Browse files
committed
Merge pull request #415 from davidsminor/blindDataThreadingFix
BlindDataHolder threading fix
2 parents 46839e0 + ae84633 commit 38230d2

File tree

3 files changed

+14
-41
lines changed

3 files changed

+14
-41
lines changed

include/IECore/BlindDataHolder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class IECORE_API BlindDataHolder : public Object
6161

6262
private :
6363

64-
mutable CompoundDataPtr m_data;
64+
CompoundDataPtr m_data;
6565

6666
static const unsigned int m_ioVersion;
6767

src/IECore/BlindDataHolder.cpp

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ IE_CORE_DEFINEOBJECTTYPEDESCRIPTION(BlindDataHolder);
4646

4747
BlindDataHolder::BlindDataHolder()
4848
{
49-
m_data = 0;
49+
m_data = new CompoundData();
5050
}
5151

5252
BlindDataHolder::BlindDataHolder(CompoundDataPtr data) : m_data(data)
@@ -60,41 +60,26 @@ BlindDataHolder::~BlindDataHolder()
6060

6161
CompoundData *BlindDataHolder::blindData()
6262
{
63-
if ( !m_data )
64-
{
65-
m_data = new CompoundData();
66-
}
6763
return m_data.get();
6864
}
6965

7066
const CompoundData *BlindDataHolder::blindData() const
7167
{
72-
if ( !m_data )
73-
{
74-
m_data = new CompoundData();
75-
}
7668
return m_data.get();
7769
}
7870

7971
void BlindDataHolder::copyFrom( const Object *other, CopyContext *context )
8072
{
8173
Object::copyFrom( other, context );
8274
const BlindDataHolder *tOther = static_cast<const BlindDataHolder *>( other );
83-
if ( tOther->m_data )
84-
{
85-
m_data = context->copy<CompoundData>( tOther->m_data.get() );
86-
}
87-
else
88-
{
89-
m_data = 0;
90-
}
75+
m_data = context->copy<CompoundData>( tOther->m_data.get() );
9176
}
9277

9378
void BlindDataHolder::save( SaveContext *context ) const
9479
{
9580
Object::save( context );
9681

97-
bool haveData = ( m_data && m_data->readable().size() );
82+
bool haveData = m_data->readable().size();
9883

9984
if ( haveData )
10085
{
@@ -117,7 +102,7 @@ void BlindDataHolder::load( LoadContextPtr context )
117102
}
118103
else
119104
{
120-
m_data = 0;
105+
m_data = new CompoundData();
121106
}
122107
}
123108

@@ -128,39 +113,21 @@ bool BlindDataHolder::isEqualTo( const Object *other ) const
128113
return false;
129114
}
130115
const BlindDataHolder *tOther = static_cast<const BlindDataHolder *>( other );
131-
if ( m_data )
132-
{
133-
if ( tOther->m_data )
134-
{
135-
return m_data->isEqualTo( tOther->m_data.get() );
136-
}
137-
else
138-
{
139-
return ( m_data->readable().size() == 0 );
140-
}
141-
}
142-
if ( tOther->m_data )
143-
{
144-
return ( tOther->m_data->readable().size() == 0 );
145-
}
146-
return true;
116+
return m_data->isEqualTo( tOther->m_data.get() );
147117
}
148118

149119
void BlindDataHolder::memoryUsage( Object::MemoryAccumulator &a ) const
150120
{
151121
Object::memoryUsage( a );
152-
if ( m_data )
153-
{
154-
a.accumulate( m_data.get() );
155-
}
122+
a.accumulate( m_data.get() );
156123
}
157124

158125
void BlindDataHolder::hash( MurmurHash &h ) const
159126
{
160127
Object::hash( h );
161128
// Our hash when blindData is empty or when m_data is unnitialized is the same.
162129
// This is currently garanteed by CompoundData but we are safer this way.
163-
if ( m_data && m_data->readable().size() )
130+
if ( m_data->readable().size() )
164131
{
165132
m_data->hash( h );
166133
}

test/IECore/BlindDataHolder.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ def testLoadSave(self):
102102

103103
b2 = Object.load( iface, "test" )
104104
self.assertEqual( b1, b2 )
105+
106+
# should have written a "blindData" entry into the indexed io hierarchy
107+
self.failUnless( isinstance( iface.directory( ["test","data","BlindDataHolder", "data", "blindData"], IndexedIO.MissingBehaviour.NullIfMissing ), IndexedIO ) )
105108

106109
# second test: overriding with no blind data
107110
b1 = BlindDataHolder()
@@ -124,6 +127,9 @@ def testLoadSave(self):
124127
g2 = Object.load( iface, "test" )
125128
self.assertEqual( g1, g2 )
126129

130+
# "blindData" entry should be excluded from the IndexedIO hierarchy
131+
self.assertEqual( iface.directory( ["test","data","BlindDataHolder"], IndexedIO.MissingBehaviour.NullIfMissing ), None )
132+
127133
def testHash( self ) :
128134

129135
b1 = BlindDataHolder()

0 commit comments

Comments
 (0)