From a4755675cf39d8a5b15242a32ef50a875ac5936a Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sat, 14 Jan 2023 00:50:25 -0600 Subject: [PATCH] Bugfix: The f_int_128_t is using incorrect size and change f_int_128_t to f_int128_t. The wrong wrapping define macros are being used. - Use __SIZEOF_INT128__ instead of _di_f_int_128_t_. - Use #ifdef instead of #ifndef. Use f_int128_t to more closely match core types like int64_t. --- level_0/f_print/c/print/common.h | 4 ++-- level_0/f_type/c/type.h | 30 +++++++++++++----------------- level_1/fl_print/c/print.h | 6 +++--- level_1/fl_print/c/private-print.c | 4 ++-- 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/level_0/f_print/c/print/common.h b/level_0/f_print/c/print/common.h index 84b42b5..d84329b 100644 --- a/level_0/f_print/c/print/common.h +++ b/level_0/f_print/c/print/common.h @@ -332,7 +332,7 @@ extern "C" { * - signed_16: "ii", "II", Type is a int16_t digit. * - signed_32: "i", "I", Type is a int32_t digit. * - signed_64: "il", "IL", Type is a signed int64_t digit. - * - signed_128: "ill", "ILL", Type is a f_int_128_t digit. + * - signed_128: "ill", "ILL", Type is a f_int128_t digit. * - number: "in", "IN", Type is a f_number_signed_t digit. * - size: "z", "Z", Type is a size_t digit. * - string: "s", Type is a NULL terminated string, where the string is printed as-is. @@ -345,7 +345,7 @@ extern "C" { * - unsigned_16: "ui", "UI", Type is a uint16_t digit. * - unsigned_32: "u", "U", Type is a uint32_t digit. * - unsigned_64: "ul", "UL", Type is a uint64_t digit. - * - unsigned_128: "ull", "ULL", Type is a f_uint_128_t digit. + * - unsigned_128: "ull", "ULL", Type is a f_uint128_t digit. * - unsigned_number: "un", "UN", Type is a f_number_unsigned_t digit (which by default is what f_array_length_t is a type of). * * @see fprintf() diff --git a/level_0/f_type/c/type.h b/level_0/f_type/c/type.h index 9126b30..3e0d7c8 100644 --- a/level_0/f_type/c/type.h +++ b/level_0/f_type/c/type.h @@ -147,15 +147,15 @@ extern "C" { * This should work in GCC, but other compilers this may not be available. * When not supported, these will fallback to 64-bit. */ -#ifndef _di_f_int_128_t_ +#ifndef _di_f_int128_t_ #ifdef __SIZEOF_INT128__ - typedef __int128_t f_int_128_t; - typedef __uint128_t f_uint_128_t; + typedef __int128_t f_int128_t; + typedef __uint128_t f_uint128_t; #else - typedef int64_t f_int_128_t; - typedef uint64_t f_uint_128_t; + typedef int64_t f_int128_t; + typedef uint64_t f_uint128_t; #endif // __SIZEOF_INT128__ -#endif // _di_f_int_128_t_ +#endif // _di_f_int128_t_ /** * Defines the maximum size to be supported. @@ -188,7 +188,7 @@ extern "C" { #define F_type_size_64_positive_d 0x7ffffffffffffffe #define F_type_size_64_unsigned_d 0xfffffffffffffffe - #ifndef _di_f_int_128_t_ + #ifdef __SIZEOF_INT128__ #define F_type_size_128_negative_d 0x7fffffffffffffffffffffff #define F_type_size_128_positive_d 0x7ffffffffffffffffffffffe #define F_type_size_128_unsigned_d 0xfffffffffffffffffffffffe @@ -196,7 +196,7 @@ extern "C" { #define F_type_size_128_negative_d F_type_size_64_negative_d #define F_type_size_128_positive_d F_type_size_64_positive_d #define F_type_size_128_unsigned_d F_type_size_64_unsigned_d - #endif // _di_f_int_128_t_ + #endif // __SIZEOF_INT128__ #define F_type_size_max_8_negative_d 0x80 #define F_type_size_max_8_positive_d 0x7f @@ -214,7 +214,7 @@ extern "C" { #define F_type_size_max_64_positive_d 0x7fffffffffffffff #define F_type_size_max_64_unsigned_d 0xffffffffffffffff - #ifndef _di_f_int_128_t_ + #ifdef __SIZEOF_INT128__ #define F_type_size_max_128_negative_d 0x800000000000000000000000 #define F_type_size_max_128_positive_d 0x7fffffffffffffffffffffff #define F_type_size_max_128_unsigned_d 0xffffffffffffffffffffffff @@ -222,7 +222,7 @@ extern "C" { #define F_type_size_max_128_negative_d F_type_size_max_64_negative_d #define F_type_size_max_128_positive_d F_type_size_max_64_positive_d #define F_type_size_max_128_unsigned_d F_type_size_max_64_unsigned_d - #endif // _di_f_int_128_t_ + #endif // __SIZEOF_INT128__ #endif // _di_f_type_sizes_d_ /** @@ -264,8 +264,8 @@ extern "C" { #define F_number_t_size_max_positive_d F_type_size_max_32_positive_d #define F_number_t_size_max_negative_d F_type_size_max_32_negative_d #elif defined(_en_f_type_number_128_t_) - typedef f_int_128_t f_number_signed_t; - typedef f_uint_128_t f_number_unsigned_t; + typedef f_int128_t f_number_signed_t; + typedef f_uint128_t f_number_unsigned_t; #define f_number_signed_t_initialize 0 #define f_number_unsigned_t_initialize 0 @@ -951,8 +951,7 @@ extern "C" { * * This provides the types without the normal "f_" leading prefixes to be more in line with the core types like int64_t. */ -#ifndef __SIZEOF_INT128__ - +#ifdef __SIZEOF_INT128__ #ifndef _di_f_int128_t_ typedef __int128_t int128_t; #endif // _di_f_int128_t_ @@ -960,9 +959,7 @@ extern "C" { #ifndef _di_f_uint128_t_ typedef __uint128_t uint128_t; #endif // _di_f_uint128_t_ - #else // __SIZEOF_INT128__ - #ifndef _di_f_int128_t_ typedef int64_t int128_t; #endif // _di_f_int128_t_ @@ -970,7 +967,6 @@ extern "C" { #ifndef _di_f_uint128_t_ typedef uint64_t uint128_t; #endif // _di_f_uint128_t_ - #endif // __SIZEOF_INT128__ /** diff --git a/level_1/fl_print/c/print.h b/level_1/fl_print/c/print.h index 2c43059..ba1a581 100644 --- a/level_1/fl_print/c/print.h +++ b/level_1/fl_print/c/print.h @@ -128,8 +128,8 @@ extern "C" { * - "iii" "III": Type is a int8_t digit. * - "ii", "II": Type is a int16_t digit. * - "i", "I": Type is a int32_t digit. - * - "il", "IL": Type is a signed int64_t digit. - * - "ill", "ILL": Type is a f_int_128_t digit. + * - "il", "IL": Type is a int64_t digit. + * - "ill", "ILL": Type is a f_int128_t digit. * - "in", "IN": Type is a f_number_signed_t digit. * - "z", "Z": Type is a size_t digit. * - "s": Type is a NULL terminated string, where the string is printed as-is. @@ -142,7 +142,7 @@ extern "C" { * - "ui", "UI": Type is a uint16_t digit. * - "u", "U": Type is a uint32_t digit. * - "ul", "UL": Type is a uint64_t digit. - * - "ull", "ULL": Type is a f_uint_128_t digit. + * - "ull", "ULL": Type is a f_uint128_t digit. * - "un", "UN": Type is a f_number_unsigned_t digit (which by default is what f_array_length_t is a type of). * * The following are control characters and their replacements for "safe" printing (unknown is used for invalid UTF-8 sequences): diff --git a/level_1/fl_print/c/private-print.c b/level_1/fl_print/c/private-print.c index 29c28dc..c97eab1 100644 --- a/level_1/fl_print/c/private-print.c +++ b/level_1/fl_print/c/private-print.c @@ -1044,7 +1044,7 @@ extern "C" { *status = f_conversion_number_signed_print((f_number_signed_t) va_arg(apl, int64_t), conversion_data, file); } else if (type == f_print_format_type_signed_128_e) { - *status = f_conversion_number_signed_print((f_number_signed_t) va_arg(apl, f_int_128_t), conversion_data, file); + *status = f_conversion_number_signed_print((f_number_signed_t) va_arg(apl, f_int128_t), conversion_data, file); } else if (type == f_print_format_type_signed_number_e) { *status = f_conversion_number_signed_print(va_arg(apl, f_number_signed_t), conversion_data, file); @@ -1069,7 +1069,7 @@ extern "C" { *status = f_conversion_number_unsigned_print((f_number_unsigned_t) va_arg(apl, uint64_t), conversion_data, file); } else if (type == f_print_format_type_unsigned_128_e) { - *status = f_conversion_number_unsigned_print((f_number_unsigned_t) va_arg(apl, f_uint_128_t), conversion_data, file); + *status = f_conversion_number_unsigned_print((f_number_unsigned_t) va_arg(apl, f_uint128_t), conversion_data, file); } else if (type == f_print_format_type_unsigned_number_e) { *status = f_conversion_number_unsigned_print(va_arg(apl, f_number_unsigned_t), conversion_data, file); -- 1.8.3.1