unity::util::unique_gobject() and friends have ambiguous ownership semantics
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
unity-api (Ubuntu) |
Fix Released
|
Medium
|
Pete Woods |
Bug Description
The unique_gobject() helper has ownership semantics that are likely to introduce bugs in code using it. It's current logic is essentially:
1. if the object passed as an argument has a floating reference, increment its ref count.
2. if not, steal the caller's reference.
So we can't tell statically whether this function steals a reference or creates its own. This makes it more difficult to reason about code using this helper.
It would be better to choose one of the following:
1. Always create your own reference, using ref_sink() to sink any floating reference.
2. Always steal the caller's reference. Treat the presence of a floating reference as an
error, since it indicates that the caller doesn't know if it owns the object.
(1) can be a pain because the caller will need to do a manual unref if they pass a newly constructed object to unique_gobject() that doesn't have a floating reference.
(2) means that the caller will need to do their own ref_sink() call if they are passing an object they don't actually own a reference to.
We picked (2) for thumbnailer's gobj_ptr smart pointer class.
Related branches
- James Henstridge: Approve
- Unity8 CI Bot: Approve (continuous-integration)
- Unity Team: Pending requested
-
Diff: 79 lines (+26/-9)2 files modifiedinclude/unity/util/GObjectMemory.h (+9/-5)
test/gtest/unity/util/GObjectMemory/GObjectMemory_test.cpp (+17/-4)
Changed in unity-api (Ubuntu): | |
status: | New → In Progress |
importance: | Undecided → Medium |
assignee: | nobody → Pete Woods (pete-woods) |
This bug was fixed in the package unity-api - 8.6+17. 04.20170317- 0ubuntu1
--------------- 04.20170317- 0ubuntu1) zesty; urgency=medium
unity-api (8.6+17.
[ Michael Zanetti ]
* Add appId property to MirSurfaceInterface
[ Pete Woods ]
* unity::util - unique_gobject and share_gobject now throw for
floating references (LP: #1672657)
-- Lukáš Tinkl <email address hidden> Fri, 17 Mar 2017 11:08:20 +0000