Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve type of function callbacks in register_upgrade_function and register_downgrade_function #1445

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/py-opentimelineio/opentimelineio-bindings/otio_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright Contributors to the OpenTimelineIO project

#include <pybind11/pybind11.h>
#include <pybind11/functional.h>
#include "otio_anyDictionary.h"
#include "otio_anyVector.h"
#include "otio_bindings.h"
Expand Down Expand Up @@ -71,13 +72,12 @@ static void register_python_type(py::object class_object,

static bool register_upgrade_function(std::string const& schema_name,
int version_to_upgrade_to,
py::object const& upgrade_function_obj) {
std::function<void(AnyDictionaryProxy*)> const& upgrade_function_obj) {
std::function<void (AnyDictionary* d)> upgrade_function = [upgrade_function_obj](AnyDictionary* d) {
py::gil_scoped_acquire acquire;

auto ptr = d->get_or_create_mutation_stamp();
py::object dobj = py::cast((AnyDictionaryProxy*)ptr);
upgrade_function_obj(dobj);
upgrade_function_obj((AnyDictionaryProxy*)ptr);
};

// further discussion required about preventing double registering
Expand Down Expand Up @@ -112,16 +112,15 @@ static bool
register_downgrade_function(
std::string const& schema_name,
int version_to_downgrade_from,
py::object const& downgrade_function_obj)
std::function<void(AnyDictionaryProxy*)> const& downgrade_function_obj)
{
std::function<void (AnyDictionary* d)> downgrade_function = (
[downgrade_function_obj](AnyDictionary* d)
{
py::gil_scoped_acquire acquire;

auto ptr = d->get_or_create_mutation_stamp();
py::object dobj = py::cast((AnyDictionaryProxy*)ptr);
downgrade_function_obj(dobj);
downgrade_function_obj((AnyDictionaryProxy*)ptr);
}
);

Expand Down