@@ -1948,8 +1948,15 @@ auto DictionaryDecoder(Members... m) {
19481948#define XLA_FFI_ATTRIBUTE_UNUSED
19491949#endif
19501950
1951- // Use captureless lambda to function pointer conversion to create a static
1952- // XLA_FFI_Handler function pointer variable.
1951+ // In all macros below we use captureless lambda to function pointer conversion
1952+ // to create a static XLA_FFI_Handler function pointer variable.
1953+
1954+ // Use explicit binding specification and traits to create a handler.
1955+ #define XLA_FFI_DEFINE_HANDLER_EXPLICIT_WITH_TRAITS (fn, impl, binding, traits ) \
1956+ static constexpr XLA_FFI_Handler* fn = +[](XLA_FFI_CallFrame* call_frame) { \
1957+ static auto * handler = binding.To (impl, traits).release (); \
1958+ return handler->Call (call_frame); \
1959+ }
19531960
19541961// Use explicit binding specification to create a handler.
19551962#define XLA_FFI_DEFINE_HANDLER_EXPLICIT (fn, impl, binding ) \
@@ -1958,12 +1965,6 @@ auto DictionaryDecoder(Members... m) {
19581965 return handler->Call (call_frame); \
19591966 }
19601967
1961- #define XLA_FFI_DEFINE_HANDLER_EXPLICIT_WITH_TRAITS (fn, impl, binding, traits ) \
1962- static constexpr XLA_FFI_Handler* fn = +[](XLA_FFI_CallFrame* call_frame) { \
1963- static auto * handler = binding.To (impl, traits).release (); \
1964- return handler->Call (call_frame); \
1965- }
1966-
19671968// Automatically infer binding specification from the implementation.
19681969#define XLA_FFI_DEFINE_HANDLER_AUTO (fn, impl ) \
19691970 static constexpr XLA_FFI_Handler* fn = +[](XLA_FFI_CallFrame* call_frame) { \
@@ -1978,11 +1979,11 @@ auto DictionaryDecoder(Members... m) {
19781979//
19791980// This is a trick to define macro with optional parameters.
19801981// Source: https://stackoverflow.com/a/8814003
1981- #define XLA_FFI_DEFINE_HANDLER (fn, impl, ...) \
1982- XLA_FFI_DEFINE_HANDLER_X ( \
1983- , fn, impl, ##__VA_ARGS__, \
1984- XLA_FFI_DEFINE_HANDLER_EXPLICIT_WITH_TRAITS (fn, impl, __VA_ARGS__), \
1985- XLA_FFI_DEFINE_HANDLER_EXPLICIT(fn, impl, __VA_ARGS__), \
1982+ #define XLA_FFI_DEFINE_HANDLER (fn, impl, ...) \
1983+ XLA_FFI_DEFINE_HANDLER_X ( \
1984+ , fn, impl, ##__VA_ARGS__, \
1985+ XLA_FFI_DEFINE_HANDLER_EXPLICIT_WITH_TRAITS (fn, impl, ## __VA_ARGS__), \
1986+ XLA_FFI_DEFINE_HANDLER_EXPLICIT(fn, impl, ## __VA_ARGS__), \
19861987 XLA_FFI_DEFINE_HANDLER_AUTO(fn, impl))
19871988
19881989// TODO(ezhulenev): Add a callback so that end users can log registration error
0 commit comments