Skip to content
This repository was archived by the owner on Jun 30, 2022. It is now read-only.

Commit 589d466

Browse files
fix: Only define new/del when AVR core does not provide <new>
Since AVR core 1.8.3, it provides an (incomplete) new header that breaks compilation of the uclibc++ new/delete .cpp files. Since 1.8.4 it provides a complete new header, but that also introduces a linker duplicate symbol issue for std::nothrow. This commit adds a USING_NEW_FROM_UCLIBC define to our new include file, which allows detecting which version of the new include is used. That define is used to completely skip all new/delete code (all new_*.cpp and del_*.cpp files) when the new header from the AVR-core is used. This should fix all conflicts, except: - On AVR core 1.8.3, new/delete is now imcomplete. However, the missing functions (array placement new, placement delete, nothrow versions and delete with size) are probably not commonly used. - If another library *also* offers <new>, then things might break in different ways. Again, this is a rare corner case. - This no longer provides set_new_handler, which the AVR core declares but does not define. However, since the uclibc++ version did not actually *use* the handler passed, not defining it is probably better.
1 parent 44b34b3 commit 589d466

12 files changed

+24
-27
lines changed

src/del_op.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@
1717
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1818
*/
1919

20-
// Arduino 1.0 contains an implementation for this.
21-
#if ARDUINO < 100
22-
2320
#include <new>
2421
#include <cstdlib>
2522
#include <func_exception>
2623

24+
#if defined(USING_NEW_FROM_UCLIBC) && ARDUINO < 100
2725
_UCXXEXPORT void operator delete(void* ptr) throw(){
2826
free(ptr);
2927
}
30-
31-
#endif
28+
#endif // defined(USING_NEW_FROM_UCLIBC) && ARDUINO < 100

src/del_opnt.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
#include <cstdlib>
2222
#include <func_exception>
2323

24-
#ifndef NO_NOTHROW
24+
#if defined(USING_NEW_FROM_UCLIBC) && !defined(NO_NOTHROW)
2525
_UCXXEXPORT void operator delete(void* ptr, const std::nothrow_t& ) throw() {
2626
free(ptr);
2727
}
28-
#endif
28+
#endif // defined(USING_NEW_FROM_UCLIBC) && !defined(NO_NOTHROW)

src/del_ops.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include <cstdlib>
2323
#include <func_exception>
2424

25+
#if defined(USING_NEW_FROM_UCLIBC)
2526
_UCXXEXPORT void operator delete(void* ptr, std::size_t) throw(){
2627
::operator delete (ptr);
2728
}
29+
#endif // defined(USING_NEW_FROM_UCLIBC)

src/del_opv.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@
1717
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1818
*/
1919

20-
// Arduino 1.0 contains an implementation for this.
21-
#if ARDUINO < 100
22-
20+
#if defined(USING_NEW_FROM_UCLIBC) && ARDUINO < 100
2321
#include <new>
2422
#include <cstdlib>
2523
#include <func_exception>
2624

2725
_UCXXEXPORT void operator delete[](void * ptr) throw(){
2826
free(ptr);
2927
}
30-
31-
#endif
28+
#endif // defined(USING_NEW_FROM_UCLIBC) && ARDUINO < 100

src/del_opvnt.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
#include <cstdlib>
2222
#include <func_exception>
2323

24-
#ifndef NO_NOTHROW
24+
#if defined(USING_NEW_FROM_UCLIBC) && !defined(NO_NOTHROW)
2525
_UCXXEXPORT void operator delete[](void* ptr, const std::nothrow_t& ) throw(){
2626
free(ptr);
2727
}
28-
#endif
28+
#endif // defined(USING_NEW_FROM_UCLIBC) && !defined(NO_NOTHROW)

src/del_opvs.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include <cstdlib>
2323
#include <func_exception>
2424

25+
#if defined(USING_NEW_FROM_UCLIBC)
2526
_UCXXEXPORT void operator delete[](void * ptr, std::size_t) throw(){
2627
::operator delete[] (ptr);
2728
}
29+
#endif // defined(USING_NEW_FROM_UCLIBC)

src/new

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#ifndef __STD_NEW_OPERATOR
2525
#define __STD_NEW_OPERATOR 1
2626

27+
#define USING_NEW_FROM_UCLIBC
28+
2729
#pragma GCC visibility push(default)
2830

2931
namespace std{

src/new_handler.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include <new>
2121

22+
#if defined(USING_NEW_FROM_UCLIBC)
2223
const std::nothrow_t std::nothrow = { };
2324

2425
//Name selected to be compatable with g++ code
@@ -29,3 +30,4 @@ _UCXXEXPORT std::new_handler std::set_new_handler(std::new_handler new_p) throw(
2930
__new_handler = new_p;
3031
return retval;
3132
}
33+
#endif // defined(USING_NEW_FROM_UCLIBC)

src/new_op.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@
1717
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1818
*/
1919

20-
// Arduino 1.0 contains an implementation for this.
21-
#if ARDUINO < 100
22-
2320
#include <new>
2421
#include <cstdlib>
2522
#include <func_exception>
2623

24+
#if defined(USING_NEW_FROM_UCLIBC) && ARDUINO < 100
2725
_UCXXEXPORT void* operator new(std::size_t numBytes) throw(std::bad_alloc){
2826
//C++ stardard 5.3.4.8 requires that a valid pointer be returned for
2927
//a call to new(0). Thus:
@@ -36,5 +34,4 @@ _UCXXEXPORT void* operator new(std::size_t numBytes) throw(std::bad_alloc){
3634
}
3735
return p;
3836
}
39-
40-
#endif
37+
#endif // defined(USING_NEW_FROM_UCLIBC) && ARDUINO < 100

src/new_opnt.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
#include <cstdlib>
2222
#include <func_exception>
2323

24-
#ifndef NO_NOTHROW
24+
#if defined(USING_NEW_FROM_UCLIBC) && !defined(NO_NOTHROW)
2525
_UCXXEXPORT void* operator new(std::size_t numBytes, const std::nothrow_t& ) throw(){
2626
return malloc(numBytes);
2727
}
28-
#endif
28+
#endif // defined(USING_NEW_FROM_UCLIBC) && !defined(NO_NOTHROW)

src/new_opv.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@
1717
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1818
*/
1919

20-
// Arduino 1.0 contains an implementation for this.
21-
#if ARDUINO < 100
22-
2320
#include <new>
2421
#include <cstdlib>
2522
#include <func_exception>
2623

24+
#if defined(USING_NEW_FROM_UCLIBC) && ARDUINO < 100
2725
_UCXXEXPORT void* operator new[](std::size_t numBytes) throw(std::bad_alloc){
2826
//C++ stardard 5.3.4.8 requires that a valid pointer be returned for
2927
//a call to new(0). Thus:
@@ -37,4 +35,4 @@ _UCXXEXPORT void* operator new[](std::size_t numBytes) throw(std::bad_alloc){
3735
return p;
3836
}
3937

40-
#endif
38+
#endif // defined(USING_NEW_FROM_UCLIBC) && ARDUINO < 100

src/new_opvnt.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
#include <cstdlib>
2222
#include <func_exception>
2323

24-
#ifndef NO_NOTHROW
24+
#if defined(USING_NEW_FROM_UCLIBC) && !defined(NO_NOTHROW)
2525
_UCXXEXPORT void* operator new[](std::size_t numBytes, const std::nothrow_t& ) throw(){
2626
return malloc(numBytes);
2727
}
28-
#endif
28+
#endif // defined(USING_NEW_FROM_UCLIBC) && !defined(NO_NOTHROW)

0 commit comments

Comments
 (0)