File tree Expand file tree Collapse file tree 1 file changed +37
-6
lines changed
Expand file tree Collapse file tree 1 file changed +37
-6
lines changed Original file line number Diff line number Diff line change @@ -49,16 +49,47 @@ namespace IECorePython
4949
5050struct half_to_float
5151{
52- static PyObject* convert ( const half &x )
53- {
54- return PyFloat_FromDouble ( x );
55- }
52+ static PyObject* convert ( const half &x )
53+ {
54+ return PyFloat_FromDouble ( x );
55+ }
56+ };
57+
58+ struct HalfFromPython
59+ {
60+ HalfFromPython ()
61+ {
62+ converter::registry::push_back (
63+ &convertible,
64+ &construct,
65+ type_id<half> ()
66+ );
67+ }
68+
69+ static void *convertible ( PyObject *obj_ptr )
70+ {
71+ if ( !PyFloat_Check ( obj_ptr ) )
72+ {
73+ return nullptr ;
74+ }
75+ return obj_ptr;
76+ }
77+
78+ static void construct ( PyObject *obj_ptr, converter::rvalue_from_python_stage1_data *data )
79+ {
80+ assert ( obj_ptr );
81+
82+ void * storage = (( converter::rvalue_from_python_storage<half>* ) data )->storage .bytes ;
83+ new ( storage ) half ( extract<float >( obj_ptr ) );
84+ data->convertible = storage;
85+ }
5686};
5787
5888void bindHalf ()
5989{
60- to_python_converter<half, half_to_float>();
61- implicitly_convertible<float , half>();
90+ to_python_converter<half, half_to_float>();
91+ HalfFromPython ();
92+ // implicitly_convertible<float, half>();
6293}
6394
6495}
You can’t perform that action at this time.
0 commit comments