mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-06-07 00:13:17 +00:00
Ryanunderhill/ortapibase enforce (#15940)
### Description To prevent people from accidentally changing OrtApiBase, these static_asserts will fire if anyone adds a method, rearranges the method ordering, or changes the signature of any of the methods. ### Motivation and Context People have submitted changes that have done these things and there was no mechanism to stop them besides someone noticing in a code review. An automated way to let people know is needed.
This commit is contained in:
parent
825d691617
commit
22bc020dcd
1 changed files with 7 additions and 0 deletions
|
|
@ -2728,6 +2728,13 @@ static constexpr OrtApi ort_api_1_to_16 = {
|
|||
&OrtApis::GetBuildInfoString};
|
||||
// End of Version 15 - DO NOT MODIFY ABOVE (see above text for more information)
|
||||
|
||||
// OrtApiBase can never change as there is no way to know what version of OrtApiBase is returned by OrtGetApiBase.
|
||||
static_assert(sizeof(OrtApiBase) == sizeof(void*) * 2, "New methods can't be added to OrtApiBase as it is not versioned");
|
||||
static_assert(offsetof(OrtApiBase, GetApi) / sizeof(void*) == 0, "These functions cannot be reordered");
|
||||
static_assert(offsetof(OrtApiBase, GetVersionString) / sizeof(void*) == 1, "These functions cannot be reordered");
|
||||
static_assert(std::is_same_v<decltype(OrtApiBase::GetApi), const OrtApi*(ORT_API_CALL*)(uint32_t)NO_EXCEPTION>, "This function's signature can never change");
|
||||
static_assert(std::is_same_v<decltype(OrtApiBase::GetVersionString), const char*(ORT_API_CALL*)(void)NO_EXCEPTION>, "This function's signature can never change");
|
||||
|
||||
// Asserts to do a some checks to ensure older Versions of the OrtApi never change (will detect an addition or deletion but not if they cancel out each other)
|
||||
// If any of these asserts hit, read the above 'Rules on how to add a new Ort API version'
|
||||
static_assert(offsetof(OrtApi, ReleaseCustomOpDomain) / sizeof(void*) == 101, "Size of version 1 API cannot change");
|
||||
|
|
|
|||
Loading…
Reference in a new issue