You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-07-17 01:12:23 +02:00
Move cvtDoubleToStr() to strNewDbl().
This is a more logical location and it reduces the dependencies required to compile the common/convert module.
This commit is contained in:
@ -356,7 +356,7 @@ cmdArchivePush(void)
|
||||
{
|
||||
THROW_FMT(
|
||||
ArchiveTimeoutError, "unable to push WAL file '%s' to the archive asynchronously after %s second(s)",
|
||||
strZ(archiveFile), strZ(cvtDoubleToStr((double)cfgOptionInt64(cfgOptArchiveTimeout) / MSEC_PER_SEC)));
|
||||
strZ(archiveFile), strZ(strNewDbl((double)cfgOptionInt64(cfgOptArchiveTimeout) / MSEC_PER_SEC)));
|
||||
}
|
||||
|
||||
// Log success
|
||||
|
@ -130,8 +130,7 @@ cmdOption(void)
|
||||
else if (cfgParseOptionType(optionId) == cfgOptTypeTime)
|
||||
{
|
||||
valueList = strLstNew();
|
||||
strLstAdd(
|
||||
valueList, cvtDoubleToStr((double)cfgOptionIdxInt64(optionId, optionIdx) / MSEC_PER_SEC));
|
||||
strLstAdd(valueList, strNewDbl((double)cfgOptionIdxInt64(optionId, optionIdx) / MSEC_PER_SEC));
|
||||
}
|
||||
// Else only one value
|
||||
else
|
||||
|
@ -134,7 +134,7 @@ helpRenderValue(const Variant *value, ConfigOptionType type)
|
||||
result = resultTemp;
|
||||
}
|
||||
else if (type == cfgOptTypeTime)
|
||||
result = cvtDoubleToStr((double)varInt64(value) / MSEC_PER_SEC);
|
||||
result = strNewDbl((double)varInt64(value) / MSEC_PER_SEC);
|
||||
else
|
||||
result = varStrForce(value);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/***********************************************************************************************************************************
|
||||
Convert Base Data Types
|
||||
Convert C Types
|
||||
***********************************************************************************************************************************/
|
||||
#include "build.auto.h"
|
||||
|
||||
@ -180,19 +180,6 @@ cvtDoubleToZ(double value, char *buffer, size_t bufferSize)
|
||||
FUNCTION_TEST_RETURN((size_t)(end - buffer + 1));
|
||||
}
|
||||
|
||||
String *cvtDoubleToStr(double value)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(DOUBLE, value);
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
char working[CVT_BASE10_BUFFER_SIZE];
|
||||
|
||||
cvtDoubleToZ(value, working, sizeof(working));
|
||||
|
||||
FUNCTION_TEST_RETURN(strNew(working));
|
||||
}
|
||||
|
||||
double
|
||||
cvtZToDouble(const char *value)
|
||||
{
|
||||
|
@ -1,5 +1,7 @@
|
||||
/***********************************************************************************************************************************
|
||||
Convert Base Data Types
|
||||
Convert C Types
|
||||
|
||||
Contains conversions to/from native C types. Conversions of project types should be defined in their respective type modules.
|
||||
***********************************************************************************************************************************/
|
||||
#ifndef COMMON_TYPE_CONVERT_H
|
||||
#define COMMON_TYPE_CONVERT_H
|
||||
@ -8,8 +10,6 @@ Convert Base Data Types
|
||||
#include <stdbool.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "common/type/string.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Required buffer sizes
|
||||
***********************************************************************************************************************************/
|
||||
@ -22,9 +22,8 @@ Functions
|
||||
// Convert char to zero-terminated string
|
||||
size_t cvtCharToZ(char value, char *buffer, size_t bufferSize);
|
||||
|
||||
// Convert double to zero-terminated string (or String) and vice versa
|
||||
// Convert double to zero-terminated string and vice versa
|
||||
size_t cvtDoubleToZ(double value, char *buffer, size_t bufferSize);
|
||||
String *cvtDoubleToStr(double value);
|
||||
double cvtZToDouble(const char *value);
|
||||
|
||||
// Convert int to zero-terminated string and vice versa
|
||||
|
@ -94,6 +94,20 @@ strNew(const char *string)
|
||||
FUNCTION_TEST_RETURN(this);
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
String *strNewDbl(double value)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(DOUBLE, value);
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
char working[CVT_BASE10_BUFFER_SIZE];
|
||||
|
||||
cvtDoubleToZ(value, working, sizeof(working));
|
||||
|
||||
FUNCTION_TEST_RETURN(strNew(working));
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
String *
|
||||
strNewBuf(const Buffer *buffer)
|
||||
|
@ -64,6 +64,9 @@ String *strNew(const char *string);
|
||||
// but only the data before the NULL character will be used as a string.
|
||||
String *strNewBuf(const Buffer *buffer);
|
||||
|
||||
// Create a new string by converting the double value
|
||||
String *strNewDbl(double value);
|
||||
|
||||
// Create a new string from a format string with parameters (i.e. sprintf)
|
||||
String *strNewFmt(const char *format, ...) __attribute__((format(printf, 1, 2)));
|
||||
|
||||
|
@ -113,7 +113,7 @@ cfgExecParam(ConfigCommand commandId, ConfigCommandRole commandRoleId, const Key
|
||||
else if (cfgParseOptionType(optionId) == cfgOptTypeTime)
|
||||
{
|
||||
valueList = strLstNew();
|
||||
strLstAdd(valueList, cvtDoubleToStr((double)varInt64(value) / MSEC_PER_SEC));
|
||||
strLstAdd(valueList, strNewDbl((double)varInt64(value) / MSEC_PER_SEC));
|
||||
}
|
||||
// Else only one value
|
||||
else
|
||||
|
@ -51,16 +51,8 @@ unit:
|
||||
|
||||
depend:
|
||||
- common/debug
|
||||
- common/type/convert
|
||||
- common/memContext
|
||||
- common/stackTrace
|
||||
- common/type/buffer
|
||||
- common/type/keyValue
|
||||
- common/type/list
|
||||
- common/type/string
|
||||
- common/type/stringList
|
||||
- common/type/variant
|
||||
- common/type/variantList
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------------------------------
|
||||
- name: stack-trace
|
||||
@ -69,6 +61,13 @@ unit:
|
||||
coverage:
|
||||
- common/stackTrace
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------------------------------
|
||||
- name: type-convert
|
||||
total: 11
|
||||
|
||||
coverage:
|
||||
- common/type/convert
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------------------------------
|
||||
- name: assert-off
|
||||
total: 1
|
||||
@ -105,13 +104,6 @@ unit:
|
||||
depend:
|
||||
- common/type/convert
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------------------------------
|
||||
- name: type-convert
|
||||
total: 11
|
||||
|
||||
coverage:
|
||||
- common/type/convert
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------------------------------
|
||||
- name: time
|
||||
total: 3
|
||||
@ -128,6 +120,13 @@ unit:
|
||||
- common/type/string
|
||||
- common/type/stringList
|
||||
|
||||
depend:
|
||||
- common/type/buffer
|
||||
- common/type/keyValue
|
||||
- common/type/list
|
||||
- common/type/variant
|
||||
- common/type/variantList
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------------------------------
|
||||
- name: type-list
|
||||
total: 4
|
||||
|
@ -1,5 +1,5 @@
|
||||
/***********************************************************************************************************************************
|
||||
Test Convert Base Data Types
|
||||
Test Convert C Types
|
||||
***********************************************************************************************************************************/
|
||||
#include "common/stackTrace.h"
|
||||
|
||||
@ -45,8 +45,6 @@ testRun(void)
|
||||
TEST_RESULT_UINT(cvtDoubleToZ(999.1234, buffer, STACK_TRACE_PARAM_MAX), 8, "convert double to string");
|
||||
TEST_RESULT_Z(buffer, "999.1234", " check buffer");
|
||||
|
||||
TEST_RESULT_STR_Z(cvtDoubleToStr(999.1), "999.1", "convert double to string");
|
||||
|
||||
TEST_RESULT_UINT(cvtDoubleToZ(999999999.123456, buffer, STACK_TRACE_PARAM_MAX), 16, "convert double to string");
|
||||
TEST_RESULT_Z(buffer, "999999999.123456", " check buffer");
|
||||
|
||||
|
@ -15,7 +15,7 @@ testRun(void)
|
||||
FUNCTION_HARNESS_VOID();
|
||||
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("strNew(), strNewBuf(), strNewN(), strEmpty(), strZ(), strZNull(), strSize(), and strFree()"))
|
||||
if (testBegin("strNew(), strNewBuf(), strNewDbl(), strNewN(), strEmpty(), strZ(), strZNull(), strSize(), and strFree()"))
|
||||
{
|
||||
// We don't want this struct to grow since there are generally a lot of strings, so make sure it doesn't grow without us
|
||||
// knowing about it
|
||||
@ -44,6 +44,11 @@ testRun(void)
|
||||
|
||||
TEST_RESULT_STR_Z(strNewBuf(buffer), "12345678", "new string from buffer");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("new from double");
|
||||
|
||||
TEST_RESULT_STR_Z(strNewDbl(999.1), "999.1", "new");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
string = strNewFmt("formatted %s %04d", "string", 1);
|
||||
TEST_RESULT_STR_Z(string, "formatted string 0001", "new with formatted string");
|
||||
|
Reference in New Issue
Block a user