Skip to content

Commit 35a78b1

Browse files
committed
Added virtual destructor to Printable, which also requires new and delete operators to be added
1 parent facbd27 commit 35a78b1

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

hardware/arduino/cores/arduino/Printable.h

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#ifndef Printable_h
2121
#define Printable_h
2222

23+
#include <new.h>
24+
2325
class Print;
2426

2527
/** The Printable class provides a way for new classes to allow themselves to be printed.
@@ -31,6 +33,7 @@ class Print;
3133
class Printable
3234
{
3335
public:
36+
virtual ~Printable() {};
3437
virtual void printTo(Print& p) const =0;
3538
};
3639

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <new.h>
2+
3+
void * operator new(size_t size)
4+
{
5+
return malloc(size);
6+
}
7+
8+
void operator delete(void * ptr)
9+
{
10+
free(ptr);
11+
}
12+
13+
int __cxa_guard_acquire(__guard *g) {return !*(char *)(g);};
14+
void __cxa_guard_release (__guard *g) {*(char *)g = 1;};
15+
void __cxa_guard_abort (__guard *) {};
16+
17+
void __cxa_pure_virtual(void) {};
18+

hardware/arduino/cores/arduino/new.h

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* Header to define new/delete operators as they aren't provided by avr-gcc by default
2+
Taken from http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=59453
3+
*/
4+
5+
#ifndef NEW_H
6+
#define NEW_H
7+
8+
#include <stdlib.h>
9+
10+
void * operator new(size_t size);
11+
void operator delete(void * ptr);
12+
13+
__extension__ typedef int __guard __attribute__((mode (__DI__)));
14+
15+
extern "C" int __cxa_guard_acquire(__guard *);
16+
extern "C" void __cxa_guard_release (__guard *);
17+
extern "C" void __cxa_guard_abort (__guard *);
18+
19+
extern "C" void __cxa_pure_virtual(void);
20+
21+
#endif
22+

0 commit comments

Comments
 (0)