OpenColorIO icon indicating copy to clipboard operation
OpenColorIO copied to clipboard

Add .none(false) for arguments of python exposed functions expecting strings

Open BernardLefebvre opened this issue 5 years ago • 8 comments

Several API functions are taking const char * parameters. They are often exposed to Python with: .def("function", &Class::function, "parameter"_a) This is working fine, when used in python, the parameter type is checked, but when used with None a segfault occurs. To handle that .none(false) can be added to the parameter: .def("function", &Class::function, "parameter"_a.none(false))

BernardLefebvre avatar Nov 11 '20 18:11 BernardLefebvre

May I work on this or is this resolved in a recent PR?

EmperorYP7 avatar Nov 13 '20 14:11 EmperorYP7

@EmperorYP7 Thanks to volunteer to work the issue. It only requires some Python knowledge. But I thought you wanted to work on the OpenFX plugin?

hodoulp avatar Nov 13 '20 16:11 hodoulp

That's right @hodoulp sir, I am currently working on OFX plugins but am also curious about this. If someone wants to work on this now, they're welcomed! :smile:

EmperorYP7 avatar Nov 14 '20 10:11 EmperorYP7

May I work on this issue?

divshekhar avatar Nov 17 '20 13:11 divshekhar

For example, this would crash: cfg = OCIO.Config.CreateRaw() cfg.getColorSpace(None)

BernardLefebvre avatar Nov 17 '20 13:11 BernardLefebvre

As @divshekhar noticed it is also the case for shared pointers.

BernardLefebvre avatar Nov 18 '20 12:11 BernardLefebvre

When binding a function that takes char * as parameter, automatic binding would expect a string but None is not allowed and should be excluded with none(false) if the function is bound directly.

If the binding is done with a function using std::string None would be handled (ex: def_static("CreateFromStream", [](const std::string & str)).

Other type, like ints, enums etc are already handling None.

Situation in ensure with shared pointers (empty shared pointers as parameter can be an issue for the API).

BernardLefebvre avatar Nov 20 '20 20:11 BernardLefebvre

This issue is still open, but requires some experience with pybind.

doug-walker avatar Feb 16 '21 00:02 doug-walker