pgbackrest.git / summary / log / commit / refs

commit    ec26a0594e2f1da3f2f0041ceef606f70eaeef5e
Author:   David Steele <david@pgmasters.net>
Date:     Wed Jan 16 07:05:13 2019 +0000

    Allow string Variant objects to contain null.
    
    This is more useful than the variant itself being null as it saves conditionals when creating.


doc/xml/release.xml | 4 ++++ src/common/type/variant.c | 9 ++++----- test/src/module/common/typeVariantTest.c | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/doc/xml/release.xml b/doc/xml/release.xml index 22aa4809c..c8a3d3363 100644 --- a/doc/xml/release.xml +++ b/doc/xml/release.xml @@ -53,6 +53,10 @@ <p>Add <code>kvMove()</code> and <code>varLstMove()</code>.</p> </release-item> + <release-item> + <p>Allow string <code>Variant</code> objects to contain <code>null</code>.</p> + </release-item> + <release-item> <p>Rename <code>common/io/handle</code> module to <code>common/io/handleWrite</code>.</p> </release-item> diff --git a/src/common/type/variant.c b/src/common/type/variant.c index ee44c03a9..23667858a 100644 --- a/src/common/type/variant.c +++ b/src/common/type/variant.c @@ -761,8 +761,6 @@ varNewStr(const String *data) { FUNCTION_TEST_BEGIN(); FUNCTION_TEST_PARAM(STRING, data); - - FUNCTION_TEST_ASSERT(data != NULL); FUNCTION_TEST_END(); // Create a copy of the string for the variant @@ -779,12 +777,13 @@ varNewStrZ(const char *data) { FUNCTION_TEST_BEGIN(); FUNCTION_TEST_PARAM(STRINGZ, data); - - FUNCTION_TEST_ASSERT(data != NULL); FUNCTION_TEST_END(); // Create a string for the variant - String *dataCopy = strNew(data); + String *dataCopy = NULL; + + if (data != NULL) + dataCopy = strNew(data); FUNCTION_TEST_RESULT(VARIANT, varNewInternal(varTypeString, (void *)&dataCopy, sizeof(dataCopy))); } diff --git a/test/src/module/common/typeVariantTest.c b/test/src/module/common/typeVariantTest.c index 7758e01b6..315c5977b 100644 --- a/test/src/module/common/typeVariantTest.c +++ b/test/src/module/common/typeVariantTest.c @@ -211,7 +211,7 @@ testRun(void) // ***************************************************************************************************************************** if (testBegin("String")) { - TEST_ERROR(varNewStr(NULL), AssertError, "function test assertion 'data != NULL' failed"); + TEST_RESULT_PTR(strPtr(varStr(varNewStr(NULL))), NULL, "new null str"); // ------------------------------------------------------------------------------------------------------------------------- Variant *string = varNewStr(strNew("test-str")); @@ -255,7 +255,7 @@ testRun(void) // ------------------------------------------------------------------------------------------------------------------------- TEST_RESULT_STR(strPtr(varStr(varNewStrZ("test-z-str"))), "test-z-str", "new zero-terminated string"); - TEST_ERROR(varNewStrZ(NULL), AssertError, "function test assertion 'data != NULL' failed"); + TEST_RESULT_PTR(strPtr(varStr(varNewStrZ(NULL))), NULL, "new null strz"); // ------------------------------------------------------------------------------------------------------------------------- TEST_RESULT_STR(strPtr(varStr(varDup(varNewStr(strNew("yabba-dabba-doo"))))), "yabba-dabba-doo", "dup string"); [parent: 1b334da87ffc]