Re: Problems with un-owned objects passed to closures in pygobject (gtk_cell_renderer_text_start_editing)



On 29/01/13 11:44, Simon Feltman wrote:
> It seems like the problem at hand can be solved by maintaining the
> floating ref and adding our own safety ref for the wrapper.

My impression was that floating references were purely for C
convenience, and that interpreted languages with their own refcounting
should be turning them into normal refs that can be reasoned about more
easily. Shouldn't PyGObject rather be sinking *every* floating ref it
sees? (Effectively, the Python wrapper would behave like a container, I
suppose.) Then you'd have:

(transfer none) function returning a pointer to a non-floating object:
g_object_ref_sink() refs it; the wrapper now owns a normal ref. If you
gtk_container_add() the wrapped object, the ref is no longer floating,
so the container takes a new ref and the wrapper still owns the old ref.
If the Python wrapper is destroyed, the C container still keeps the
wrapped object alive. Good?

(transfer none) function returning a pointer to a floating object:
g_object_ref_sink() turns the floating ref into a normal ref. Proceed as
above. Good?

(transfer full) function returning a normal ref (as detected by
g_object_is_floating() == FALSE): do nothing, the wrapper takes
ownership of that ref. Proceed as above. Good?

(transfer full) function returning a floating ref (as detected by
g_object_is_floating() == TRUE): g_object_ref_sink() refs it, the
wrapper now owns a normal ref. Proceed as above. Good?

Pseudocode:

    def give_me_a_real_ref(function):
        if function.transfer_none:
            return g_object_ref_sink(function())
        else:
            tmp = function()
            if g_object_is_floating(tmp):
                g_object_ref_sink(tmp)
            return tmp

Or is that wrong?

Regards,
    S


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]