diff options
| author | Patrick Williams <patrick@stwcx.xyz> | 2017-01-12 10:00:17 -0600 |
|---|---|---|
| committer | Patrick Williams <patrick@stwcx.xyz> | 2017-01-13 08:14:57 -0600 |
| commit | 560e5fd5d135c7a3d4e354fd5346220fb9483575 (patch) | |
| tree | a69051c51a016fbe9bd24d2ad07b1af14fb5df29 /tools | |
| parent | aa2e7f7170327511110a448c1314a1ef2195ee25 (diff) | |
| download | sdbusplus-560e5fd5d135c7a3d4e354fd5346220fb9483575.tar.gz sdbusplus-560e5fd5d135c7a3d4e354fd5346220fb9483575.zip | |
message: Change conversion ctor to inc ref-count
There are cases of calling the message constructor where the
ownership of the raw pointer is transfered and others where it
is duplicated. The ownership-transfer use-cases are likely all
embedded within sdbusplus itself and the ownership-duplicate
cases tend to be done by external users. This causes the current
API to be bug-prone as it requires something like:
sdbusplus::message::message(sd_bus_message_ref(m));
Change the conversion constructor to not require the external _ref
call and instead add a new constructor that bypasses the ref.
Thus, the calling conventions now look like this:
Ownership-duplicate:
sdbusplus::message::message(m); // calls _ref.
Ownership-transfer:
sdbusplus::message::message(m, std::false_type()); // no _ref.
Resolves openbmc/openbmc#950.
Change-Id: Ia1ae527c4d1235b1625368cfffeb4ed495457768
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/sdbusplus/templates/interface.mako.server.cpp | 4 | ||||
| -rw-r--r-- | tools/sdbusplus/templates/method.mako.prototype.hpp | 2 |
2 files changed, 3 insertions, 3 deletions
diff --git a/tools/sdbusplus/templates/interface.mako.server.cpp b/tools/sdbusplus/templates/interface.mako.server.cpp index 50a6cad..89fa2a9 100644 --- a/tools/sdbusplus/templates/interface.mako.server.cpp +++ b/tools/sdbusplus/templates/interface.mako.server.cpp @@ -51,7 +51,7 @@ int ${classname}::_callback_get_${p.name}( try { - auto m = message::message(sd_bus_message_ref(reply)); + auto m = message::message(reply); auto o = static_cast<${classname}*>(context); m.append(convertForMessage(o->${p.camelCase}())); @@ -84,7 +84,7 @@ int ${classname}::_callback_set_${p.name}( { try { - auto m = message::message(sd_bus_message_ref(value)); + auto m = message::message(value); auto o = static_cast<${classname}*>(context); diff --git a/tools/sdbusplus/templates/method.mako.prototype.hpp b/tools/sdbusplus/templates/method.mako.prototype.hpp index 1d3cbfb..b58a2e3 100644 --- a/tools/sdbusplus/templates/method.mako.prototype.hpp +++ b/tools/sdbusplus/templates/method.mako.prototype.hpp @@ -127,7 +127,7 @@ int ${interface_name()}::_callback_${ method.CamelCase }( { ### Need to add a ref to msg since we attached it to an ### sdbusplus::message. - auto m = message::message(sd_bus_message_ref(msg)); + auto m = message::message(msg); % if len(method.parameters) != 0: ${parameters_as_local(as_param=False)}{}; |

