Skip to content

Fix operator new #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions hardware/arduino/cores/arduino/Printable.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
#ifndef Printable_h
#define Printable_h

#include <new.h>

class Print;

/** The Printable class provides a way for new classes to allow themselves to be printed.
Expand Down
56 changes: 56 additions & 0 deletions hardware/arduino/cores/arduino/abi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <abi.h>
#include <stdint.h>
#include <exception>

#include <avr/io.h>
#include <avr/interrupt.h>

namespace {
// guard is an integer type big enough to hold flag and a mutex.
// By default gcc uses long long int and avr ABI does not change it
// So we have 32 or 64 bits available. Actually, we need 16.

inline char& flag_part(__guard *g) {
return *(reinterpret_cast<char*>(g));
}

inline uint8_t& sreg_part(__guard *g) {
return *(reinterpret_cast<uint8_t*>(g) + sizeof(char));
}
}

int __cxa_guard_acquire(__guard *g) {
uint8_t oldSREG = SREG;
cli();
// Initialization of static variable has to be done with blocked interrupts
// because if this function is called from interrupt and sees that somebody
// else is already doing initialization it MUST wait until initializations
// is complete. That's impossible.
// If you don't want this overhead compile with -fno-threadsafe-statics
if (flag_part(g)) {
SREG = oldSREG;
return false;
} else {
sreg_part(g) = oldSREG;
return true;
}
}

void __cxa_guard_release (__guard *g) {
flag_part(g) = 1;
SREG = sreg_part(g);
}

void __cxa_guard_abort (__guard *g) {
SREG = sreg_part(g);
}

void __cxa_pure_virtual(void) {
// We might want to write some diagnostics to uart in this case
std::terminate();
}

void __cxa_deleted_virtual(void) {
// We might want to write some diagnostics to uart in this case
std::terminate();
}
19 changes: 19 additions & 0 deletions hardware/arduino/cores/arduino/abi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* Header to define cxx abi parts missing from avrlibc */

#ifndef ABI_H_INCLUDED
#define ABI_H_INCLUDED

#include <stdlib.h>

__extension__ typedef int __guard __attribute__((mode (__DI__)));

extern "C" {
int __cxa_guard_acquire(__guard *);
void __cxa_guard_release (__guard *);
void __cxa_guard_abort (__guard *);

void __cxa_pure_virtual(void) __attribute__ ((__noreturn__));
void __cxa_deleted_virtual(void) __attribute__ ((__noreturn__));
}

#endif
18 changes: 0 additions & 18 deletions hardware/arduino/cores/arduino/new.cpp

This file was deleted.

22 changes: 0 additions & 22 deletions hardware/arduino/cores/arduino/new.h

This file was deleted.