Skip to content

Commit bf8dfa3

Browse files
committed
Update on "[5.1/ N] set_option/get_option API with {backend_name, backend options} only"
This PR only expose the set_option/get_option API via the pair {backend_name, backend_options}, without necessarily backend options map. The backend options map and it's corresponding API will be exposed to another PR Reference PR in #11758 which exposes the set_option/get_option with backendoptions map too Differential Revision: [D77190316](https://our.internmc.facebook.com/intern/diff/D77190316/) [ghstack-poisoned]
2 parents e44e0fc + 0e9e057 commit bf8dfa3

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

runtime/backend/options.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class BackendOptions {
9292
* @param value The boolean value to set
9393
* @return Error::Ok on success, Error::InvalidArgument if storage is full
9494
*/
95-
Error set_option(const char* key, bool value) noexcept {
95+
Error set_option(const char key[kMaxOptionKeyLength], bool value) noexcept {
9696
ET_CHECK_MSG(
9797
strlen(key) <= kMaxOptionKeyLength,
9898
"Option key %s (%zu) is too long (max %zu)",
@@ -111,7 +111,7 @@ class BackendOptions {
111111
* @param value The integer value to set
112112
* @return Error::Ok on success, Error::InvalidArgument if storage is full
113113
*/
114-
Error set_option(const char* key, int value) noexcept {
114+
Error set_option(const char key[kMaxOptionKeyLength], int value) noexcept {
115115
ET_CHECK_MSG(
116116
strlen(key) <= kMaxOptionKeyLength,
117117
"Option key %s (%zu) is too long (max %zu)",
@@ -133,13 +133,14 @@ class BackendOptions {
133133
* @param value The string value to set (must have static storage duration)
134134
* @return Error::Ok on success, Error::InvalidArgument if storage is full
135135
*/
136-
Error set_option(const char* key, const char* value) noexcept {
136+
Error set_option(const char key[kMaxOptionKeyLength], const char* value) noexcept {
137137
ET_CHECK_MSG(
138138
strlen(key) <= kMaxOptionKeyLength,
139139
"Option key %s (%zu) is too long (max %zu)",
140140
key,
141141
strlen(key),
142142
kMaxOptionKeyLength);
143+
143144
// Create a fixed-size array and copy the string
144145
std::array<char, kMaxOptionValueLength> arr;
145146
strncpy(arr.data(), value, kMaxOptionValueLength - 1);
@@ -158,7 +159,7 @@ class BackendOptions {
158159
*/
159160
template <typename T, size_t KeyLen>
160161
Error get_option(const char (&key)[KeyLen], T& out) const {
161-
static_assert(KeyLen <= kMaxOptionKeyLength, "Option key is too long");
162+
ET_CHECK_MSG(KeyLen <= kMaxOptionKeyLength, "Option key is too long");
162163
for (size_t i = 0; i < size_; ++i) {
163164
if (std::strcmp(options_[i].key, key) == 0) {
164165
// Special handling for string (convert array to const char*)

0 commit comments

Comments
 (0)