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
=== modified file 'debian/changelog'
--- debian/changelog 2017-02-17 14:12:04 +0000
+++ debian/changelog 2017-02-23 11:19:18 +0000
@@ -1,3 +1,11 @@
1unity-api (8.4-0ubuntu1) UNRELEASED; urgency=medium
2
3 [ Pete Woods ]
4 * unity::util - Make Glib and GObject memory management
5 utilities handle NULL quietly.
6
7 -- Pete <pete.woods@canonical.com> Tue, 21 Feb 2017 13:11:57 +0000
8
1unity-api (8.3+17.04.20170217-0ubuntu1) zesty; urgency=medium9unity-api (8.3+17.04.20170217-0ubuntu1) zesty; urgency=medium
210
3 [ Pete ]11 [ Pete ]
412
=== modified file 'include/unity/util/GObjectMemory.h'
--- include/unity/util/GObjectMemory.h 2017-01-19 13:49:43 +0000
+++ include/unity/util/GObjectMemory.h 2017-02-23 11:19:18 +0000
@@ -59,8 +59,10 @@
59{59{
60 void operator()(gpointer ptr)60 void operator()(gpointer ptr)
61 {61 {
62 g_return_if_fail(G_IS_OBJECT(ptr));62 if (G_IS_OBJECT(ptr))
63 g_object_unref(ptr);63 {
64 g_object_unref(ptr);
65 }
64 }66 }
65};67};
6668
6769
=== modified file 'include/unity/util/GlibMemory.h'
--- include/unity/util/GlibMemory.h 2017-02-17 13:40:58 +0000
+++ include/unity/util/GlibMemory.h 2017-02-23 11:19:18 +0000
@@ -28,18 +28,33 @@
28namespace util28namespace util
29{29{
3030
31template<typename T, typename D>
32struct GlibDeleter
33{
34 D _d;
35
36 void operator()(T* ptr)
37 {
38 if (ptr != nullptr)
39 {
40 _d(ptr);
41 }
42 }
43};
44
31#pragma push_macro("G_DEFINE_AUTOPTR_CLEANUP_FUNC")45#pragma push_macro("G_DEFINE_AUTOPTR_CLEANUP_FUNC")
32#undef G_DEFINE_AUTOPTR_CLEANUP_FUNC46#undef G_DEFINE_AUTOPTR_CLEANUP_FUNC
33#define G_DEFINE_AUTOPTR_CLEANUP_FUNC(TypeName, func) \47#define G_DEFINE_AUTOPTR_CLEANUP_FUNC(TypeName, func) \
48typedef GlibDeleter<TypeName, decltype(&func)> TypeName##Deleter; \
34typedef std::shared_ptr<TypeName> TypeName##SPtr; \49typedef std::shared_ptr<TypeName> TypeName##SPtr; \
35inline TypeName##SPtr share_glib(TypeName* ptr) \50inline TypeName##SPtr share_glib(TypeName* ptr) \
36{ \51{ \
37 return TypeName##SPtr(ptr, &func); \52 return TypeName##SPtr(ptr, TypeName##Deleter{&func}); \
38} \53} \
39typedef std::unique_ptr<TypeName, decltype(&func)> TypeName##UPtr; \54typedef std::unique_ptr<TypeName, TypeName##Deleter> TypeName##UPtr; \
40inline TypeName##UPtr unique_glib(TypeName* ptr) \55inline TypeName##UPtr unique_glib(TypeName* ptr) \
41{ \56{ \
42 return TypeName##UPtr(ptr, &func); \57 return TypeName##UPtr(ptr, TypeName##Deleter{&func}); \
43}58}
4459
45#pragma push_macro("G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC")60#pragma push_macro("G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC")
4661
=== modified file 'test/gtest/unity/util/GObjectMemory/GObjectMemory_test.cpp'
--- test/gtest/unity/util/GObjectMemory/GObjectMemory_test.cpp 2017-01-19 13:49:43 +0000
+++ test/gtest/unity/util/GObjectMemory/GObjectMemory_test.cpp 2017-02-23 11:19:18 +0000
@@ -174,6 +174,11 @@
174class GObjectMemoryTest: public testing::Test174class GObjectMemoryTest: public testing::Test
175{175{
176protected:176protected:
177 static void SetUpTestCase()
178 {
179 g_log_set_always_fatal((GLogLevelFlags) (G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL));
180 }
181
177 void SetUp() override182 void SetUp() override
178 {183 {
179 DELETED_OBJECTS.clear();184 DELETED_OBJECTS.clear();
@@ -298,6 +303,7 @@
298 auto u1 = unique_gobject(o1);303 auto u1 = unique_gobject(o1);
299 auto u2 = unique_gobject<FooBar>(nullptr);304 auto u2 = unique_gobject<FooBar>(nullptr);
300 auto u3 = unique_gobject(o3);305 auto u3 = unique_gobject(o3);
306 auto u4 = unique_gobject((FooBar *) NULL);
301307
302 EXPECT_TRUE(!u1);308 EXPECT_TRUE(!u1);
303 EXPECT_TRUE(!u2);309 EXPECT_TRUE(!u2);
304310
=== modified file 'test/gtest/unity/util/GlibMemory/GlibMemory_test.cpp'
--- test/gtest/unity/util/GlibMemory/GlibMemory_test.cpp 2017-02-17 13:40:58 +0000
+++ test/gtest/unity/util/GlibMemory/GlibMemory_test.cpp 2017-02-23 11:19:18 +0000
@@ -37,6 +37,11 @@
37class GlibMemoryTest: public testing::Test37class GlibMemoryTest: public testing::Test
38{38{
39protected:39protected:
40 static void SetUpTestCase()
41 {
42 g_log_set_always_fatal((GLogLevelFlags) (G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL));
43 }
44
40 void SetUp() override45 void SetUp() override
41 {46 {
42 keys.clear();47 keys.clear();
@@ -108,6 +113,10 @@
108 EXPECT_EQ(set<string>({"hello", "hash"}), keys);113 EXPECT_EQ(set<string>({"hello", "hash"}), keys);
109 EXPECT_EQ(set<string>({"there", "world"}), values);114 EXPECT_EQ(set<string>({"there", "world"}), values);
110 }115 }
116
117 {
118 auto emptyVariant = unique_glib((GVariant*) NULL);
119 }
111}120}
112121
113TEST_F(GlibMemoryTest, Share)122TEST_F(GlibMemoryTest, Share)
@@ -132,6 +141,10 @@
132 EXPECT_EQ(set<string>({"hello", "hash"}), keys);141 EXPECT_EQ(set<string>({"hello", "hash"}), keys);
133 EXPECT_EQ(set<string>({"there", "world"}), values);142 EXPECT_EQ(set<string>({"there", "world"}), values);
134 }143 }
144
145 {
146 auto emptyVariant = share_glib((GVariant*) NULL);
147 }
135}148}
136149
137}150}

Subscribers

People subscribed via source and target branches

to all changes: