1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-01-18 04:58:51 +02:00

Cleanup C types.

* Remove pgBackRest defined types included with the C types.
* Remove redefinition of standard C types.
This commit is contained in:
David Steele 2018-04-05 22:38:11 -04:00
parent bd25248df0
commit b9f636cab4
35 changed files with 88 additions and 102 deletions

View File

@ -59,6 +59,10 @@
<p>Add <code>ASSERT()</code> that is preserved in production builds.</p> <p>Add <code>ASSERT()</code> that is preserved in production builds.</p>
</release-item> </release-item>
<release-item>
<p>Cleanup C types. Remove <backrest/> defined types included with the C types. Remove redefinition of standard C types.</p>
</release-item>
<release-item> <release-item>
<p>Fix header exclusion defines that do not match the general pattern.</p> <p>Fix header exclusion defines that do not match the general pattern.</p>
</release-item> </release-item>

View File

@ -4,7 +4,7 @@ Cipher Header
#ifndef CIPHER_CIPHER_H #ifndef CIPHER_CIPHER_H
#define CIPHER_CIPHER_H #define CIPHER_CIPHER_H
#include "common/type.h" #include "common/typec.h"
// Define cipher modes // Define cipher modes
typedef enum typedef enum

View File

@ -12,7 +12,7 @@ Archive Push Command
#include "common/log.h" #include "common/log.h"
#include "common/memContext.h" #include "common/memContext.h"
#include "common/regExp.h" #include "common/regExp.h"
#include "common/type.h" #include "common/typec.h"
#include "common/wait.h" #include "common/wait.h"
#include "config/config.h" #include "config/config.h"
#include "perl/exec.h" #include "perl/exec.h"

View File

@ -6,7 +6,7 @@ Help Command
#include "common/io/handle.h" #include "common/io/handle.h"
#include "common/memContext.h" #include "common/memContext.h"
#include "common/type.h" #include "common/typec.h"
#include "config/config.h" #include "config/config.h"
#include "config/define.h" #include "config/define.h"
#include "version.h" #include "version.h"

View File

@ -6,7 +6,7 @@ These high-level functions are preferred to the low-level functions for each enc
#ifndef COMMON_ENCODE_H #ifndef COMMON_ENCODE_H
#define COMMON_ENCODE_H #define COMMON_ENCODE_H
#include "common/type.h" #include "common/typec.h"
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Encoding types Encoding types

View File

@ -6,7 +6,7 @@ The high-level functions in encode.c should be used in preference to these low-l
#ifndef COMMON_ENCODE_BASE64_H #ifndef COMMON_ENCODE_BASE64_H
#define COMMON_ENCODE_BASE64_H #define COMMON_ENCODE_BASE64_H
#include "common/type.h" #include "common/typec.h"
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Functions Functions

View File

@ -40,7 +40,7 @@ IMPORTANT: Never call return from within any of the error-handling blocks.
#include <errno.h> #include <errno.h>
#include <setjmp.h> #include <setjmp.h>
#include "common/type.h" #include "common/typec.h"
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Error type object Error type object

View File

@ -9,6 +9,8 @@ Ini object
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
typedef struct Ini Ini; typedef struct Ini Ini;
#include "common/type/variant.h"
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Functions Functions
***********************************************************************************************************************************/ ***********************************************************************************************************************************/

View File

@ -4,7 +4,7 @@ Handle IO
#ifndef COMMON_IO_HANDLE_H #ifndef COMMON_IO_HANDLE_H
#define COMMON_IO_HANDLE_H #define COMMON_IO_HANDLE_H
#include "common/type.h" #include "common/type/string.h"
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Functions Functions

View File

@ -4,7 +4,7 @@ Log Handler
#ifndef COMMON_LOG_H #ifndef COMMON_LOG_H
#define COMMON_LOG_H #define COMMON_LOG_H
#include "common/type.h" #include "common/typec.h"
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Log types Log types

View File

@ -5,7 +5,7 @@ Memory Context Manager
#define COMMON_MEMCONTEXT_H #define COMMON_MEMCONTEXT_H
#include "common/error.h" #include "common/error.h"
#include "common/type.h" #include "common/typec.h"
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Memory context names cannot be larger than this size (excluding terminator) or an error will be thrown Memory context names cannot be larger than this size (excluding terminator) or an error will be thrown

View File

@ -6,7 +6,7 @@ Regular Expression Handler
#include "common/memContext.h" #include "common/memContext.h"
#include "common/regExp.h" #include "common/regExp.h"
#include "common/type.h" #include "common/typec.h"
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Contains information about the regular expression handler Contains information about the regular expression handler

View File

@ -9,6 +9,8 @@ Ini object
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
typedef struct RegExp RegExp; typedef struct RegExp RegExp;
#include "common/type/string.h"
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Functions Functions
***********************************************************************************************************************************/ ***********************************************************************************************************************************/

View File

@ -4,7 +4,7 @@ Time Management
#include "sys/time.h" #include "sys/time.h"
#include "common/time.h" #include "common/time.h"
#include "common/type.h" #include "common/typec.h"
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Constants describing number of sub-units in an interval Constants describing number of sub-units in an interval

View File

@ -4,12 +4,12 @@ Time Management
#ifndef COMMON_TIME_H #ifndef COMMON_TIME_H
#define COMMON_TIME_H #define COMMON_TIME_H
#include "common/type.h" #include "common/typec.h"
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Time types Time types
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
typedef uint64 TimeMSec; typedef uint64_t TimeMSec;
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Constants describing number of sub-units in an interval Constants describing number of sub-units in an interval

View File

@ -4,7 +4,7 @@ Buffer Handler
#ifndef COMMON_TYPE_BUFFER_H #ifndef COMMON_TYPE_BUFFER_H
#define COMMON_TYPE_BUFFER_H #define COMMON_TYPE_BUFFER_H
#include "common/type.h" #include "common/typec.h"
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Buffer object Buffer object

View File

@ -2,8 +2,8 @@
Key Value Handler Key Value Handler
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
#include "common/memContext.h" #include "common/memContext.h"
#include "common/type.h"
#include "common/type/keyValue.h" #include "common/type/keyValue.h"
#include "common/type/list.h"
#include "common/type/variantList.h" #include "common/type/variantList.h"
/*********************************************************************************************************************************** /***********************************************************************************************************************************

View File

@ -4,13 +4,13 @@ Key Value Handler
#ifndef COMMON_TYPE_KEYVALUE_H #ifndef COMMON_TYPE_KEYVALUE_H
#define COMMON_TYPE_KEYVALUE_H #define COMMON_TYPE_KEYVALUE_H
#include "common/type/variant.h"
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Key value object Key value object
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
typedef struct KeyValue KeyValue; typedef struct KeyValue KeyValue;
#include "common/type/variantList.h"
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Functions Functions
***********************************************************************************************************************************/ ***********************************************************************************************************************************/

View File

@ -395,7 +395,7 @@ varIntForce(const Variant *this)
case varTypeInt64: case varTypeInt64:
{ {
int64 resultTest = varInt64(this); int64_t resultTest = varInt64(this);
if (resultTest > 2147483647 || resultTest < -2147483648) if (resultTest > 2147483647 || resultTest < -2147483648)
THROW( THROW(
@ -427,7 +427,7 @@ varIntForce(const Variant *this)
New int64 variant New int64 variant
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
Variant * Variant *
varNewInt64(int64 data) varNewInt64(int64_t data)
{ {
return varNewInternal(varTypeInt64, (void *)&data, sizeof(data)); return varNewInternal(varTypeInt64, (void *)&data, sizeof(data));
} }
@ -435,7 +435,7 @@ varNewInt64(int64 data)
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Return int64 Return int64
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
int64 int64_t
varInt64(const Variant *this) varInt64(const Variant *this)
{ {
// Only valid for int // Only valid for int
@ -443,16 +443,16 @@ varInt64(const Variant *this)
THROW(AssertError, "variant type is not %s", variantTypeName[varTypeInt64]); THROW(AssertError, "variant type is not %s", variantTypeName[varTypeInt64]);
// Get the int // Get the int
return *((int64 *)varData(this)); return *((int64_t *)varData(this));
} }
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Return int64 regardless of variant type Return int64 regardless of variant type
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
int64 int64_t
varInt64Force(const Variant *this) varInt64Force(const Variant *this)
{ {
int64 result = 0; int64_t result = 0;
switch (this->type) switch (this->type)
{ {
@ -464,7 +464,7 @@ varInt64Force(const Variant *this)
case varTypeInt: case varTypeInt:
{ {
result = (int64)varInt(this); result = (int64_t)varInt(this);
break; break;
} }

View File

@ -4,7 +4,7 @@ Variant Data Type
#ifndef COMMON_TYPE_VARIANT_H #ifndef COMMON_TYPE_VARIANT_H
#define COMMON_TYPE_VARIANT_H #define COMMON_TYPE_VARIANT_H
#include <stdbool.h> #include "common/typec.h"
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Variant type Variant type
@ -44,9 +44,9 @@ Variant *varNewInt(int data);
int varInt(const Variant *this); int varInt(const Variant *this);
int varIntForce(const Variant *this); int varIntForce(const Variant *this);
Variant *varNewInt64(int64 data); Variant *varNewInt64(int64_t data);
int64 varInt64(const Variant *this); int64_t varInt64(const Variant *this);
int64 varInt64Force(const Variant *this); int64_t varInt64Force(const Variant *this);
Variant *varNewKv(); Variant *varNewKv();
KeyValue *varKv(const Variant *this); KeyValue *varKv(const Variant *this);

View File

@ -9,11 +9,12 @@ Variant list type
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
typedef struct VariantList VariantList; typedef struct VariantList VariantList;
#include "common/type/stringList.h"
#include "common/type/variant.h"
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Functions Functions
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
#include "common/type/variant.h"
VariantList *varLstNew(); VariantList *varLstNew();
VariantList *varLstNewStrLst(const StringList *stringList); VariantList *varLstNewStrLst(const StringList *stringList);
VariantList *varLstDup(const VariantList *source); VariantList *varLstDup(const VariantList *source);

View File

@ -1,8 +1,8 @@
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Common Types C Types
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
#ifndef TYPE_H #ifndef COMMON_TYPEC_H
#define TYPE_H #define COMMON_TYPEC_H
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Include true/false Include true/false
@ -24,16 +24,6 @@ Define standard integer types for portability
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
#include <stdint.h> #include <stdint.h>
typedef uint8_t uint8;
typedef uint16_t uint16;
typedef uint32_t uint32;
typedef uint64_t uint64;
typedef int8_t int8;
typedef int16_t int16;
typedef int32_t int32;
typedef int64_t int64;
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Ensure that ints are at least 32 bits Ensure that ints are at least 32 bits
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
@ -41,14 +31,4 @@ Ensure that ints are at least 32 bits
#error "int type must be at least 32 bits" #error "int type must be at least 32 bits"
#endif #endif
/***********************************************************************************************************************************
Include all header files in type directory for convenience
***********************************************************************************************************************************/
#include "common/type/buffer.h"
#include "common/type/list.h"
#include "common/type/string.h"
#include "common/type/stringList.h"
#include "common/type/variant.h"
#include "common/type/variantList.h"
#endif #endif

View File

@ -547,7 +547,7 @@ cfgOptionInt(ConfigOption optionId)
return varIntForce(configOptionValue[optionId].value); return varIntForce(configOptionValue[optionId].value);
} }
int64 int64_t
cfgOptionInt64(ConfigOption optionId) cfgOptionInt64(ConfigOption optionId)
{ {
cfgOptionCheck(optionId); cfgOptionCheck(optionId);

View File

@ -8,7 +8,7 @@ config/parse.c sets the command and options and determines which options are val
#define CONFIG_CONFIG_H #define CONFIG_CONFIG_H
#include "common/log.h" #include "common/log.h"
#include "common/type.h" #include "common/type/stringList.h"
#include "config/define.h" #include "config/define.h"
#include "config/config.auto.h" #include "config/config.auto.h"
@ -45,7 +45,7 @@ const Variant *cfgOption(ConfigOption optionId);
bool cfgOptionBool(ConfigOption optionId); bool cfgOptionBool(ConfigOption optionId);
double cfgOptionDbl(ConfigOption optionId); double cfgOptionDbl(ConfigOption optionId);
int cfgOptionInt(ConfigOption optionId); int cfgOptionInt(ConfigOption optionId);
int64 cfgOptionInt64(ConfigOption optionId); int64_t cfgOptionInt64(ConfigOption optionId);
const KeyValue *cfgOptionKv(ConfigOption optionId); const KeyValue *cfgOptionKv(ConfigOption optionId);
const VariantList *cfgOptionLst(ConfigOption optionId); const VariantList *cfgOptionLst(ConfigOption optionId);
const String *cfgOptionStr(ConfigOption optionId); const String *cfgOptionStr(ConfigOption optionId);

View File

@ -106,10 +106,10 @@ typedef enum
} ConfigDefineDataType; } ConfigDefineDataType;
#define CFGDATA_OPTION_OPTIONAL_PUSH_LIST(type, size, data, ...) \ #define CFGDATA_OPTION_OPTIONAL_PUSH_LIST(type, size, data, ...) \
(const void *)((uint32)type << 24 | (uint32)size << 16 | (uint32)data), __VA_ARGS__ (const void *)((uint32_t)type << 24 | (uint32_t)size << 16 | (uint32_t)data), __VA_ARGS__
#define CFGDATA_OPTION_OPTIONAL_PUSH(type, size, data) \ #define CFGDATA_OPTION_OPTIONAL_PUSH(type, size, data) \
(const void *)((uint32)type << 24 | (uint32)size << 16 | (uint32)data) (const void *)((uint32_t)type << 24 | (uint32_t)size << 16 | (uint32_t)data)
#define CFGDEFDATA_OPTION_COMMAND_LIST(...) \ #define CFGDEFDATA_OPTION_COMMAND_LIST(...) \
.commandValid = 0 __VA_ARGS__, .commandValid = 0 __VA_ARGS__,
@ -130,10 +130,10 @@ typedef enum
#define CFGDEFDATA_OPTION_OPTIONAL_ALLOW_RANGE(rangeMinParam, rangeMaxParam) \ #define CFGDEFDATA_OPTION_OPTIONAL_ALLOW_RANGE(rangeMinParam, rangeMaxParam) \
CFGDATA_OPTION_OPTIONAL_PUSH_LIST( \ CFGDATA_OPTION_OPTIONAL_PUSH_LIST( \
configDefDataTypeAllowRange, 4, 0, \ configDefDataTypeAllowRange, 4, 0, \
(const void *)(intptr_t)(int32)(((int64)((double)rangeMinParam * 100)) % 1000000000L), \ (const void *)(intptr_t)(int32_t)(((int64_t)((double)rangeMinParam * 100)) % 1000000000L), \
(const void *)(intptr_t)(int32)(((int64)((double)rangeMinParam * 100)) / 1000000000L), \ (const void *)(intptr_t)(int32_t)(((int64_t)((double)rangeMinParam * 100)) / 1000000000L), \
(const void *)(intptr_t)(int32)(((int64)((double)rangeMaxParam * 100)) % 1000000000L), \ (const void *)(intptr_t)(int32_t)(((int64_t)((double)rangeMaxParam * 100)) % 1000000000L), \
(const void *)(intptr_t)(int32)(((int64)((double)rangeMaxParam * 100)) / 1000000000L)), (const void *)(intptr_t)(int32_t)(((int64_t)((double)rangeMaxParam * 100)) / 1000000000L)),
#define CFGDEFDATA_OPTION_OPTIONAL_PREFIX(prefixParam) \ #define CFGDEFDATA_OPTION_OPTIONAL_PREFIX(prefixParam) \
CFGDATA_OPTION_OPTIONAL_PUSH_LIST(configDefDataTypePrefix, 1, 0, prefixParam), CFGDATA_OPTION_OPTIONAL_PUSH_LIST(configDefDataTypePrefix, 1, 0, prefixParam),
@ -365,7 +365,7 @@ cfgDefOptionAllowRangeMax(ConfigDefineCommand commandDefId, ConfigDefineOption o
CONFIG_DEFINE_DATA_FIND(commandDefId, optionDefId, configDefDataTypeAllowRange); CONFIG_DEFINE_DATA_FIND(commandDefId, optionDefId, configDefDataTypeAllowRange);
return ((double)(((int64)(intptr_t)dataDefList[2]) + (((int64)(intptr_t)dataDefList[3]) * 1000000000L))) / 100; return ((double)(((int64_t)(intptr_t)dataDefList[2]) + (((int64_t)(intptr_t)dataDefList[3]) * 1000000000L))) / 100;
} }
double double
@ -375,7 +375,7 @@ cfgDefOptionAllowRangeMin(ConfigDefineCommand commandDefId, ConfigDefineOption o
CONFIG_DEFINE_DATA_FIND(commandDefId, optionDefId, configDefDataTypeAllowRange); CONFIG_DEFINE_DATA_FIND(commandDefId, optionDefId, configDefDataTypeAllowRange);
return ((double)(((int64)(intptr_t)dataDefList[0]) + (((int64)(intptr_t)dataDefList[1]) * 1000000000L))) / 100; return ((double)(((int64_t)(intptr_t)dataDefList[0]) + (((int64_t)(intptr_t)dataDefList[1]) * 1000000000L))) / 100;
} }
/*********************************************************************************************************************************** /***********************************************************************************************************************************

View File

@ -4,7 +4,7 @@ Command and Option Configuration Definition
#ifndef CONFIG_DEFINE_H #ifndef CONFIG_DEFINE_H
#define CONFIG_DEFINE_H #define CONFIG_DEFINE_H
#include "common/type.h" #include "common/typec.h"
#include "config/define.auto.h" #include "config/define.auto.h"
/*********************************************************************************************************************************** /***********************************************************************************************************************************

View File

@ -4,8 +4,6 @@ Perl Configuration
#ifndef PERL_CONFIG_H #ifndef PERL_CONFIG_H
#define PERL_CONFIG_H #define PERL_CONFIG_H
#include "common/type.h"
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Functions Functions
***********************************************************************************************************************************/ ***********************************************************************************************************************************/

View File

@ -10,7 +10,7 @@ Execute Perl for Legacy Functionality
#include "version.h" #include "version.h"
#include "common/error.h" #include "common/error.h"
#include "common/memContext.h" #include "common/memContext.h"
#include "common/type.h" #include "common/typec.h"
#include "config/config.h" #include "config/config.h"
#include "perl/config.h" #include "perl/config.h"

View File

@ -72,8 +72,8 @@ For historical reasons, the 64-bit LSN value is stored as two 32-bit values.
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
typedef struct typedef struct
{ {
uint32 walid; // high bits uint32_t walid; // high bits
uint32 xrecoff; // low bits uint32_t xrecoff; // low bits
} PageWalRecPtr; } PageWalRecPtr;
/*********************************************************************************************************************************** /***********************************************************************************************************************************
@ -95,11 +95,11 @@ relating to checksums.
typedef struct PageHeaderData typedef struct PageHeaderData
{ {
// LSN is member of *any* block, not only page-organized ones // LSN is member of *any* block, not only page-organized ones
PageWalRecPtr pd_lsn; /* LSN: next byte after last byte of wal * record for last change to this page */ PageWalRecPtr pd_lsn; // Lsn for last change to this page
uint16 pd_checksum; /* checksum */ uint16_t pd_checksum; // checksum
uint16 pd_flags; /* flag bits, see below */ uint16_t pd_flags; // flag bits, see below
uint16 pd_lower; /* offset to start of free space */ uint16_t pd_lower; // offset to start of free space
uint16 pd_upper; /* offset to end of free space */ uint16_t pd_upper; // offset to end of free space
} PageHeaderData; } PageHeaderData;
typedef PageHeaderData *PageHeader; typedef PageHeaderData *PageHeader;
@ -116,7 +116,7 @@ The data argument must be aligned on a 4-byte boundary.
#define FNV_PRIME 16777619 #define FNV_PRIME 16777619
// Base offsets to initialize each of the parallel FNV hashes into a different initial state. // Base offsets to initialize each of the parallel FNV hashes into a different initial state.
static const uint32 checksumBaseOffsets[N_SUMS] = static const uint32_t checksumBaseOffsets[N_SUMS] =
{ {
0x5B1F36E9, 0xB8525960, 0x02AB50AA, 0x1DE66D2A, 0x79FF467A, 0x9BB9F8A3, 0x217E7CD2, 0x83E13D2C, 0x5B1F36E9, 0xB8525960, 0x02AB50AA, 0x1DE66D2A, 0x79FF467A, 0x9BB9F8A3, 0x217E7CD2, 0x83E13D2C,
0xF8D4474F, 0xE39EB970, 0x42C6AE16, 0x993216FA, 0x7B093B5D, 0x98DAFF3C, 0xF718902A, 0x0B1C9CDB, 0xF8D4474F, 0xE39EB970, 0x42C6AE16, 0x993216FA, 0x7B093B5D, 0x98DAFF3C, 0xF718902A, 0x0B1C9CDB,
@ -127,23 +127,23 @@ static const uint32 checksumBaseOffsets[N_SUMS] =
// Calculate one round of the checksum. // Calculate one round of the checksum.
#define CHECKSUM_COMP(checksum, value) \ #define CHECKSUM_COMP(checksum, value) \
do { \ do { \
uint32 temp = (checksum) ^ (value); \ uint32_t temp = (checksum) ^ (value); \
(checksum) = temp * FNV_PRIME ^ (temp >> 17); \ (checksum) = temp * FNV_PRIME ^ (temp >> 17); \
} while (0) } while (0)
static uint32 static uint32_t
pageChecksumBlock(const unsigned char *data, uint32 size) pageChecksumBlock(const unsigned char *data, uint32_t size)
{ {
uint32 sums[N_SUMS]; uint32_t sums[N_SUMS];
uint32 (*dataArray)[N_SUMS] = (uint32 (*)[N_SUMS])data; uint32_t (*dataArray)[N_SUMS] = (uint32_t (*)[N_SUMS])data;
uint32 result = 0; uint32_t result = 0;
uint32 i, j; uint32_t i, j;
/* initialize partial checksums to their corresponding offsets */ /* initialize partial checksums to their corresponding offsets */
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets)); memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets));
/* main checksum calculation */ /* main checksum calculation */
for (i = 0; i < size / sizeof(uint32) / N_SUMS; i++) for (i = 0; i < size / sizeof(uint32_t) / N_SUMS; i++)
for (j = 0; j < N_SUMS; j++) for (j = 0; j < N_SUMS; j++)
CHECKSUM_COMP(sums[j], dataArray[i][j]); CHECKSUM_COMP(sums[j], dataArray[i][j]);
@ -165,30 +165,31 @@ pageChecksum - compute the checksum for a PostgreSQL page
The checksum includes the block number (to detect the case where a page is somehow moved to a different location), the page header The checksum includes the block number (to detect the case where a page is somehow moved to a different location), the page header
(excluding the checksum itself), and the page data. (excluding the checksum itself), and the page data.
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
uint16 uint16_t
pageChecksum(const unsigned char *page, unsigned int blockNo, unsigned int pageSize) pageChecksum(const unsigned char *page, unsigned int blockNo, unsigned int pageSize)
{ {
// Save pd_checksum and temporarily set it to zero, so that the checksum calculation isn't affected by the old checksum stored // Save pd_checksum and temporarily set it to zero, so that the checksum calculation isn't affected by the old checksum stored
// on the page. Restore it after, because actually updating the checksum is NOT part of the API of this function. // on the page. Restore it after, because actually updating the checksum is NOT part of the API of this function.
PageHeader pageHeader = (PageHeader)page; PageHeader pageHeader = (PageHeader)page;
uint16 originalChecksum = pageHeader->pd_checksum; uint16_t originalChecksum = pageHeader->pd_checksum;
pageHeader->pd_checksum = 0; pageHeader->pd_checksum = 0;
uint32 checksum = pageChecksumBlock(page, pageSize); uint32_t checksum = pageChecksumBlock(page, pageSize);
pageHeader->pd_checksum = originalChecksum; pageHeader->pd_checksum = originalChecksum;
// Mix in the block number to detect transposed pages // Mix in the block number to detect transposed pages
checksum ^= blockNo; checksum ^= blockNo;
// Reduce to a uint16 with an offset of one. That avoids checksums of zero, which seems like a good idea. // Reduce to a uint16 with an offset of one. That avoids checksums of zero, which seems like a good idea.
return (uint16)((checksum % 65535) + 1); return (uint16_t)((checksum % 65535) + 1);
} }
/*********************************************************************************************************************************** /***********************************************************************************************************************************
pageChecksumTest - test if checksum is valid for a single page pageChecksumTest - test if checksum is valid for a single page
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
bool bool
pageChecksumTest(const unsigned char *page, unsigned int blockNo, unsigned int pageSize, uint32 ignoreWalId, uint32 ignoreWalOffset) pageChecksumTest(
const unsigned char *page, unsigned int blockNo, unsigned int pageSize, uint32_t ignoreWalId, uint32_t ignoreWalOffset)
{ {
return return
// This is a new page so don't test checksum // This is a new page so don't test checksum
@ -205,7 +206,7 @@ pageChecksumBufferTest - test if checksums are valid for all pages in a buffer
bool bool
pageChecksumBufferTest( pageChecksumBufferTest(
const unsigned char *pageBuffer, unsigned int pageBufferSize, unsigned int blockNoBegin, unsigned int pageSize, const unsigned char *pageBuffer, unsigned int pageBufferSize, unsigned int blockNoBegin, unsigned int pageSize,
uint32 ignoreWalId, uint32 ignoreWalOffset) uint32_t ignoreWalId, uint32_t ignoreWalOffset)
{ {
// If the buffer does not represent an even number of pages then error // If the buffer does not represent an even number of pages then error
if (pageBufferSize % pageSize != 0 || pageBufferSize / pageSize == 0) if (pageBufferSize % pageSize != 0 || pageBufferSize / pageSize == 0)

View File

@ -4,16 +4,16 @@ Checksum Implementation for Data Pages
#ifndef POSTGRES_PAGECHECKSUM_H #ifndef POSTGRES_PAGECHECKSUM_H
#define POSTGRES_PAGECHECKSUM_H #define POSTGRES_PAGECHECKSUM_H
#include "common/type.h" #include "common/typec.h"
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Functions Functions
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
uint16 pageChecksum(const unsigned char *page, unsigned int blockNo, unsigned int pageSize); uint16_t pageChecksum(const unsigned char *page, unsigned int blockNo, unsigned int pageSize);
bool pageChecksumTest( bool pageChecksumTest(
const unsigned char *page, unsigned int blockNo, unsigned int pageSize, uint32 ignoreWalId, uint32 ignoreWalOffset); const unsigned char *page, unsigned int blockNo, unsigned int pageSize, uint32_t ignoreWalId, uint32_t ignoreWalOffset);
bool pageChecksumBufferTest( bool pageChecksumBufferTest(
const unsigned char *pageBuffer, unsigned int pageBufferSize, unsigned int blockNoBegin, unsigned int pageSize, const unsigned char *pageBuffer, unsigned int pageBufferSize, unsigned int blockNoBegin, unsigned int pageSize,
uint32 ignoreWalId, uint32 ignoreWalOffset); uint32_t ignoreWalId, uint32_t ignoreWalOffset);
#endif #endif

View File

@ -7,7 +7,7 @@ Storage Manager
#include <sys/types.h> #include <sys/types.h>
#include "common/type/buffer.h" #include "common/type/buffer.h"
#include "common/type/string.h" #include "common/type/stringList.h"
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Default buffer size Default buffer size

View File

@ -101,14 +101,14 @@ my $oTestDef =
&TESTDEF_TEST => &TESTDEF_TEST =>
[ [
{ {
&TESTDEF_NAME => 'type', &TESTDEF_NAME => 'typec',
&TESTDEF_TOTAL => 2, &TESTDEF_TOTAL => 2,
&TESTDEF_C => true, &TESTDEF_C => true,
&TESTDEF_CDEF => '-DNO_ERROR -DNO_LOG', &TESTDEF_CDEF => '-DNO_ERROR -DNO_LOG',
&TESTDEF_COVERAGE => &TESTDEF_COVERAGE =>
{ {
'common/type' => TESTDEF_COVERAGE_NOCODE, 'common/typec' => TESTDEF_COVERAGE_NOCODE,
}, },
}, },
{ {

View File

@ -7,7 +7,6 @@ C Test Harness
#include <inttypes.h> #include <inttypes.h>
#include "common/error.h" #include "common/error.h"
#include "common/type.h"
// Bogus values // Bogus values
#define BOGUS_STR "BOGUS" #define BOGUS_STR "BOGUS"
@ -218,7 +217,7 @@ Macros to ease the use of common data types
TEST_RESULT_DOUBLE_PARAM(statement, resultExpected, ==, __VA_ARGS__); TEST_RESULT_DOUBLE_PARAM(statement, resultExpected, ==, __VA_ARGS__);
#define TEST_RESULT_INT_PARAM(statement, resultExpected, typeOp, ...) \ #define TEST_RESULT_INT_PARAM(statement, resultExpected, typeOp, ...) \
TEST_RESULT(statement, resultExpected, int64, "%" PRId64, TEST_TYPE_FORMAT, typeOp, TEST_TYPE_COMPARE, __VA_ARGS__); TEST_RESULT(statement, resultExpected, int64_t, "%" PRId64, TEST_TYPE_FORMAT, typeOp, TEST_TYPE_COMPARE, __VA_ARGS__);
#define TEST_RESULT_INT(statement, resultExpected, ...) \ #define TEST_RESULT_INT(statement, resultExpected, ...) \
TEST_RESULT_INT_PARAM(statement, resultExpected, ==, __VA_ARGS__); TEST_RESULT_INT_PARAM(statement, resultExpected, ==, __VA_ARGS__);
#define TEST_RESULT_INT_NE(statement, resultExpected, ...) \ #define TEST_RESULT_INT_NE(statement, resultExpected, ...) \
@ -239,6 +238,6 @@ Macros to ease the use of common data types
TEST_RESULT_STR_PARAM(statement, resultExpected, !=, __VA_ARGS__); TEST_RESULT_STR_PARAM(statement, resultExpected, !=, __VA_ARGS__);
#define TEST_RESULT_U16_HEX(statement, resultExpected, ...) \ #define TEST_RESULT_U16_HEX(statement, resultExpected, ...) \
TEST_RESULT(statement, resultExpected, uint16, "0x%04X", TEST_TYPE_FORMAT, ==, TEST_TYPE_COMPARE, __VA_ARGS__); TEST_RESULT(statement, resultExpected, uint16_t, "0x%04X", TEST_TYPE_FORMAT, ==, TEST_TYPE_COMPARE, __VA_ARGS__);
#endif #endif

View File

@ -7,7 +7,6 @@ Log Test Harness
#include "common/harnessTest.h" #include "common/harnessTest.h"
#include "common/log.h" #include "common/log.h"
#include "common/type.h"
#include "storage/helper.h" #include "storage/helper.h"
#ifndef NO_LOG #ifndef NO_LOG

View File

@ -1,5 +1,5 @@
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Test Types Test C Types
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
#include <assert.h> #include <assert.h>