From ffb8a381900687eee99aa25d1370f3f97ba9e4a4 Mon Sep 17 00:00:00 2001 From: Joo Youngjin <68979537+youngjinj@users.noreply.github.com> Date: Tue, 7 Feb 2023 14:56:21 +0900 Subject: [PATCH] [CBRD-24632] Change data put, get and support functions using OR_BUF in object_representation.c to inline functions (#4066) http://jira.cubrid.org/browse/CBRD-24632 Change data put, get and support functions using OR_BUF in object_representation.c to inline functions --- cs/CMakeLists.txt | 11 +- cubrid/CMakeLists.txt | 3 +- sa/CMakeLists.txt | 3 +- src/base/object_representation.h | 1821 ++++++++++++++--- src/base/object_representation_constants.h | 7 + src/base/object_representation_sr.c | 10 +- src/base/packer.cpp | 4 +- src/method/method_query_cursor.cpp | 4 +- src/method/method_scan.cpp | 2 +- src/object/object_primitive.c | 4 +- src/object/object_representation.c | 2114 +++----------------- src/query/execute_statement.c | 2 +- src/query/fetch.c | 4 +- src/query/list_file.c | 16 +- src/query/query_aggregate.cpp | 4 +- src/query/query_analytic.cpp | 2 +- src/query/query_evaluator.c | 8 +- src/query/query_executor.c | 4 +- src/query/query_opfunc.c | 4 +- src/query/scan_manager.c | 2 +- src/storage/btree.c | 6 +- src/storage/btree_load.c | 4 +- src/storage/byte_order.c | 197 ++ src/storage/byte_order.h | 16 +- src/storage/heap_file.c | 5 +- src/transaction/log_recovery.c | 2 +- win/cubridcs/cubridcs.def | 5 + win/cubridsa/cubridsa.def | 5 + 28 files changed, 2173 insertions(+), 2096 deletions(-) create mode 100644 src/storage/byte_order.c diff --git a/cs/CMakeLists.txt b/cs/CMakeLists.txt index 6157094eccf..49318787f56 100644 --- a/cs/CMakeLists.txt +++ b/cs/CMakeLists.txt @@ -327,13 +327,14 @@ set(TRANSACTION_HEADERS ) set(STORAGE_SOURCES - ${STORAGE_DIR}/storage_common.c - ${STORAGE_DIR}/oid.c - ${STORAGE_DIR}/statistics_cl.c - ${STORAGE_DIR}/file_io.c - ${STORAGE_DIR}/es_common.c + ${STORAGE_DIR}/byte_order.c ${STORAGE_DIR}/es.c + ${STORAGE_DIR}/es_common.c ${STORAGE_DIR}/es_posix.c + ${STORAGE_DIR}/file_io.c + ${STORAGE_DIR}/oid.c + ${STORAGE_DIR}/statistics_cl.c + ${STORAGE_DIR}/storage_common.c ${STORAGE_DIR}/tde.c ) diff --git a/cubrid/CMakeLists.txt b/cubrid/CMakeLists.txt index ca120b52eb5..5bfe71a0f22 100644 --- a/cubrid/CMakeLists.txt +++ b/cubrid/CMakeLists.txt @@ -339,10 +339,11 @@ set(STORAGE_SOURCES ${STORAGE_DIR}/btree.c ${STORAGE_DIR}/btree_load.c ${STORAGE_DIR}/btree_unique.cpp + ${STORAGE_DIR}/byte_order.c ${STORAGE_DIR}/catalog_class.c ${STORAGE_DIR}/compactdb_sr.c - ${STORAGE_DIR}/double_write_buffer.c ${STORAGE_DIR}/disk_manager.c + ${STORAGE_DIR}/double_write_buffer.c ${STORAGE_DIR}/es.c ${STORAGE_DIR}/es_common.c ${STORAGE_DIR}/es_posix.c diff --git a/sa/CMakeLists.txt b/sa/CMakeLists.txt index d7b516d5710..33e195cc1bf 100644 --- a/sa/CMakeLists.txt +++ b/sa/CMakeLists.txt @@ -418,10 +418,11 @@ set(STORAGE_SOURCES ${STORAGE_DIR}/btree.c ${STORAGE_DIR}/btree_load.c ${STORAGE_DIR}/btree_unique.cpp + ${STORAGE_DIR}/byte_order.c ${STORAGE_DIR}/catalog_class.c ${STORAGE_DIR}/compactdb_sr.c - ${STORAGE_DIR}/double_write_buffer.c ${STORAGE_DIR}/disk_manager.c + ${STORAGE_DIR}/double_write_buffer.c ${STORAGE_DIR}/es.c ${STORAGE_DIR}/es_common.c ${STORAGE_DIR}/es_owfs.c diff --git a/src/base/object_representation.h b/src/base/object_representation.h index 83f7dc4ba44..287c499d5e5 100644 --- a/src/base/object_representation.h +++ b/src/base/object_representation.h @@ -85,138 +85,98 @@ struct setobj; #define OR_CHECK_FLOAT_OVERFLOW(i) ((i) > FLT_MAX || (-(i)) > FLT_MAX) #define OR_CHECK_DOUBLE_OVERFLOW(i) ((i) > DBL_MAX || (-(i)) > DBL_MAX) +/* simple macro to calculate minimum bytes to contain given bits */ +#define BITS_TO_BYTES(bit_cnt) (((bit_cnt) + 7) / 8) + /* PACK/UNPACK MACROS */ -#define OR_GET_BYTE(ptr) \ - (*(unsigned char *) ((char *) (ptr))) -#define OR_GET_SHORT(ptr) \ - ((short) ntohs (*(short *) ((char *) (ptr)))) -#define OR_GET_INT(ptr) \ - ((int) ntohl (*(int *) ((char *) (ptr)))) -#define OR_GET_FLOAT(ptr, value) \ - (*(value) = ntohf (*(UINT32 *) (ptr))) -#define OR_GET_DOUBLE(ptr, value) \ - (*(value) = ntohd (*(UINT64 *) (ptr))) -#define OR_GET_STRING(ptr) \ - ((char *) ((char *) (ptr))) +/* NUMERIC */ #define OR_PUT_BYTE(ptr, val) \ (*((unsigned char *) (ptr)) = (unsigned char) (val)) + +#define OR_GET_BYTE(ptr) \ + (*(unsigned char *) ((char *) (ptr))) + #define OR_PUT_SHORT(ptr, val) \ (*(short *) ((char *) (ptr)) = htons ((short) (val))) + +#define OR_GET_SHORT(ptr) \ + ((short) ntohs (*(short *) ((char *) (ptr)))) + #define OR_PUT_INT(ptr, val) \ (*(int *) ((char *) (ptr)) = htonl ((int) (val))) -inline void -OR_PUT_FLOAT (char *ptr, float val) -{ - UINT32 ui; - ui = htonf (val); - memcpy (ptr, &ui, sizeof (ui)); -} - -inline void -OR_PUT_DOUBLE (char *ptr, double val) -{ - UINT64 ui; - ui = htond (val); - memcpy (ptr, &ui, sizeof (ui)); -} -#define OR_GET_BIG_VAR_OFFSET(ptr) OR_GET_INT (ptr) /* 4byte */ -#define OR_PUT_BIG_VAR_OFFSET(ptr, val) OR_PUT_INT (ptr, val) /* 4byte */ +#define OR_GET_INT(ptr) \ + ((int) ntohl (*(int *) ((char *) (ptr)))) -#define OR_PUT_OFFSET(ptr, val) \ - OR_PUT_OFFSET_INTERNAL(ptr, val, BIG_VAR_OFFSET_SIZE) +#define OR_PUT_INT64(ptr, val) \ + do { \ + INT64 packed_value; \ + packed_value = ((INT64) swap64 (*(INT64*) val)); \ + memcpy (ptr, &packed_value, OR_INT64_SIZE); \ + } while (0) -#define OR_PUT_OFFSET_INTERNAL(ptr, val, offset_size) \ +#define OR_GET_INT64(ptr, val) \ do { \ - if (offset_size == OR_BYTE_SIZE) \ - { \ - OR_PUT_BYTE(ptr, val); \ - } \ - else if (offset_size == OR_SHORT_SIZE) \ - { \ - OR_PUT_SHORT(ptr, val); \ - } \ - else if (offset_size == OR_INT_SIZE) \ - { \ - OR_PUT_INT(ptr, val); \ - } \ + INT64 packed_value; \ + memcpy (&packed_value, ptr, OR_INT64_SIZE); \ + *((INT64*) (val)) = ((INT64) swap64 (packed_value)); \ } while (0) -#define OR_GET_OFFSET(ptr) \ - OR_GET_OFFSET_INTERNAL (ptr, BIG_VAR_OFFSET_SIZE) +#define OR_PUT_BIGINT(ptr, val) \ + OR_PUT_INT64 (ptr, val) -#define OR_GET_OFFSET_INTERNAL(ptr, offset_size) \ - (offset_size == OR_BYTE_SIZE) \ - ? OR_GET_BYTE (ptr) \ - : ((offset_size == OR_SHORT_SIZE) \ - ? OR_GET_SHORT (ptr) : OR_GET_INT (ptr)) +#define OR_GET_BIGINT(ptr, val) \ + OR_GET_INT64 (ptr, val) -#define OR_MOVE_MONETARY(src, dst) \ - do { \ - OR_MOVE_DOUBLE (src, dst); \ - ((DB_MONETARY *) dst)->type = ((DB_MONETARY *) src)->type; \ - } while (0) +STATIC_INLINE void +OR_PUT_FLOAT (char *ptr, float val) +{ + UINT32 ui = htonf (val); + memcpy (ptr, &ui, sizeof (ui)); +} -#if OR_BYTE_ORDER == OR_LITTLE_ENDIAN +#define OR_GET_FLOAT(ptr, value) \ + (*(value) = ntohf (*(UINT32 *) (ptr))) -#define swap64(x) \ - ((((unsigned long long) (x) & (0x00000000000000FFULL)) << 56) \ - | (((unsigned long long) (x) & (0xFF00000000000000ULL)) >> 56) \ - | (((unsigned long long) (x) & (0x000000000000FF00ULL)) << 40) \ - | (((unsigned long long) (x) & (0x00FF000000000000ULL)) >> 40) \ - | (((unsigned long long) (x) & (0x0000000000FF0000ULL)) << 24) \ - | (((unsigned long long) (x) & (0x0000FF0000000000ULL)) >> 24) \ - | (((unsigned long long) (x) & (0x00000000FF000000ULL)) << 8) \ - | (((unsigned long long) (x) & (0x000000FF00000000ULL)) >> 8)) +STATIC_INLINE void +OR_PUT_DOUBLE (char *ptr, double val) +{ + UINT64 ui = htond (val); + memcpy (ptr, &ui, sizeof (ui)); +} -#else /* OR_BYTE_ORDER == OR_LITTLE_ENDIAN */ -#define swap64(x) (x) -#endif /* OR_BYTE_ORDER == OR_LITTLE_ENDIAN */ +#define OR_GET_DOUBLE(ptr, value) \ + (*(value) = ntohd (*(UINT64 *) (ptr))) #if __WORDSIZE == 32 -#define OR_PTR_SIZE 4 #define OR_PUT_PTR(ptr, val) OR_PUT_INT ((ptr), (val)) #define OR_GET_PTR(ptr) OR_GET_INT ((ptr)) #else /* __WORDSIZE == 32 */ -#define OR_PTR_SIZE 8 #define OR_PUT_PTR(ptr, val) (*(UINTPTR *) ((char *) (ptr)) = swap64 ((UINTPTR) val)) #define OR_GET_PTR(ptr) ((UINTPTR) swap64 (*(UINTPTR *) ((char *) (ptr)))) -#endif /* __WORDSIZE == 32 */ - -#define OR_INT64_SIZE 8 - -/* EXTENDED TYPES */ - -#define OR_PUT_BIGINT(ptr, val) OR_PUT_INT64 (ptr, val) -#define OR_GET_BIGINT(ptr, val) OR_GET_INT64 (ptr, val) +#endif /* __WORDSIZE == 64 */ -#define OR_GET_INT64(ptr, val) \ - do { \ - INT64 packed_value; \ - memcpy (&packed_value, ptr, OR_INT64_SIZE); \ - *((INT64*) (val)) = ((INT64) swap64 (packed_value)); \ - } while (0) +/* EXTENDED TYPE */ -#define OR_PUT_INT64(ptr, val) \ - do { \ - INT64 packed_value; \ - packed_value = ((INT64) swap64 (*(INT64*) val)); \ - memcpy (ptr, &packed_value, OR_INT64_SIZE);\ - } while (0) +#define OR_PUT_TIME(ptr, value) \ + OR_PUT_INT (ptr, *((DB_TIME *) (value))) #define OR_GET_TIME(ptr, value) \ *((DB_TIME *) (value)) = OR_GET_INT (ptr) -#define OR_PUT_TIME(ptr, value) \ - OR_PUT_INT (ptr, *((DB_TIME *) (value))) +#define OR_PUT_UTIME(ptr, value) \ + OR_PUT_INT (ptr, *((DB_UTIME *) (value))) #define OR_GET_UTIME(ptr, value) \ *((DB_UTIME *) (value)) = OR_GET_INT (ptr) -#define OR_PUT_UTIME(ptr, value) \ - OR_PUT_INT (ptr, *((DB_UTIME *) (value))) +#define OR_PUT_TIMESTAMPTZ(ptr, ts_tz) \ + do { \ + OR_PUT_INT (((char *) ptr), (ts_tz)->timestamp); \ + OR_PUT_INT (((char *) ptr) + OR_TIMESTAMPTZ_TZID, (ts_tz)->tz_id); \ + } while (0) #define OR_GET_TIMESTAMPTZ(ptr, ts_tz) \ do { \ @@ -224,17 +184,17 @@ OR_PUT_DOUBLE (char *ptr, double val) (ts_tz)->tz_id = OR_GET_INT (((char *) (ptr)) + OR_TIMESTAMPTZ_TZID); \ } while (0) -#define OR_PUT_TIMESTAMPTZ(ptr, ts_tz) \ - do { \ - OR_PUT_INT (((char *) ptr), (ts_tz)->timestamp); \ - OR_PUT_INT (((char *) ptr) + OR_TIMESTAMPTZ_TZID, (ts_tz)->tz_id); \ - } while (0) +#define OR_PUT_DATE(ptr, value) \ + OR_PUT_INT (ptr, *((DB_DATE *) (value))) #define OR_GET_DATE(ptr, value) \ *((DB_DATE *) (value)) = OR_GET_INT (ptr) -#define OR_PUT_DATE(ptr, value) \ - OR_PUT_INT (ptr, *((DB_DATE *) (value))) +#define OR_PUT_DATETIME(ptr, datetime) \ + do { \ + OR_PUT_INT (((char *)ptr) + OR_DATETIME_DATE, (datetime)->date); \ + OR_PUT_INT (((char *)ptr) + OR_DATETIME_TIME, (datetime)->time); \ + } while (0) #define OR_GET_DATETIME(ptr, datetime) \ do { \ @@ -242,10 +202,11 @@ OR_PUT_DOUBLE (char *ptr, double val) (datetime)->time = OR_GET_INT (((char *) (ptr)) + OR_DATETIME_TIME); \ } while (0) -#define OR_PUT_DATETIME(ptr, datetime) \ +#define OR_PUT_DATETIMETZ(ptr, datetimetz) \ do { \ - OR_PUT_INT (((char *)ptr) + OR_DATETIME_DATE, (datetime)->date); \ - OR_PUT_INT (((char *)ptr) + OR_DATETIME_TIME, (datetime)->time); \ + OR_PUT_DATETIME (((char *) ptr), \ + &((DB_DATETIMETZ *) datetimetz)->datetime); \ + OR_PUT_INT (((char *) ptr) + OR_DATETIMETZ_TZID, (datetimetz)->tz_id); \ } while (0) #define OR_GET_DATETIMETZ(ptr, datetimetz) \ @@ -255,11 +216,12 @@ OR_PUT_DOUBLE (char *ptr, double val) (datetimetz)->tz_id = OR_GET_INT (((char *) (ptr)) + OR_DATETIMETZ_TZID); \ } while (0) -#define OR_PUT_DATETIMETZ(ptr, datetimetz) \ +#define OR_PUT_MONETARY(ptr, value) \ do { \ - OR_PUT_DATETIME (((char *) ptr), \ - &((DB_DATETIMETZ *) datetimetz)->datetime); \ - OR_PUT_INT (((char *) ptr) + OR_DATETIMETZ_TZID, (datetimetz)->tz_id); \ + char pack_value[OR_DOUBLE_SIZE]; \ + OR_PUT_INT (((char *) (ptr)) + OR_MONETARY_TYPE, (int) (value)->type); \ + OR_PUT_DOUBLE (pack_value, (value)->amount); \ + memcpy (((char *) (ptr)) + OR_MONETARY_AMOUNT, pack_value, OR_DOUBLE_SIZE); \ } while (0) #define OR_GET_MONETARY(ptr, value) \ @@ -270,35 +232,36 @@ OR_PUT_DOUBLE (char *ptr, double val) OR_GET_DOUBLE (&pack_value, &(value)->amount); \ } while (0) -#define OR_GET_CURRENCY_TYPE(ptr) \ - (DB_CURRENCY) OR_GET_INT (((char *) (ptr)) + OR_MONETARY_TYPE) - -#define OR_PUT_MONETARY(ptr, value) \ +#define OR_MOVE_MONETARY(src, dst) \ do { \ - char pack_value[OR_DOUBLE_SIZE]; \ - OR_PUT_INT (((char *) (ptr)) + OR_MONETARY_TYPE, (int) (value)->type); \ - OR_PUT_DOUBLE (pack_value, (value)->amount); \ - memcpy (((char *) (ptr)) + OR_MONETARY_AMOUNT, pack_value, OR_DOUBLE_SIZE); \ + OR_MOVE_DOUBLE (src, dst); \ + ((DB_MONETARY *) dst)->type = ((DB_MONETARY *) src)->type; \ } while (0) -/* Sha1 */ -#define OR_GET_SHA1(ptr, value) \ +#define OR_GET_CURRENCY_TYPE(ptr) \ + (DB_CURRENCY) OR_GET_INT (((char *) (ptr)) + OR_MONETARY_TYPE) + +#define OR_PUT_SHA1(ptr, value) \ do { \ int i = 0; \ for (; i < 5; i++) \ { \ - ((SHA1Hash *) (value))->h[i] = (INT32) OR_GET_INT (ptr + i * OR_INT_SIZE); \ + OR_PUT_INT (ptr + i * OR_INT_SIZE, ((SHA1Hash *) (value))->h[i]); \ } \ } while (0) -#define OR_PUT_SHA1(ptr, value) \ + +#define OR_GET_SHA1(ptr, value) \ do { \ int i = 0; \ for (; i < 5; i++) \ { \ - OR_PUT_INT (ptr + i * OR_INT_SIZE, ((SHA1Hash *) (value))->h[i]); \ + ((SHA1Hash *) (value))->h[i] = (INT32) OR_GET_INT (ptr + i * OR_INT_SIZE); \ } \ } while (0) +#define OR_GET_STRING(ptr) \ + ((char *) ((char *) (ptr))) + /* DISK IDENTIFIERS */ #define OR_GET_OID(ptr, oid) \ @@ -326,6 +289,7 @@ OR_PUT_DOUBLE (char *ptr, double val) OR_PUT_INT (((char *) (ptr)) + OR_VPID_PAGEID, (vpid)->pageid); \ OR_PUT_SHORT (((char *) (ptr)) + OR_VPID_VOLID, (vpid)->volid); \ } while (0) + #define OR_PUT_VPID_ALIGNED(ptr, vpid) \ do { \ OR_PUT_INT (((char *) (ptr)) + OR_VPID_PAGEID, (vpid)->pageid); \ @@ -418,6 +382,43 @@ OR_PUT_DOUBLE (char *ptr, double val) OR_PUT_SHORT (((char *) (ptr)) + OR_LOG_LSA_OFFSET, -1); \ } while (0) +/* VARIABLE OFFSET ACCESSORS */ + +#define OR_PUT_BIG_VAR_OFFSET(ptr, val) \ + OR_PUT_INT ((ptr), (val)) + +#define OR_GET_BIG_VAR_OFFSET(ptr) \ + OR_GET_INT ((ptr)) + +#define OR_PUT_OFFSET(ptr, val) \ + OR_PUT_BIG_VAR_OFFSET ((ptr), (val)) + +#define OR_GET_OFFSET(ptr) \ + OR_GET_BIG_VAR_OFFSET ((ptr)) + +#define OR_PUT_OFFSET_INTERNAL(ptr, val, offset_size) \ + do { \ + if ((offset_size) == OR_BYTE_SIZE) \ + { \ + OR_PUT_BYTE ((ptr), (val)); \ + } \ + else if ((offset_size) == OR_SHORT_SIZE) \ + { \ + OR_PUT_SHORT ((ptr), (val)); \ + } \ + else \ + { \ + assert ((offset_size) == OR_INT_SIZE); \ + OR_PUT_INT ((ptr), (val)); \ + } \ + } while (0) + +#define OR_GET_OFFSET_INTERNAL(ptr, offset_size) \ + ((offset_size) == OR_BYTE_SIZE) \ + ? OR_GET_BYTE ((ptr)) \ + : (((offset_size) == OR_SHORT_SIZE) \ + ? OR_GET_SHORT ((ptr)) : OR_GET_INT ((ptr))) + /* * VARIABLE OFFSET TABLE ACCESSORS * The variable offset table is present in the headers of objects and sets. @@ -1067,26 +1068,6 @@ struct or_buf int error_abort; }; -/* TODO: LP64 check DB_INT32_MAX */ - -#define OR_BUF_INIT(buf, data, size) \ - do { \ - (buf).buffer = (buf).ptr = (data); \ - (buf).endptr = ((size) <= 0 || (size) == DB_INT32_MAX) \ - ? (char *) OR_INFINITE_POINTER : (data) + (size); \ - (buf).error_abort = 0; \ - (buf).fixups = NULL; \ - } while (0) - -#define OR_BUF_INIT2(buf, data, size) \ - do { \ - (buf).buffer = (buf).ptr = (data); \ - (buf).endptr = ((size) <= 0 || (size) == DB_INT32_MAX) \ - ? (char *) OR_INFINITE_POINTER : (data) + (size); \ - (buf).error_abort = 1; \ - (buf).fixups = NULL; \ - } while (0) - /* Need to translate types of DB_TYPE_OBJECT into DB_TYPE_OID in server-side */ #define OR_PACK_DOMAIN_OBJECT_TO_OID(p, d, o, n) \ or_pack_domain ((p), \ @@ -1229,10 +1210,6 @@ extern int or_packed_string_length (const char *string, int *strlen); extern int or_align_length (int length); #endif /* ENABLE_UNUSED_FUNCTION */ extern int or_packed_varbit_length (int bitlen); -extern int or_varbit_length (int bitlen); -extern int or_packed_varchar_length (int charlen); -extern int or_varchar_length (int charlen); -extern int or_packed_recdesc_length (int length); /* * to avoid circular dependencies, don't require the definition of QFILE_LIST_ID in @@ -1250,91 +1227,133 @@ extern int or_packed_db_value_array_length (int count, DB_VALUE * val); extern void or_encode (char *buffer, const char *source, int size); extern void or_decode (const char *buffer, char *dest, int size); -extern void or_init (OR_BUF * buf, char *data, int length); +STATIC_INLINE void or_init (OR_BUF * buf, char *data, int length) __attribute__ ((ALWAYS_INLINE)); /* These are called when overflow/underflow are detected */ extern int or_overflow (OR_BUF * buf); extern int or_underflow (OR_BUF * buf); extern void or_abort (OR_BUF * buf); -/* Data packing functions */ -extern int or_put_byte (OR_BUF * buf, int num); -extern int or_put_short (OR_BUF * buf, int num); -extern int or_put_int (OR_BUF * buf, int num); -extern int or_put_bigint (OR_BUF * buf, DB_BIGINT num); -extern int or_put_float (OR_BUF * buf, float num); -extern int or_put_double (OR_BUF * buf, double num); -extern int or_put_time (OR_BUF * buf, DB_TIME * timeval); -extern int or_put_utime (OR_BUF * buf, DB_UTIME * timeval); -extern int or_put_timestamptz (OR_BUF * buf, DB_TIMESTAMPTZ * ts_tz); -extern int or_put_date (OR_BUF * buf, DB_DATE * date); -extern int or_put_datetime (OR_BUF * buf, DB_DATETIME * datetimeval); -extern int or_put_datetimetz (OR_BUF * buf, DB_DATETIMETZ * datetimetz); +/* Pack/unpack support functions */ +STATIC_INLINE int or_advance (OR_BUF * buf, int offset) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_seek (OR_BUF * buf, int psn) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_pad (OR_BUF * buf, int length) __attribute__ ((ALWAYS_INLINE)); + +STATIC_INLINE int or_put_align32 (OR_BUF * buf) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_align (OR_BUF * buf, int alignment) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_get_align (OR_BUF * buf, int align) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_get_align32 (OR_BUF * buf) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_get_align64 (OR_BUF * buf) __attribute__ ((ALWAYS_INLINE)); + +/* + * NUMERIC DATA TRANSFORMS + * This set of functions handles the transformation of the + * numeric types byte, short, integer, float, and double. + * + */ + +STATIC_INLINE int or_put_byte (OR_BUF * buf, int num) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_put_short (OR_BUF * buf, int num) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_put_int (OR_BUF * buf, int num) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_put_bigint (OR_BUF * buf, DB_BIGINT num) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_put_float (OR_BUF * buf, float num) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_put_double (OR_BUF * buf, double num) __attribute__ ((ALWAYS_INLINE)); + +STATIC_INLINE int or_get_byte (OR_BUF * buf, int *error) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_get_short (OR_BUF * buf, int *error) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_get_int (OR_BUF * buf, int *error) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE DB_BIGINT or_get_bigint (OR_BUF * buf, int *error) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE float or_get_float (OR_BUF * buf, int *error) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE double or_get_double (OR_BUF * buf, int *error) __attribute__ ((ALWAYS_INLINE)); + +/* + * EXTENDED TYPE TRANSLATORS + * This set of functions reads and writes the extended types time, + * utime, date, and monetary. + */ + +STATIC_INLINE int or_put_time (OR_BUF * buf, DB_TIME * timeval) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_put_utime (OR_BUF * buf, DB_UTIME * timeval) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_put_timestamptz (OR_BUF * buf, DB_TIMESTAMPTZ * ts_tz) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_put_date (OR_BUF * buf, DB_DATE * date) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_put_datetime (OR_BUF * buf, DB_DATETIME * datetimeval) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_put_datetimetz (OR_BUF * buf, DB_DATETIMETZ * datetimetz) __attribute__ ((ALWAYS_INLINE)); extern int or_put_monetary (OR_BUF * buf, DB_MONETARY * monetary); -extern int or_put_string_aligned (OR_BUF * buf, char *string); -extern int or_put_string_aligned_with_length (OR_BUF * buf, const char *str); + +STATIC_INLINE int or_get_time (OR_BUF * buf, DB_TIME * timeval) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_get_utime (OR_BUF * buf, DB_UTIME * timeval) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_get_timestamptz (OR_BUF * buf, DB_TIMESTAMPTZ * ts_tz) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_get_date (OR_BUF * buf, DB_DATE * date) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_get_datetime (OR_BUF * buf, DB_DATETIME * datetime) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_get_datetimetz (OR_BUF * buf, DB_DATETIMETZ * datetimetz) __attribute__ ((ALWAYS_INLINE)); +extern int or_get_monetary (OR_BUF * buf, DB_MONETARY * monetary); + #if defined(ENABLE_UNUSED_FUNCTION) extern int or_put_binary (OR_BUF * buf, DB_BINARY * binary); #endif -extern int or_put_data (OR_BUF * buf, const char *data, int length); -extern int or_put_oid (OR_BUF * buf, const OID * oid); +STATIC_INLINE int or_put_data (OR_BUF * buf, const char *data, int length) __attribute__ ((ALWAYS_INLINE)); extern int or_put_varbit (OR_BUF * buf, const char *string, int bitlen); -extern int or_packed_put_varbit (OR_BUF * buf, const char *string, int bitlen); extern int or_put_varchar (OR_BUF * buf, char *string, int charlen); -extern int or_packed_put_varchar (OR_BUF * buf, char *string, int charlen); -extern int or_put_align32 (OR_BUF * buf); -extern int or_put_offset (OR_BUF * buf, int num); -extern int or_put_offset_internal (OR_BUF * buf, int num, int offset_size); -extern int or_put_mvccid (OR_BUF * buf, MVCCID mvccid); +STATIC_INLINE int or_put_string_aligned (OR_BUF * buf, char *string) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_put_string_aligned_with_length (OR_BUF * buf, const char *str) __attribute__ ((ALWAYS_INLINE)); -/* Data unpacking functions */ -extern int or_get_byte (OR_BUF * buf, int *error); -extern int or_get_short (OR_BUF * buf, int *error); -extern int or_get_int (OR_BUF * buf, int *error); -extern DB_BIGINT or_get_bigint (OR_BUF * buf, int *error); -extern float or_get_float (OR_BUF * buf, int *error); -extern double or_get_double (OR_BUF * buf, int *error); -extern int or_get_time (OR_BUF * buf, DB_TIME * timeval); -extern int or_get_utime (OR_BUF * buf, DB_UTIME * timeval); -extern int or_get_timestamptz (OR_BUF * buf, DB_TIMESTAMPTZ * ts_tz); -extern int or_get_date (OR_BUF * buf, DB_DATE * date); -extern int or_get_datetime (OR_BUF * buf, DB_DATETIME * datetime); -extern int or_get_datetimetz (OR_BUF * buf, DB_DATETIMETZ * datetimetz); -extern int or_get_monetary (OR_BUF * buf, DB_MONETARY * monetary); -extern int or_get_data (OR_BUF * buf, char *data, int length); -extern int or_get_oid (OR_BUF * buf, OID * oid); -extern int or_get_offset (OR_BUF * buf, int *error); -extern int or_get_offset_internal (OR_BUF * buf, int *error, int offset_size); -extern int or_get_mvccid (OR_BUF * buf, MVCCID * mvccid); +STATIC_INLINE int or_get_data (OR_BUF * buf, char *data, int length) __attribute__ ((ALWAYS_INLINE)); +#if defined(ENABLE_UNUSED_FUNCTION) +extern char *or_get_varbit (OR_BUF * buf, int *length_ptr); +extern char *or_get_varchar (OR_BUF * buf, int *length_ptr); +#endif +STATIC_INLINE int or_get_varbit_length (OR_BUF * buf, int *intval) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_get_varchar_length (OR_BUF * buf, int *intval) __attribute__ ((ALWAYS_INLINE)); +/* Get the compressed and the decompressed lengths of a string stored in buffer */ +STATIC_INLINE int or_get_varchar_compression_lengths (OR_BUF * buf, int *compressed_size, int *decompressed_size) + __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_get_string_size_byte (OR_BUF * buf, int *error) __attribute__ ((ALWAYS_INLINE)); -extern int or_skip_varchar_remainder (OR_BUF * buf, int charlen, int align); -extern int or_skip_varchar (OR_BUF * buf, int align); -extern int or_skip_varbit (OR_BUF * buf, int align); -extern int or_skip_varbit_remainder (OR_BUF * buf, int bitlen, int align); +STATIC_INLINE int or_varbit_length (int bitlen) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_varchar_length (int charlen) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_varbit_length_internal (int bitlen, int align) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_varchar_length_internal (int charlen, int align) __attribute__ ((ALWAYS_INLINE)); + +STATIC_INLINE int or_skip_varbit (OR_BUF * buf, int align) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_skip_varchar (OR_BUF * buf, int align) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_skip_varbit_remainder (OR_BUF * buf, int bitlen, int align) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_skip_varchar_remainder (OR_BUF * buf, int charlen, int align) __attribute__ ((ALWAYS_INLINE)); -/* Pack/unpack support functions */ -extern int or_advance (OR_BUF * buf, int offset); -extern int or_seek (OR_BUF * buf, int psn); -extern int or_align (OR_BUF * buf, int alignment); -extern int or_pad (OR_BUF * buf, int length); #if defined(ENABLE_UNUSED_FUNCTION) -extern int or_length_string (char *string); extern int or_length_binary (DB_BINARY * binary); +extern int or_length_string (char *string); #endif -extern int or_get_varchar_length (OR_BUF * buf, int *intval); -extern int or_get_align (OR_BUF * buf, int align); -extern int or_get_align32 (OR_BUF * buf); -extern int or_get_align64 (OR_BUF * buf); -#if defined(ENABLE_UNUSED_FUNCTION) -extern char *or_get_varchar (OR_BUF * buf, int *length_ptr); -extern char *or_get_varbit (OR_BUF * buf, int *length_ptr); -#endif -extern int or_get_varbit_length (OR_BUF * buf, int *intval); +/* + * DISK IDENTIFIER TRANSLATORS + * Translators for the disk identifiers OID, HFID, BTID, EHID. + */ + +STATIC_INLINE int or_put_oid (OR_BUF * buf, const OID * oid) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_put_mvccid (OR_BUF * buf, MVCCID mvccid) __attribute__ ((ALWAYS_INLINE)); + +STATIC_INLINE int or_get_oid (OR_BUF * buf, OID * oid) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_get_mvccid (OR_BUF * buf, MVCCID * mvccid) __attribute__ ((ALWAYS_INLINE)); + +/* VARIABLE OFFSET TABLE ACCESSORS */ + +STATIC_INLINE int or_put_big_var_offset (OR_BUF * buf, int num) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_put_offset (OR_BUF * buf, int num) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_put_offset_internal (OR_BUF * buf, int num, int offset_size) __attribute__ ((ALWAYS_INLINE)); + +STATIC_INLINE int or_get_big_var_offset (OR_BUF * buf, int *error) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_get_offset (OR_BUF * buf, int *error) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE int or_get_offset_internal (OR_BUF * buf, int *error, int offset_size) __attribute__ ((ALWAYS_INLINE)); + +/* Data unpacking functions */ + +extern int or_packed_put_varbit (OR_BUF * buf, const char *string, int bitlen); +extern int or_packed_put_varchar (OR_BUF * buf, char *string, int charlen); +extern int or_packed_varchar_length (int charlen); +extern int or_packed_recdesc_length (int length); extern char *or_unpack_var_table (char *ptr, int nvars, OR_VARINFO * vars); extern OR_VARINFO *or_get_var_table (OR_BUF * buf, int nvars, char *(*allocator) (int)); - extern OR_VARINFO *or_get_var_table_internal (OR_BUF * buf, int nvars, char *(*allocator) (int), int offset_size); /* DOMAIN functions */ @@ -1388,11 +1407,6 @@ extern char *or_unpack_mvccid (char *ptr, MVCCID * mvccid); extern char *or_pack_sha1 (char *ptr, const SHA1Hash * sha1); extern char *or_unpack_sha1 (char *ptr, SHA1Hash * sha1); -STATIC_INLINE int or_get_string_size_byte (OR_BUF * buf, int *error) __attribute__ ((ALWAYS_INLINE)); -/* Get the compressed and the decompressed lengths of a string stored in buffer */ -STATIC_INLINE int or_get_varchar_compression_lengths (OR_BUF * buf, int *compressed_size, int *decompressed_size) - __attribute__ ((ALWAYS_INLINE)); - extern int or_packed_spacedb_size (const SPACEDB_ALL * all, const SPACEDB_ONEVOL * vols, const SPACEDB_FILES * files); extern char *or_pack_spacedb (char *ptr, const SPACEDB_ALL * all, const SPACEDB_ONEVOL * vols, const SPACEDB_FILES * files); @@ -1416,30 +1430,880 @@ extern int or_put_json_schema (OR_BUF * buf, const char *schema); ((str_length) >= OR_MINIMUM_STRING_LENGTH_FOR_COMPRESSION && (str_length) <= LZ4_MAX_INPUT_SIZE) /* - * or_get_string_size_byte - read string size byte value from or buffer - * return: byte value read - * buf(in/out): or buffer - * error(out): NO_ERROR or error code - * - * NOTE that it is really same as or_get_byte function. It is duplicated to inline the function for performance. + * or_init - initialize the field of an OR_BUF + * return: void + * buf(in/out): or buffer to initialize + * data(in): buffer data + * length(in): buffer data length */ -STATIC_INLINE int -or_get_string_size_byte (OR_BUF * buf, int *error) +STATIC_INLINE void +or_init (OR_BUF * buf, char *data, int length) { - int size_prefix; + buf->buffer = data; + buf->ptr = data; - if ((buf->ptr + OR_BYTE_SIZE) > buf->endptr) + /* TODO: LP64 check DB_INT32_MAX */ + if (length <= 0 || length == DB_INT32_MAX) { - *error = or_underflow (buf); - size_prefix = 0; + buf->endptr = (char *) OR_INFINITE_POINTER; } else { - size_prefix = OR_GET_BYTE (buf->ptr); - buf->ptr += OR_BYTE_SIZE; - *error = NO_ERROR; + buf->endptr = data + length; } - return size_prefix; + + buf->error_abort = 0; + buf->fixups = NULL; +} + +/* + * OR_BUF PACK/UNPACK FUNCTIONS + */ + +/* + * or_seek - This sets the translation pointer directly to a certain byte in + * the buffer. + * return: ERROR_SUCCESS or error code + * buf(in/out): or buffer + * psn(in): position within buffer + */ +STATIC_INLINE int +or_seek (OR_BUF * buf, int psn) +{ + if ((buf->buffer + psn) > buf->endptr) + { + return (or_overflow (buf)); + } + else + { + buf->ptr = buf->buffer + psn; + } + return NO_ERROR; +} + +/* + * or_advance - This advances the translation pointer + * return: NO_ERROR or error code + * buf(in/out): or buffer + * offset(in): number of bytes to skip + */ +STATIC_INLINE int +or_advance (OR_BUF * buf, int offset) +{ + if ((buf->ptr + offset) > buf->endptr) + { + return (or_overflow (buf)); + } + else + { + buf->ptr += offset; + return NO_ERROR; + } +} + +/* + * or_pad - This advances the translation pointer and adds bytes of zero. + * return: NO_ERROR or error code + * buf(in/out): or buffer + * length(in): number of bytes to pad + * + * Note: + * This advances the translation pointer and adds bytes of zero. + * This is used add padding bytes to ensure proper alignment of + * some data types. + */ +STATIC_INLINE int +or_pad (OR_BUF * buf, int length) +{ + if ((buf->ptr + length) > buf->endptr) + { + return (or_overflow (buf)); + } + else + { + (void) memset (buf->ptr, 0, length); + buf->ptr += length; + } + return NO_ERROR; +} + +/* + * or_put_align32 - pad zero bytes round up to 4 byte bound + * return: NO_ERROR or error code + * buf(in/out): or buffer + */ +STATIC_INLINE int +or_put_align32 (OR_BUF * buf) +{ + unsigned int bits; + int rc = NO_ERROR; + + bits = (UINTPTR) buf->ptr & 3; + if (bits) + { + rc = or_pad (buf, 4 - bits); + } + + return rc; +} + +/* + * or_align () - Align current buffer pointer to given alignment. + * + * return : Error code. + * buf (in/out) : Buffer. + * alignment (in) : Desired alignment. + */ +STATIC_INLINE int +or_align (OR_BUF * buf, int alignment) +{ + char *new_ptr = PTR_ALIGN (buf->ptr, alignment); + if (new_ptr > buf->endptr) + { + return (or_overflow (buf)); + } + buf->ptr = new_ptr; + return NO_ERROR; +} + +/* + * or_get_align - adnvance or buf pointer to next alignment position + * return: NO_ERROR or error code + * buf(in/out): or buffer + * align(in): + */ +STATIC_INLINE int +or_get_align (OR_BUF * buf, int align) +{ + char *ptr; + + ptr = PTR_ALIGN (buf->ptr, align); + if (ptr > buf->endptr) + { + return (or_overflow (buf)); + } + else + { + buf->ptr = ptr; + return NO_ERROR; + } +} + +/* + * or_get_align32 - adnvance or buf pointer to next 4 byte alignment position + * return: NO_ERROR or error code + * buf(in/out): or buffer + */ +STATIC_INLINE int +or_get_align32 (OR_BUF * buf) +{ + unsigned int bits; + int rc = NO_ERROR; + + bits = (UINTPTR) (buf->ptr) & 3; + if (bits) + { + rc = or_advance (buf, 4 - bits); + } + + return rc; +} + +/* + * or_get_align64 - adnvance or buf pointer to next 8 byte alignment position + * return: NO_ERROR or error code + * buf(in/out): or buffer + */ +STATIC_INLINE int +or_get_align64 (OR_BUF * buf) +{ + unsigned int bits; + int rc = NO_ERROR; + + bits = (UINTPTR) (buf->ptr) & 7; + if (bits) + { + rc = or_advance (buf, 8 - bits); + } + + return rc; +} + +/* + * NUMERIC DATA TRANSFORMS + * This set of functions handles the transformation of the + * numeric types byte, short, integer, float, and double. + * + */ + +/* + * or_put_byte - put a byte to or buffer + * return: NO_ERROR or error code + * buf(out/out): or buffer + * num(in): byte value + */ +STATIC_INLINE int +or_put_byte (OR_BUF * buf, int num) +{ + if ((buf->ptr + OR_BYTE_SIZE) > buf->endptr) + { + return (or_overflow (buf)); + } + else + { + OR_PUT_BYTE (buf->ptr, num); + buf->ptr += OR_BYTE_SIZE; + } + return NO_ERROR; +} + +/* + * or_get_byte - read a byte value from or buffer + * return: byte value read + * buf(in/out): or buffer + * error(out): NO_ERROR or error code + */ +STATIC_INLINE int +or_get_byte (OR_BUF * buf, int *error) +{ + int value = 0; + + if ((buf->ptr + OR_BYTE_SIZE) > buf->endptr) + { + *error = or_underflow (buf); + return 0; + } + else + { + value = OR_GET_BYTE (buf->ptr); + buf->ptr += OR_BYTE_SIZE; + *error = NO_ERROR; + } + return value; +} + +/* + * or_put_short - put a short value to or buffer + * return: NO_ERROR or error code + * buf(in/out): or buffer + * num(in): short value to put + */ +STATIC_INLINE int +or_put_short (OR_BUF * buf, int num) +{ + ASSERT_ALIGN (buf->ptr, SHORT_ALIGNMENT); + + if ((buf->ptr + OR_SHORT_SIZE) > buf->endptr) + { + return (or_overflow (buf)); + } + else + { + OR_PUT_SHORT (buf->ptr, num); + buf->ptr += OR_SHORT_SIZE; + } + return NO_ERROR; +} + +/* + * or_get_short - read a short value from or buffer + * return: short value read + * buf(in/out): or buffer + * error(out): NO_ERROR or error code + */ +STATIC_INLINE int +or_get_short (OR_BUF * buf, int *error) +{ + int value = 0; + + ASSERT_ALIGN (buf->ptr, SHORT_ALIGNMENT); + + if ((buf->ptr + OR_SHORT_SIZE) > buf->endptr) + { + *error = or_underflow (buf); + return 0; + } + else + { + value = OR_GET_SHORT (buf->ptr); + buf->ptr += OR_SHORT_SIZE; + } + *error = NO_ERROR; + return value; +} + +/* + * or_put_int - put int value to or buffer + * return: NO_ERROR or error code + * buf(in/out): or buffer + * num(in): int value to put + */ +STATIC_INLINE int +or_put_int (OR_BUF * buf, int num) +{ + ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); + + if ((buf->ptr + OR_INT_SIZE) > buf->endptr) + { + return (or_overflow (buf)); + } + else + { + OR_PUT_INT (buf->ptr, num); + buf->ptr += OR_INT_SIZE; + } + return NO_ERROR; +} + +/* + * or_get_int - get int value from or buffer + * return: int value read + * buf(in/out): or buffer + * error(out): NO_ERROR or error code + */ +STATIC_INLINE int +or_get_int (OR_BUF * buf, int *error) +{ + int value = 0; + + ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); + + if ((buf->ptr + OR_INT_SIZE) > buf->endptr) + { + *error = or_underflow (buf); + } + else + { + value = OR_GET_INT (buf->ptr); + buf->ptr += OR_INT_SIZE; + *error = NO_ERROR; + } + return value; +} + +/* + * or_put_bigint - put bigint value to or buffer + * return: NO_ERROR or error code + * buf(in/out): or buffer + * num(in): bigint value to put + */ +STATIC_INLINE int +or_put_bigint (OR_BUF * buf, DB_BIGINT num) +{ + ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); + + if ((buf->ptr + OR_BIGINT_SIZE) > buf->endptr) + { + return (or_overflow (buf)); + } + else + { + OR_PUT_BIGINT (buf->ptr, &num); + buf->ptr += OR_BIGINT_SIZE; + } + return NO_ERROR; +} + +/* + * or_get_bigint - get bigint value from or buffer + * return: bigint value read + * buf(in/out): or buffer + * error(out): NO_ERROR or error code + */ +STATIC_INLINE DB_BIGINT +or_get_bigint (OR_BUF * buf, int *error) +{ + DB_BIGINT value = 0; + + ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); + + if ((buf->ptr + OR_BIGINT_SIZE) > buf->endptr) + { + *error = or_underflow (buf); + } + else + { + OR_GET_BIGINT (buf->ptr, &value); + buf->ptr += OR_BIGINT_SIZE; + *error = NO_ERROR; + } + return value; +} + +/* + * or_put_float - put a float value to or buffer + * return: NO_ERROR or error code + * buf(in/out): or buffer + * fnum(in): float value to put + */ +STATIC_INLINE int +or_put_float (OR_BUF * buf, float fnum) +{ + ASSERT_ALIGN (buf->ptr, FLOAT_ALIGNMENT); + + if ((buf->ptr + OR_FLOAT_SIZE) > buf->endptr) + { + return (or_overflow (buf)); + } + else + { + OR_PUT_FLOAT (buf->ptr, fnum); + buf->ptr += OR_FLOAT_SIZE; + } + return NO_ERROR; +} + +/* + * or_get_float - read a float value from or buffer + * return: float value read + * buf(in/out): or buffer + * error(out): NO_ERROR or error code + */ +STATIC_INLINE float +or_get_float (OR_BUF * buf, int *error) +{ + float value = 0.0; + + ASSERT_ALIGN (buf->ptr, FLOAT_ALIGNMENT); + + if ((buf->ptr + OR_FLOAT_SIZE) > buf->endptr) + { + *error = or_underflow (buf); + } + else + { + OR_GET_FLOAT (buf->ptr, &value); + buf->ptr += OR_FLOAT_SIZE; + *error = NO_ERROR; + } + return value; +} + +/* + * or_put_double - put a double value to or buffer + * return: NO_ERROR or error code + * buf(in/out): or buffer + * dnum(in): double value to put + */ +STATIC_INLINE int +or_put_double (OR_BUF * buf, double dnum) +{ + ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); + + if ((buf->ptr + OR_DOUBLE_SIZE) > buf->endptr) + { + return (or_overflow (buf)); + } + else + { + OR_PUT_DOUBLE (buf->ptr, dnum); + buf->ptr += OR_DOUBLE_SIZE; + } + return NO_ERROR; +} + +/* + * or_get_double - read a double value from or buffer + * return: double value read + * buf(in/out): or buffer + * error(out): NO_ERROR or error code + */ +STATIC_INLINE double +or_get_double (OR_BUF * buf, int *error) +{ + double value = 0.0; + + ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); + + if ((buf->ptr + OR_DOUBLE_SIZE) > buf->endptr) + { + *error = or_underflow (buf); + } + else + { + OR_GET_DOUBLE (buf->ptr, &value); + buf->ptr += OR_DOUBLE_SIZE; + *error = NO_ERROR; + } + return value; +} + +/* + * EXTENDED TYPE TRANSLATORS + * This set of functions reads and writes the extended types time, + * utime, date, and monetary. + */ + +/* + * or_put_time - write a DB_TIME to or buffer + * return: NO_ERROR or error code + * buf(in/out): or buffer + * timeval(in): time value to write + */ +STATIC_INLINE int +or_put_time (OR_BUF * buf, DB_TIME * timeval) +{ + ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); + + if ((buf->ptr + OR_TIME_SIZE) > buf->endptr) + { + return (or_overflow (buf)); + } + else + { + OR_PUT_TIME (buf->ptr, timeval); + buf->ptr += OR_TIME_SIZE; + } + return NO_ERROR; +} + +/* + * or_get_time - read a DB_TIME from or buffer + * return: NO_ERROR or error code + * buf(in/out): or buffer + * timeval(out): pointer to DB_TIME value + */ +STATIC_INLINE int +or_get_time (OR_BUF * buf, DB_TIME * timeval) +{ + ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); + + if ((buf->ptr + OR_TIME_SIZE) > buf->endptr) + { + return or_underflow (buf); + } + else + { + OR_GET_TIME (buf->ptr, timeval); + buf->ptr += OR_TIME_SIZE; + } + return NO_ERROR; +} + +/* + * or_put_utime - write a timestamp value to or buffer + * return: NO_ERROR or error code + * buf(in/out): or buffer + * timeval(in): pointer to timestamp value + */ +STATIC_INLINE int +or_put_utime (OR_BUF * buf, DB_UTIME * timeval) +{ + ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); + + if ((buf->ptr + OR_UTIME_SIZE) > buf->endptr) + { + return (or_overflow (buf)); + } + else + { + OR_PUT_UTIME (buf->ptr, timeval); + buf->ptr += OR_UTIME_SIZE; + } + return NO_ERROR; +} + +/* + * or_get_utime - read a timestamp value from or buffer + * return: NO_ERROR or error code + * buf(in/out): or buffer + * timeval(out): pointer to timestamp value + */ +STATIC_INLINE int +or_get_utime (OR_BUF * buf, DB_UTIME * timeval) +{ + ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); + + if ((buf->ptr + OR_UTIME_SIZE) > buf->endptr) + { + return or_underflow (buf); + } + else + { + OR_GET_UTIME (buf->ptr, timeval); + buf->ptr += OR_UTIME_SIZE; + } + return NO_ERROR; +} + +/* + * or_put_timestamptz - write a timestamp with tz value to or buffer + * return: NO_ERROR or error code + * buf(in/out): or buffer + * ts_tz(in): pointer to DB_TIMESTAMPTZ value + */ +STATIC_INLINE int +or_put_timestamptz (OR_BUF * buf, DB_TIMESTAMPTZ * ts_tz) +{ + ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); + + if ((buf->ptr + OR_TIMESTAMPTZ_SIZE) > buf->endptr) + { + return (or_overflow (buf)); + } + else + { + OR_PUT_TIMESTAMPTZ (buf->ptr, ts_tz); + buf->ptr += OR_TIMESTAMPTZ_SIZE; + } + return NO_ERROR; +} + +/* + * or_get_timestamptz - read a timestamp with tz value from or buffer + * return: NO_ERROR or error code + * buf(in/out): or buffer + * ts_tz(out): pointer to DB_TIMESTAMPTZ value + */ +STATIC_INLINE int +or_get_timestamptz (OR_BUF * buf, DB_TIMESTAMPTZ * ts_tz) +{ + ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); + + if ((buf->ptr + OR_TIMESTAMPTZ_SIZE) > buf->endptr) + { + return or_underflow (buf); + } + else + { + OR_GET_TIMESTAMPTZ (buf->ptr, ts_tz); + buf->ptr += OR_TIMESTAMPTZ_SIZE; + } + return NO_ERROR; +} + +/* + * or_put_date - write a DB_DATE value to or_buffer + * return: NO_ERROR or error code + * buf(in/out): or buffer + * date(in): pointer to DB_DATE value + */ +STATIC_INLINE int +or_put_date (OR_BUF * buf, DB_DATE * date) +{ + ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); + + if ((buf->ptr + OR_DATE_SIZE) > buf->endptr) + { + return (or_overflow (buf)); + } + else + { + OR_PUT_DATE (buf->ptr, date); + buf->ptr += OR_DATE_SIZE; + } + return NO_ERROR; +} + +/* + * or_get_date - read a DB_DATE value from or_buffer + * return: NO_ERROR or error code + * buf(in/out): or buffer + * date(out): pointer to DB_DATE value + */ +STATIC_INLINE int +or_get_date (OR_BUF * buf, DB_DATE * date) +{ + ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); + + if ((buf->ptr + OR_DATE_SIZE) > buf->endptr) + { + return or_underflow (buf); + } + else + { + OR_GET_DATE (buf->ptr, date); + buf->ptr += OR_DATE_SIZE; + } + return NO_ERROR; +} + +/* + * or_put_datetime - write a datetime value to or buffer + * return: NO_ERROR or error code + * buf(in/out): or buffer + * datetimeval(in): pointer to datetime value + */ +STATIC_INLINE int +or_put_datetime (OR_BUF * buf, DB_DATETIME * datetimeval) +{ + ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); + + if ((buf->ptr + OR_DATETIME_SIZE) > buf->endptr) + { + return (or_overflow (buf)); + } + else + { + OR_PUT_DATETIME (buf->ptr, datetimeval); + buf->ptr += OR_DATETIME_SIZE; + } + return NO_ERROR; +} + +/* + * or_get_datetime - read a DB_DATETIME value from or_buffer + * return: NO_ERROR or error code + * buf(in/out): or buffer + * date(out): pointer to DB_DATETIME value + */ +STATIC_INLINE int +or_get_datetime (OR_BUF * buf, DB_DATETIME * datetime) +{ + ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); + + if ((buf->ptr + OR_DATETIME_SIZE) > buf->endptr) + { + return or_underflow (buf); + } + else + { + OR_GET_DATETIME (buf->ptr, datetime); + buf->ptr += OR_DATETIME_SIZE; + } + return NO_ERROR; +} + +/* + * or_put_datetimetz - write a datetime with tz value to or buffer + * return: NO_ERROR or error code + * buf(in/out): or buffer + * datetimetz(in): pointer to DB_DATETIMETZ value + */ +STATIC_INLINE int +or_put_datetimetz (OR_BUF * buf, DB_DATETIMETZ * datetimetz) +{ + ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); + + if ((buf->ptr + OR_DATETIMETZ_SIZE) > buf->endptr) + { + return (or_overflow (buf)); + } + else + { + OR_PUT_DATETIMETZ (buf->ptr, datetimetz); + buf->ptr += OR_DATETIMETZ_SIZE; + } + return NO_ERROR; +} + +/* + * or_get_datetimetz - read a datetime with tz value from or_buffer + * return: NO_ERROR or error code + * buf(in/out): or buffer + * datetimetz(out): pointer to DB_DATETIMETZ value + */ +STATIC_INLINE int +or_get_datetimetz (OR_BUF * buf, DB_DATETIMETZ * datetimetz) +{ + ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); + + if ((buf->ptr + OR_DATETIMETZ_SIZE) > buf->endptr) + { + return or_underflow (buf); + } + else + { + OR_GET_DATETIMETZ (buf->ptr, datetimetz); + buf->ptr += OR_DATETIMETZ_SIZE; + } + return NO_ERROR; +} + +/* + * or_put_data - write an array of bytes to or buffer + * return: NO_ERROR or error code + * buf(in/out): or buffer + * data(in): pointer to data + * length(in): length in bytes + */ +STATIC_INLINE int +or_put_data (OR_BUF * buf, const char *data, int length) +{ + if ((buf->ptr + length) > buf->endptr) + { + return (or_overflow (buf)); + } + else + { + (void) memcpy (buf->ptr, data, length); + buf->ptr += length; + } + return NO_ERROR; +} + +/* + * or_get_data - read an array of bytes from or buffer for given length + * return: NO_ERROR or error code + * buf(in/out): or buffer + * data(in): pointer to buffer to read data into + * length(in): length of read data + */ +STATIC_INLINE int +or_get_data (OR_BUF * buf, char *data, int length) +{ + if ((buf->ptr + length) > buf->endptr) + { + return or_underflow (buf); + } + else + { + (void) memcpy (data, buf->ptr, length); + buf->ptr += length; + } + return NO_ERROR; +} + +/* + * or_get_varbit_length - get varbit length from or buffer + * return: length of varbit or 0 if error + * buf(in/out): or buffer + * rc(out): NO_ERROR or error code + */ +STATIC_INLINE int +or_get_varbit_length (OR_BUF * buf, int *rc) +{ + int net_bitlen = 0, bitlen = 0; + + /* unpack the size prefix */ + bitlen = or_get_byte (buf, rc); + + if (*rc != NO_ERROR) + { + return bitlen; + } + + if (bitlen == 0xFF) + { + *rc = or_get_data (buf, (char *) &net_bitlen, OR_INT_SIZE); + bitlen = OR_GET_INT (&net_bitlen); + } + return bitlen; +} + +/* + * or_get_varchar_length - get varchar length from or buffer + * return: length of varchar or 0 if error. + * buf(in/out): or buffer + * rc(out): status code + */ +STATIC_INLINE int +or_get_varchar_length (OR_BUF * buf, int *rc) +{ + int charlen, compressed_length = 0, decompressed_length = 0; + + *rc = or_get_varchar_compression_lengths (buf, &compressed_length, &decompressed_length); + + if (compressed_length > 0) + { + charlen = compressed_length; + } + else + { + charlen = decompressed_length; + } + + return charlen; } /* or_get_varchar_compression_lengths() - Function to get the compressed length and the uncompressed length of @@ -1451,49 +2315,496 @@ or_get_string_size_byte (OR_BUF * buf, int *error) * decompressed_size(out) : The uncompressed size of the string. */ STATIC_INLINE int -or_get_varchar_compression_lengths (OR_BUF * buf, int *compressed_size, int *decompressed_size) +or_get_varchar_compression_lengths (OR_BUF * buf, int *compressed_size, int *decompressed_size) +{ + int compressed_length = 0, decompressed_length = 0, rc = NO_ERROR, net_charlen = 0; + int size_prefix = 0; + + /* Check if the string is compressed */ + size_prefix = or_get_string_size_byte (buf, &rc); + if (rc != NO_ERROR) + { + assert (size_prefix == 0); + return rc; + } + + if (size_prefix == OR_MINIMUM_STRING_LENGTH_FOR_COMPRESSION) + { + /* String was compressed */ + /* Get the compressed size */ + rc = or_get_data (buf, (char *) &net_charlen, OR_INT_SIZE); + compressed_length = OR_GET_INT ((char *) &net_charlen); + if (rc != NO_ERROR) + { + return rc; + } + *compressed_size = compressed_length; + + net_charlen = 0; + + /* Get the decompressed size */ + rc = or_get_data (buf, (char *) &net_charlen, OR_INT_SIZE); + decompressed_length = OR_GET_INT ((char *) &net_charlen); + if (rc != NO_ERROR) + { + return rc; + } + *decompressed_size = decompressed_length; + } + else + { + /* String was not compressed so we set compressed_size to 0 to know that no compression happened. */ + *compressed_size = 0; + *decompressed_size = size_prefix; + } + + return rc; +} + +/* + * or_put_string - write string to or buf + * return: NO_ERROR or error code + * buf(in/out): or buffer + * str(in): string to write + * + * Note: + * Does byte padding on strings to bring them up to 4 byte boundary. + * + * There is no or_get_string since this is the same as or_get_data. + * Since the workspace allocator (and most other Unix allocators) will + * keep track of the size of allocated blocks (and they will be + * in word multiples anyway), we can just include the disk padding + * bytes with the string when it is brought in from disk even though + * the total length may be more than that returned by strlen. + */ +STATIC_INLINE int +or_put_string_aligned (OR_BUF * buf, char *str) { - int compressed_length = 0, decompressed_length = 0, rc = NO_ERROR, net_charlen = 0; - int size_prefix = 0; + int len, bits, pad; + int rc = NO_ERROR; - /* Check if the string is compressed */ - size_prefix = or_get_string_size_byte (buf, &rc); + if (str == NULL) + { + return rc; + } + len = strlen (str) + 1; + rc = or_put_data (buf, str, len); + if (rc == NO_ERROR) + { + /* PAD */ + bits = len & 3; + if (bits) + { + pad = 4 - bits; + rc = or_pad (buf, pad); + } + } + return rc; +} + +/* + * this function also adds + * the length of the string to the buffer + */ +STATIC_INLINE int +or_put_string_aligned_with_length (OR_BUF * buf, const char *str) +{ + int len; + int rc = NO_ERROR; + + if (str == NULL) + { + return rc; + } + len = (int) strlen (str) + 1; + + rc = or_put_int (buf, len); if (rc != NO_ERROR) { - assert (size_prefix == 0); return rc; } - if (size_prefix == OR_MINIMUM_STRING_LENGTH_FOR_COMPRESSION) + rc = or_put_data (buf, str, len); + if (rc == NO_ERROR) { - /* String was compressed */ - /* Get the compressed size */ - rc = or_get_data (buf, (char *) &net_charlen, OR_INT_SIZE); - compressed_length = OR_GET_INT ((char *) &net_charlen); - if (rc != NO_ERROR) + or_align (buf, OR_INT_SIZE); + } + return rc; +} + +/* + * or_get_string_size_byte - read string size byte value from or buffer + * return: byte value read + * buf(in/out): or buffer + * error(out): NO_ERROR or error code + * + * NOTE that it is really same as or_get_byte function. It is duplicated to inline the function for performance. + */ +STATIC_INLINE int +or_get_string_size_byte (OR_BUF * buf, int *error) +{ + int size_prefix; + + if ((buf->ptr + OR_BYTE_SIZE) > buf->endptr) + { + *error = or_underflow (buf); + size_prefix = 0; + } + else + { + size_prefix = OR_GET_BYTE (buf->ptr); + buf->ptr += OR_BYTE_SIZE; + *error = NO_ERROR; + } + return size_prefix; +} + +/* + * or_packed_varbit_length - returns packed varbit length of or buffer encoding + * return: varbit encoding length + * bitlen(in): varbit length + */ +STATIC_INLINE int +or_varbit_length (int bitlen) +{ + return or_varbit_length_internal (bitlen, CHAR_ALIGNMENT); +} + +/* + * or_varchar_length - returns length of place holder that can contain + * package varchar length. + * return: length of place holder that can contain packed varchar length + * charlen(in): varchar length + */ +STATIC_INLINE int +or_varchar_length (int charlen) +{ + return or_varchar_length_internal (charlen, CHAR_ALIGNMENT); +} + +STATIC_INLINE int +or_varbit_length_internal (int bitlen, int align) +{ + int len; + + /* calculate size of length prefix */ + if (bitlen < 0xFF) + { + len = 1; + } + else + { + len = 1 + OR_INT_SIZE; + } + + /* add in the string length in bytes */ + len += ((bitlen + 7) / 8); + + if (align == INT_ALIGNMENT) + { + /* round up to a word boundary */ + len = DB_ALIGN (len, INT_ALIGNMENT); + } + return len; +} + +STATIC_INLINE int +or_varchar_length_internal (int charlen, int align) +{ + int len; + + if (charlen < OR_MINIMUM_STRING_LENGTH_FOR_COMPRESSION) + { + len = OR_BYTE_SIZE + charlen; + } + else + { + /* + * Regarding the new encoding for VARCHAR and VARNCHAR, the strings stored in buffers have this representation: + * OR_BYTE_SIZE : First byte in encoding. If it's 0xFF, the string's length is greater than 255. + * : Otherwise, the first byte states the length of the string. + * 1st OR_INT_SIZE : string's compressed length + * 2nd OR_INT_SIZE : string's decompressed length + * charlen : string's disk length + */ + len = OR_BYTE_SIZE + OR_INT_SIZE + OR_INT_SIZE + charlen; + } + + if (align == INT_ALIGNMENT) + { + /* size of NULL terminator */ + len += OR_BYTE_SIZE; + + len = DB_ALIGN (len, INT_ALIGNMENT); + } + + return len; +} + +/* + * or_skip_varbit - skip varbit in or buffer + * return: NO_ERROR or error code + * buf(in/out): or buffer + * align(in): + */ +STATIC_INLINE int +or_skip_varbit (OR_BUF * buf, int align) +{ + int bitlen; + int rc = NO_ERROR; + + bitlen = or_get_varbit_length (buf, &rc); + if (rc == NO_ERROR) + { + return (or_skip_varbit_remainder (buf, bitlen, align)); + } + return rc; +} + +/* + * or_skip_varchar - skip varchar field (length + data) from or buffer + * return: NO_ERROR or error code. + * buf(in/out): or buffer + * align(in): + */ +STATIC_INLINE int +or_skip_varchar (OR_BUF * buf, int align) +{ + int charlen, rc = NO_ERROR; + + charlen = or_get_varchar_length (buf, &rc); + + if (rc == NO_ERROR) + { + return (or_skip_varchar_remainder (buf, charlen, align)); + } + + return rc; +} + +/* + * or_skip_varbit_remainder - skip varbit field of given length in or buffer + * return: NO_ERROR or error code + * buf(in/out): or buffer + * bitlen(in): bitlen to skip + * align(in): + */ +STATIC_INLINE int +or_skip_varbit_remainder (OR_BUF * buf, int bitlen, int align) +{ + int rc = NO_ERROR; + + rc = or_advance (buf, BITS_TO_BYTES (bitlen)); + if (rc == NO_ERROR && align == INT_ALIGNMENT) + { + rc = or_get_align32 (buf); + } + return rc; +} + +/* + * or_skip_varchar_remainder - skip varchar field of given length + * return: NO_ERROR if successful, error code otherwise + * buf(in/out): or buffer + * charlen(in): length of varchar field to skip + * align(in): + */ +STATIC_INLINE int +or_skip_varchar_remainder (OR_BUF * buf, int charlen, int align) +{ + int rc = NO_ERROR; + + if (align == INT_ALIGNMENT) + { + rc = or_advance (buf, charlen + 1); + if (rc == NO_ERROR) { - return rc; + rc = or_get_align32 (buf); } - *compressed_size = compressed_length; + } + else + { + rc = or_advance (buf, charlen); + } - net_charlen = 0; + return rc; +} - /* Get the decompressed size */ - rc = or_get_data (buf, (char *) &net_charlen, OR_INT_SIZE); - decompressed_length = OR_GET_INT ((char *) &net_charlen); - if (rc != NO_ERROR) +/* + * DISK IDENTIFIER TRANSLATORS + * Translators for the disk identifiers OID, HFID, BTID, EHID. + */ + +/* + * or_put_oid - write content of an OID structure from or buffer + * return: NO_ERROR or error code + * buf(in/out): or buffer + * oid(in): pointer to OID + */ +STATIC_INLINE int +or_put_oid (OR_BUF * buf, const OID * oid) +{ + ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); + + if ((buf->ptr + OR_OID_SIZE) > buf->endptr) + { + return (or_overflow (buf)); + } + else + { + if (oid == NULL) { - return rc; + OR_PUT_NULL_OID (buf->ptr); } - *decompressed_size = decompressed_length; + else + { + /* Cannot allow any temp oid's to be written */ + if (OID_ISTEMP (oid)) + { + er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_GENERIC_ERROR, 0); + or_abort (buf); + } + OR_PUT_OID (buf->ptr, oid); + } + buf->ptr += OR_OID_SIZE; + } + return NO_ERROR; +} + +/* + * or_get_oid - read content of an OID structure from or buffer + * return: NO_ERROR or error code + * buf(in/out): or buffer + * oid(out): pointer to OID + */ +STATIC_INLINE int +or_get_oid (OR_BUF * buf, OID * oid) +{ + ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); + + if ((buf->ptr + OR_OID_SIZE) > buf->endptr) + { + return or_underflow (buf); } else { - /* String was not compressed so we set compressed_size to 0 to know that no compression happened. */ - *compressed_size = 0; - *decompressed_size = size_prefix; + OR_GET_OID (buf->ptr, oid); + buf->ptr += OR_OID_SIZE; } + return NO_ERROR; +} - return rc; +/* + * or_put_mvccid () - Put an MVCCID to OR Buffer. + * + * return : Error code. + * buf (in) : OR Buffer + * mvccid (in) : MVCCID + */ +STATIC_INLINE int +or_put_mvccid (OR_BUF * buf, MVCCID mvccid) +{ + ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); + + if ((buf->ptr + OR_MVCCID_SIZE) > buf->endptr) + { + return (or_overflow (buf)); + } + else + { + OR_PUT_MVCCID (buf->ptr, &mvccid); + buf->ptr += OR_MVCCID_SIZE; + } + return NO_ERROR; +} + +/* + * or_get_mvccid () - Get an MVCCID from OR Buffer. + * + * return : MVCCID + * buf (in/out) : OR Buffer. + * error (out) : Error code. + */ +STATIC_INLINE int +or_get_mvccid (OR_BUF * buf, MVCCID * mvccid) +{ + assert (mvccid != NULL); + ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); + + *mvccid = MVCCID_NULL; + + if ((buf->ptr + OR_MVCCID_SIZE) > buf->endptr) + { + return or_underflow (buf); + } + else + { + OR_GET_MVCCID (buf->ptr, mvccid); + buf->ptr += OR_MVCCID_SIZE; + } + return NO_ERROR; +} + +/* VARIABLE OFFSET TABLE ACCESSORS */ + +STATIC_INLINE int +or_put_big_var_offset (OR_BUF * buf, int num) +{ + return or_put_int (buf, num); +} + +STATIC_INLINE int +or_get_big_var_offset (OR_BUF * buf, int *error) +{ + return or_get_int (buf, error); +} + +STATIC_INLINE int +or_put_offset (OR_BUF * buf, int num) +{ + return or_put_big_var_offset (buf, num); +} + +STATIC_INLINE int +or_get_offset (OR_BUF * buf, int *error) +{ + return or_get_big_var_offset (buf, error); +} + +STATIC_INLINE int +or_put_offset_internal (OR_BUF * buf, int num, int offset_size) +{ + if (offset_size == OR_BYTE_SIZE) + { + return or_put_byte (buf, num); + } + else if (offset_size == OR_SHORT_SIZE) + { + return or_put_short (buf, num); + } + else + { + assert (offset_size == OR_INT_SIZE); + return or_put_int (buf, num); + } +} + +STATIC_INLINE int +or_get_offset_internal (OR_BUF * buf, int *error, int offset_size) +{ + if (offset_size == OR_BYTE_SIZE) + { + return or_get_byte (buf, error); + } + else if (offset_size == OR_SHORT_SIZE) + { + return or_get_short (buf, error); + } + else + { + assert (offset_size == OR_INT_SIZE); + return or_get_int (buf, error); + } } + #endif /* _OBJECT_REPRESENTATION_H_ */ diff --git a/src/base/object_representation_constants.h b/src/base/object_representation_constants.h index a5f99762ca2..a8e4917d30f 100644 --- a/src/base/object_representation_constants.h +++ b/src/base/object_representation_constants.h @@ -41,10 +41,17 @@ #define OR_BYTE_SIZE 1 #define OR_SHORT_SIZE 2 #define OR_INT_SIZE 4 +#define OR_INT64_SIZE 8 #define OR_BIGINT_SIZE 8 #define OR_FLOAT_SIZE 4 #define OR_DOUBLE_SIZE 8 +#if __WORDSIZE == 32 +#define OR_PTR_SIZE 4 +#else /* __WORDSIZE == 32 */ +#define OR_PTR_SIZE 8 +#endif /* __WORDSIZE == 64 */ + #define OR_BIGINT_ALIGNED_SIZE (OR_BIGINT_SIZE + MAX_ALIGNMENT) #define OR_DOUBLE_ALIGNED_SIZE (OR_DOUBLE_SIZE + MAX_ALIGNMENT) #define OR_PTR_ALIGNED_SIZE (OR_PTR_SIZE + MAX_ALIGNMENT) diff --git a/src/base/object_representation_sr.c b/src/base/object_representation_sr.c index 7964844ce73..9e3eb63dfb7 100644 --- a/src/base/object_representation_sr.c +++ b/src/base/object_representation_sr.c @@ -3925,7 +3925,7 @@ or_get_attr_string (RECDES * record, int attr_id, int attr_index, char **string, } else { - OR_BUF_INIT (buffer, attr, -1); + or_init (&buffer, attr, -1); rc = or_get_varchar_compression_lengths (&buffer, &compressed_length, &decompressed_length); if (rc != NO_ERROR) @@ -4137,7 +4137,7 @@ or_replace_rep_id (RECDES * record, int repid) char mvcc_flag; bool is_bound_bit = false; - OR_BUF_INIT (orep, record->data, record->area_size); + or_init (&orep, record->data, record->area_size); buf = &orep; mvcc_flag = or_mvcc_get_flag (record); @@ -4277,7 +4277,7 @@ or_mvcc_set_header (RECDES * record, MVCC_REC_HEADER * mvcc_rec_header) HEAP_MOVE_INSIDE_RECORD (record, new_mvcc_size, old_mvcc_size); } - OR_BUF_INIT (orep, record->data, record->area_size); + or_init (&orep, record->data, record->area_size); buf = &orep; error = @@ -4340,7 +4340,7 @@ or_mvcc_add_header (RECDES * record, MVCC_REC_HEADER * mvcc_rec_header, int boun assert (record != NULL && record->data != NULL && record->length == 0); - OR_BUF_INIT (orep, record->data, record->area_size); + or_init (&orep, record->data, record->area_size); buf = &orep; error = @@ -4454,7 +4454,7 @@ or_mvcc_set_flag (RECDES * record, char flags) /* Set new mvcc flags */ repid_and_flag += ((flags & OR_MVCC_FLAG_MASK) << OR_MVCC_FLAG_SHIFT_BITS); - OR_BUF_INIT (orep, record->data, record->area_size); + or_init (&orep, record->data, record->area_size); buf = &orep; buf->ptr = buf->buffer + OR_REP_OFFSET; or_put_int (buf, repid_and_flag); diff --git a/src/base/packer.cpp b/src/base/packer.cpp index a2529cdc9cd..1546a76ad81 100644 --- a/src/base/packer.cpp +++ b/src/base/packer.cpp @@ -948,7 +948,7 @@ namespace cubpacking packer::delegate_to_or_buf (const size_t size, or_buf &buf) { check_range (m_ptr, m_end_ptr, size); - OR_BUF_INIT (buf, m_ptr, size); + or_init (&buf, m_ptr, size); m_ptr += size; } @@ -993,7 +993,7 @@ namespace cubpacking { check_range (m_ptr, m_end_ptr, size); // promise you won't write on it! - OR_BUF_INIT (buf, const_cast (m_ptr), size); + or_init (&buf, const_cast (m_ptr), size); m_ptr += size; } diff --git a/src/method/method_query_cursor.cpp b/src/method/method_query_cursor.cpp index 274237f2c5e..fda67ffcf10 100644 --- a/src/method/method_query_cursor.cpp +++ b/src/method/method_query_cursor.cpp @@ -93,7 +93,7 @@ namespace cubmethod for (int i = 0; i < m_list_id->type_list.type_cnt; i++) { QFILE_TUPLE_VALUE_FLAG flag = (QFILE_TUPLE_VALUE_FLAG) qfile_locate_tuple_value_r (tuple_record.tpl, i, &ptr, &length); - OR_BUF_INIT (buf, ptr, length); + or_init (&buf, ptr, length); TP_DOMAIN *domain = m_list_id->type_list.domp[i]; if (domain == NULL || domain->type == NULL) @@ -160,7 +160,7 @@ namespace cubmethod return S_ERROR; } - OR_BUF_INIT (buf, ptr, length); + or_init (&buf, ptr, length); if (pr_type->data_readval (&buf, value, domain, -1, true, NULL, 0) != NO_ERROR) { diff --git a/src/method/method_scan.cpp b/src/method/method_scan.cpp index 94c3db949da..2ca92a4276c 100644 --- a/src/method/method_scan.cpp +++ b/src/method/method_scan.cpp @@ -243,7 +243,7 @@ namespace cubscan for (int i = 0; i < m_list_id->type_list.type_cnt; i++) { QFILE_TUPLE_VALUE_FLAG flag = (QFILE_TUPLE_VALUE_FLAG) qfile_locate_tuple_value (tuple_record.tpl, i, &ptr, &length); - OR_BUF_INIT (buf, ptr, length); + or_init (&buf, ptr, length); DB_VALUE *value = &m_arg_vector [i]; TP_DOMAIN *domain = m_arg_dom_vector [i]; diff --git a/src/object/object_primitive.c b/src/object/object_primitive.c index 90accb6fe19..93a51bdf8b3 100644 --- a/src/object/object_primitive.c +++ b/src/object/object_primitive.c @@ -7719,8 +7719,8 @@ pr_midxkey_compare_element (char *mem1, char *mem2, TP_DOMAIN * dom1, TP_DOMAIN return DB_UNK; /* impossible case */ } - OR_BUF_INIT (buf_val1, mem1, -1); - OR_BUF_INIT (buf_val2, mem2, -1); + or_init (&buf_val1, mem1, -1); + or_init (&buf_val2, mem2, -1); db_make_null (&val1); db_make_null (&val2); diff --git a/src/object/object_representation.c b/src/object/object_representation.c index 80e825cf7ba..b05853875d4 100644 --- a/src/object/object_representation.c +++ b/src/object/object_representation.c @@ -50,9 +50,6 @@ #define strlen(s1) ((int) strlen(s1)) #endif /* defined (SUPPRESS_STRLEN_WARNING) */ -/* simple macro to calculate minimum bytes to contain given bits */ -#define BITS_TO_BYTES(bit_cnt) (((bit_cnt) + 7) / 8) - /* * Lookup to compute the MVCC header size faster: * INDEX MVCC FLAGS SIZE @@ -84,10 +81,8 @@ static char *or_unpack_method_sig (char *ptr, void **method_sig_ptr, int n); #if defined(ENABLE_UNUSED_FUNCTION) static char *unpack_str_array (char *buffer, char ***string_array, int count); #endif -static int or_put_varchar_internal (OR_BUF * buf, char *string, int charlen, int align); -static int or_varbit_length_internal (int bitlen, int align); -static int or_varchar_length_internal (int charlen, int align); static int or_put_varbit_internal (OR_BUF * buf, const char *string, int bitlen, int align); +static int or_put_varchar_internal (OR_BUF * buf, char *string, int charlen, int align); static int or_packed_json_schema_length (const char *json_schema); static int or_packed_json_validator_length (JSON_VALIDATOR * json_validator); static char *or_unpack_var_table_internal (char *ptr, int nvars, OR_VARINFO * vars, int offset_size); @@ -163,7 +158,6 @@ classobj_get_prop (DB_SEQ * properties, const char *name, DB_VALUE * pvalue) return found; } - /* * classobj_decompose_property_oid - parse oid string from buffer * return: zero if decompose error, 3 if successful @@ -371,7 +365,7 @@ or_set_rep_id (RECDES * record, int repid) return ER_FAILED; } - OR_BUF_INIT (orep, record->data, record->area_size); + or_init (&orep, record->data, record->area_size); buf = &orep; new_bits = OR_GET_MVCC_REPID_AND_FLAG (record->data); @@ -426,7 +420,7 @@ or_replace_chn (RECDES * record, int chn) int offset; int error; - OR_BUF_INIT (orep, record->data, record->area_size); + or_init (&orep, record->data, record->area_size); buf = &orep; offset = OR_CHN_OFFSET; @@ -549,10 +543,6 @@ or_put_bound_bit (char *bound_bits, int element, int bound) #endif /* ENABLE_UNUSED_FUNCTION */ #endif /* !SERVER_MODE */ -/* - * OR_BUF PACK/UNPACK FUNCTIONS - */ - /* * or_overflow - called by the or_put_ functions when there is not enough * room in the buffer to hold a particular value. @@ -629,176 +619,204 @@ or_abort (OR_BUF * buf) } /* - * or_init - initialize the field of an OR_BUF - * return: void - * buf(in/out): or buffer to initialize - * data(in): buffer data - * length(in): buffer data length + * or_put_monetary - write a DB_MONETARY value to or buffer + * return: NO_ERROR or error code + * buf(in/out): or buffer + * monetary(in): pointer to DB_MONETARY value */ -void -or_init (OR_BUF * buf, char *data, int length) +int +or_put_monetary (OR_BUF * buf, DB_MONETARY * monetary) { - buf->buffer = data; - buf->ptr = data; + int error; + + ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); + + /* check for valid currency type don't put default case in the switch!!! */ + error = ER_INVALID_CURRENCY_TYPE; + switch (monetary->type) + { + case DB_CURRENCY_DOLLAR: + case DB_CURRENCY_YEN: + case DB_CURRENCY_WON: + case DB_CURRENCY_TL: + case DB_CURRENCY_BRITISH_POUND: + case DB_CURRENCY_CAMBODIAN_RIEL: + case DB_CURRENCY_CHINESE_RENMINBI: + case DB_CURRENCY_INDIAN_RUPEE: + case DB_CURRENCY_RUSSIAN_RUBLE: + case DB_CURRENCY_AUSTRALIAN_DOLLAR: + case DB_CURRENCY_CANADIAN_DOLLAR: + case DB_CURRENCY_BRASILIAN_REAL: + case DB_CURRENCY_ROMANIAN_LEU: + case DB_CURRENCY_EURO: + case DB_CURRENCY_SWISS_FRANC: + case DB_CURRENCY_DANISH_KRONE: + case DB_CURRENCY_NORWEGIAN_KRONE: + case DB_CURRENCY_BULGARIAN_LEV: + case DB_CURRENCY_VIETNAMESE_DONG: + case DB_CURRENCY_CZECH_KORUNA: + case DB_CURRENCY_POLISH_ZLOTY: + case DB_CURRENCY_SWEDISH_KRONA: + case DB_CURRENCY_CROATIAN_KUNA: + case DB_CURRENCY_SERBIAN_DINAR: + error = NO_ERROR; /* it's a type we expect */ + break; + default: + break; + } + + if (error != NO_ERROR) + { + er_set (ER_WARNING_SEVERITY, ARG_FILE_LINE, error, 1, monetary->type); + return error; + } - if (length == 0 || length == -1 || length == DB_INT32_MAX) + if ((buf->ptr + OR_MONETARY_SIZE) > buf->endptr) { - buf->endptr = (char *) OR_INFINITE_POINTER; + return (or_overflow (buf)); } else { - buf->endptr = data + length; + OR_PUT_MONETARY (buf->ptr, monetary); + buf->ptr += OR_MONETARY_SIZE; } - buf->error_abort = 0; - buf->fixups = NULL; + return error; } /* - * or_put_align32 - pad zero bytes round up to 4 byte bound + * or_get_monetary - read a DB_MONETARY from or buffer * return: NO_ERROR or error code * buf(in/out): or buffer + * monetary(out): pointer to DB_MONETARY value */ int -or_put_align32 (OR_BUF * buf) +or_get_monetary (OR_BUF * buf, DB_MONETARY * monetary) { - unsigned int bits; - int rc = NO_ERROR; + ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); - bits = (UINTPTR) buf->ptr & 3; - if (bits) + if ((buf->ptr + OR_MONETARY_SIZE) > buf->endptr) + { + return or_underflow (buf); + } + else { - rc = or_pad (buf, 4 - bits); + OR_GET_MONETARY (buf->ptr, monetary); + buf->ptr += OR_MONETARY_SIZE; } - - return rc; + return NO_ERROR; } +#if defined(ENABLE_UNUSED_FUNCTION) /* - * or_get_align32 - adnvance or buf pointer to next 4 byte alignment position + * or_put_binary - Writes a binary array into the translation buffer. * return: NO_ERROR or error code * buf(in/out): or buffer + * binary(in): binary data + * + * Note: + * The length of the array is part of the binary data descriptor. + * This is similar to or_put_string in that it also must pad out the + * binary data to be on a word boundary. */ int -or_get_align32 (OR_BUF * buf) +or_put_binary (OR_BUF * buf, DB_BINARY * binary) { - unsigned int bits; + int header, len, bits, pad; int rc = NO_ERROR; - bits = (UINTPTR) (buf->ptr) & 3; - if (bits) + if (binary != NULL && binary->length < OR_BINARY_MAX_LENGTH) { - rc = or_advance (buf, 4 - bits); + len = binary->length + OR_INT_SIZE; + pad = 0; + bits = len & 3; + if (bits) + { + pad = 4 - bits; + } + header = binary->length | (pad << OR_BINARY_PAD_SHIFT); + rc = or_put_int (buf, header); + if (rc == NO_ERROR) + { + rc = or_put_data (buf, (char *) binary->data, binary->length); + if (rc == NO_ERROR) + { + rc = or_pad (buf, pad); + } + } } - return rc; } +#endif /* ENABLE_UNUSED_FUNCTION */ /* - * or_get_align64 - adnvance or buf pointer to next 8 byte alignment position + * or_put_varbit - put varbit into or buffer * return: NO_ERROR or error code * buf(in/out): or buffer + * string(in): string contains varbit value + * bitlen(in): length of varbit */ -int -or_get_align64 (OR_BUF * buf) +extern int +or_put_varbit (OR_BUF * buf, const char *string, int bitlen) { - unsigned int bits; - int rc = NO_ERROR; - - bits = (UINTPTR) (buf->ptr) & 7; - if (bits) - { - rc = or_advance (buf, 8 - bits); - } - - return rc; + return or_put_varbit_internal (buf, string, bitlen, CHAR_ALIGNMENT); } +#if defined(ENABLE_UNUSED_FUNCTION) /* - * or_get_align - adnvance or buf pointer to next alignment position + * or_get_varbit - get varbit from or buffer * return: NO_ERROR or error code * buf(in/out): or buffer - * align(in): + * length_ptr(out): length of varbit read */ -int -or_get_align (OR_BUF * buf, int align) +char * +or_get_varbit (OR_BUF * buf, int *length_ptr) { - char *ptr; + int bitlen, charlen; + char *new_ = NULL; + int rc = NO_ERROR; - ptr = PTR_ALIGN (buf->ptr, align); - if (ptr > buf->endptr) - { - return (or_overflow (buf)); - } - else + bitlen = or_get_varbit_length (buf, &rc); + + if (rc != NO_ERROR) { - buf->ptr = ptr; - return NO_ERROR; + return NULL; } -} - -/* - * or_packed_varchar_length - returns length of place holder that can contain - * package varchar length. Also ajust length up to 4 byte boundary. - * return: length of placeholder that can contain packed varchar length - * charlen(in): varchar length - */ -int -or_packed_varchar_length (int charlen) -{ - return or_varchar_length_internal (charlen, INT_ALIGNMENT); -} - -/* - * or_varchar_length - returns length of place holder that can contain - * package varchar length. - * return: length of place holder that can contain packed varchar length - * charlen(in): varchar length - */ -int -or_varchar_length (int charlen) -{ - return or_varchar_length_internal (charlen, CHAR_ALIGNMENT); -} - -int -or_packed_recdesc_length (int length) -{ - return OR_INT_SIZE * 2 + or_packed_stream_length (length); -} -static int -or_varchar_length_internal (int charlen, int align) -{ - int len; + /* Allocate storage for the string including the kludge NULL terminator */ + charlen = BITS_TO_BYTES (bitlen); + new_ = db_private_alloc (NULL, charlen + 1); - if (charlen < OR_MINIMUM_STRING_LENGTH_FOR_COMPRESSION) - { - len = OR_BYTE_SIZE + charlen; - } - else + if (new_ == NULL) { - /* - * Regarding the new encoding for VARCHAR and VARNCHAR, the strings stored in buffers have this representation: - * OR_BYTE_SIZE : First byte in encoding. If it's 0xFF, the string's length is greater than 255. - * : Otherwise, the first byte states the length of the string. - * 1st OR_INT_SIZE : string's compressed length - * 2nd OR_INT_SIZE : string's decompressed length - * charlen : string's disk length - */ - len = OR_BYTE_SIZE + OR_INT_SIZE + OR_INT_SIZE + charlen; + or_abort (buf); + return NULL; } + rc = or_get_data (buf, new_, charlen); - if (align == INT_ALIGNMENT) + if (rc == NO_ERROR) { - /* size of NULL terminator */ - len += OR_BYTE_SIZE; + /* return the length */ + if (length_ptr != NULL) + { + *length_ptr = bitlen; + } - len = DB_ALIGN (len, INT_ALIGNMENT); + /* round up to a word boundary */ + rc = or_get_align32 (buf); + } + if (rc != NO_ERROR) + { + if (new_) + { + db_private_free_and_init (NULL, new_); + } + return NULL; } - return len; + return new_; } +#endif /* ENABLE_UNUSED_FUNCTION */ /* * or_put_varchar - put varchar to or buffer @@ -813,53 +831,166 @@ or_put_varchar (OR_BUF * buf, char *string, int charlen) return or_put_varchar_internal (buf, string, charlen, CHAR_ALIGNMENT); } +#if defined(ENABLE_UNUSED_FUNCTION) /* - * or_packed_put_varchar - put varchar to or buffer - * return: NO_ERROR or error code + * or_get_varchar - get varchar from or buffer + * return: varchar pointer read from the or buffer. or NULL for error * buf(in/out): or buffer - * string(in): string to put into the or buffer - * charlen(in): string length + * length_ptr(out): length of returned string */ -int -or_packed_put_varchar (OR_BUF * buf, char *string, int charlen) -{ - return or_put_varchar_internal (buf, string, charlen, INT_ALIGNMENT); -} - -static int -or_put_varchar_internal (OR_BUF * buf, char *string, int charlen, int align) +char * +or_get_varchar (OR_BUF * buf, int *length_ptr) { - int net_charlen = 0, compress_buffer_size; - char *compressed_string = NULL; int rc = NO_ERROR; - bool compressable = false; - int compressed_length = 0; - int error_abort = 0; - - error_abort = buf->error_abort; + int charlen; + char *new_; - buf->error_abort = 0; + charlen = or_get_varchar_length (buf, &rc); - /* store the size prefix */ - if (charlen < OR_MINIMUM_STRING_LENGTH_FOR_COMPRESSION) - { - rc = or_put_byte (buf, charlen); - } - else + if (rc != NO_ERROR) { - rc = or_put_byte (buf, OR_MINIMUM_STRING_LENGTH_FOR_COMPRESSION); - compressable = true; + return NULL; } - if (rc != NO_ERROR) + /* Allocate storage for the string including the kludge NULL terminator */ + new_ = db_private_alloc (NULL, charlen + 1); + + if (new_ == NULL) { - goto cleanup; + or_abort (buf); + return NULL; } + rc = or_get_data (buf, new_, charlen + 1); - if (compressable == true) + if (rc == NO_ERROR) { - if (!pr_Enable_string_compression || charlen > LZ4_MAX_INPUT_SIZE) /* compression is not set */ - { + + /* return the length */ + if (length_ptr != NULL) + { + *length_ptr = charlen; + } + + /* round up to a word boundary */ + rc = or_get_align32 (buf); + } + if (rc != NO_ERROR) + { + db_private_free_and_init (NULL, new_); + return NULL; + } + else + { + return new_; + } +} +#endif /* ENABLE_UNUSED_FUNCTION */ + +static int +or_put_varbit_internal (OR_BUF * buf, const char *string, int bitlen, int align) +{ + int net_bitlen; + int bytelen; + char *start; + int status; + int valid_buf; + jmp_buf save_buf; + + if (buf->error_abort) + { + memcpy (&save_buf, &buf->env, sizeof (save_buf)); + } + + valid_buf = buf->error_abort; + buf->error_abort = 1; + status = _setjmp (buf->env); + + if (status == 0) + { + start = buf->ptr; + bytelen = BITS_TO_BYTES (bitlen); + + /* store the size prefix */ + if (bitlen < 0xFF) + { + or_put_byte (buf, bitlen); + } + else + { + or_put_byte (buf, 0xFF); + OR_PUT_INT (&net_bitlen, bitlen); + or_put_data (buf, (char *) &net_bitlen, OR_INT_SIZE); + } + + /* store the string bytes */ + or_put_data (buf, string, bytelen); + + if (align == INT_ALIGNMENT) + { + /* round up to a word boundary */ + or_put_align32 (buf); + } + } + else + { + if (valid_buf) + { + memcpy (&buf->env, &save_buf, sizeof (save_buf)); + _longjmp (buf->env, status); + } + } + + if (valid_buf) + { + memcpy (&buf->env, &save_buf, sizeof (save_buf)); + } + else + { + buf->error_abort = 0; + } + + if (status == 0) + { + return NO_ERROR; + } + + return status; +} + +static int +or_put_varchar_internal (OR_BUF * buf, char *string, int charlen, int align) +{ + int net_charlen = 0, compress_buffer_size; + char *compressed_string = NULL; + int rc = NO_ERROR; + bool compressable = false; + int compressed_length = 0; + int error_abort = 0; + + error_abort = buf->error_abort; + + buf->error_abort = 0; + + /* store the size prefix */ + if (charlen < OR_MINIMUM_STRING_LENGTH_FOR_COMPRESSION) + { + rc = or_put_byte (buf, charlen); + } + else + { + rc = or_put_byte (buf, OR_MINIMUM_STRING_LENGTH_FOR_COMPRESSION); + compressable = true; + } + + if (rc != NO_ERROR) + { + goto cleanup; + } + + if (compressable == true) + { + if (!pr_Enable_string_compression || charlen > LZ4_MAX_INPUT_SIZE) /* compression is not set */ + { compressed_length = 0; goto after_compression; } @@ -976,1265 +1107,33 @@ or_put_varchar_internal (OR_BUF * buf, char *string, int charlen, int align) #if defined(ENABLE_UNUSED_FUNCTION) /* - * or_get_varchar - get varchar from or buffer - * return: varchar pointer read from the or buffer. or NULL for error - * buf(in/out): or buffer - * length_ptr(out): length of returned string - */ -char * -or_get_varchar (OR_BUF * buf, int *length_ptr) -{ - int rc = NO_ERROR; - int charlen; - char *new_; - - charlen = or_get_varchar_length (buf, &rc); - - if (rc != NO_ERROR) - { - return NULL; - } - - /* Allocate storage for the string including the kludge NULL terminator */ - new_ = db_private_alloc (NULL, charlen + 1); - - if (new_ == NULL) - { - or_abort (buf); - return NULL; - } - rc = or_get_data (buf, new_, charlen + 1); - - if (rc == NO_ERROR) - { - - /* return the length */ - if (length_ptr != NULL) - { - *length_ptr = charlen; - } - - /* round up to a word boundary */ - rc = or_get_align32 (buf); - } - if (rc != NO_ERROR) - { - db_private_free_and_init (NULL, new_); - return NULL; - } - else - { - return new_; - } -} -#endif /* ENABLE_UNUSED_FUNCTION */ - -/* - * or_get_varchar_length - get varchar length from or buffer - * return: length of varchar or 0 if error. - * buf(in/out): or buffer - * rc(out): status code - */ -int -or_get_varchar_length (OR_BUF * buf, int *rc) -{ - int charlen, compressed_length = 0, decompressed_length = 0; - - *rc = or_get_varchar_compression_lengths (buf, &compressed_length, &decompressed_length); - - if (compressed_length > 0) - { - charlen = compressed_length; - } - else - { - charlen = decompressed_length; - } - - return charlen; -} - -/* - * or_skip_varchar_remainder - skip varchar field of given length - * return: NO_ERROR if successful, error code otherwise - * buf(in/out): or buffer - * charlen(in): length of varchar field to skip - * align(in): - */ -int -or_skip_varchar_remainder (OR_BUF * buf, int charlen, int align) -{ - int rc = NO_ERROR; - - if (align == INT_ALIGNMENT) - { - rc = or_advance (buf, charlen + 1); - if (rc == NO_ERROR) - { - rc = or_get_align32 (buf); - } - } - else - { - rc = or_advance (buf, charlen); - } - - return rc; -} - -/* - * or_skip_varchar - skip varchar field (length + data) from or buffer - * return: NO_ERROR or error code. - * buf(in/out): or buffer - * align(in): - */ -int -or_skip_varchar (OR_BUF * buf, int align) -{ - int charlen, rc = NO_ERROR; - - charlen = or_get_varchar_length (buf, &rc); - - if (rc == NO_ERROR) - { - return (or_skip_varchar_remainder (buf, charlen, align)); - } - - return rc; -} - -/* - * or_packed_varbit_length - returns packed varbit length of or buffer encoding - * return: packed varbit encoding length - * bitlen(in): varbit length - */ -int -or_packed_varbit_length (int bitlen) -{ - return or_varbit_length_internal (bitlen, INT_ALIGNMENT); -} - -/* - * or_packed_varbit_length - returns packed varbit length of or buffer encoding - * return: varbit encoding length - * bitlen(in): varbit length - */ -int -or_varbit_length (int bitlen) -{ - return or_varbit_length_internal (bitlen, CHAR_ALIGNMENT); -} - -static int -or_varbit_length_internal (int bitlen, int align) -{ - int len; - - /* calculate size of length prefix */ - if (bitlen < 0xFF) - { - len = 1; - } - else - { - len = 1 + OR_INT_SIZE; - } - - /* add in the string length in bytes */ - len += ((bitlen + 7) / 8); - - if (align == INT_ALIGNMENT) - { - /* round up to a word boundary */ - len = DB_ALIGN (len, INT_ALIGNMENT); - } - return len; -} - -/* - * or_put_varbit - put varbit into or buffer - * return: NO_ERROR or error code - * buf(in/out): or buffer - * string(in): string contains varbit value - * bitlen(in): length of varbit - */ -int -or_packed_put_varbit (OR_BUF * buf, const char *string, int bitlen) -{ - return or_put_varbit_internal (buf, string, bitlen, INT_ALIGNMENT); -} - -/* - * or_put_varbit - put varbit into or buffer - * return: NO_ERROR or error code - * buf(in/out): or buffer - * string(in): string contains varbit value - * bitlen(in): length of varbit - */ -int -or_put_varbit (OR_BUF * buf, const char *string, int bitlen) -{ - return or_put_varbit_internal (buf, string, bitlen, CHAR_ALIGNMENT); -} - -static int -or_put_varbit_internal (OR_BUF * buf, const char *string, int bitlen, int align) -{ - int net_bitlen; - int bytelen; - char *start; - int status; - int valid_buf; - jmp_buf save_buf; - - if (buf->error_abort) - { - memcpy (&save_buf, &buf->env, sizeof (save_buf)); - } - - valid_buf = buf->error_abort; - buf->error_abort = 1; - status = _setjmp (buf->env); - - if (status == 0) - { - start = buf->ptr; - bytelen = BITS_TO_BYTES (bitlen); - - /* store the size prefix */ - if (bitlen < 0xFF) - { - or_put_byte (buf, bitlen); - } - else - { - or_put_byte (buf, 0xFF); - OR_PUT_INT (&net_bitlen, bitlen); - or_put_data (buf, (char *) &net_bitlen, OR_INT_SIZE); - } - - /* store the string bytes */ - or_put_data (buf, string, bytelen); - - if (align == INT_ALIGNMENT) - { - /* round up to a word boundary */ - or_put_align32 (buf); - } - } - else - { - if (valid_buf) - { - memcpy (&buf->env, &save_buf, sizeof (save_buf)); - _longjmp (buf->env, status); - } - } - - if (valid_buf) - { - memcpy (&buf->env, &save_buf, sizeof (save_buf)); - } - else - { - buf->error_abort = 0; - } - - if (status == 0) - { - return NO_ERROR; - } - - return status; - -} - -int -or_put_offset (OR_BUF * buf, int num) -{ - return or_put_offset_internal (buf, num, BIG_VAR_OFFSET_SIZE); -} - -int -or_put_offset_internal (OR_BUF * buf, int num, int offset_size) -{ - if (offset_size == OR_BYTE_SIZE) - { - return or_put_byte (buf, num); - } - else if (offset_size == OR_SHORT_SIZE) - { - return or_put_short (buf, num); - } - else - { - assert (offset_size == BIG_VAR_OFFSET_SIZE); - - return or_put_int (buf, num); - } -} - -int -or_get_offset (OR_BUF * buf, int *error) -{ - return or_get_offset_internal (buf, error, BIG_VAR_OFFSET_SIZE); -} - -int -or_get_offset_internal (OR_BUF * buf, int *error, int offset_size) -{ - if (offset_size == OR_BYTE_SIZE) - { - return or_get_byte (buf, error); - } - else if (offset_size == OR_SHORT_SIZE) - { - return or_get_short (buf, error); - } - else - { - assert (offset_size == BIG_VAR_OFFSET_SIZE); - return or_get_int (buf, error); - } -} - -#if defined(ENABLE_UNUSED_FUNCTION) -/* - * or_get_varbit - get varbit from or buffer - * return: NO_ERROR or error code - * buf(in/out): or buffer - * length_ptr(out): length of varbit read - */ -char * -or_get_varbit (OR_BUF * buf, int *length_ptr) -{ - int bitlen, charlen; - char *new_ = NULL; - int rc = NO_ERROR; - - bitlen = or_get_varbit_length (buf, &rc); - - if (rc != NO_ERROR) - { - return NULL; - } - - /* Allocate storage for the string including the kludge NULL terminator */ - charlen = BITS_TO_BYTES (bitlen); - new_ = db_private_alloc (NULL, charlen + 1); - - if (new_ == NULL) - { - or_abort (buf); - return NULL; - } - rc = or_get_data (buf, new_, charlen); - - if (rc == NO_ERROR) - { - /* return the length */ - if (length_ptr != NULL) - { - *length_ptr = bitlen; - } - - /* round up to a word boundary */ - rc = or_get_align32 (buf); - } - if (rc != NO_ERROR) - { - if (new_) - { - db_private_free_and_init (NULL, new_); - } - return NULL; - } - - return new_; -} -#endif /* ENABLE_UNUSED_FUNCTION */ - -/* - * or_get_varbit_length - get varbit length from or buffer - * return: length of varbit or 0 if error - * buf(in/out): or buffer - * rc(out): NO_ERROR or error code - */ -int -or_get_varbit_length (OR_BUF * buf, int *rc) -{ - int net_bitlen = 0, bitlen = 0; - - /* unpack the size prefix */ - bitlen = or_get_byte (buf, rc); - - if (*rc != NO_ERROR) - { - return bitlen; - } - - if (bitlen == 0xFF) - { - *rc = or_get_data (buf, (char *) &net_bitlen, OR_INT_SIZE); - bitlen = OR_GET_INT (&net_bitlen); - } - return bitlen; -} - -/* - * or_skip_varbit_remainder - skip varbit field of given length in or buffer - * return: NO_ERROR or error code - * buf(in/out): or buffer - * bitlen(in): bitlen to skip - * align(in): - */ -int -or_skip_varbit_remainder (OR_BUF * buf, int bitlen, int align) -{ - int rc = NO_ERROR; - - rc = or_advance (buf, BITS_TO_BYTES (bitlen)); - if (rc == NO_ERROR && align == INT_ALIGNMENT) - { - rc = or_get_align32 (buf); - } - return rc; -} - -/* - * or_skip_varbit - skip varbit in or buffer - * return: NO_ERROR or error code - * buf(in/out): or buffer - * align(in): - */ -int -or_skip_varbit (OR_BUF * buf, int align) -{ - int bitlen; - int rc = NO_ERROR; - - bitlen = or_get_varbit_length (buf, &rc); - if (rc == NO_ERROR) - { - return (or_skip_varbit_remainder (buf, bitlen, align)); - } - return rc; -} - -/* - * NUMERIC DATA TRANSFORMS - * This set of functions handles the transformation of the - * numeric types byte, short, integer, float, and double. - * - */ - - -/* - * or_put_byte - put a byte to or buffer - * return: NO_ERROR or error code - * buf(out/out): or buffer - * num(in): byte value - */ -int -or_put_byte (OR_BUF * buf, int num) -{ - if ((buf->ptr + OR_BYTE_SIZE) > buf->endptr) - { - return (or_overflow (buf)); - } - else - { - OR_PUT_BYTE (buf->ptr, num); - buf->ptr += OR_BYTE_SIZE; - } - return NO_ERROR; -} - -/* - * or_get_byte - read a byte value from or buffer - * return: byte value read - * buf(in/out): or buffer - * error(out): NO_ERROR or error code - */ -int -or_get_byte (OR_BUF * buf, int *error) -{ - int value = 0; - - if ((buf->ptr + OR_BYTE_SIZE) > buf->endptr) - { - *error = or_underflow (buf); - return 0; - } - else - { - value = OR_GET_BYTE (buf->ptr); - buf->ptr += OR_BYTE_SIZE; - *error = NO_ERROR; - } - return value; -} - -/* - * or_put_short - put a short value to or buffer - * return: NO_ERROR or error code - * buf(in/out): or buffer - * num(in): short value to put - */ -int -or_put_short (OR_BUF * buf, int num) -{ - ASSERT_ALIGN (buf->ptr, SHORT_ALIGNMENT); - - if ((buf->ptr + OR_SHORT_SIZE) > buf->endptr) - { - return (or_overflow (buf)); - } - else - { - OR_PUT_SHORT (buf->ptr, num); - buf->ptr += OR_SHORT_SIZE; - } - return NO_ERROR; -} - -/* - * or_get_short - read a short value from or buffer - * return: short value read - * buf(in/out): or buffer - * error(out): NO_ERROR or error code - */ -int -or_get_short (OR_BUF * buf, int *error) -{ - int value = 0; - - ASSERT_ALIGN (buf->ptr, SHORT_ALIGNMENT); - - if ((buf->ptr + OR_SHORT_SIZE) > buf->endptr) - { - *error = or_underflow (buf); - return 0; - } - else - { - value = OR_GET_SHORT (buf->ptr); - buf->ptr += OR_SHORT_SIZE; - } - *error = NO_ERROR; - return value; -} - -/* - * or_put_int - put int value to or buffer - * return: NO_ERROR or error code - * buf(in/out): or buffer - * num(in): int value to put - */ -int -or_put_int (OR_BUF * buf, int num) -{ - ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); - - if ((buf->ptr + OR_INT_SIZE) > buf->endptr) - { - return (or_overflow (buf)); - } - else - { - OR_PUT_INT (buf->ptr, num); - buf->ptr += OR_INT_SIZE; - } - return NO_ERROR; -} - -/* - * or_get_int - get int value from or buffer - * return: int value read - * buf(in/out): or buffer - * error(out): NO_ERROR or error code - */ -int -or_get_int (OR_BUF * buf, int *error) -{ - int value = 0; - - ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); - - if ((buf->ptr + OR_INT_SIZE) > buf->endptr) - { - *error = or_underflow (buf); - } - else - { - value = OR_GET_INT (buf->ptr); - buf->ptr += OR_INT_SIZE; - *error = NO_ERROR; - } - return value; -} - -/* - * or_put_bigint - put bigint value to or buffer - * return: NO_ERROR or error code - * buf(in/out): or buffer - * num(in): bigint value to put - */ -int -or_put_bigint (OR_BUF * buf, DB_BIGINT num) -{ - ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); - - if ((buf->ptr + OR_BIGINT_SIZE) > buf->endptr) - { - return (or_overflow (buf)); - } - else - { - OR_PUT_BIGINT (buf->ptr, &num); - buf->ptr += OR_BIGINT_SIZE; - } - return NO_ERROR; -} - -/* - * or_get_bigint - get bigint value from or buffer - * return: bigint value read - * buf(in/out): or buffer - * error(out): NO_ERROR or error code - */ -DB_BIGINT -or_get_bigint (OR_BUF * buf, int *error) -{ - DB_BIGINT value = 0; - - ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); - - if ((buf->ptr + OR_BIGINT_SIZE) > buf->endptr) - { - *error = or_underflow (buf); - } - else - { - OR_GET_BIGINT (buf->ptr, &value); - buf->ptr += OR_BIGINT_SIZE; - *error = NO_ERROR; - } - return value; -} - -/* - * or_put_float - put a float value to or buffer - * return: NO_ERROR or error code - * buf(in/out): or buffer - * fnum(in): float value to put - */ -int -or_put_float (OR_BUF * buf, float fnum) -{ - ASSERT_ALIGN (buf->ptr, FLOAT_ALIGNMENT); - - if ((buf->ptr + OR_FLOAT_SIZE) > buf->endptr) - { - return (or_overflow (buf)); - } - else - { - OR_PUT_FLOAT (buf->ptr, fnum); - buf->ptr += OR_FLOAT_SIZE; - } - return NO_ERROR; -} - -/* - * or_get_float - read a float value from or buffer - * return: float value read - * buf(in/out): or buffer - * error(out): NO_ERROR or error code - */ -float -or_get_float (OR_BUF * buf, int *error) -{ - float value = 0.0; - - ASSERT_ALIGN (buf->ptr, FLOAT_ALIGNMENT); - - if ((buf->ptr + OR_FLOAT_SIZE) > buf->endptr) - { - *error = or_underflow (buf); - } - else - { - OR_GET_FLOAT (buf->ptr, &value); - buf->ptr += OR_FLOAT_SIZE; - *error = NO_ERROR; - } - return value; -} - -/* - * or_put_double - put a double value to or buffer - * return: NO_ERROR or error code - * buf(in/out): or buffer - * dnum(in): double value to put - */ -int -or_put_double (OR_BUF * buf, double dnum) -{ - ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); - - if ((buf->ptr + OR_DOUBLE_SIZE) > buf->endptr) - { - return (or_overflow (buf)); - } - else - { - OR_PUT_DOUBLE (buf->ptr, dnum); - buf->ptr += OR_DOUBLE_SIZE; - } - return NO_ERROR; -} - -/* - * or_get_double - read a double value from or buffer - * return: double value read - * buf(in/out): or buffer - * error(out): NO_ERROR or error code - */ -double -or_get_double (OR_BUF * buf, int *error) -{ - double value = 0.0; - - ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); - - if ((buf->ptr + OR_DOUBLE_SIZE) > buf->endptr) - { - *error = or_underflow (buf); - } - else - { - OR_GET_DOUBLE (buf->ptr, &value); - buf->ptr += OR_DOUBLE_SIZE; - *error = NO_ERROR; - } - return value; -} - -/* - * EXTENDED TYPE TRANSLATORS - * This set of functions reads and writes the extended types time, - * utime, date, and monetary. - */ - -/* - * or_put_time - write a DB_TIME to or buffer - * return: NO_ERROR or error code - * buf(in/out): or buffer - * timeval(in): time value to write - */ -int -or_put_time (OR_BUF * buf, DB_TIME * timeval) -{ - ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); - - if ((buf->ptr + OR_TIME_SIZE) > buf->endptr) - { - return (or_overflow (buf)); - } - else - { - OR_PUT_TIME (buf->ptr, timeval); - buf->ptr += OR_TIME_SIZE; - } - return NO_ERROR; -} - -/* - * or_get_time - read a DB_TIME from or buffer - * return: NO_ERROR or error code - * buf(in/out): or buffer - * timeval(out): pointer to DB_TIME value - */ -int -or_get_time (OR_BUF * buf, DB_TIME * timeval) -{ - ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); - - if ((buf->ptr + OR_TIME_SIZE) > buf->endptr) - { - return or_underflow (buf); - } - else - { - OR_GET_TIME (buf->ptr, timeval); - buf->ptr += OR_TIME_SIZE; - } - return NO_ERROR; -} - -/* - * or_put_utime - write a timestamp value to or buffer - * return: NO_ERROR or error code - * buf(in/out): or buffer - * timeval(in): pointer to timestamp value - */ -int -or_put_utime (OR_BUF * buf, DB_UTIME * timeval) -{ - ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); - - if ((buf->ptr + OR_UTIME_SIZE) > buf->endptr) - { - return (or_overflow (buf)); - } - else - { - OR_PUT_UTIME (buf->ptr, timeval); - buf->ptr += OR_UTIME_SIZE; - } - return NO_ERROR; -} - -/* - * or_get_utime - read a timestamp value from or buffer - * return: NO_ERROR or error code - * buf(in/out): or buffer - * timeval(out): pointer to timestamp value - */ -int -or_get_utime (OR_BUF * buf, DB_UTIME * timeval) -{ - ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); - - if ((buf->ptr + OR_UTIME_SIZE) > buf->endptr) - { - return or_underflow (buf); - } - else - { - OR_GET_UTIME (buf->ptr, timeval); - buf->ptr += OR_UTIME_SIZE; - } - return NO_ERROR; -} - -/* - * or_put_timestamptz - write a timestamp with tz value to or buffer - * return: NO_ERROR or error code - * buf(in/out): or buffer - * ts_tz(in): pointer to DB_TIMESTAMPTZ value - */ -int -or_put_timestamptz (OR_BUF * buf, DB_TIMESTAMPTZ * ts_tz) -{ - ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); - - if ((buf->ptr + OR_TIMESTAMPTZ_SIZE) > buf->endptr) - { - return (or_overflow (buf)); - } - else - { - OR_PUT_TIMESTAMPTZ (buf->ptr, ts_tz); - buf->ptr += OR_TIMESTAMPTZ_SIZE; - } - return NO_ERROR; -} - -/* - * or_get_timestamptz - read a timestamp with tz value from or buffer - * return: NO_ERROR or error code - * buf(in/out): or buffer - * ts_tz(out): pointer to DB_TIMESTAMPTZ value - */ -int -or_get_timestamptz (OR_BUF * buf, DB_TIMESTAMPTZ * ts_tz) -{ - ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); - - if ((buf->ptr + OR_TIMESTAMPTZ_SIZE) > buf->endptr) - { - return or_underflow (buf); - } - else - { - OR_GET_TIMESTAMPTZ (buf->ptr, ts_tz); - buf->ptr += OR_TIMESTAMPTZ_SIZE; - } - return NO_ERROR; -} - -/* - * or_put_date - write a DB_DATE value to or_buffer - * return: NO_ERROR or error code - * buf(in/out): or buffer - * date(in): pointer to DB_DATE value - */ -int -or_put_date (OR_BUF * buf, DB_DATE * date) -{ - ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); - - if ((buf->ptr + OR_DATE_SIZE) > buf->endptr) - { - return (or_overflow (buf)); - } - else - { - OR_PUT_DATE (buf->ptr, date); - buf->ptr += OR_DATE_SIZE; - } - return NO_ERROR; -} - -/* - * or_get_date - read a DB_DATE value from or_buffer - * return: NO_ERROR or error code - * buf(in/out): or buffer - * date(out): pointer to DB_DATE value - */ -int -or_get_date (OR_BUF * buf, DB_DATE * date) -{ - ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); - - if ((buf->ptr + OR_DATE_SIZE) > buf->endptr) - { - return or_underflow (buf); - } - else - { - OR_GET_DATE (buf->ptr, date); - buf->ptr += OR_DATE_SIZE; - } - return NO_ERROR; -} - -/* - * or_put_datetime - write a datetime value to or buffer - * return: NO_ERROR or error code - * buf(in/out): or buffer - * datetimeval(in): pointer to datetime value - */ -int -or_put_datetime (OR_BUF * buf, DB_DATETIME * datetimeval) -{ - ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); - - if ((buf->ptr + OR_DATETIME_SIZE) > buf->endptr) - { - return (or_overflow (buf)); - } - else - { - OR_PUT_DATETIME (buf->ptr, datetimeval); - buf->ptr += OR_DATETIME_SIZE; - } - return NO_ERROR; -} - -/* - * or_get_datetime - read a DB_DATETIME value from or_buffer - * return: NO_ERROR or error code - * buf(in/out): or buffer - * date(out): pointer to DB_DATETIME value - */ -int -or_get_datetime (OR_BUF * buf, DB_DATETIME * datetime) -{ - ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); - - if ((buf->ptr + OR_DATETIME_SIZE) > buf->endptr) - { - return or_underflow (buf); - } - else - { - OR_GET_DATETIME (buf->ptr, datetime); - buf->ptr += OR_DATETIME_SIZE; - } - return NO_ERROR; -} - -/* - * or_put_datetimetz - write a datetime with tz value to or buffer - * return: NO_ERROR or error code - * buf(in/out): or buffer - * datetimetz(in): pointer to DB_DATETIMETZ value - */ -int -or_put_datetimetz (OR_BUF * buf, DB_DATETIMETZ * datetimetz) -{ - ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); - - if ((buf->ptr + OR_DATETIMETZ_SIZE) > buf->endptr) - { - return (or_overflow (buf)); - } - else - { - OR_PUT_DATETIMETZ (buf->ptr, datetimetz); - buf->ptr += OR_DATETIMETZ_SIZE; - } - return NO_ERROR; -} - -/* - * or_get_datetimetz - read a datetime with tz value from or_buffer - * return: NO_ERROR or error code - * buf(in/out): or buffer - * datetimetz(out): pointer to DB_DATETIMETZ value - */ -int -or_get_datetimetz (OR_BUF * buf, DB_DATETIMETZ * datetimetz) -{ - ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); - - if ((buf->ptr + OR_DATETIMETZ_SIZE) > buf->endptr) - { - return or_underflow (buf); - } - else - { - OR_GET_DATETIMETZ (buf->ptr, datetimetz); - buf->ptr += OR_DATETIMETZ_SIZE; - } - return NO_ERROR; -} - -/* - * or_put_monetary - write a DB_MONETARY value to or buffer - * return: NO_ERROR or error code - * buf(in/out): or buffer - * monetary(in): pointer to DB_MONETARY value - */ -int -or_put_monetary (OR_BUF * buf, DB_MONETARY * monetary) -{ - int error; - - ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); - - /* check for valid currency type don't put default case in the switch!!! */ - error = ER_INVALID_CURRENCY_TYPE; - switch (monetary->type) - { - case DB_CURRENCY_DOLLAR: - case DB_CURRENCY_YEN: - case DB_CURRENCY_WON: - case DB_CURRENCY_TL: - case DB_CURRENCY_BRITISH_POUND: - case DB_CURRENCY_CAMBODIAN_RIEL: - case DB_CURRENCY_CHINESE_RENMINBI: - case DB_CURRENCY_INDIAN_RUPEE: - case DB_CURRENCY_RUSSIAN_RUBLE: - case DB_CURRENCY_AUSTRALIAN_DOLLAR: - case DB_CURRENCY_CANADIAN_DOLLAR: - case DB_CURRENCY_BRASILIAN_REAL: - case DB_CURRENCY_ROMANIAN_LEU: - case DB_CURRENCY_EURO: - case DB_CURRENCY_SWISS_FRANC: - case DB_CURRENCY_DANISH_KRONE: - case DB_CURRENCY_NORWEGIAN_KRONE: - case DB_CURRENCY_BULGARIAN_LEV: - case DB_CURRENCY_VIETNAMESE_DONG: - case DB_CURRENCY_CZECH_KORUNA: - case DB_CURRENCY_POLISH_ZLOTY: - case DB_CURRENCY_SWEDISH_KRONA: - case DB_CURRENCY_CROATIAN_KUNA: - case DB_CURRENCY_SERBIAN_DINAR: - error = NO_ERROR; /* it's a type we expect */ - break; - default: - break; - } - - if (error != NO_ERROR) - { - er_set (ER_WARNING_SEVERITY, ARG_FILE_LINE, error, 1, monetary->type); - return error; - } - - if ((buf->ptr + OR_MONETARY_SIZE) > buf->endptr) - { - return (or_overflow (buf)); - } - else - { - OR_PUT_MONETARY (buf->ptr, monetary); - buf->ptr += OR_MONETARY_SIZE; - } - - return error; -} - -/* - * or_get_monetary - read a DB_MONETARY from or buffer - * return: NO_ERROR or error code - * buf(in/out): or buffer - * monetary(out): pointer to DB_MONETARY value - */ -int -or_get_monetary (OR_BUF * buf, DB_MONETARY * monetary) -{ - ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); - - if ((buf->ptr + OR_MONETARY_SIZE) > buf->endptr) - { - return or_underflow (buf); - } - else - { - OR_GET_MONETARY (buf->ptr, monetary); - buf->ptr += OR_MONETARY_SIZE; - } - return NO_ERROR; -} - -/* - * or_put_oid - write content of an OID structure from or buffer - * return: NO_ERROR or error code - * buf(in/out): or buffer - * oid(in): pointer to OID - */ -int -or_put_oid (OR_BUF * buf, const OID * oid) -{ - ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); - - if ((buf->ptr + OR_OID_SIZE) > buf->endptr) - { - return (or_overflow (buf)); - } - else - { - if (oid == NULL) - { - OR_PUT_NULL_OID (buf->ptr); - } - else - { - /* Cannot allow any temp oid's to be written */ - if (OID_ISTEMP (oid)) - { - er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_GENERIC_ERROR, 0); - or_abort (buf); - } - OR_PUT_OID (buf->ptr, oid); - } - buf->ptr += OR_OID_SIZE; - } - return NO_ERROR; -} - -/* - * or_get_oid - read content of an OID structure from or buffer - * return: NO_ERROR or error code - * buf(in/out): or buffer - * oid(out): pointer to OID - */ -int -or_get_oid (OR_BUF * buf, OID * oid) -{ - ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); - - if ((buf->ptr + OR_OID_SIZE) > buf->endptr) - { - return or_underflow (buf); - } - else - { - OR_GET_OID (buf->ptr, oid); - buf->ptr += OR_OID_SIZE; - } - return NO_ERROR; -} - -/* - * or_put_data - write an array of bytes to or buffer - * return: NO_ERROR or error code - * buf(in/out): or buffer - * data(in): pointer to data - * length(in): length in bytes - */ -int -or_put_data (OR_BUF * buf, const char *data, int length) -{ - if ((buf->ptr + length) > buf->endptr) - { - return (or_overflow (buf)); - } - else - { - (void) memcpy (buf->ptr, data, length); - buf->ptr += length; - } - return NO_ERROR; -} - -/* - * or_get_data - read an array of bytes from or buffer for given length - * return: NO_ERROR or error code - * buf(in/out): or buffer - * data(in): pointer to buffer to read data into - * length(in): length of read data - */ -int -or_get_data (OR_BUF * buf, char *data, int length) -{ - if ((buf->ptr + length) > buf->endptr) - { - return or_underflow (buf); - } - else - { - (void) memcpy (data, buf->ptr, length); - buf->ptr += length; - } - return NO_ERROR; -} - -/* - * or_put_string - write string to or buf - * return: NO_ERROR or error code - * buf(in/out): or buffer - * str(in): string to write + * or_length_binary - Calculates the number of bytes required for the disk + * representaion of binary data. + * return: bytes required or 0 for error + * binary(in): binary data * * Note: - * Does byte padding on strings to bring them up to 4 byte boundary. - * - * There is no or_get_string since this is the same as or_get_data. - * Since the workspace allocator (and most other Unix allocators) will - * keep track of the size of allocated blocks (and they will be - * in word multiples anyway), we can just include the disk padding - * bytes with the string when it is brought in from disk even though - * the total length may be more than that returned by strlen. + * Included in this number are any padding bytes required to bring the data + * up to a word boundary. */ int -or_put_string_aligned (OR_BUF * buf, char *str) +or_length_binary (DB_BINARY * binary) { - int len, bits, pad; - int rc = NO_ERROR; + int len, bits; - if (str == NULL) - { - return rc; - } - len = strlen (str) + 1; - rc = or_put_data (buf, str, len); - if (rc == NO_ERROR) + len = 0; + if (binary != NULL && binary->length < OR_BINARY_MAX_LENGTH) { - /* PAD */ + len = binary->length + OR_INT_SIZE; /* always a header word for sizes */ bits = len & 3; if (bits) { - pad = 4 - bits; - rc = or_pad (buf, pad); + len += 4 - bits; } } - return rc; + return len; } +#endif /* ENABLE_UNUSED_FUNCTION */ #if defined(ENABLE_UNUSED_FUNCTION) /* @@ -2263,160 +1162,61 @@ or_length_string (char *string) } return len; } +#endif /* ENABLE_UNUSED_FUNCTION */ /* - * or_put_binary - Writes a binary array into the translation buffer. + * or_put_varbit - put varbit into or buffer * return: NO_ERROR or error code * buf(in/out): or buffer - * binary(in): binary data - * - * Note: - * The length of the array is part of the binary data descriptor. - * This is similar to or_put_string in that it also must pad out the - * binary data to be on a word boundary. - */ -int -or_put_binary (OR_BUF * buf, DB_BINARY * binary) -{ - int header, len, bits, pad; - int rc = NO_ERROR; - - if (binary != NULL && binary->length < OR_BINARY_MAX_LENGTH) - { - len = binary->length + OR_INT_SIZE; - pad = 0; - bits = len & 3; - if (bits) - { - pad = 4 - bits; - } - header = binary->length | (pad << OR_BINARY_PAD_SHIFT); - rc = or_put_int (buf, header); - if (rc == NO_ERROR) - { - rc = or_put_data (buf, (char *) binary->data, binary->length); - if (rc == NO_ERROR) - { - rc = or_pad (buf, pad); - } - } - } - return rc; -} - -/* - * or_length_binary - Calculates the number of bytes required for the disk - * representaion of binary data. - * return: bytes required or 0 for error - * binary(in): binary data - * - * Note: - * Included in this number are any padding bytes required to bring the data - * up to a word boundary. + * string(in): string contains varbit value + * bitlen(in): length of varbit */ int -or_length_binary (DB_BINARY * binary) +or_packed_put_varbit (OR_BUF * buf, const char *string, int bitlen) { - int len, bits; - - len = 0; - if (binary != NULL && binary->length < OR_BINARY_MAX_LENGTH) - { - len = binary->length + OR_INT_SIZE; /* always a header word for sizes */ - bits = len & 3; - if (bits) - { - len += 4 - bits; - } - } - return len; + return or_put_varbit_internal (buf, string, bitlen, INT_ALIGNMENT); } -#endif /* ENABLE_UNUSED_FUNCTION */ /* - * or_pad - This advances the translation pointer and adds bytes of zero. - * return: NO_ERROR or error code - * buf(in/out): or buffer - * length(in): number of bytes to pad - * - * Note: - * This advances the translation pointer and adds bytes of zero. - * This is used add padding bytes to ensure proper alignment of - * some data types. + * or_packed_varbit_length - returns packed varbit length of or buffer encoding + * return: packed varbit encoding length + * bitlen(in): varbit length */ int -or_pad (OR_BUF * buf, int length) +or_packed_varbit_length (int bitlen) { - if ((buf->ptr + length) > buf->endptr) - { - return (or_overflow (buf)); - } - else - { - (void) memset (buf->ptr, 0, length); - buf->ptr += length; - } - return NO_ERROR; + return or_varbit_length_internal (bitlen, INT_ALIGNMENT); } /* - * or_advance - This advances the translation pointer + * or_packed_put_varchar - put varchar to or buffer * return: NO_ERROR or error code * buf(in/out): or buffer - * offset(in): number of bytes to skip + * string(in): string to put into the or buffer + * charlen(in): string length */ int -or_advance (OR_BUF * buf, int offset) +or_packed_put_varchar (OR_BUF * buf, char *string, int charlen) { - if ((buf->ptr + offset) > buf->endptr) - { - return (or_overflow (buf)); - } - else - { - buf->ptr += offset; - return NO_ERROR; - } + return or_put_varchar_internal (buf, string, charlen, INT_ALIGNMENT); } /* - * or_seek - This sets the translation pointer directly to a certain byte in - * the buffer. - * return: ERROR_SUCCESS or error code - * buf(in/out): or buffer - * psn(in): position within buffer + * or_packed_varchar_length - returns length of place holder that can contain + * package varchar length. Also ajust length up to 4 byte boundary. + * return: length of placeholder that can contain packed varchar length + * charlen(in): varchar length */ int -or_seek (OR_BUF * buf, int psn) +or_packed_varchar_length (int charlen) { - if ((buf->buffer + psn) > buf->endptr) - { - return (or_overflow (buf)); - } - else - { - buf->ptr = buf->buffer + psn; - } - return NO_ERROR; + return or_varchar_length_internal (charlen, INT_ALIGNMENT); } -/* - * or_align () - Align current buffer pointer to given alignment. - * - * return : Error code. - * buf (in/out) : Buffer. - * alignment (in) : Desired alignment. - */ int -or_align (OR_BUF * buf, int alignment) +or_packed_recdesc_length (int length) { - char *new_ptr = PTR_ALIGN (buf->ptr, alignment); - if (new_ptr > buf->endptr) - { - return (or_overflow (buf)); - } - buf->ptr = new_ptr; - return NO_ERROR; + return OR_INT_SIZE * 2 + or_packed_stream_length (length); } /* @@ -2539,12 +1339,6 @@ or_get_var_table_internal (OR_BUF * buf, int nvars, char *(*allocator) (int), in * COMMUNICATION BUFFER PACK/UNPACK FUNCTIONS */ - -/* - * NUMERIC DATA TYPE TRANSLATORS - * Translators for the numeric data types int, short, errcode, lock... - */ - /* * or_pack_int - write int value to ptr * return: advanced buffer pointer @@ -7568,62 +6362,6 @@ or_unpack_ptr (char *ptr, UINTPTR * ptrval) /* * MVCCID: */ -/* - * or_put_mvccid () - Put an MVCCID to OR Buffer. - * - * return : Error code. - * buf (in) : OR Buffer - * mvccid (in) : MVCCID - */ -int -or_put_mvccid (OR_BUF * buf, MVCCID mvccid) -{ - ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); - - if ((buf->ptr + OR_MVCCID_SIZE) > buf->endptr) - { - return (or_overflow (buf)); - } - else - { - OR_PUT_MVCCID (buf->ptr, &mvccid); - buf->ptr += OR_MVCCID_SIZE; - } - return NO_ERROR; -} - -/* - * or_get_mvccid - get bigint value from or buffer - * return: bigint value read - * buf(in/out): or buffer - * error(out): NO_ERROR or error code - */ -/* - * or_get_mvccid () - Get an MVCCID from OR Buffer. - * - * return : MVCCID - * buf (in/out) : OR Buffer. - * error (out) : Error code. - */ -int -or_get_mvccid (OR_BUF * buf, MVCCID * mvccid) -{ - assert (mvccid != NULL); - ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT); - - *mvccid = MVCCID_NULL; - - if ((buf->ptr + OR_MVCCID_SIZE) > buf->endptr) - { - return or_underflow (buf); - } - else - { - OR_GET_MVCCID (buf->ptr, mvccid); - buf->ptr += OR_MVCCID_SIZE; - } - return NO_ERROR; -} /* * or_pack_mvccid () - Pack an MVCCID at the give pointer. @@ -7708,178 +6446,6 @@ or_unpack_sha1 (char *ptr, SHA1Hash * sha1) return ptr + OR_SHA1_SIZE; } -/* - * LITTLE ENDIAN TRANSFORMATION FUNCTIONS - */ - -/* - * little endian support functions. - * Could just leave these in all the time. - * Try to speed these up, consider making them inline. - * - */ -#if OR_BYTE_ORDER == OR_LITTLE_ENDIAN - -#if !defined (OR_HAVE_NTOHS) -unsigned short -ntohs (unsigned short from) -{ - unsigned short to; - char *ptr, *vptr; - - ptr = (char *) &from; - vptr = (char *) &to; - vptr[0] = ptr[1]; - vptr[1] = ptr[0]; - - return to; -} -#endif /* !OR_HAVE_NTOHS */ - -#if !defined (OR_HAVE_NTOHL) -unsigned int -ntohl (unsigned int from) -{ - unsigned int to; - char *ptr, *vptr; - - ptr = (char *) &from; - vptr = (char *) &to; - vptr[0] = ptr[3]; - vptr[1] = ptr[2]; - vptr[2] = ptr[1]; - vptr[3] = ptr[0]; - - return to; -} -#endif /* !OR_HAVE_NTOHL */ - -#if !defined (OR_HAVE_NTOHF) -float -ntohf (UINT32 from) -{ - char *ptr, *vptr; - float to; - - ptr = (char *) &from; - vptr = (char *) &to; - vptr[0] = ptr[3]; - vptr[1] = ptr[2]; - vptr[2] = ptr[1]; - vptr[3] = ptr[0]; - - return to; -} -#endif /* !OR_HAVE_NTOHF */ - -#if !defined (OR_HAVE_NTOHD) -double -ntohd (UINT64 from) -{ - char *ptr, *vptr; - double to; - - ptr = (char *) &from; - vptr = (char *) &to; - vptr[0] = ptr[7]; - vptr[1] = ptr[6]; - vptr[2] = ptr[5]; - vptr[3] = ptr[4]; - vptr[4] = ptr[3]; - vptr[5] = ptr[2]; - vptr[6] = ptr[1]; - vptr[7] = ptr[0]; - - return to; -} -#endif /* !OR_HAVE_NTOHD */ - -UINT64 -ntohi64 (UINT64 from) -{ - UINT64 to; - char *ptr, *vptr; - - ptr = (char *) &from; - vptr = (char *) &to; - vptr[0] = ptr[7]; - vptr[1] = ptr[6]; - vptr[2] = ptr[5]; - vptr[3] = ptr[4]; - vptr[4] = ptr[3]; - vptr[5] = ptr[2]; - vptr[6] = ptr[1]; - vptr[7] = ptr[0]; - - return to; -} - -#if !defined (OR_HAVE_HTONS) -unsigned short -htons (unsigned short from) -{ - return ntohs (from); -} -#endif /* !OR_HAVE_HTONS */ - -#if !defined (OR_HAVE_HTONL) -unsigned int -htonl (unsigned int from) -{ - return ntohl (from); -} -#endif /* !OR_HAVE_HTONL */ - -UINT64 -htoni64 (UINT64 from) -{ - return ntohi64 (from); -} - -#if !defined (OR_HAVE_HTONF) -UINT32 -htonf (float from) -{ - UINT32 to; - char *p, *q; - - p = (char *) &from; - q = (char *) &to; - - q[0] = p[3]; - q[1] = p[2]; - q[2] = p[1]; - q[3] = p[0]; - - return to; -} -#endif /* !OR_HAVE_HTONL */ - -#if !defined (OR_HAVE_HTOND) -UINT64 -htond (double from) -{ - UINT64 to; - char *p, *q; - - p = (char *) &from; - q = (char *) &to; - - q[0] = p[7]; - q[1] = p[6]; - q[2] = p[5]; - q[3] = p[4]; - q[4] = p[3]; - q[5] = p[2]; - q[6] = p[1]; - q[7] = p[0]; - - return to; -} -#endif /* ! OR_HAVE_HTOND */ - -#endif /* OR_BYTE_ORDER == OR_LITTLE_ENDIAN */ - /* * or_packed_spacedb_size () - compute the size required to pack all space info * @@ -8055,36 +6621,6 @@ or_unpack_spacedb (char *ptr, SPACEDB_ALL * all, SPACEDB_ONEVOL ** vols, SPACEDB return ptr; } -/* - * this function also adds - * the length of the string to the buffer - */ -int -or_put_string_aligned_with_length (OR_BUF * buf, const char *str) -{ - int len; - int rc = NO_ERROR; - - if (str == NULL) - { - return rc; - } - len = (int) strlen (str) + 1; - - rc = or_put_int (buf, len); - if (rc != NO_ERROR) - { - return rc; - } - - rc = or_put_data (buf, str, len); - if (rc == NO_ERROR) - { - or_align (buf, OR_INT_SIZE); - } - return rc; -} - /* * classobj_initialize_default_expr() - Initializes default expression * return: nothing diff --git a/src/query/execute_statement.c b/src/query/execute_statement.c index bea4274db2e..e6e56bfb23c 100644 --- a/src/query/execute_statement.c +++ b/src/query/execute_statement.c @@ -11685,7 +11685,7 @@ do_create_midxkey_for_constraint (DB_OTMPL * tmpl, SM_CLASS_CONSTRAINT * constra bound_bits = midxkey.buf; key_ptr = bound_bits + bitmap_size; - OR_BUF_INIT (buf, key_ptr, buf_size - bitmap_size); + or_init (&buf, key_ptr, buf_size - bitmap_size); MIDXKEY_BOUNDBITS_INIT (bound_bits, bitmap_size); for (i = 0, attr = constraint->attributes; *attr != NULL; attr++, i++) diff --git a/src/query/fetch.c b/src/query/fetch.c index a89be92eb7b..49aa7e80373 100644 --- a/src/query/fetch.c +++ b/src/query/fetch.c @@ -3841,7 +3841,7 @@ fetch_peek_dbval (THREAD_ENTRY * thread_p, REGU_VARIABLE * regu_var, val_descr * goto exit_on_error; } - OR_BUF_INIT (buf, ptr, length); + or_init (&buf, ptr, length); if (pr_type->data_readval (&buf, *peek_dbval, regu_var->value.pos_descr.dom, -1, false /* Don't copy */ , NULL, 0) != NO_ERROR) @@ -4324,7 +4324,7 @@ fetch_peek_dbval_pos (REGU_VARIABLE * regu_var, QFILE_TUPLE tpl, int pos, DB_VAL return ER_FAILED; } - OR_BUF_INIT (buf, ptr, length); + or_init (&buf, ptr, length); /* read value from the tuple */ if (pr_type->data_readval (&buf, *peek_dbval, pos_descr->dom, -1, false /* Don't copy */ , NULL, 0) != NO_ERROR) { diff --git a/src/query/list_file.c b/src/query/list_file.c index f2a804e8f29..c4ba5c29d35 100644 --- a/src/query/list_file.c +++ b/src/query/list_file.c @@ -981,7 +981,7 @@ qfile_locate_tuple_next_value (OR_BUF * iterator, OR_BUF * buf, QFILE_TUPLE_VALU *flag = QFILE_GET_TUPLE_VALUE_FLAG (iterator->ptr); /* initialize output buffer */ - OR_BUF_INIT ((*buf), iterator->ptr + QFILE_TUPLE_VALUE_HEADER_SIZE, value_size); + or_init (buf, iterator->ptr + QFILE_TUPLE_VALUE_HEADER_SIZE, value_size); /* advance iterator */ return or_advance (iterator, QFILE_TUPLE_VALUE_HEADER_SIZE + value_size); @@ -1975,7 +1975,7 @@ qfile_fast_intval_tuple_to_list (THREAD_ENTRY * thread_p, QFILE_LIST_ID * list_i QFILE_PUT_TUPLE_VALUE_FLAG (tuple_p, V_BOUND); QFILE_PUT_TUPLE_VALUE_LENGTH (tuple_p, tuple_value_size); - OR_BUF_INIT (buf, tuple_p + QFILE_TUPLE_VALUE_HEADER_SIZE, tuple_value_size); + or_init (&buf, tuple_p + QFILE_TUPLE_VALUE_HEADER_SIZE, tuple_value_size); if (pr_type == NULL || pr_type->data_writeval (&buf, v2) != NO_ERROR) { return ER_FAILED; @@ -2054,7 +2054,7 @@ qfile_fast_val_tuple_to_list (THREAD_ENTRY * thread_p, QFILE_LIST_ID * list_id_p QFILE_PUT_TUPLE_VALUE_FLAG (tuple_p, V_BOUND); QFILE_PUT_TUPLE_VALUE_LENGTH (tuple_p, tuple_value_size); - OR_BUF_INIT (buf, tuple_p + QFILE_TUPLE_VALUE_HEADER_SIZE, tuple_value_size); + or_init (&buf, tuple_p + QFILE_TUPLE_VALUE_HEADER_SIZE, tuple_value_size); if (pr_type == NULL || pr_type->data_writeval (&buf, val) != NO_ERROR) { return ER_FAILED; @@ -6323,7 +6323,7 @@ qfile_set_tuple_column_value (THREAD_ENTRY * thread_p, QFILE_LIST_ID * list_id_p flag = (QFILE_TUPLE_VALUE_FLAG) qfile_locate_tuple_value (tuple_p, col_num, &ptr, &length); if (flag == V_BOUND) { - OR_BUF_INIT (buf, ptr, length); + or_init (&buf, ptr, length); if (pr_type->data_writeval (&buf, value_p) != NO_ERROR) { @@ -6362,7 +6362,7 @@ qfile_set_tuple_column_value (THREAD_ENTRY * thread_p, QFILE_LIST_ID * list_id_p flag = (QFILE_TUPLE_VALUE_FLAG) qfile_locate_tuple_value (tuple_rec.tpl, col_num, &ptr, &length); if (flag == V_BOUND) { - OR_BUF_INIT (buf, ptr, length); + or_init (&buf, ptr, length); if (pr_type->data_writeval (&buf, value_p) != NO_ERROR) { @@ -6509,7 +6509,7 @@ qfile_compare_with_interpolation_domain (char *fp0, char *fp1, SUBKEY_INFO * sub /* get the proper domain NOTE: col_dom is string type. See qexec_initialize_analytic_state */ pr_clear_value (&val0); - OR_BUF_INIT (buf0, d0, QFILE_GET_TUPLE_VALUE_LENGTH (fp0)); + or_init (&buf0, d0, QFILE_GET_TUPLE_VALUE_LENGTH (fp0)); error = subkey->col_dom->type->data_readval (&buf0, &val0, subkey->col_dom, QFILE_GET_TUPLE_VALUE_LENGTH (fp0), false, NULL, 0); @@ -6534,8 +6534,8 @@ qfile_compare_with_interpolation_domain (char *fp0, char *fp1, SUBKEY_INFO * sub pr_clear_value (&val0); pr_clear_value (&val1); - OR_BUF_INIT (buf0, d0, QFILE_GET_TUPLE_VALUE_LENGTH (fp0)); - OR_BUF_INIT (buf1, d1, QFILE_GET_TUPLE_VALUE_LENGTH (fp1)); + or_init (&buf0, d0, QFILE_GET_TUPLE_VALUE_LENGTH (fp0)); + or_init (&buf1, d1, QFILE_GET_TUPLE_VALUE_LENGTH (fp1)); error = subkey->col_dom->type->data_readval (&buf0, &val0, subkey->col_dom, QFILE_GET_TUPLE_VALUE_LENGTH (fp0), false, NULL, 0); diff --git a/src/query/query_aggregate.cpp b/src/query/query_aggregate.cpp index 97e09b93082..ae0e946d68e 100644 --- a/src/query/query_aggregate.cpp +++ b/src/query/query_aggregate.cpp @@ -741,7 +741,7 @@ qdata_evaluate_aggregate_list (cubthread::entry *thread_p, cubxasl::aggregate_li dbval_size = pr_data_writeval_disk_size (db_value_p); if (dbval_size > 0 && (disk_repr_p = (char *) db_private_alloc (thread_p, dbval_size)) != NULL) { - OR_BUF_INIT (buf, disk_repr_p, dbval_size); + or_init (&buf, disk_repr_p, dbval_size); error = pr_type_p->data_writeval (&buf, db_value_p); if (error != NO_ERROR) { @@ -2472,7 +2472,7 @@ qdata_load_agg_hentry_from_tuple (cubthread::entry *thread_p, QFILE_TUPLE tuple, /* initialize buffer */ db_make_int (&int_val, 0); - OR_BUF_INIT (iterator, tuple, QFILE_GET_TUPLE_LENGTH (tuple)); + or_init (&iterator, tuple, QFILE_GET_TUPLE_LENGTH (tuple)); rc = or_advance (&iterator, QFILE_TUPLE_LENGTH_SIZE); if (rc != NO_ERROR) { diff --git a/src/query/query_analytic.cpp b/src/query/query_analytic.cpp index 5a8e78f91a3..dcf973e93e2 100644 --- a/src/query/query_analytic.cpp +++ b/src/query/query_analytic.cpp @@ -222,7 +222,7 @@ qdata_evaluate_analytic_func (cubthread::entry *thread_p, ANALYTIC_TYPE *func_p, dbval_size = pr_data_writeval_disk_size (&dbval); if (dbval_size > 0 && (disk_repr_p = (char *) db_private_alloc (thread_p, dbval_size)) != NULL) { - OR_BUF_INIT (buf, disk_repr_p, dbval_size); + or_init (&buf, disk_repr_p, dbval_size); error = pr_type_p->data_writeval (&buf, &dbval); if (error != NO_ERROR) { diff --git a/src/query/query_evaluator.c b/src/query/query_evaluator.c index 6af1e238585..93e3d73a861 100644 --- a/src/query/query_evaluator.c +++ b/src/query/query_evaluator.c @@ -589,7 +589,7 @@ eval_some_list_eval (THREAD_ENTRY * thread_p, DB_VALUE * item, QFILE_LIST_ID * l } else { - OR_BUF_INIT (buf, ptr, length); + or_init (&buf, ptr, length); if (pr_type->data_readval (&buf, &list_val, list_id->type_list.domp[0], -1, true, NULL, 0) != NO_ERROR) { @@ -731,7 +731,7 @@ eval_item_card_sort_list (THREAD_ENTRY * thread_p, DB_VALUE * item, QFILE_LIST_I return UNKNOWN_CARD; } - OR_BUF_INIT (buf, ptr, length); + or_init (&buf, ptr, length); pr_type->data_readval (&buf, &list_val, list_id->type_list.domp[0], -1, true, NULL, 0); @@ -960,7 +960,7 @@ eval_sub_sort_list_to_multi_set (THREAD_ENTRY * thread_p, QFILE_LIST_ID * list_i goto end; } - OR_BUF_INIT (buf, ptr, length); + or_init (&buf, ptr, length); pr_type->data_readval (&buf, &list_val, list_id->type_list.domp[0], -1, true, NULL, 0); @@ -1136,7 +1136,7 @@ eval_sub_sort_list_to_sort_list (THREAD_ENTRY * thread_p, QFILE_LIST_ID * list_i goto end; } - OR_BUF_INIT (buf, ptr, length); + or_init (&buf, ptr, length); pr_type->data_readval (&buf, &list_val, list_id1->type_list.domp[0], -1, true, NULL, 0); diff --git a/src/query/query_executor.c b/src/query/query_executor.c index bbda40b87b2..422ca56d421 100644 --- a/src/query/query_executor.c +++ b/src/query/query_executor.c @@ -16281,7 +16281,7 @@ qexec_get_tuple_column_value (QFILE_TUPLE tpl, int index, DB_VALUE * valp, tp_do return ER_FAILED; } - OR_BUF_INIT (buf, ptr, length); + or_init (&buf, ptr, length); if (pr_type->data_readval (&buf, valp, domain, -1, false, NULL, 0) != NO_ERROR) { @@ -20918,7 +20918,7 @@ qexec_analytic_sort_key_header_load (ANALYTIC_FUNCTION_STATE * func_state, bool { length = QFILE_GET_TUPLE_VALUE_LENGTH (tuple_p); tuple_p += QFILE_TUPLE_VALUE_HEADER_SIZE; - OR_BUF_INIT (buf, tuple_p, length); + or_init (&buf, tuple_p, length); rc = func_state->func_p->domain->type->data_readval (&buf, func_state->func_p->value, func_state->func_p->domain, -1, diff --git a/src/query/query_opfunc.c b/src/query/query_opfunc.c index 58aeb6708aa..489c09b2b5f 100644 --- a/src/query/query_opfunc.c +++ b/src/query/query_opfunc.c @@ -378,7 +378,7 @@ qdata_copy_db_value_to_tuple_value (DB_VALUE * dbval_p, bool clear_compressed_st } val_size = pr_data_writeval_disk_size (dbval_p); - OR_BUF_INIT (buf, val_p, val_size); + or_init (&buf, val_p, val_size); rc = pr_type->data_writeval (&buf, dbval_p); if (rc != NO_ERROR) @@ -6363,7 +6363,7 @@ qdata_get_single_tuple_from_list_id (THREAD_ENTRY * thread_p, qfile_list_id * li } flag = (QFILE_TUPLE_VALUE_FLAG) qfile_locate_tuple_value (tuple_record.tpl, i, &ptr, &length); - OR_BUF_INIT (buf, ptr, length); + or_init (&buf, ptr, length); if (flag == V_BOUND) { if (pr_type_p->data_readval (&buf, value_list->val, domain_p, -1, true, NULL, 0) != NO_ERROR) diff --git a/src/query/scan_manager.c b/src/query/scan_manager.c index 4601a4dfdcb..37dbeb3c1ba 100644 --- a/src/query/scan_manager.c +++ b/src/query/scan_manager.c @@ -1756,7 +1756,7 @@ scan_dbvals_to_midxkey (THREAD_ENTRY * thread_p, DB_VALUE * retval, bool * index nullmap_ptr = midxkey.buf; key_ptr = nullmap_ptr + nullmap_size; - OR_BUF_INIT (buf, key_ptr, buf_size - nullmap_size); + or_init (&buf, key_ptr, buf_size - nullmap_size); MIDXKEY_BOUNDBITS_INIT (nullmap_ptr, nullmap_size); /* generate multi columns key (values -> midxkey.buf) */ diff --git a/src/storage/btree.c b/src/storage/btree.c index b64805e2695..f2a023f2c55 100644 --- a/src/storage/btree.c +++ b/src/storage/btree.c @@ -256,7 +256,7 @@ { \ size -= DB_ALIGN (DISK_VPID_SIZE, BTREE_MAX_ALIGN); \ } \ - OR_BUF_INIT (buf, (btree_rec)->data, size); \ + or_init (&buf, (btree_rec)->data, size); \ } \ while (false) @@ -21434,7 +21434,7 @@ btree_pack_object (char *ptr, BTID_INT * btid_int, BTREE_NODE_TYPE node_type, RE { OR_BUF buffer; - OR_BUF_INIT (buffer, record->data, record->area_size); + or_init (&buffer, record->data, record->area_size); buffer.ptr = ptr; if (btree_or_put_object (&buffer, btid_int, node_type, object_info) != NO_ERROR) @@ -27529,7 +27529,7 @@ btree_key_insert_new_key (THREAD_ENTRY * thread_p, BTID_INT * btid_int, DB_VALUE VPID vpid_key = VPID_INITIALIZER; int rc = NO_ERROR; - OR_BUF_INIT (buf_vpid_key, record.data + record.length - DISK_VPID_ALIGNED_SIZE, DISK_VPID_ALIGNED_SIZE); + or_init (&buf_vpid_key, record.data + record.length - DISK_VPID_ALIGNED_SIZE, DISK_VPID_ALIGNED_SIZE); vpid_key.pageid = or_get_int (&buf_vpid_key, &rc); vpid_key.volid = or_get_short (&buf_vpid_key, &rc); diff --git a/src/storage/btree_load.c b/src/storage/btree_load.c index 17bbb3c1eae..0c9106a5afa 100644 --- a/src/storage/btree_load.c +++ b/src/storage/btree_load.c @@ -3631,8 +3631,8 @@ compare_driver (const void *first, const void *second, void *arg) OR_BUF buf_val1, buf_val2; DB_VALUE val1, val2; - OR_BUF_INIT (buf_val1, mem1, -1); - OR_BUF_INIT (buf_val2, mem2, -1); + or_init (&buf_val1, mem1, -1); + or_init (&buf_val2, mem2, -1); if (key_type->type->data_readval (&buf_val1, &val1, key_type, -1, false, NULL, 0) != NO_ERROR) { diff --git a/src/storage/byte_order.c b/src/storage/byte_order.c new file mode 100644 index 00000000000..945291a8c62 --- /dev/null +++ b/src/storage/byte_order.c @@ -0,0 +1,197 @@ +/* + * Copyright 2008 Search Solution Corporation + * Copyright 2016 CUBRID Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +/* + * byte_order.c - Definitions related to disk storage order + */ + +#ident "$Id$" + +#include "byte_order.h" + +/* + * LITTLE ENDIAN TRANSFORMATION FUNCTIONS + */ + +/* + * little endian support functions. + * Could just leave these in all the time. + * Try to speed these up, consider making them inline. + * + */ +#if OR_BYTE_ORDER == OR_LITTLE_ENDIAN + +#if !defined (OR_HAVE_NTOHS) +unsigned short +ntohs (unsigned short from) +{ + unsigned short to; + char *ptr, *vptr; + + ptr = (char *) &from; + vptr = (char *) &to; + vptr[0] = ptr[1]; + vptr[1] = ptr[0]; + + return to; +} +#endif /* !OR_HAVE_NTOHS */ + +#if !defined (OR_HAVE_NTOHL) +unsigned int +ntohl (unsigned int from) +{ + unsigned int to; + char *ptr, *vptr; + + ptr = (char *) &from; + vptr = (char *) &to; + vptr[0] = ptr[3]; + vptr[1] = ptr[2]; + vptr[2] = ptr[1]; + vptr[3] = ptr[0]; + + return to; +} +#endif /* !OR_HAVE_NTOHL */ + +#if !defined (OR_HAVE_NTOHF) +float +ntohf (UINT32 from) +{ + char *ptr, *vptr; + float to; + + ptr = (char *) &from; + vptr = (char *) &to; + vptr[0] = ptr[3]; + vptr[1] = ptr[2]; + vptr[2] = ptr[1]; + vptr[3] = ptr[0]; + + return to; +} +#endif /* !OR_HAVE_NTOHF */ + +#if !defined (OR_HAVE_NTOHD) +double +ntohd (UINT64 from) +{ + char *ptr, *vptr; + double to; + + ptr = (char *) &from; + vptr = (char *) &to; + vptr[0] = ptr[7]; + vptr[1] = ptr[6]; + vptr[2] = ptr[5]; + vptr[3] = ptr[4]; + vptr[4] = ptr[3]; + vptr[5] = ptr[2]; + vptr[6] = ptr[1]; + vptr[7] = ptr[0]; + + return to; +} +#endif /* !OR_HAVE_NTOHD */ + +UINT64 +ntohi64 (UINT64 from) +{ + UINT64 to; + char *ptr, *vptr; + + ptr = (char *) &from; + vptr = (char *) &to; + vptr[0] = ptr[7]; + vptr[1] = ptr[6]; + vptr[2] = ptr[5]; + vptr[3] = ptr[4]; + vptr[4] = ptr[3]; + vptr[5] = ptr[2]; + vptr[6] = ptr[1]; + vptr[7] = ptr[0]; + + return to; +} + +#if !defined (OR_HAVE_HTONS) +unsigned short +htons (unsigned short from) +{ + return ntohs (from); +} +#endif /* !OR_HAVE_HTONS */ + +#if !defined (OR_HAVE_HTONL) +unsigned int +htonl (unsigned int from) +{ + return ntohl (from); +} +#endif /* !OR_HAVE_HTONL */ + +UINT64 +htoni64 (UINT64 from) +{ + return ntohi64 (from); +} + +#if !defined (OR_HAVE_HTONF) +UINT32 +htonf (float from) +{ + UINT32 to; + char *p, *q; + + p = (char *) &from; + q = (char *) &to; + + q[0] = p[3]; + q[1] = p[2]; + q[2] = p[1]; + q[3] = p[0]; + + return to; +} +#endif /* !OR_HAVE_HTONF */ + +#if !defined (OR_HAVE_HTOND) +UINT64 +htond (double from) +{ + UINT64 to; + char *p, *q; + + p = (char *) &from; + q = (char *) &to; + + q[0] = p[7]; + q[1] = p[6]; + q[2] = p[5]; + q[3] = p[4]; + q[4] = p[3]; + q[5] = p[2]; + q[6] = p[1]; + q[7] = p[0]; + + return to; +} +#endif /* ! OR_HAVE_HTOND */ + +#endif /* OR_BYTE_ORDER == OR_LITTLE_ENDIAN */ diff --git a/src/storage/byte_order.h b/src/storage/byte_order.h index f7cee35ca64..7b0e368ccca 100644 --- a/src/storage/byte_order.h +++ b/src/storage/byte_order.h @@ -73,8 +73,6 @@ #define OR_HAVE_HTONL #endif /* HPUX || _AIX || WINDOWS || LINUX */ - - typedef union moving_van MOVING_VAN; union moving_van { @@ -94,6 +92,20 @@ union moving_van sizeof(MOVING_VAN)) #endif /* !IA64 */ +#if OR_BYTE_ORDER == OR_LITTLE_ENDIAN +#define swap64(x) \ + ((((unsigned long long) (x) & (0x00000000000000FFULL)) << 56) \ + | (((unsigned long long) (x) & (0xFF00000000000000ULL)) >> 56) \ + | (((unsigned long long) (x) & (0x000000000000FF00ULL)) << 40) \ + | (((unsigned long long) (x) & (0x00FF000000000000ULL)) >> 40) \ + | (((unsigned long long) (x) & (0x0000000000FF0000ULL)) << 24) \ + | (((unsigned long long) (x) & (0x0000FF0000000000ULL)) >> 24) \ + | (((unsigned long long) (x) & (0x00000000FF000000ULL)) << 8) \ + | (((unsigned long long) (x) & (0x000000FF00000000ULL)) >> 8)) +#else /* OR_BYTE_ORDER == OR_LITTLE_ENDIAN */ +#define swap64(x) (x) +#endif /* OR_BYTE_ORDER == OR_BIG_ENDIAN */ + #if OR_BYTE_ORDER == OR_LITTLE_ENDIAN #ifndef OR_HAVE_NTOHS diff --git a/src/storage/heap_file.c b/src/storage/heap_file.c index dd399f8ddee..38c5046a15d 100644 --- a/src/storage/heap_file.c +++ b/src/storage/heap_file.c @@ -10140,7 +10140,7 @@ heap_attrvalue_read (RECDES * recdes, HEAP_ATTRVALUE * value, HEAP_CACHE_ATTRINF /* * Read the value according to disk information that was found */ - OR_BUF_INIT2 (buf, disk_data, disk_length); + or_init (&buf, disk_data, disk_length); buf.error_abort = 1; switch (_setjmp (buf.env)) @@ -11565,7 +11565,8 @@ heap_attrinfo_transform_to_disk_internal (THREAD_ENTRY * thread_p, HEAP_CACHE_AT resize_and_start: new_recdes->resize_buffer (expected_size); - OR_BUF_INIT2 (orep, new_recdes->get_data_for_modify (), (int) expected_size); + or_init (&orep, new_recdes->get_data_for_modify (), (int) expected_size); + orep.error_abort = 1; buf = &orep; switch (_setjmp (buf->env)) diff --git a/src/transaction/log_recovery.c b/src/transaction/log_recovery.c index 4c8a6921084..20bd0a20d51 100644 --- a/src/transaction/log_recovery.c +++ b/src/transaction/log_recovery.c @@ -6314,7 +6314,7 @@ log_rv_undoredo_record_partial_changes (THREAD_ENTRY * thread_p, char *rcv_data, assert (record != NULL); /* Prepare buffer. */ - OR_BUF_INIT (rcv_buf, rcv_data, rcv_data_length); + or_init (&rcv_buf, rcv_data, rcv_data_length); return log_rv_undoredo_partial_changes_recursive (thread_p, &rcv_buf, record, is_undo); } diff --git a/win/cubridcs/cubridcs.def b/win/cubridcs/cubridcs.def index bfa4a11699e..0c88c410d63 100644 --- a/win/cubridcs/cubridcs.def +++ b/win/cubridcs/cubridcs.def @@ -410,7 +410,12 @@ EXPORTS msgcat_final msgcat_message net_client_ping_server + ntohs + ntohl ntohi64 + htons + htonl + htoni64 numeric_db_value_print os_set_signal_handler prm_get_master_port_id diff --git a/win/cubridsa/cubridsa.def b/win/cubridsa/cubridsa.def index 55ad97db11e..073fe813ecd 100644 --- a/win/cubridsa/cubridsa.def +++ b/win/cubridsa/cubridsa.def @@ -74,7 +74,12 @@ EXPORTS er_errid_if_has_error fileio_make_volume_info_name locator_has_heap + ntohs + ntohl ntohi64 + htons + htonl + htoni64 numeric_coerce_int_to_num pgbuf_fix_release pgbuf_fix_debug