| 5054 | TSReturnCode TSUserArgIndexNameLookup(TSUserArgType type, const char *name, int *arg_idx, const char **description); |
| 5055 | |
| 5056 | TSReturnCode |
| 5057 | TSUserArgIndexReserve(TSUserArgType type, const char *name, const char *description, int *ptr_idx) |
| 5058 | { |
| 5059 | sdk_assert(sdk_sanity_check_null_ptr(ptr_idx) == TS_SUCCESS); |
| 5060 | sdk_assert(sdk_sanity_check_null_ptr(name) == TS_SUCCESS); |
| 5061 | sdk_assert(0 <= type && type < TS_USER_ARGS_COUNT); |
| 5062 | |
| 5063 | int idx; |
| 5064 | |
| 5065 | /* Since this function is meant to be called during plugin initialization we could end up "leaking" indices during plugins |
| 5066 | * reload. Make sure we allocate 1 index per name, also current TSUserArgIndexNameLookup() implementation assumes 1-1 |
| 5067 | * relationship as well. */ |
| 5068 | const char *desc; |
| 5069 | |
| 5070 | if (TS_SUCCESS == TSUserArgIndexNameLookup(type, name, &idx, &desc)) { |
| 5071 | // Found existing index. |
| 5072 | |
| 5073 | // No need to add get_user_arg_offset(type) here since |
| 5074 | // TSUserArgIndexNameLookup already does so. |
| 5075 | *ptr_idx = idx; |
| 5076 | return TS_SUCCESS; |
| 5077 | } |
| 5078 | |
| 5079 | idx = UserArgIdx[type]++; |
| 5080 | int limit = MAX_USER_ARGS[type]; |
| 5081 | |
| 5082 | if (idx < limit) { |
| 5083 | UserArg &arg(UserArgTable[type][idx]); |
| 5084 | arg.name = name; |
| 5085 | if (description) { |
| 5086 | arg.description = description; |
| 5087 | } |
| 5088 | *ptr_idx = idx + get_user_arg_offset(type); |
| 5089 | |
| 5090 | return TS_SUCCESS; |
| 5091 | } |
| 5092 | return TS_ERROR; |
| 5093 | } |
| 5094 | |
| 5095 | TSReturnCode |
| 5096 | TSUserArgIndexLookup(TSUserArgType type, int idx, const char **name, const char **description) |
no test coverage detected