Merge lp:~pete-woods/unity-api/handle-null-quietly into lp:unity-api

Proposed by Pete Woods
Status: Merged
Approved by: Pete Woods
Approved revision: 277
Merged at revision: 274
Proposed branch: lp:~pete-woods/unity-api/handle-null-quietly
Merge into: lp:unity-api
Diff against target: 135 lines (+49/-5)
5 files modified
debian/changelog (+8/-0)
include/unity/util/GObjectMemory.h (+4/-2)
include/unity/util/GlibMemory.h (+18/-3)
test/gtest/unity/util/GObjectMemory/GObjectMemory_test.cpp (+6/-0)
test/gtest/unity/util/GlibMemory/GlibMemory_test.cpp (+13/-0)
To merge this branch: bzr merge lp:~pete-woods/unity-api/handle-null-quietly
Reviewer Review Type Date Requested Status
Unity8 CI Bot continuous-integration Approve
Charles Kerr (community) Approve
Review via email: mp+317803@code.launchpad.net

Commit message

unity::util - Make Glib and GObject memory management utilities handle NULL quietly.

Description of the change

unity::util - Make Glib and GObject memory management utilities handle NULL quietly.

To post a comment you must log in.
Revision history for this message
Unity8 CI Bot (unity8-ci-bot) wrote :

FAILED: Continuous integration, rev:274
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~pete-woods/unity-api/handle-null-quietly/+merge/317803/+edit-commit-message

https://unity8-jenkins.ubuntu.com/job/lp-unity-api-ci/140/
Executed test runs:
    FAILURE: https://unity8-jenkins.ubuntu.com/job/build/4140/console
    FAILURE: https://unity8-jenkins.ubuntu.com/job/build-0-fetch/4168/console

Click here to trigger a rebuild:
https://unity8-jenkins.ubuntu.com/job/lp-unity-api-ci/140/rebuild

review: Needs Fixing (continuous-integration)
275. By Pete Woods

Fix changelog

Revision history for this message
Unity8 CI Bot (unity8-ci-bot) wrote :

FAILED: Continuous integration, rev:275
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~pete-woods/unity-api/handle-null-quietly/+merge/317803/+edit-commit-message

https://unity8-jenkins.ubuntu.com/job/lp-unity-api-ci/141/
Executed test runs:
    FAILURE: https://unity8-jenkins.ubuntu.com/job/build/4142/console
    FAILURE: https://unity8-jenkins.ubuntu.com/job/build-0-fetch/4170/console

Click here to trigger a rebuild:
https://unity8-jenkins.ubuntu.com/job/lp-unity-api-ci/141/rebuild

review: Needs Fixing (continuous-integration)
276. By Pete Woods

Really fix the changelog this time

Revision history for this message
Unity8 CI Bot (unity8-ci-bot) wrote :

PASSED: Continuous integration, rev:276
https://unity8-jenkins.ubuntu.com/job/lp-unity-api-ci/143/
Executed test runs:
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build/4147
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-0-fetch/4175
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/4012
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/4012/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=zesty/4012
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=zesty/4012/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/4012
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/4012/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=zesty/4012
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=zesty/4012/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/4012
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/4012/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=zesty/4012
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=zesty/4012/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://unity8-jenkins.ubuntu.com/job/lp-unity-api-ci/143/rebuild

review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

The idea looks sound, code works as-is. Optional comments inline

review: Approve
277. By Pete Woods

Trying out the deleter methods as charles suggested, making CRITICAL be a fatal error so we know if the deleter logic worked (g_variant_unref logs CRITICAL on null)

Revision history for this message
Unity8 CI Bot (unity8-ci-bot) wrote :

PASSED: Continuous integration, rev:277
https://unity8-jenkins.ubuntu.com/job/lp-unity-api-ci/144/
Executed test runs:
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build/4182
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-0-fetch/4210
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/4047
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/4047/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=zesty/4047
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=zesty/4047/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/4047
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/4047/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=zesty/4047
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=zesty/4047/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/4047
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/4047/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=zesty/4047
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=zesty/4047/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://unity8-jenkins.ubuntu.com/job/lp-unity-api-ci/144/rebuild

review: Approve (continuous-integration)
Revision history for this message
Pete Woods (pete-woods) wrote :

Well clearly my paranoia with the == FALSE thing was based on madness, and we have a successful build on powerpc without it.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2017-02-17 14:12:04 +0000
3+++ debian/changelog 2017-02-23 11:19:18 +0000
4@@ -1,3 +1,11 @@
5+unity-api (8.4-0ubuntu1) UNRELEASED; urgency=medium
6+
7+ [ Pete Woods ]
8+ * unity::util - Make Glib and GObject memory management
9+ utilities handle NULL quietly.
10+
11+ -- Pete <pete.woods@canonical.com> Tue, 21 Feb 2017 13:11:57 +0000
12+
13 unity-api (8.3+17.04.20170217-0ubuntu1) zesty; urgency=medium
14
15 [ Pete ]
16
17=== modified file 'include/unity/util/GObjectMemory.h'
18--- include/unity/util/GObjectMemory.h 2017-01-19 13:49:43 +0000
19+++ include/unity/util/GObjectMemory.h 2017-02-23 11:19:18 +0000
20@@ -59,8 +59,10 @@
21 {
22 void operator()(gpointer ptr)
23 {
24- g_return_if_fail(G_IS_OBJECT(ptr));
25- g_object_unref(ptr);
26+ if (G_IS_OBJECT(ptr))
27+ {
28+ g_object_unref(ptr);
29+ }
30 }
31 };
32
33
34=== modified file 'include/unity/util/GlibMemory.h'
35--- include/unity/util/GlibMemory.h 2017-02-17 13:40:58 +0000
36+++ include/unity/util/GlibMemory.h 2017-02-23 11:19:18 +0000
37@@ -28,18 +28,33 @@
38 namespace util
39 {
40
41+template<typename T, typename D>
42+struct GlibDeleter
43+{
44+ D _d;
45+
46+ void operator()(T* ptr)
47+ {
48+ if (ptr != nullptr)
49+ {
50+ _d(ptr);
51+ }
52+ }
53+};
54+
55 #pragma push_macro("G_DEFINE_AUTOPTR_CLEANUP_FUNC")
56 #undef G_DEFINE_AUTOPTR_CLEANUP_FUNC
57 #define G_DEFINE_AUTOPTR_CLEANUP_FUNC(TypeName, func) \
58+typedef GlibDeleter<TypeName, decltype(&func)> TypeName##Deleter; \
59 typedef std::shared_ptr<TypeName> TypeName##SPtr; \
60 inline TypeName##SPtr share_glib(TypeName* ptr) \
61 { \
62- return TypeName##SPtr(ptr, &func); \
63+ return TypeName##SPtr(ptr, TypeName##Deleter{&func}); \
64 } \
65-typedef std::unique_ptr<TypeName, decltype(&func)> TypeName##UPtr; \
66+typedef std::unique_ptr<TypeName, TypeName##Deleter> TypeName##UPtr; \
67 inline TypeName##UPtr unique_glib(TypeName* ptr) \
68 { \
69- return TypeName##UPtr(ptr, &func); \
70+ return TypeName##UPtr(ptr, TypeName##Deleter{&func}); \
71 }
72
73 #pragma push_macro("G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC")
74
75=== modified file 'test/gtest/unity/util/GObjectMemory/GObjectMemory_test.cpp'
76--- test/gtest/unity/util/GObjectMemory/GObjectMemory_test.cpp 2017-01-19 13:49:43 +0000
77+++ test/gtest/unity/util/GObjectMemory/GObjectMemory_test.cpp 2017-02-23 11:19:18 +0000
78@@ -174,6 +174,11 @@
79 class GObjectMemoryTest: public testing::Test
80 {
81 protected:
82+ static void SetUpTestCase()
83+ {
84+ g_log_set_always_fatal((GLogLevelFlags) (G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL));
85+ }
86+
87 void SetUp() override
88 {
89 DELETED_OBJECTS.clear();
90@@ -298,6 +303,7 @@
91 auto u1 = unique_gobject(o1);
92 auto u2 = unique_gobject<FooBar>(nullptr);
93 auto u3 = unique_gobject(o3);
94+ auto u4 = unique_gobject((FooBar *) NULL);
95
96 EXPECT_TRUE(!u1);
97 EXPECT_TRUE(!u2);
98
99=== modified file 'test/gtest/unity/util/GlibMemory/GlibMemory_test.cpp'
100--- test/gtest/unity/util/GlibMemory/GlibMemory_test.cpp 2017-02-17 13:40:58 +0000
101+++ test/gtest/unity/util/GlibMemory/GlibMemory_test.cpp 2017-02-23 11:19:18 +0000
102@@ -37,6 +37,11 @@
103 class GlibMemoryTest: public testing::Test
104 {
105 protected:
106+ static void SetUpTestCase()
107+ {
108+ g_log_set_always_fatal((GLogLevelFlags) (G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL));
109+ }
110+
111 void SetUp() override
112 {
113 keys.clear();
114@@ -108,6 +113,10 @@
115 EXPECT_EQ(set<string>({"hello", "hash"}), keys);
116 EXPECT_EQ(set<string>({"there", "world"}), values);
117 }
118+
119+ {
120+ auto emptyVariant = unique_glib((GVariant*) NULL);
121+ }
122 }
123
124 TEST_F(GlibMemoryTest, Share)
125@@ -132,6 +141,10 @@
126 EXPECT_EQ(set<string>({"hello", "hash"}), keys);
127 EXPECT_EQ(set<string>({"there", "world"}), values);
128 }
129+
130+ {
131+ auto emptyVariant = share_glib((GVariant*) NULL);
132+ }
133 }
134
135 }

Subscribers

People subscribed via source and target branches

to all changes: