Skip to content

Commit 1af7819

Browse files
committed
SimpleTypedDataBinding : Fix half on clang
1 parent 9237632 commit 1af7819

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

include/IECorePython/SimpleTypedDataBinding.inl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,42 @@ struct TypedDataFromType<IECore::BoolData>
101101

102102
};
103103

104+
// Specialize `half` to build on clang. See comment in `construct()` below.
105+
template<>
106+
struct TypedDataFromType<IECore::HalfData>
107+
{
108+
109+
TypedDataFromType()
110+
{
111+
boost::python::converter::registry::push_back(
112+
&convertible,
113+
&construct,
114+
boost::python::type_id<IECore::HalfDataPtr>()
115+
);
116+
117+
}
118+
119+
static void *convertible( PyObject *obj )
120+
{
121+
boost::python::extract<Imath::half> e( obj );
122+
if( e.check() )
123+
{
124+
return obj;
125+
}
126+
return nullptr;
127+
}
128+
129+
static void construct( PyObject *obj, boost::python::converter::rvalue_from_python_stage1_data *data )
130+
{
131+
void *storage = ((boost::python::converter::rvalue_from_python_storage<IECore::HalfDataPtr>*)data)->storage.bytes;
132+
// This line is needed to force clang to find the right `half` constructor. Not specializing this, or
133+
// creating `HalfData` directly from the return value of `extract<Imath::half>()` results in
134+
// `error: no viable conversion from 'boost::python::extract<Imath::half>' to 'Imath_3_1::half'`.
135+
Imath::half v = boost::python::extract<Imath::half>( obj );
136+
new (storage) IECore::HalfDataPtr( new IECore::HalfData( v ) );
137+
data->convertible = storage;
138+
}
139+
140+
};
141+
104142
} // namespace IECorePython

0 commit comments

Comments
 (0)