Skip to content
Permalink
Browse files

Add cfgOptionUInt() and cfgOptionUInt64().

These are better than casting from cfgOptionInt() since bounds checking is performed.
  • Loading branch information...
dwsteele committed Apr 19, 2019
1 parent 1adcbc5 commit 9f0829cbf2fcd9be869cac21fbf974fd7ecce019
Showing with 34 additions and 1 deletion.
  1. +4 −0 doc/xml/release.xml
  2. +26 −0 src/config/config.c
  3. +2 −0 src/config/config.h
  4. +2 −1 test/src/module/config/configTest.c
@@ -18,6 +18,10 @@
<release-item>
<p>Add <code>unsigned int</code> <code>Variant</code> type.</p>
</release-item>

<release-item>
<p>Add <code>cfgOptionUInt()</code> and <code>cfgOptionUInt64()</code>.</p>
</release-item>
</release-development-list>
</release-core-list>
</release>
@@ -838,6 +838,32 @@ cfgOptionInt64(ConfigOption optionId)
FUNCTION_LOG_RETURN(INT64, varInt64(configOptionValue[optionId].value));
}

unsigned int
cfgOptionUInt(ConfigOption optionId)
{
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(ENUM, optionId);
FUNCTION_LOG_END();

ASSERT(optionId < CFG_OPTION_TOTAL);
ASSERT(varType(configOptionValue[optionId].value) == varTypeInt64);

FUNCTION_LOG_RETURN(UINT, varUIntForce(configOptionValue[optionId].value));
}

uint64_t
cfgOptionUInt64(ConfigOption optionId)
{
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(ENUM, optionId);
FUNCTION_LOG_END();

ASSERT(optionId < CFG_OPTION_TOTAL);
ASSERT(varType(configOptionValue[optionId].value) == varTypeInt64);

FUNCTION_LOG_RETURN(UINT64, varUInt64Force(configOptionValue[optionId].value));
}

const KeyValue *
cfgOptionKv(ConfigOption optionId)
{
@@ -57,6 +57,8 @@ int64_t cfgOptionInt64(ConfigOption optionId);
const KeyValue *cfgOptionKv(ConfigOption optionId);
const VariantList *cfgOptionLst(ConfigOption optionId);
const String *cfgOptionStr(ConfigOption optionId);
unsigned int cfgOptionUInt(ConfigOption optionId);
uint64_t cfgOptionUInt64(ConfigOption optionId);

unsigned int cfgOptionIndex(ConfigOption optionId);
unsigned int cfgOptionIndexTotal(ConfigOption optionDefId);
@@ -136,7 +136,7 @@ testRun(void)
TEST_RESULT_VOID(cfgOptionSet(cfgOptCompressLevel, cfgSourceParam, varNewInt64(1)), "set compress-level");
TEST_RESULT_INT(cfgOptionInt(cfgOptCompressLevel), 1, "compress-level is set");
TEST_RESULT_VOID(cfgOptionSet(cfgOptCompressLevel, cfgSourceDefault, varNewStrZ("3")), "set compress-level");
TEST_RESULT_INT(cfgOptionInt(cfgOptCompressLevel), 3, "compress-level is set");
TEST_RESULT_INT(cfgOptionUInt(cfgOptCompressLevel), 3, "compress-level is set");
TEST_RESULT_INT(cfgOptionSource(cfgOptCompressLevel), cfgSourceDefault, "compress source is set");
TEST_ERROR(
cfgOptionBool(cfgOptCompressLevel), AssertError,
@@ -145,6 +145,7 @@ testRun(void)
TEST_RESULT_VOID(
cfgOptionSet(cfgOptArchivePushQueueMax, cfgSourceParam, varNewInt64(999999999999)), "set archive-push-queue-max");
TEST_RESULT_INT(cfgOptionInt64(cfgOptArchivePushQueueMax), 999999999999, "archive-push-queue-max is set");
TEST_RESULT_INT(cfgOptionUInt64(cfgOptArchivePushQueueMax), 999999999999, "archive-push-queue-max is set");

TEST_RESULT_VOID(cfgOptionSet(cfgOptProtocolTimeout, cfgSourceParam, varNewDbl(1.1)), "set protocol-timeout");
TEST_RESULT_DOUBLE(cfgOptionDbl(cfgOptProtocolTimeout), 1.1, "protocol-timeout is set");

0 comments on commit 9f0829c

Please sign in to comment.
You can’t perform that action at this time.