diff options
author | Nirav Atre <natre@google.com> | 2018-07-09 11:49:03 -0700 |
---|---|---|
committer | Nirav Atre <natre@google.com> | 2018-07-09 15:43:18 -0700 |
commit | 2505641557b6020f289d098945230e65b0f41141 (patch) | |
tree | b61fb2feedd4958bc9f653b31ba2f32d18be6f48 | |
parent | 9fd3387f62af5f53b7cfcf4f03df62e9e06f45ed (diff) | |
download | libhidl-2505641557b6020f289d098945230e65b0f41141.tar.gz |
HIDL templated destructorandroid-o-mr1-iot-release-1.0.2
This change implements a simple template function to explicitly destruct
objects in HIDL. This is particularly useful in the context of HIDL safe
unions, where non-primitive objects are constructed using the placement
new operator.
Bug: n/a
Test: Ran make
Change-Id: Iceb7d311732f7ea67e132a32ab7410b78ce371c2
-rw-r--r-- | base/include/hidl/HidlInternal.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/base/include/hidl/HidlInternal.h b/base/include/hidl/HidlInternal.h index 5a08bc3..d000a87 100644 --- a/base/include/hidl/HidlInternal.h +++ b/base/include/hidl/HidlInternal.h @@ -48,6 +48,15 @@ void logAlwaysFatal(const char *message); // If "ro.vndk.version" is not set or set to "current", it returns empty string. std::string getVndkVersionStr(); +// Explicitly invokes the parameterized element's destructor; +// intended to be used alongside the placement new operator. +template<typename T> +void destructElement(T* element) { + if (element != nullptr) { + element->~T(); + } +} + // HIDL client/server code should *NOT* use this class. // // hidl_pointer wraps a pointer without taking ownership, |