Function tvm::ffi::reflection::CallFieldSetterToDefault#
Defined in File accessor.h
Function Documentation#
-
inline int tvm::ffi::reflection::CallFieldSetterToDefault(const TVMFFIFieldInfo *field_info, void *field_addr)#
Set a field to its default value, returning the setter’s status code.
When kTVMFFIFieldFlagBitMaskDefaultFromFactory is set, extracts the Function from default_value_or_factory, calls it with no arguments, and uses the result. Otherwise, passes default_value_or_factory directly to the setter.
A default is converted by the same setter as an explicitly passed value, so a default whose type does not match the field fails here exactly as that value would. Callers must not drop the status: the setter reports failure through the safe-call slot rather than by throwing, so ignoring it leaves the field at its zero-initialized value — a silently null object field — and strands the raised error for an unrelated call to pick up.
- Parameters:
field_info – The field info (must have kTVMFFIFieldFlagBitMaskHasDefault set).
field_addr – The address of the field in the object.
- Returns:
0 on success, non-zero if the setter rejected the default value.