2009-04-19 23:52:35 +08:00
|
|
|
//***************************************************************************
|
2021-08-29 21:36:24 +08:00
|
|
|
// libs/libxx/libcxxmini/libxx_new.cxx
|
2009-04-19 23:52:35 +08:00
|
|
|
//
|
2024-09-13 21:11:30 +08:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
//
|
2021-02-24 02:12:11 +08:00
|
|
|
// Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
// contributor license agreements. See the NOTICE file distributed with
|
|
|
|
// this work for additional information regarding copyright ownership. The
|
|
|
|
// ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
// "License"); you may not use this file except in compliance with the
|
|
|
|
// License. You may obtain a copy of the License at
|
2009-04-19 23:52:35 +08:00
|
|
|
//
|
2021-02-24 02:12:11 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2009-04-19 23:52:35 +08:00
|
|
|
//
|
2021-02-24 02:12:11 +08:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
// License for the specific language governing permissions and limitations
|
2009-04-19 23:52:35 +08:00
|
|
|
//
|
|
|
|
//***************************************************************************
|
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
// Included Files
|
|
|
|
//***************************************************************************
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
2022-01-11 14:07:27 +08:00
|
|
|
#include <assert.h>
|
2009-04-19 23:52:35 +08:00
|
|
|
#include <cstddef>
|
|
|
|
#include <debug.h>
|
|
|
|
|
2021-08-29 21:36:24 +08:00
|
|
|
#include <nuttx/lib/lib.h>
|
2013-03-10 05:12:20 +08:00
|
|
|
|
2009-04-19 23:52:35 +08:00
|
|
|
//***************************************************************************
|
|
|
|
// Operators
|
|
|
|
//***************************************************************************
|
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
// Name: new
|
|
|
|
//
|
|
|
|
// NOTE:
|
2011-10-04 05:10:11 +08:00
|
|
|
// This should take a type of size_t. But size_t has an unknown underlying
|
|
|
|
// type. In the nuttx sys/types.h header file, size_t is typed as uint32_t
|
|
|
|
// (which is determined by architecture-specific logic). But the C++
|
|
|
|
// compiler may believe that size_t is of a different type resulting in
|
|
|
|
// compilation errors in the operator. Using the underlying integer type
|
|
|
|
// instead of size_t seems to resolve the compilation issues. Need to
|
|
|
|
// REVISIT this.
|
2009-06-17 02:11:12 +08:00
|
|
|
//
|
2009-04-19 23:52:35 +08:00
|
|
|
//***************************************************************************
|
|
|
|
|
2020-02-17 20:19:25 +08:00
|
|
|
FAR void *operator new(std::size_t nbytes)
|
2009-04-19 23:52:35 +08:00
|
|
|
{
|
|
|
|
// Perform the allocation
|
|
|
|
|
2020-02-17 20:19:25 +08:00
|
|
|
FAR void *alloc = lib_malloc(nbytes);
|
2009-04-19 23:52:35 +08:00
|
|
|
|
2016-08-23 00:31:52 +08:00
|
|
|
#ifdef CONFIG_DEBUG_ERROR
|
2009-04-19 23:52:35 +08:00
|
|
|
if (alloc == 0)
|
|
|
|
{
|
|
|
|
// Oh my.. we are required to return a valid pointer and
|
|
|
|
// we cannot throw an exception! We are bad.
|
|
|
|
|
2016-06-17 02:33:32 +08:00
|
|
|
_err("ERROR: Failed to allocate\n");
|
2009-04-19 23:52:35 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-05-15 13:03:17 +08:00
|
|
|
DEBUGASSERT(alloc != NULL);
|
2022-01-11 14:07:27 +08:00
|
|
|
|
2009-04-19 23:52:35 +08:00
|
|
|
// Return the allocated value
|
|
|
|
|
|
|
|
return alloc;
|
|
|
|
}
|
2021-01-13 20:10:25 +08:00
|
|
|
|
|
|
|
FAR void *operator new(std::size_t nbytes, FAR void *ptr)
|
|
|
|
{
|
2022-05-15 13:03:17 +08:00
|
|
|
DEBUGASSERT(ptr != NULL);
|
2021-01-13 20:10:25 +08:00
|
|
|
|
|
|
|
// Return the ptr pointer
|
|
|
|
|
|
|
|
return ptr;
|
|
|
|
}
|