Code review comment for lp:~pete-woods/unity-api/add-glib-assigner-class

Revision history for this message
Pete Woods (pete-woods) wrote :

So one of the design goals I had for this was to use the built in unique_ptr and shared_ptr classes as much as possible:
* Developers are familiar with their semantics.
* unique_ptr "moves" to shared_ptr implicitly.

I agree it'd be nicer to try and make this a template, so I'll see if I can get that to work.

I plan to (if I can get it to work) make the technique also apply to glib style property getters (mainly for char arrays).

e.g. instead of:

gchar* a = nullptr;
gchar* b = nullptr;
g_get_properties(o, "a", &a, "b", &b, nullptr);
g_free(a);
g_free(b);

doing:

GCharUPtr a, b;
g_get_properties(o, "a", Assigner<gchar>(a), "b", Assigner<gchar>(b), nullptr);

I would also like it to apply generally to any glib or gobject type that is allocated this way.

e.g. a factory method:

unique_ptr<GApple> cpp_get_apple() {
    unique_ptr<GApple> a;
    if (!g_get_apple(_gFactory.get(), Assigner(a))) {
        throw some_error();
    }
    return a;
}

which I can then assign to a shared_ptr:

shared_ptr<GApple> a(cpp_get_apple());
other_method_call_that_wants_a_shared_ptr(a);

« Back to merge proposal