[lib][libcpp] move c++ specific shims out of libc and heap
Consolidate into a single library. Also renames legacy new.h to the more standard new. Possible that some C++ code will need to get this added to their MODULE_DEPS.
This commit is contained in:
@@ -8,9 +8,6 @@ MODULE_SRCS += \
|
||||
$(LOCAL_DIR)/heap_wrapper.c \
|
||||
$(LOCAL_DIR)/page_alloc.c
|
||||
|
||||
MODULE_SRCS += \
|
||||
$(LOCAL_DIR)/new.cpp
|
||||
|
||||
# pick a heap implementation
|
||||
ifndef LK_HEAP_IMPLEMENTATION
|
||||
LK_HEAP_IMPLEMENTATION=miniheap
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Travis Geiselbrecht
|
||||
*
|
||||
* Use of this source code is governed by a MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
void *operator new (size_t);
|
||||
void *operator new (size_t, void *ptr);
|
||||
void *operator new[](size_t);
|
||||
void *operator new[](size_t, void *ptr);
|
||||
void operator delete (void *p);
|
||||
void operator delete[](void *p);
|
||||
|
||||
@@ -21,9 +21,6 @@ MODULE_SRCS += \
|
||||
$(LOCAL_DIR)/qsort.c \
|
||||
$(LOCAL_DIR)/eabi.c
|
||||
|
||||
MODULE_SRCS += \
|
||||
$(LOCAL_DIR)/pure_virtual.cpp
|
||||
|
||||
MODULE_COMPILEFLAGS += -fno-builtin
|
||||
|
||||
include $(LOCAL_DIR)/string/rules.mk
|
||||
|
||||
48
lib/libcpp/include/initializer_list
Normal file
48
lib/libcpp/include/initializer_list
Normal file
@@ -0,0 +1,48 @@
|
||||
// Copyright 2017 The Fuchsia Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
//
|
||||
// Provides std::initializer_list<T> on behalf of the Magenta toolchain
|
||||
// when compiling without the C++ standard library.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
// This implementation is known to be compatible with our GCC and Clang toolchains.
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
namespace std {
|
||||
template <typename T>
|
||||
class initializer_list {
|
||||
public:
|
||||
using value_type = T;
|
||||
using reference = const T&;
|
||||
using const_reference = const T&;
|
||||
using size_type = size_t;
|
||||
using iterator = const T*;
|
||||
using const_iterator = const T*;
|
||||
|
||||
constexpr initializer_list()
|
||||
: items_(nullptr), size_(0u) {}
|
||||
|
||||
constexpr size_t size() const { return size_; }
|
||||
constexpr const T* begin() const { return items_; }
|
||||
constexpr const T* end() const { return items_ + size_; }
|
||||
|
||||
private:
|
||||
constexpr initializer_list(const T* items, size_t size)
|
||||
: items_(items), size_(size) {}
|
||||
|
||||
const T* items_;
|
||||
size_t size_;
|
||||
};
|
||||
} // namespace std
|
||||
|
||||
#else
|
||||
#error "std::initializer_list<T> not supported by this toolchain"
|
||||
#endif // defined(__GNUC__) || defined(__clang__)
|
||||
|
||||
// vim: syntax=cpp
|
||||
27
lib/libcpp/include/new
Normal file
27
lib/libcpp/include/new
Normal file
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// Copyright (c) 2008 Travis Geiselbrecht
|
||||
//
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file or at
|
||||
// https://opensource.org/licenses/MIT
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
// Fake std::nothrow_t without a standard C++ library.
|
||||
namespace std {
|
||||
struct nothrow_t {};
|
||||
} // namespace std
|
||||
|
||||
void* operator new(size_t, const std::nothrow_t&) noexcept;
|
||||
void* operator new[](size_t, const std::nothrow_t&) noexcept;
|
||||
|
||||
inline void* operator new(size_t, void *ptr) noexcept { return ptr; }
|
||||
inline void* operator new[](size_t, void *ptr) noexcept { return ptr; }
|
||||
|
||||
void operator delete(void *p);
|
||||
void operator delete[](void *p);
|
||||
void operator delete(void *p, size_t);
|
||||
void operator delete[](void *p, size_t);
|
||||
|
||||
// vim: syntax=cpp
|
||||
@@ -5,7 +5,7 @@
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
#include <new.h>
|
||||
#include <new>
|
||||
#include <lk/debug.h>
|
||||
#include <lib/heap.h>
|
||||
|
||||
@@ -17,8 +17,12 @@ void *operator new[](size_t s) {
|
||||
return malloc(s);
|
||||
}
|
||||
|
||||
void *operator new (size_t, void *p) {
|
||||
return p;
|
||||
void *operator new (size_t s, const std::nothrow_t &) noexcept {
|
||||
return malloc(s);
|
||||
}
|
||||
|
||||
void *operator new[](size_t s, const std::nothrow_t &) noexcept {
|
||||
return malloc(s);
|
||||
}
|
||||
|
||||
void operator delete (void *p) {
|
||||
@@ -29,3 +33,10 @@ void operator delete[](void *p) {
|
||||
return free(p);
|
||||
}
|
||||
|
||||
void operator delete (void *p, size_t s) {
|
||||
return free(p);
|
||||
}
|
||||
|
||||
void operator delete[](void *p, size_t s) {
|
||||
return free(p);
|
||||
}
|
||||
10
lib/libcpp/rules.mk
Normal file
10
lib/libcpp/rules.mk
Normal file
@@ -0,0 +1,10 @@
|
||||
LOCAL_DIR := $(GET_LOCAL_DIR)
|
||||
|
||||
MODULE := $(LOCAL_DIR)
|
||||
|
||||
MODULE_DEPS :=
|
||||
|
||||
MODULE_SRCS += $(LOCAL_DIR)/new.cpp
|
||||
MODULE_SRCS += $(LOCAL_DIR)/pure_virtual.cpp
|
||||
|
||||
include make/module.mk
|
||||
Reference in New Issue
Block a user