mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-11-09 21:24:14 +00:00
oil: add fallible build option
Summary: Add a second form for OIL AoT compilation which returns a `std::optional` instead of throwing. This is preferred if it's possible for the symbol to not be defined and you must not throw, instead preferring to handle the failure a different way. This still calls the throwing interface as that's what oilgen depends on, but makes sure the precondition is true first such that it won't throw. Differential Revision: D50363926
This commit is contained in:
parent
f7bb1e75ad
commit
57c1a76228
@ -20,6 +20,7 @@
|
||||
#include <oi/types/dy.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
@ -31,9 +32,6 @@ enum class Feature {
|
||||
GenJitDebug,
|
||||
};
|
||||
|
||||
template <typename T, Feature... Fs>
|
||||
IntrospectionResult __attribute__((noinline)) introspect(const T& objectAddr);
|
||||
|
||||
#ifdef OIL_AOT_COMPILATION
|
||||
|
||||
template <class T, Feature... Fs>
|
||||
@ -48,6 +46,16 @@ IntrospectionResult introspect(const T& objectAddr) {
|
||||
return introspectImpl<T, Fs...>(objectAddr);
|
||||
}
|
||||
|
||||
template <typename T, Feature... Fs>
|
||||
std::optional<IntrospectionResult> tryIntrospect(const T& objectAddr) {
|
||||
if (!introspectImpl<T, Fs...>)
|
||||
return std::nullopt;
|
||||
|
||||
// This checks twice but is necessary for compile time as it currently
|
||||
// depends on the presence of the strong symbol.
|
||||
return introspect(objectAddr);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace oi
|
||||
|
Loading…
Reference in New Issue
Block a user