From e7d92600147c1bb1e5160360fde33e744e385544 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Mon, 17 Feb 2020 20:19:25 +0800 Subject: [PATCH] arch: Customize the typedef of size_t instead of intptr_t To ensure size_t same as toolchain definition in the first place and rename CXX_NEWLONG to ARCH_SIZET_LONG. The change also check whether __SIZE_TYPE__ exist before CONFIG_ARCH_SIZET_LONG so our definition can align with toolchain(gcc/clang) definition automatically. --- TODO | 11 ++--- arch/Kconfig | 8 ++++ arch/arm/include/types.h | 21 ++++++++-- arch/avr/include/avr/types.h | 18 +++++++-- arch/avr/include/avr32/types.h | 21 ++++++++-- arch/hc/include/hc12/types.h | 18 +++++++-- arch/hc/include/hcs12/types.h | 18 +++++++-- arch/mips/include/types.h | 21 ++++++++-- arch/misoc/include/types.h | 21 ++++++++-- arch/or1k/include/types.h | 21 ++++++++-- arch/renesas/include/m16c/types.h | 18 +++++++-- arch/renesas/include/rx65n/types.h | 21 ++++++++-- arch/renesas/include/sh1/types.h | 21 ++++++++-- arch/risc-v/include/types.h | 39 +++++++++++++++--- arch/sim/include/types.h | 40 ++++++++++++++++--- arch/x86/include/i486/types.h | 21 ++++++++-- arch/xtensa/include/types.h | 21 ++++++++-- arch/z16/include/types.h | 21 ++++++++-- arch/z80/include/ez80/types.h | 20 +++++++--- arch/z80/include/z180/types.h | 18 +++++++-- arch/z80/include/z8/types.h | 18 +++++++-- arch/z80/include/z80/types.h | 18 +++++++-- boards/arm/moxart/moxa/configs/nsh/defconfig | 1 - boards/arm/sam34/sam3u-ek/README.txt | 2 +- .../arm/sam34/sam3u-ek/configs/nxwm/defconfig | 1 - boards/arm/sam34/sam4e-ek/README.txt | 2 +- boards/arm/sam34/sam4l-xplained/README.txt | 2 +- boards/arm/samd2l2/samd20-xplained/README.txt | 2 +- boards/arm/samd2l2/samd21-xplained/README.txt | 2 +- boards/arm/samd2l2/saml21-xplained/README.txt | 2 +- boards/arm/stm32/stm3240g-eval/README.txt | 4 +- .../stm3240g-eval/configs/knxwm/defconfig | 1 - boards/sim/sim/sim/configs/cxxtest/defconfig | 1 - boards/sim/sim/sim/configs/nsh2/defconfig | 1 - boards/sim/sim/sim/configs/nxlines/defconfig | 1 - boards/sim/sim/sim/configs/nxwm/defconfig | 1 - include/stdint.h | 10 +++-- include/sys/types.h | 10 ++--- libs/libxx/Kconfig | 8 ---- libs/libxx/libxx_delete.cxx | 2 +- libs/libxx/libxx_delete_sized.cxx | 9 ++--- libs/libxx/libxx_deletea.cxx | 2 +- libs/libxx/libxx_deletea_sized.cxx | 9 ++--- libs/libxx/libxx_new.cxx | 9 +---- libs/libxx/libxx_newa.cxx | 9 +---- tools/testbuild.sh | 4 +- 46 files changed, 413 insertions(+), 136 deletions(-) diff --git a/TODO b/TODO index 029a46fa75..779a2be2fa 100644 --- a/TODO +++ b/TODO @@ -1164,11 +1164,12 @@ o C++ Support that size_t is of a different type resulting in compilation errors in the operator. Using the underlying integer type Instead of size_t seems to resolve the compilation issues. - Status: Kind of open. There is a workaround. Setting CONFIG_CXX_NEWLONG=y - will define the operators with argument of type unsigned long; - Setting CONFIG_CXX_NEWLONG=n will define the operators with argument - of type unsigned int. But this is pretty ugly! A better solution - would be to get a hold of the compilers definition of size_t. + Status: Kind of open. There is a workaround. Setting CONFIG_ARCH_SIZET_LONG + =y will define the operators with argument of type unsigned long; + Setting CONFIG_ARCH_SIZET_LONG=n will define the operators with + argument of type unsigned int. But this is pretty ugly! A better + solution would be to get a hold of the compilers definition of + size_t. Priority: Low. Title: STATIC CONSTRUCTORS AND MULTITASKING diff --git a/arch/Kconfig b/arch/Kconfig index 7f97c835cd..a37637faa1 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -156,6 +156,14 @@ config ARCH_GNU_NO_WEAKFUNCTIONS ---help--- Disable support for weak functions. +config ARCH_SIZET_LONG + bool "size_t is type long" + default n + ---help--- + size_t may be type long or type int. This matters for some + C++ library routines because the NuttX size_t might not have + the same underlying type as your toolchain's size_t. + comment "Architecture Options" config ARCH_NOINTC diff --git a/arch/arm/include/types.h b/arch/arm/include/types.h index ea0675d0e9..4991ca2b58 100644 --- a/arch/arm/include/types.h +++ b/arch/arm/include/types.h @@ -78,10 +78,25 @@ typedef signed long long _int64_t; typedef unsigned long long _uint64_t; #define __INT64_DEFINED -/* A pointer is 4 bytes */ +/* A size is 4 bytes */ -typedef signed int _intptr_t; -typedef unsigned int _uintptr_t; +#if defined(__SIZE_TYPE__) +/* If __SIZE_TYPE__ is defined we define ssize_t based on size_t. + * We simply change "unsigned" to "signed" for this single definition + * to make sure ssize_t and size_t only differ by their signedness. + */ + +#define unsigned signed +typedef __SIZE_TYPE__ _ssize_t; +#undef unsigned +typedef __SIZE_TYPE__ _size_t; +#elif defined(CONFIG_ARCH_SIZET_LONG) +typedef signed long _ssize_t; +typedef unsigned long _size_t; +#else +typedef signed int _ssize_t; +typedef unsigned int _size_t; +#endif /* This is the size of the interrupt state save returned by up_irq_save(). For * ARM, a 32 register value is returned, for the thumb2, Cortex-M3, the 16-bit diff --git a/arch/avr/include/avr/types.h b/arch/avr/include/avr/types.h index 23c7637393..b9db44ee60 100644 --- a/arch/avr/include/avr/types.h +++ b/arch/avr/include/avr/types.h @@ -76,10 +76,22 @@ typedef signed long long _int64_t; /* long long is 64-bits */ typedef unsigned long long _uint64_t; #define __INT64_DEFINED -/* A (near) pointer is 2 bytes */ +/* A (near) size is 2 bytes */ -typedef signed int _intptr_t; -typedef unsigned int _uintptr_t; +#if defined(__SIZE_TYPE__) +/* If __SIZE_TYPE__ is defined we define ssize_t based on size_t. + * We simply change "unsigned" to "signed" for this single definition + * to make sure ssize_t and size_t only differ by their signedness. + */ + +#define unsigned signed +typedef __SIZE_TYPE__ _ssize_t; +#undef unsigned +typedef __SIZE_TYPE__ _size_t; +#else +typedef signed int _ssize_t; +typedef unsigned int _size_t; +#endif /* A FAR pointer is 4 bytes */ diff --git a/arch/avr/include/avr32/types.h b/arch/avr/include/avr32/types.h index 95823ec48d..e0202167cd 100644 --- a/arch/avr/include/avr32/types.h +++ b/arch/avr/include/avr32/types.h @@ -76,10 +76,25 @@ typedef signed long long _int64_t; typedef unsigned long long _uint64_t; #define __INT64_DEFINED -/* A pointer is 4 bytes */ +/* A size is 4 bytes */ -typedef signed int _intptr_t; -typedef unsigned int _uintptr_t; +#if defined(__SIZE_TYPE__) +/* If __SIZE_TYPE__ is defined we define ssize_t based on size_t. + * We simply change "unsigned" to "signed" for this single definition + * to make sure ssize_t and size_t only differ by their signedness. + */ + +#define unsigned signed +typedef __SIZE_TYPE__ _ssize_t; +#undef unsigned +typedef __SIZE_TYPE__ _size_t; +#elif defined(CONFIG_ARCH_SIZET_LONG) +typedef signed long _ssize_t; +typedef unsigned long _size_t; +#else +typedef signed int _ssize_t; +typedef unsigned int _size_t; +#endif /* This is the size of the interrupt state save returned by up_irq_save(). */ diff --git a/arch/hc/include/hc12/types.h b/arch/hc/include/hc12/types.h index bfc4993541..3787eaf935 100644 --- a/arch/hc/include/hc12/types.h +++ b/arch/hc/include/hc12/types.h @@ -85,10 +85,22 @@ typedef signed long long _int64_t; typedef unsigned long long _uint64_t; #define __INT64_DEFINED -/* A pointer is two bytes */ +/* A size is two bytes */ -typedef signed short _intptr_t; -typedef unsigned short _uintptr_t; +#if defined(__SIZE_TYPE__) +/* If __SIZE_TYPE__ is defined we define ssize_t based on size_t. + * We simply change "unsigned" to "signed" for this single definition + * to make sure ssize_t and size_t only differ by their signedness. + */ + +#define unsigned signed +typedef __SIZE_TYPE__ _ssize_t; +#undef unsigned +typedef __SIZE_TYPE__ _size_t; +#else +typedef signed short _ssize_t; +typedef unsigned short _size_t; +#endif /* This is the size of the interrupt state save returned by up_irq_save()*/ diff --git a/arch/hc/include/hcs12/types.h b/arch/hc/include/hcs12/types.h index 87762c2040..96823e4f11 100644 --- a/arch/hc/include/hcs12/types.h +++ b/arch/hc/include/hcs12/types.h @@ -86,10 +86,22 @@ typedef signed long long _int64_t; typedef unsigned long long _uint64_t; #define __INT64_DEFINED -/* A pointer is two bytes */ +/* A size is two bytes */ -typedef signed short _intptr_t; -typedef unsigned short _uintptr_t; +#if defined(__SIZE_TYPE__) +/* If __SIZE_TYPE__ is defined we define ssize_t based on size_t. + * We simply change "unsigned" to "signed" for this single definition + * to make sure ssize_t and size_t only differ by their signedness. + */ + +#define unsigned signed +typedef __SIZE_TYPE__ _ssize_t; +#undef unsigned +typedef __SIZE_TYPE__ _size_t; +#else +typedef signed short _ssize_t; +typedef unsigned short _size_t; +#endif /* This is the size of the interrupt state save returned by up_irq_save()*/ diff --git a/arch/mips/include/types.h b/arch/mips/include/types.h index 26ee3434ef..c0decbdc71 100644 --- a/arch/mips/include/types.h +++ b/arch/mips/include/types.h @@ -76,10 +76,25 @@ typedef signed long long _int64_t; typedef unsigned long long _uint64_t; #define __INT64_DEFINED -/* A pointer is 4 bytes */ +/* A size is 4 bytes */ -typedef signed int _intptr_t; -typedef unsigned int _uintptr_t; +#if defined(__SIZE_TYPE__) +/* If __SIZE_TYPE__ is defined we define ssize_t based on size_t. + * We simply change "unsigned" to "signed" for this single definition + * to make sure ssize_t and size_t only differ by their signedness. + */ + +#define unsigned signed +typedef __SIZE_TYPE__ _ssize_t; +#undef unsigned +typedef __SIZE_TYPE__ _size_t; +#elif defined(CONFIG_ARCH_SIZET_LONG) +typedef signed long _ssize_t; +typedef unsigned long _size_t; +#else +typedef signed int _ssize_t; +typedef unsigned int _size_t; +#endif /* This is the size of the interrupt state save returned by up_irq_save(). */ diff --git a/arch/misoc/include/types.h b/arch/misoc/include/types.h index f63ab15f19..e98bbf2167 100644 --- a/arch/misoc/include/types.h +++ b/arch/misoc/include/types.h @@ -76,10 +76,25 @@ typedef signed long long _int64_t; typedef unsigned long long _uint64_t; #define __INT64_DEFINED -/* A pointer is 4 bytes */ +/* A size is 4 bytes */ -typedef signed int _intptr_t; -typedef unsigned int _uintptr_t; +#if defined(__SIZE_TYPE__) +/* If __SIZE_TYPE__ is defined we define ssize_t based on size_t. + * We simply change "unsigned" to "signed" for this single definition + * to make sure ssize_t and size_t only differ by their signedness. + */ + +#define unsigned signed +typedef __SIZE_TYPE__ _ssize_t; +#undef unsigned +typedef __SIZE_TYPE__ _size_t; +#elif defined(CONFIG_ARCH_SIZET_LONG) +typedef signed long _ssize_t; +typedef unsigned long _size_t; +#else +typedef signed int _ssize_t; +typedef unsigned int _size_t; +#endif /* This is the size of the interrupt state save returned by up_irq_save(). */ diff --git a/arch/or1k/include/types.h b/arch/or1k/include/types.h index f7aee6f71f..61df12d133 100644 --- a/arch/or1k/include/types.h +++ b/arch/or1k/include/types.h @@ -79,10 +79,25 @@ typedef unsigned long long _uint64_t; #define __INT64_DEFINED 1 -/* A pointer is 4 bytes */ +/* A size is 4 bytes */ -typedef signed int _intptr_t; -typedef unsigned int _uintptr_t; +#if defined(__SIZE_TYPE__) +/* If __SIZE_TYPE__ is defined we define ssize_t based on size_t. + * We simply change "unsigned" to "signed" for this single definition + * to make sure ssize_t and size_t only differ by their signedness. + */ + +#define unsigned signed +typedef __SIZE_TYPE__ _ssize_t; +#undef unsigned +typedef __SIZE_TYPE__ _size_t; +#elif defined(CONFIG_ARCH_SIZET_LONG) +typedef signed long _ssize_t; +typedef unsigned long _size_t; +#else +typedef signed int _ssize_t; +typedef unsigned int _size_t; +#endif /* This is the size of the interrupt state save returned by up_irq_save(). */ diff --git a/arch/renesas/include/m16c/types.h b/arch/renesas/include/m16c/types.h index 8eb3528833..53a6bfa14b 100644 --- a/arch/renesas/include/m16c/types.h +++ b/arch/renesas/include/m16c/types.h @@ -78,10 +78,22 @@ typedef signed long long _int64_t; typedef unsigned long long _uint64_t; #define __INT64_DEFINED -/* A pointer is 2 bytes */ +/* A size is 2 bytes */ -typedef signed int _intptr_t; -typedef unsigned int _uintptr_t; +#if defined(__SIZE_TYPE__) +/* If __SIZE_TYPE__ is defined we define ssize_t based on size_t. + * We simply change "unsigned" to "signed" for this single definition + * to make sure ssize_t and size_t only differ by their signedness. + */ + +#define unsigned signed +typedef __SIZE_TYPE__ _ssize_t; +#undef unsigned +typedef __SIZE_TYPE__ _size_t; +#else +typedef signed int _ssize_t; +typedef unsigned int _size_t; +#endif /* This is the size of the interrupt state save returned by * up_irq_save() diff --git a/arch/renesas/include/rx65n/types.h b/arch/renesas/include/rx65n/types.h index 5848183c91..39215d7f3d 100644 --- a/arch/renesas/include/rx65n/types.h +++ b/arch/renesas/include/rx65n/types.h @@ -76,10 +76,25 @@ typedef signed long long _int64_t; typedef unsigned long long _uint64_t; #define __INT64_DEFINED -/* A pointer is 4 bytes */ +/* A size is 4 bytes */ -typedef signed int _intptr_t; -typedef unsigned int _uintptr_t; +#if defined(__SIZE_TYPE__) +/* If __SIZE_TYPE__ is defined we define ssize_t based on size_t. + * We simply change "unsigned" to "signed" for this single definition + * to make sure ssize_t and size_t only differ by their signedness. + */ + +#define unsigned signed +typedef __SIZE_TYPE__ _ssize_t; +#undef unsigned +typedef __SIZE_TYPE__ _size_t; +#elif defined(CONFIG_ARCH_SIZET_LONG) +typedef signed long _ssize_t; +typedef unsigned long _size_t; +#else +typedef signed int _ssize_t; +typedef unsigned int _size_t; +#endif /* This is the size of the interrupt state save returned by * up_irq_save() diff --git a/arch/renesas/include/sh1/types.h b/arch/renesas/include/sh1/types.h index 86d7b5b9bb..fbb7e75989 100644 --- a/arch/renesas/include/sh1/types.h +++ b/arch/renesas/include/sh1/types.h @@ -76,10 +76,25 @@ typedef signed long long _int64_t; typedef unsigned long long _uint64_t; #define __INT64_DEFINED -/* A pointer is 4 bytes */ +/* A size is 4 bytes */ -typedef signed int _intptr_t; -typedef unsigned int _uintptr_t; +#if defined(__SIZE_TYPE__) +/* If __SIZE_TYPE__ is defined we define ssize_t based on size_t. + * We simply change "unsigned" to "signed" for this single definition + * to make sure ssize_t and size_t only differ by their signedness. + */ + +#define unsigned signed +typedef __SIZE_TYPE__ _ssize_t; +#undef unsigned +typedef __SIZE_TYPE__ _size_t; +#elif defined(CONFIG_ARCH_SIZET_LONG) +typedef signed long _ssize_t; +typedef unsigned long _size_t; +#else +typedef signed int _ssize_t; +typedef unsigned int _size_t; +#endif /* This is the size of the interrupt state save returned by * up_irq_save() diff --git a/arch/risc-v/include/types.h b/arch/risc-v/include/types.h index 8c0df57a54..da0e5db656 100644 --- a/arch/risc-v/include/types.h +++ b/arch/risc-v/include/types.h @@ -77,19 +77,46 @@ typedef unsigned long long _uint64_t; #define __INT64_DEFINED #ifdef __LP64__ -/* A pointer is 8 bytes */ +/* A size is 8 bytes */ -typedef signed long _intptr_t; -typedef unsigned long _uintptr_t; +#if defined(__SIZE_TYPE__) +/* If __SIZE_TYPE__ is defined we define ssize_t based on size_t. + * We simply change "unsigned" to "signed" for this single definition + * to make sure ssize_t and size_t only differ by their signedness. + */ + +#define unsigned signed +typedef __SIZE_TYPE__ _ssize_t; +#undef unsigned +typedef __SIZE_TYPE__ _size_t; +#else +typedef signed long _ssize_t; +typedef unsigned long _size_t; +#endif /* This is the size of the interrupt state save returned by irqsave(). */ typedef unsigned long long irqstate_t; #else -/* A pointer is 4 bytes */ +/* A size is 4 bytes */ -typedef signed int _intptr_t; -typedef unsigned int _uintptr_t; +#if defined(__SIZE_TYPE__) +/* If __SIZE_TYPE__ is defined we define ssize_t based on size_t. + * We simply change "unsigned" to "signed" for this single definition + * to make sure ssize_t and size_t only differ by their signedness. + */ + +#define unsigned signed +typedef __SIZE_TYPE__ _ssize_t; +#undef unsigned +typedef __SIZE_TYPE__ _size_t; +#elif defined(CONFIG_ARCH_SIZET_LONG) +typedef signed long _ssize_t; +typedef unsigned long _size_t; +#else +typedef signed int _ssize_t; +typedef unsigned int _size_t; +#endif /* This is the size of the interrupt state save returned by irqsave(). */ diff --git a/arch/sim/include/types.h b/arch/sim/include/types.h index 83669eac3e..e5d2a856af 100644 --- a/arch/sim/include/types.h +++ b/arch/sim/include/types.h @@ -77,16 +77,44 @@ typedef unsigned long long _uint64_t; #define __INT64_DEFINED #if defined(CONFIG_HOST_X86_64) && !defined(CONFIG_SIM_M32) -/* 64-bit build on 64-bit machine: A pointer is 8 bytes */ +/* 64-bit build on 64-bit machine: A size is 8 bytes */ -typedef signed long long _intptr_t; -typedef unsigned long long _uintptr_t; +#if defined(__SIZE_TYPE__) +/* If __SIZE_TYPE__ is defined we define ssize_t based on size_t. + * We simply change "unsigned" to "signed" for this single definition + * to make sure ssize_t and size_t only differ by their signedness. + */ + +#define unsigned signed +typedef __SIZE_TYPE__ _ssize_t; +#undef unsigned +typedef __SIZE_TYPE__ _size_t; +#else +typedef signed long long _ssize_t; +typedef unsigned long long _size_t; +#endif #else -/* 32-bit build on 32- or 64-bit machine: A pointer is 4 bytes */ +/* 32-bit build on 32- or 64-bit machine: A size is 4 bytes */ + +#if defined(__SIZE_TYPE__) +/* If __SIZE_TYPE__ is defined we define ssize_t based on size_t. + * We simply change "unsigned" to "signed" for this single definition + * to make sure ssize_t and size_t only differ by their signedness. + */ + +#define unsigned signed +typedef __SIZE_TYPE__ _ssize_t; +#undef unsigned +typedef __SIZE_TYPE__ _size_t; +#elif defined(CONFIG_ARCH_SIZET_LONG) +typedef signed long _ssize_t; +typedef unsigned long _size_t; +#else +typedef signed int _ssize_t; +typedef unsigned int _size_t; +#endif -typedef signed int _intptr_t; -typedef unsigned int _uintptr_t; #endif /* This is the size of the interrupt state save returned by diff --git a/arch/x86/include/i486/types.h b/arch/x86/include/i486/types.h index 5e1f2ced31..ab91056827 100644 --- a/arch/x86/include/i486/types.h +++ b/arch/x86/include/i486/types.h @@ -77,10 +77,25 @@ typedef signed long long _int64_t; typedef unsigned long long _uint64_t; #define __INT64_DEFINED -/* A pointer is 4 bytes */ +/* A size is 4 bytes */ -typedef signed int _intptr_t; -typedef unsigned int _uintptr_t; +#if defined(__SIZE_TYPE__) +/* If __SIZE_TYPE__ is defined we define ssize_t based on size_t. + * We simply change "unsigned" to "signed" for this single definition + * to make sure ssize_t and size_t only differ by their signedness. + */ + +#define unsigned signed +typedef __SIZE_TYPE__ _ssize_t; +#undef unsigned +typedef __SIZE_TYPE__ _size_t; +#elif defined(CONFIG_ARCH_SIZET_LONG) +typedef signed long _ssize_t; +typedef unsigned long _size_t; +#else +typedef signed int _ssize_t; +typedef unsigned int _size_t; +#endif /* This is the size of the interrupt state save returned by * up_irq_save() diff --git a/arch/xtensa/include/types.h b/arch/xtensa/include/types.h index 55d2fee188..e668aec38e 100644 --- a/arch/xtensa/include/types.h +++ b/arch/xtensa/include/types.h @@ -76,10 +76,25 @@ typedef signed long long _int64_t; typedef unsigned long long _uint64_t; #define __INT64_DEFINED -/* A pointer is 4 bytes */ +/* A size is 4 bytes */ -typedef signed long _intptr_t; -typedef unsigned long _uintptr_t; +#if defined(__SIZE_TYPE__) +/* If __SIZE_TYPE__ is defined we define ssize_t based on size_t. + * We simply change "unsigned" to "signed" for this single definition + * to make sure ssize_t and size_t only differ by their signedness. + */ + +#define unsigned signed +typedef __SIZE_TYPE__ _ssize_t; +#undef unsigned +typedef __SIZE_TYPE__ _size_t; +#elif defined(CONFIG_ARCH_SIZET_LONG) +typedef signed long _ssize_t; +typedef unsigned long _size_t; +#else +typedef signed int _ssize_t; +typedef unsigned int _size_t; +#endif /* This is the size of the interrupt state save returned by up_irq_save(). */ diff --git a/arch/z16/include/types.h b/arch/z16/include/types.h index cafeeb4c28..6c7886824e 100644 --- a/arch/z16/include/types.h +++ b/arch/z16/include/types.h @@ -72,10 +72,25 @@ typedef unsigned short _uint16_t; typedef signed int _int32_t; typedef unsigned int _uint32_t; -/* A pointer is 4 bytes */ +/* A size is 4 bytes */ -typedef signed int _intptr_t; -typedef unsigned int _uintptr_t; +#if defined(__SIZE_TYPE__) +/* If __SIZE_TYPE__ is defined we define ssize_t based on size_t. + * We simply change "unsigned" to "signed" for this single definition + * to make sure ssize_t and size_t only differ by their signedness. + */ + +#define unsigned signed +typedef __SIZE_TYPE__ _ssize_t; +#undef unsigned +typedef __SIZE_TYPE__ _size_t; +#elif defined(CONFIG_ARCH_SIZET_LONG) +typedef signed long _ssize_t; +typedef unsigned long _size_t; +#else +typedef signed int _ssize_t; +typedef unsigned int _size_t; +#endif /* This is the size of the interrupt state save returned by * up_irq_save() diff --git a/arch/z80/include/ez80/types.h b/arch/z80/include/ez80/types.h index 21f256d6ef..ef2e883268 100644 --- a/arch/z80/include/ez80/types.h +++ b/arch/z80/include/ez80/types.h @@ -91,12 +91,22 @@ typedef unsigned long _uint32_t; * ADL mode - 24 bits */ -#ifdef CONFIG_EZ80_Z80MODE -typedef signed short _intptr_t; -typedef unsigned short _uintptr_t; +#if defined(__SIZE_TYPE__) +/* If __SIZE_TYPE__ is defined we define ssize_t based on size_t. + * We simply change "unsigned" to "signed" for this single definition + * to make sure ssize_t and size_t only differ by their signedness. + */ + +#define unsigned signed +typedef __SIZE_TYPE__ _ssize_t; +#undef unsigned +typedef __SIZE_TYPE__ _size_t; +#elif defined(CONFIG_EZ80_Z80MODE) +typedef signed short _ssize_t; +typedef unsigned short _size_t; #else -typedef signed int _intptr_t; -typedef unsigned int _uintptr_t; +typedef signed int _ssize_t; +typedef unsigned int _size_t; #endif /* This is the size of the interrupt state save returned by up_irq_save(). diff --git a/arch/z80/include/z180/types.h b/arch/z80/include/z180/types.h index 0e723b333a..d6a8b4d579 100644 --- a/arch/z80/include/z180/types.h +++ b/arch/z80/include/z180/types.h @@ -84,10 +84,22 @@ typedef signed long long _int64_t; typedef unsigned long long _uint64_t; #define __INT64_DEFINED -/* A pointer is 2 bytes */ +/* A size is 2 bytes */ -typedef signed int _intptr_t; -typedef unsigned int _uintptr_t; +#if defined(__SIZE_TYPE__) +/* If __SIZE_TYPE__ is defined we define ssize_t based on size_t. + * We simply change "unsigned" to "signed" for this single definition + * to make sure ssize_t and size_t only differ by their signedness. + */ + +#define unsigned signed +typedef __SIZE_TYPE__ _ssize_t; +#undef unsigned +typedef __SIZE_TYPE__ _size_t; +#else +typedef signed int _ssize_t; +typedef unsigned int _size_t; +#endif /* This is the size of the interrupt state save returned by up_irq_save() */ diff --git a/arch/z80/include/z8/types.h b/arch/z80/include/z8/types.h index 01e642cc6d..da5642da68 100644 --- a/arch/z80/include/z8/types.h +++ b/arch/z80/include/z8/types.h @@ -87,10 +87,22 @@ typedef unsigned int _uint16_t; typedef signed long _int32_t; typedef unsigned long _uint32_t; -/* A pointer is 2 bytes */ +/* A size is 2 bytes */ -typedef signed int _intptr_t; -typedef unsigned int _uintptr_t; +#if defined(__SIZE_TYPE__) +/* If __SIZE_TYPE__ is defined we define ssize_t based on size_t. + * We simply change "unsigned" to "signed" for this single definition + * to make sure ssize_t and size_t only differ by their signedness. + */ + +#define unsigned signed +typedef __SIZE_TYPE__ _ssize_t; +#undef unsigned +typedef __SIZE_TYPE__ _size_t; +#else +typedef signed int _ssize_t; +typedef unsigned int _size_t; +#endif /* This is the size of the interrupt state save returned by up_irq_save() */ diff --git a/arch/z80/include/z80/types.h b/arch/z80/include/z80/types.h index eece6f1f24..d6dee9b828 100644 --- a/arch/z80/include/z80/types.h +++ b/arch/z80/include/z80/types.h @@ -84,10 +84,22 @@ typedef signed long long _int64_t; typedef unsigned long long _uint64_t; #define __INT64_DEFINED -/* A pointer is 2 bytes */ +/* A size is 2 bytes */ -typedef signed int _intptr_t; -typedef unsigned int _uintptr_t; +#if defined(__SIZE_TYPE__) +/* If __SIZE_TYPE__ is defined we define ssize_t based on size_t. + * We simply change "unsigned" to "signed" for this single definition + * to make sure ssize_t and size_t only differ by their signedness. + */ + +#define unsigned signed +typedef __SIZE_TYPE__ _ssize_t; +#undef unsigned +typedef __SIZE_TYPE__ _size_t; +#else +typedef signed int _ssize_t; +typedef unsigned int _size_t; +#endif /* This is the size of the interrupt state save returned by up_irq_save() */ diff --git a/boards/arm/moxart/moxa/configs/nsh/defconfig b/boards/arm/moxart/moxa/configs/nsh/defconfig index 506993d9ca..da7979053a 100644 --- a/boards/arm/moxart/moxa/configs/nsh/defconfig +++ b/boards/arm/moxart/moxa/configs/nsh/defconfig @@ -48,7 +48,6 @@ CONFIG_BOARD_LATE_INITIALIZE=y CONFIG_BOARD_LOOPSPERMSEC=6965 CONFIG_BOOT_RUNFROMISRAM=y CONFIG_BUILTIN=y -CONFIG_CXX_NEWLONG=y CONFIG_DEFAULT_SMALL=y CONFIG_FS_BINFS=y CONFIG_FS_ROMFS=y diff --git a/boards/arm/sam34/sam3u-ek/README.txt b/boards/arm/sam34/sam3u-ek/README.txt index 25171a216a..774b888327 100644 --- a/boards/arm/sam34/sam3u-ek/README.txt +++ b/boards/arm/sam34/sam3u-ek/README.txt @@ -261,7 +261,7 @@ Configurations CONFIG_ARMV7M_TOOLCHAIN_GNU_EABIW=y : General GCC EABI toolchain under windows Library Routines -> - CONFIG_CXX_NEWLONG=n : size_t is an unsigned int, not long + CONFIG_ARCH_SIZET_LONG=n : size_t is an unsigned int, not long This re-configuration should be done before making NuttX or else the subsequent 'make' will fail. If you have already attempted building diff --git a/boards/arm/sam34/sam3u-ek/configs/nxwm/defconfig b/boards/arm/sam34/sam3u-ek/configs/nxwm/defconfig index 096fe5d8a8..cebc4926c9 100644 --- a/boards/arm/sam34/sam3u-ek/configs/nxwm/defconfig +++ b/boards/arm/sam34/sam3u-ek/configs/nxwm/defconfig @@ -27,7 +27,6 @@ CONFIG_ARCH_STACKDUMP=y CONFIG_ARMV7M_OABI_TOOLCHAIN=y CONFIG_ARMV7M_TOOLCHAIN_BUILDROOT=y CONFIG_BOARD_LOOPSPERMSEC=8720 -CONFIG_CXX_NEWLONG=y CONFIG_HAVE_CXX=y CONFIG_HAVE_CXXINITIALIZE=y CONFIG_INPUT=y diff --git a/boards/arm/sam34/sam4e-ek/README.txt b/boards/arm/sam34/sam4e-ek/README.txt index 404237b0a0..c3fc3c928a 100644 --- a/boards/arm/sam34/sam4e-ek/README.txt +++ b/boards/arm/sam34/sam4e-ek/README.txt @@ -1074,7 +1074,7 @@ Configurations CONFIG_ARMV7M_TOOLCHAIN_GNU_EABIW=y : General GCC EABI toolchain under windows Library Routines -> - CONFIG_CXX_NEWLONG=n : size_t is an unsigned int, not long + CONFIG_ARCH_SIZET_LONG=n : size_t is an unsigned int, not long This re-configuration should be done before making NuttX or else the subsequent 'make' will fail. If you have already attempted building diff --git a/boards/arm/sam34/sam4l-xplained/README.txt b/boards/arm/sam34/sam4l-xplained/README.txt index e4d75b675e..1fb71b6984 100644 --- a/boards/arm/sam34/sam4l-xplained/README.txt +++ b/boards/arm/sam34/sam4l-xplained/README.txt @@ -490,7 +490,7 @@ Configuration sub-directories Sometimes NuttX and your toolchain will disagree on the underlying type of size_t; sometimes it is an 'unsigned int' and sometimes it is an 'unsigned long int'. If this error occurs, then you may need to - toggle the value of CONFIG_CXX_NEWLONG. + toggle the value of CONFIG_ARCH_SIZET_LONG. 2. If the I/O1 module is connected to the SAM4L Xplained Pro, then support for the SD card slot can be enabled by making the following diff --git a/boards/arm/samd2l2/samd20-xplained/README.txt b/boards/arm/samd2l2/samd20-xplained/README.txt index 5934d4776d..6fcd0e75b6 100644 --- a/boards/arm/samd2l2/samd20-xplained/README.txt +++ b/boards/arm/samd2l2/samd20-xplained/README.txt @@ -721,7 +721,7 @@ Configuration sub-directories Sometimes NuttX and your toolchain will disagree on the underlying type of size_t; sometimes it is an 'unsigned int' and sometimes it is an 'unsigned long int'. If this error occurs, then you may need to - toggle the value of CONFIG_CXX_NEWLONG. + toggle the value of CONFIG_ARCH_SIZET_LONG. 4. If the I/O1 module is connected to the SAMD20 Xplained Pro, then support for the SD card slot can be enabled by making the following diff --git a/boards/arm/samd2l2/samd21-xplained/README.txt b/boards/arm/samd2l2/samd21-xplained/README.txt index 8ef73308df..d5405b67cc 100644 --- a/boards/arm/samd2l2/samd21-xplained/README.txt +++ b/boards/arm/samd2l2/samd21-xplained/README.txt @@ -588,7 +588,7 @@ Configuration sub-directories Sometimes NuttX and your toolchain will disagree on the underlying type of size_t; sometimes it is an 'unsigned int' and sometimes it is an 'unsigned long int'. If this error occurs, then you may need to - toggle the value of CONFIG_CXX_NEWLONG. + toggle the value of CONFIG_ARCH_SIZET_LONG. 4. If the I/O1 module is connected to the SAMD21 Xplained Pro, then support for the SD card slot can be enabled by making the following diff --git a/boards/arm/samd2l2/saml21-xplained/README.txt b/boards/arm/samd2l2/saml21-xplained/README.txt index 01257c894d..b5994ff2de 100644 --- a/boards/arm/samd2l2/saml21-xplained/README.txt +++ b/boards/arm/samd2l2/saml21-xplained/README.txt @@ -750,7 +750,7 @@ Configuration sub-directories Sometimes NuttX and your toolchain will disagree on the underlying type of size_t; sometimes it is an 'unsigned int' and sometimes it is an 'unsigned long int'. If this error occurs, then you may need to - toggle the value of CONFIG_CXX_NEWLONG. + toggle the value of CONFIG_ARCH_SIZET_LONG. 4. WARNING: This info comes from the SAMD20 Xplained README. I have not tried the I/O1 module on the SAML21! diff --git a/boards/arm/stm32/stm3240g-eval/README.txt b/boards/arm/stm32/stm3240g-eval/README.txt index 9ab1f6f56b..05efcc0387 100644 --- a/boards/arm/stm32/stm3240g-eval/README.txt +++ b/boards/arm/stm32/stm3240g-eval/README.txt @@ -753,7 +753,7 @@ Where is one of the following: CONFIG_HOST_WINDOWS=y : Windows CONFIG_WINDOWS_CYGWIN=y : Cygwin environment on Windows CONFIG_ARMV7M_TOOLCHAIN_BUILDROOT=y : NuttX EABI buildroot toolchain - CONFIG_CXX_NEWLONG=y : size_t is long (maybe?) + CONFIG_ARCH_SIZET_LONG=y : size_t is long (maybe?) This is easily changed by modifying the configuration. @@ -764,7 +764,7 @@ Where is one of the following: can try for yourself setting: CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYW=y : CodeSourcery under Windows - CONFIG_CXX_NEWLONG=n : size_t is unsigned int (maybe?) + CONFIG_ARCH_SIZET_LONG=n : size_t is unsigned int (maybe?) 3. In addition to the protected mode build, this NxWM configuration differences from the nxwm configuration in that: diff --git a/boards/arm/stm32/stm3240g-eval/configs/knxwm/defconfig b/boards/arm/stm32/stm3240g-eval/configs/knxwm/defconfig index 8022eb2c1c..58d5dae6bc 100644 --- a/boards/arm/stm32/stm3240g-eval/configs/knxwm/defconfig +++ b/boards/arm/stm32/stm3240g-eval/configs/knxwm/defconfig @@ -23,7 +23,6 @@ CONFIG_ARMV7M_TOOLCHAIN_BUILDROOT=y CONFIG_ARM_MPU=y CONFIG_BOARD_LOOPSPERMSEC=16717 CONFIG_BUILD_PROTECTED=y -CONFIG_CXX_NEWLONG=y CONFIG_FAT_LCNAMES=y CONFIG_FAT_LFN=y CONFIG_FS_FAT=y diff --git a/boards/sim/sim/sim/configs/cxxtest/defconfig b/boards/sim/sim/sim/configs/cxxtest/defconfig index e2a392be25..1542b10965 100644 --- a/boards/sim/sim/sim/configs/cxxtest/defconfig +++ b/boards/sim/sim/sim/configs/cxxtest/defconfig @@ -12,7 +12,6 @@ CONFIG_ARCH_BOARD_SIM=y CONFIG_ARCH_CHIP="sim" CONFIG_ARCH_SIM=y CONFIG_BOARD_LOOPSPERMSEC=100 -CONFIG_CXX_NEWLONG=y CONFIG_HAVE_CXX=y CONFIG_IDLETHREAD_STACKSIZE=4096 CONFIG_LIBM=y diff --git a/boards/sim/sim/sim/configs/nsh2/defconfig b/boards/sim/sim/sim/configs/nsh2/defconfig index dd1b1f52eb..5c16b7afdd 100644 --- a/boards/sim/sim/sim/configs/nsh2/defconfig +++ b/boards/sim/sim/sim/configs/nsh2/defconfig @@ -14,7 +14,6 @@ CONFIG_ARCH_BOARD_SIM=y CONFIG_ARCH_CHIP="sim" CONFIG_ARCH_SIM=y CONFIG_BUILTIN=y -CONFIG_CXX_NEWLONG=y CONFIG_DEBUG_SYMBOLS=y CONFIG_DISABLE_POSIX_TIMERS=y CONFIG_EXAMPLES_NX=y diff --git a/boards/sim/sim/sim/configs/nxlines/defconfig b/boards/sim/sim/sim/configs/nxlines/defconfig index f7ff39f9cf..9218689c98 100644 --- a/boards/sim/sim/sim/configs/nxlines/defconfig +++ b/boards/sim/sim/sim/configs/nxlines/defconfig @@ -15,7 +15,6 @@ CONFIG_ARCH_BOARD_SIM=y CONFIG_ARCH_CHIP="sim" CONFIG_ARCH_SIM=y CONFIG_BOARD_LOOPSPERMSEC=0 -CONFIG_CXX_NEWLONG=y CONFIG_DEBUG_SYMBOLS=y CONFIG_DISABLE_POSIX_TIMERS=y CONFIG_EXAMPLES_NXLINES=y diff --git a/boards/sim/sim/sim/configs/nxwm/defconfig b/boards/sim/sim/sim/configs/nxwm/defconfig index 6c54b022b4..45f760c948 100644 --- a/boards/sim/sim/sim/configs/nxwm/defconfig +++ b/boards/sim/sim/sim/configs/nxwm/defconfig @@ -13,7 +13,6 @@ CONFIG_ARCH_BOARD="sim" CONFIG_ARCH_BOARD_SIM=y CONFIG_ARCH_CHIP="sim" CONFIG_ARCH_SIM=y -CONFIG_CXX_NEWLONG=y CONFIG_DEBUG_SYMBOLS=y CONFIG_DISABLE_POSIX_TIMERS=y CONFIG_FAT_LCNAMES=y diff --git a/include/stdint.h b/include/stdint.h index 9914ae094a..6f2f153f54 100644 --- a/include/stdint.h +++ b/include/stdint.h @@ -271,10 +271,14 @@ typedef _int64_t int_fast64_t; typedef _uint64_t uint_fast64_t; #endif -/* Integer types capable of holding object pointers */ +/* Integer types capable of holding object pointers + * As a general rule, the size of size_t should be the same as the size of + * uintptr_t: 32-bits on a machine with 32-bit addressing but 64-bits on a + * machine with 64-bit addressing. + */ -typedef _intptr_t intptr_t; -typedef _uintptr_t uintptr_t; +typedef _ssize_t intptr_t; +typedef _size_t uintptr_t; /* Some architectures support a FAR pointer which is larger then the normal * (near) pointer diff --git a/include/sys/types.h b/include/sys/types.h index b89298e272..1785d776af 100644 --- a/include/sys/types.h +++ b/include/sys/types.h @@ -139,14 +139,10 @@ typedef int16_t ssize_t; typedef uint16_t rsize_t; #else /* CONFIG_SMALL_MEMORY */ -/* As a general rule, the size of size_t should be the same as the size of - * uintptr_t: 32-bits on a machine with 32-bit addressing but 64-bits on a - * machine with 64-bit addressing. - */ -typedef uintptr_t size_t; -typedef intptr_t ssize_t; -typedef uintptr_t rsize_t; +typedef _size_t size_t; +typedef _ssize_t ssize_t; +typedef _size_t rsize_t; #endif /* CONFIG_SMALL_MEMORY */ diff --git a/libs/libxx/Kconfig b/libs/libxx/Kconfig index f342066aad..f9eb934e4a 100644 --- a/libs/libxx/Kconfig +++ b/libs/libxx/Kconfig @@ -22,14 +22,6 @@ config HAVE_CXX if HAVE_CXX -config CXX_NEWLONG - bool "size_t is type long" - default n - ---help--- - size_t may be type long or type int. This matters for some - C++ library routines because the NuttX size_t might not have - the same underlying type as your toolchain's size_t. - config CXX_EXCEPTION bool diff --git a/libs/libxx/libxx_delete.cxx b/libs/libxx/libxx_delete.cxx index da966b55d3..c57e5d1c2d 100644 --- a/libs/libxx/libxx_delete.cxx +++ b/libs/libxx/libxx_delete.cxx @@ -49,7 +49,7 @@ // Name: delete //*************************************************************************** -void operator delete(void* ptr) +void operator delete(FAR void *ptr) { lib_free(ptr); } diff --git a/libs/libxx/libxx_delete_sized.cxx b/libs/libxx/libxx_delete_sized.cxx index 99f97e4549..5f2cd9d789 100644 --- a/libs/libxx/libxx_delete_sized.cxx +++ b/libs/libxx/libxx_delete_sized.cxx @@ -39,6 +39,8 @@ #include +#include + #include "libxx.hxx" #ifdef CONFIG_HAVE_CXX14 @@ -61,12 +63,7 @@ // //*************************************************************************** -//void operator delete(FAR void *ptr, std::size_t size) -#ifdef CONFIG_CXX_NEWLONG -void operator delete(FAR void *ptr, unsigned long size) -#else -void operator delete(FAR void *ptr, unsigned int size) -#endif +void operator delete(FAR void *ptr, std::size_t size) { lib_free(ptr); } diff --git a/libs/libxx/libxx_deletea.cxx b/libs/libxx/libxx_deletea.cxx index f9e944265d..845d1ac0ab 100644 --- a/libs/libxx/libxx_deletea.cxx +++ b/libs/libxx/libxx_deletea.cxx @@ -49,7 +49,7 @@ // Name: delete[] //*************************************************************************** -void operator delete[](void *ptr) +void operator delete[](FAR void *ptr) { lib_free(ptr); } diff --git a/libs/libxx/libxx_deletea_sized.cxx b/libs/libxx/libxx_deletea_sized.cxx index 134722ab8d..d8ba31b265 100644 --- a/libs/libxx/libxx_deletea_sized.cxx +++ b/libs/libxx/libxx_deletea_sized.cxx @@ -40,6 +40,8 @@ #include #include +#include + #include "libxx.hxx" #ifdef CONFIG_HAVE_CXX14 @@ -52,12 +54,7 @@ // Name: delete[] //*************************************************************************** -//void operator delete[](void *ptr std::size_t size) -#ifdef CONFIG_CXX_NEWLONG -void operator delete[](FAR void *ptr, unsigned long size) -#else -void operator delete[](FAR void *ptr, unsigned int size) -#endif +void operator delete[](FAR void *ptr, std::size_t size) { lib_free(ptr); } diff --git a/libs/libxx/libxx_new.cxx b/libs/libxx/libxx_new.cxx index 32b58e7c93..652eb342fd 100644 --- a/libs/libxx/libxx_new.cxx +++ b/libs/libxx/libxx_new.cxx @@ -61,12 +61,7 @@ // //*************************************************************************** -//void *operator new(size_t nbytes) -#ifdef CONFIG_CXX_NEWLONG -void *operator new(unsigned long nbytes) -#else -void *operator new(unsigned int nbytes) -#endif +FAR void *operator new(std::size_t nbytes) { // We have to allocate something @@ -77,7 +72,7 @@ void *operator new(unsigned int nbytes) // Perform the allocation - void *alloc = lib_malloc(nbytes); + FAR void *alloc = lib_malloc(nbytes); #ifdef CONFIG_DEBUG_ERROR if (alloc == 0) diff --git a/libs/libxx/libxx_newa.cxx b/libs/libxx/libxx_newa.cxx index 78ed6eeff0..8cab9f55e6 100644 --- a/libs/libxx/libxx_newa.cxx +++ b/libs/libxx/libxx_newa.cxx @@ -69,12 +69,7 @@ // //*************************************************************************** -//void *operator new[](size_t size) -#ifdef CONFIG_CXX_NEWLONG -void *operator new[](unsigned long nbytes) -#else -void *operator new[](unsigned int nbytes) -#endif +FAR void *operator new[](std::size_t nbytes) { // We have to allocate something @@ -85,7 +80,7 @@ void *operator new[](unsigned int nbytes) // Perform the allocation - void *alloc = lib_malloc(nbytes); + FAR void *alloc = lib_malloc(nbytes); #ifdef CONFIG_DEBUG_ERROR if (alloc == 0) diff --git a/tools/testbuild.sh b/tools/testbuild.sh index 8e0d29c7d7..b8288c00f0 100755 --- a/tools/testbuild.sh +++ b/tools/testbuild.sh @@ -180,9 +180,9 @@ function configure { fi if [ "X$sizet" != "Xdefault" ]; then - sed -i -e "/CONFIG_CXX_NEWLONG/d" $nuttx/.config + sed -i -e "/CONFIG_ARCH_SIZET_LONG/d" $nuttx/.config if [ "X$sizet" == "Xulong" ]; then - sed -i -e "\$aCONFIG_CXX_NEWLONG=y" $nuttx/.config + sed -i -e "\$aCONFIG_ARCH_SIZET_LONG=y" $nuttx/.config fi fi