Mir

Merge lp:~raof/mir/optional-check-precondition into lp:mir

Proposed by Chris Halse Rogers on 2015-06-01
Status: Merged
Approved by: Alberto Aguirre on 2015-06-09
Approved revision: 2608
Merged at revision: 2644
Proposed branch: lp:~raof/mir/optional-check-precondition
Merge into: lp:mir
Diff against target: 112 lines (+16/-8)
6 files modified
include/common/mir/optional_value.h (+10/-1)
src/client/mir_surface.cpp (+1/-1)
src/common/CMakeLists.txt (+2/-0)
src/common/symbols.map (+3/-1)
src/platform/CMakeLists.txt (+0/-2)
src/platform/symbols.map (+0/-3)
To merge this branch: bzr merge lp:~raof/mir/optional-check-precondition
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve on 2015-06-09
Alberto Aguirre Approve on 2015-06-09
Alan Griffiths 2015-06-01 Needs Fixing on 2015-06-03
Kevin DuBois (community) Approve on 2015-06-02
Review via email: mp+260672@code.launchpad.net

Commit Message

Make optional_value<>::value() check its precondition.

Namely, that a value has been set.

Then fix the place in the code where we access an unset optional_value.

Description of the Change

Make optional_value<>::value() check its precondition.

Namely, that a value has been set.

This then breaks all the acceptance tests, because the MirSurface constructor accesses the value of an unset optional_value, so fix that.

To post a comment you must log in.
Alan Griffiths (alan-griffiths) wrote :

*Needs Discussion*

I'd prefer a mir::fatal_error:

20 + if (!is_set())
21 + {
22 + BOOST_THROW_EXCEPTION(std::logic_error("Accessing value of unset optional_value"));
23 + }

As you say, it is a *precondition* failure and exceptions are for *postcondition* failures.

8 +#include <boost/throw_exception.hpp>

This pulls quite a lot into what was previously a lightweight include.

review: Needs Information
Chris Halse Rogers (raof) wrote :

FWIW, std::experimental::optional<>::value() throws bad_optional_access in the case of a disengaged optional value.

I'd also be happy with mir::fatal_error; optional<>::operator*() invokes undefined behaviour in the case of a disengaged optional value.

The throw_exception.hpp include is indeed pretty big, and I don't think any of our other public headers include it. I'm happy to just throw, if it's deemed excessive.

Kevin DuBois (kdub) wrote :

I'd be more in favor of throwing like std::experimental::optional does, just in the name of not bringing down the server (esp as optional is used a fair amount in client requests, which would just fail on that client's request and recover).

Kevin DuBois (kdub) wrote :

I guess approve, although I also would prefer not pulling in boost and just throwing a std exception type.

review: Approve
Alan Griffiths (alan-griffiths) wrote :

I'm more concerned that we should detect and correct invalid logic during testing than have it accidentally hidden a catch clause intended for a different case. So I'd prefer being able to abort. fatal_error gives that option:

/**
 * fatal_error() is strictly for "this should never happen" situations that
 * you cannot recover from. By default it points at fatal_error_except().
 * Note the reason parameter is a simple char* so its value is clearly visible
 * in stack trace output.
 * \param [in] reason A printf-style format string.
 */

...

  --on-fatal-error-abort On "fatal error" conditions [e.g.
                                        drivers behaving in unexpected ways]
                                        abort (to get a core dump)

review: Needs Fixing
Alberto Aguirre (albaguirre) wrote :

>I'm more concerned that we should detect and correct invalid logic during testing

+1 I also prefer fatal_error for this case.

review: Needs Fixing
Kevin DuBois (kdub) wrote :

> I'm more concerned that we should detect and correct invalid logic during
> testing than have it accidentally hidden a catch clause intended for a
> different case. So I'd prefer being able to abort. fatal_error gives that
> option:
Ah, had forgotten about the option to have a nicer fatal error... with that fatal_error makes more sense to me too

2606. By Chris Halse Rogers on 2015-06-04

Move mir::fatal_error to mircommon

2607. By Chris Halse Rogers on 2015-06-04

Use mir::fatal_error rather than throwing an exception for optional_value precondition violations

Alberto Aguirre (albaguirre) wrote :

 +# Symbols moved from libmirplatform; can be folded into a MIR_COMMON stanza
66 +# at next mirplatform ABI break.
67 +MIRPLATFORM_7 {
68 + global:
69 + extern "C++" {
70 + mir::fatal_error*;
71 + mir::fatal_error_abort*;
72 + mir::fatal_error_except*;
73 + };
74 +};

We already broke MIRPLATFORM ABI :)

review: Needs Fixing
2608. By Chris Halse Rogers on 2015-06-09

Merge trunk

Alberto Aguirre (albaguirre) wrote :

^--
Looks like lp:1463315

LGTM.

review: Approve
Alberto Aguirre (albaguirre) wrote :

Alan's Needs fixing has been addressed. TA'ing.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== renamed file 'include/platform/mir/fatal.h' => 'include/common/mir/fatal.h'
2=== modified file 'include/common/mir/optional_value.h'
3--- include/common/mir/optional_value.h 2015-05-07 09:06:20 +0000
4+++ include/common/mir/optional_value.h 2015-06-09 07:41:50 +0000
5@@ -19,6 +19,8 @@
6 #ifndef MIR_OPTIONAL_VALUE_H_
7 #define MIR_OPTIONAL_VALUE_H_
8
9+#include "mir/fatal.h"
10+
11 namespace mir
12 {
13 template<typename T>
14@@ -36,7 +38,14 @@
15 }
16
17 bool is_set() const { return is_set_; }
18- T value() const { return value_; }
19+ T value() const
20+ {
21+ if (!is_set())
22+ {
23+ (*fatal_error)("Accessing value of unset optional");
24+ }
25+ return value_;
26+ }
27
28 private:
29 T value_;
30
31=== modified file 'src/client/mir_surface.cpp'
32--- src/client/mir_surface.cpp 2015-05-21 19:25:51 +0000
33+++ src/client/mir_surface.cpp 2015-06-09 07:41:50 +0000
34@@ -145,7 +145,7 @@
35 mir_surface_callback callback, void * context)
36 : server{&the_server},
37 debug{debug},
38- name{spec.surface_name.value()},
39+ name{spec.surface_name.is_set() ? spec.surface_name.value() : ""},
40 connection(allocating_connection),
41 buffer_stream_factory(buffer_stream_factory),
42 input_platform(input_platform),
43
44=== modified file 'src/common/CMakeLists.txt'
45--- src/common/CMakeLists.txt 2015-06-02 15:07:18 +0000
46+++ src/common/CMakeLists.txt 2015-06-09 07:41:50 +0000
47@@ -17,9 +17,11 @@
48 add_subdirectory(thread)
49 add_subdirectory(time)
50 add_subdirectory(dispatch)
51+add_subdirectory(fatal)
52
53 list(APPEND MIR_COMMON_SOURCES
54 $<TARGET_OBJECTS:mirtime>
55+ $<TARGET_OBJECTS:mirfatal>
56 ${CMAKE_CURRENT_SOURCE_DIR}/log.cpp
57 )
58
59
60=== renamed directory 'src/platform/fatal' => 'src/common/fatal'
61=== modified file 'src/common/symbols.map'
62--- src/common/symbols.map 2015-06-02 15:07:18 +0000
63+++ src/common/symbols.map 2015-06-09 07:41:50 +0000
64@@ -1,4 +1,3 @@
65-
66 MIR_COMMON_5 {
67 global: mir_*;
68 extern "C++" {
69@@ -28,6 +27,9 @@
70 mir::dispatch::ThreadedDispatcher::?ThreadedDispatcher*;
71 mir::dispatch::ThreadedDispatcher::add_thread*;
72 mir::dispatch::ThreadedDispatcher::remove_thread*;
73+ mir::fatal_error*;
74+ mir::fatal_error_abort*;
75+ mir::fatal_error_except*;
76 mir::Fd::Fd*;
77 mir::Fd::invalid*;
78 mir::Fd::operator*;
79
80=== modified file 'src/platform/CMakeLists.txt'
81--- src/platform/CMakeLists.txt 2015-03-31 02:35:42 +0000
82+++ src/platform/CMakeLists.txt 2015-06-09 07:41:50 +0000
83@@ -13,7 +13,6 @@
84 set(MIR_PLATFORM_OBJECTS
85 $<TARGET_OBJECTS:mirplatformgraphicscommon>
86 $<TARGET_OBJECTS:miroptions>
87- $<TARGET_OBJECTS:mirfatal>
88 $<TARGET_OBJECTS:mirudev>
89 )
90
91@@ -24,7 +23,6 @@
92
93 add_subdirectory(graphics/)
94 add_subdirectory(options)
95-add_subdirectory(fatal)
96 add_subdirectory(udev)
97
98 set(MIR_PLATFORM_OBJECTS ${MIR_PLATFORM_OBJECTS} PARENT_SCOPE)
99
100=== modified file 'src/platform/symbols.map'
101--- src/platform/symbols.map 2015-05-19 21:34:34 +0000
102+++ src/platform/symbols.map 2015-06-09 07:41:50 +0000
103@@ -3,9 +3,6 @@
104 extern "C++" {
105 # The following symbols come from running a script over the generated docs. Vis:
106 # ../tools/process_doxygen_xml.py doc/xml/*.xml | grep "^mirplatform public" | sed "s/mirplatform public: / /" | sort
107- mir::fatal_error*;
108- mir::fatal_error_abort*;
109- mir::fatal_error_except*;
110 mir::graphics::BufferBasic::BufferBasic*;
111 mir::graphics::Buffer::Buffer*;
112 mir::graphics::Buffer::gl_bind_to_texture*;

Subscribers

People subscribed via source and target branches