OR_RETURN supports status_t
This change provide a specialization of android::base::OkOrFail for
status_t. As a result, a statement whose type is status_t can be used
with OR_RETURN.
The specialization also provides conversion operators to Result<T,
StatusT> where StatusT is a wrapper type for status_t. This allows
OR_RETURN macro to be used in newer functions that returns Result<T,
StatusT>.
Example usage:
\#include <utils/ErrorsMacros.h>
status_t legacy_inner();
status_t legacy_outer() {
OR_RETURN(legacy_inner());
return OK;
}
Result<T, StatusT> new_outer() {
OR_RETURN(legacy_inner()); // the same macro
return T{...};
}
Bug: 209929099
Test: atest libutils_test
Change-Id: I0def0e84ce3f0c4ff6d508c202bd51902dfc9618
diff --git a/libutils/Android.bp b/libutils/Android.bp
index e6d9a4c..45d010f 100644
--- a/libutils/Android.bp
+++ b/libutils/Android.bp
@@ -32,12 +32,14 @@
"libsystem_headers",
"libcutils_headers",
"libprocessgroup_headers",
+ "libbase_headers",
],
export_header_lib_headers: [
"liblog_headers",
"libsystem_headers",
"libcutils_headers",
"libprocessgroup_headers",
+ "libbase_headers",
],
export_include_dirs: ["include"],
@@ -297,13 +299,14 @@
srcs: [
"BitSet_test.cpp",
+ "Errors_test.cpp",
"FileMap_test.cpp",
"LruCache_test.cpp",
"Mutex_test.cpp",
"SharedBuffer_test.cpp",
"Singleton_test.cpp",
- "String8_test.cpp",
"String16_test.cpp",
+ "String8_test.cpp",
"StrongPointer_test.cpp",
"Timers_test.cpp",
"Unicode_test.cpp",
@@ -362,6 +365,7 @@
"-Wall",
"-Werror",
],
+ header_libs: ["libutils_headers"],
}
cc_test_library {
@@ -374,6 +378,7 @@
"-Werror",
],
shared_libs: ["libutils_test_singleton1"],
+ header_libs: ["libutils_headers"],
}
cc_benchmark {