Skip to content

Commit d179695

Browse files
committed
Add new/delete implementations
This is needed to pass C++ validation in test suite
1 parent cd4f66d commit d179695

File tree

3 files changed

+77
-1
lines changed

3 files changed

+77
-1
lines changed

cores/arduino/WString.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include <string.h>
3232
#include <ctype.h>
3333
#include "stdlib_noniso.h"
34-
//#include <avr/pgmspace.h>
34+
#include <avr/pgmspace.h>
3535

3636
// When compiling programs with this class, the following gcc parameters
3737
// dramatically increase performance and memory (RAM) efficiency, typically

cores/arduino/new.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Copyright (c) 2014 Arduino. All right reserved.
3+
4+
This library is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
8+
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
See the GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with this library; if not, write to the Free Software
16+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
#include <stdlib.h>
20+
#include "new.h"
21+
22+
void *operator new(size_t size) {
23+
return malloc(size);
24+
}
25+
26+
void *operator new[](size_t size) {
27+
return malloc(size);
28+
}
29+
30+
void operator delete(void * ptr) {
31+
free(ptr);
32+
}
33+
34+
void operator delete[](void * ptr) {
35+
free(ptr);
36+
}
37+
38+
extern "C" {
39+
__extension__ typedef int __guard __attribute__((mode (__DI__)));
40+
41+
int __cxa_guard_acquire(__guard g) {return !(char )(g);};
42+
void __cxa_guard_release (__guard *g) {*(char *)g = 1;};
43+
};

cores/arduino/new.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
Copyright (c) 2014 Arduino. All right reserved.
3+
4+
This library is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
8+
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
See the GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with this library; if not, write to the Free Software
16+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
#ifndef NEW_H
20+
#define NEW_H
21+
22+
#ifdef __cplusplus
23+
24+
#include <stdlib.h>
25+
26+
void * operator new(size_t size);
27+
void * operator new[](size_t size);
28+
void operator delete(void * ptr);
29+
void operator delete[](void * ptr);
30+
31+
#endif
32+
#endif
33+

0 commit comments

Comments
 (0)