pgbackrest.git / summary / log / commit / refs

commit    9f0829cbf2fcd9be869cac21fbf974fd7ecce019
Author:   David Steele <david@pgmasters.net>
Date:     Fri Apr 19 15:29:08 2019 +0000

    Add cfgOptionUInt() and cfgOptionUInt64().
    
    These are better than casting from cfgOptionInt() since bounds checking is performed.


doc/xml/release.xml | 4 ++++ src/config/config.c | 26 ++++++++++++++++++++++++++ src/config/config.h | 2 ++ test/src/module/config/configTest.c | 3 ++- 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/doc/xml/release.xml b/doc/xml/release.xml index 082cbd3c6..199dfb84e 100644 --- a/doc/xml/release.xml +++ b/doc/xml/release.xml @@ -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> diff --git a/src/config/config.c b/src/config/config.c index 7c7cb8c1a..ebde1b56e 100644 --- a/src/config/config.c +++ b/src/config/config.c @@ -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) { diff --git a/src/config/config.h b/src/config/config.h index 879e00d34..ad63f9380 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -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); diff --git a/test/src/module/config/configTest.c b/test/src/module/config/configTest.c index 567fbb7bf..1195e1379 100644 --- a/test/src/module/config/configTest.c +++ b/test/src/module/config/configTest.c @@ -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"); [parent: 1adcbc5c913b]