Skip to content

Commit

Permalink
Use the standard nothrow tag instead of our own type (dotnet#101811)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkoritzinsky authored and michaelgsharp committed May 8, 2024
1 parent 87e94af commit 12312c2
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 50 deletions.
4 changes: 2 additions & 2 deletions src/coreclr/debug/ee/debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -3613,7 +3613,7 @@ inline void * __cdecl operator new[](size_t n, const InteropSafe&)
return result;
}

inline void * __cdecl operator new(size_t n, const InteropSafe&, const NoThrow&) throw()
inline void * __cdecl operator new(size_t n, const InteropSafe&, const std::nothrow_t&) noexcept
{
CONTRACTL
{
Expand All @@ -3632,7 +3632,7 @@ inline void * __cdecl operator new(size_t n, const InteropSafe&, const NoThrow&)
return result;
}

inline void * __cdecl operator new[](size_t n, const InteropSafe&, const NoThrow&) throw()
inline void * __cdecl operator new[](size_t n, const InteropSafe&, const std::nothrow_t&) noexcept
{
CONTRACTL
{
Expand Down
12 changes: 2 additions & 10 deletions src/coreclr/inc/new.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,9 @@
#ifndef __new__hpp
#define __new__hpp

#if defined(_MSC_VER) && _MSC_VER < 1900
#define NOEXCEPT
#else
#define NOEXCEPT noexcept
#endif

struct NoThrow { int x; };
extern const NoThrow nothrow;
#include <new>

void * __cdecl operator new(size_t n, const NoThrow&) NOEXCEPT;
void * __cdecl operator new[](size_t n, const NoThrow&) NOEXCEPT;
using std::nothrow;

#ifdef _DEBUG
void DisableThrowCheck();
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/inc/stresslog.h
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ class ThreadStressLog {
#endif //!STRESS_LOG_READONLY && !STRESS_LOG_ANALYZER

#if defined(MEMORY_MAPPED_STRESSLOG) && !defined(STRESS_LOG_ANALYZER)
void* __cdecl operator new(size_t n, const NoThrow&) NOEXCEPT;
void* __cdecl operator new(size_t n, const std::nothrow_t&) noexcept;
void __cdecl operator delete (void * chunk);
#endif

Expand Down
8 changes: 4 additions & 4 deletions src/coreclr/inc/utilcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,10 @@ _Ret_bytecap_(n) void * __cdecl
operator new[](size_t n);

void __cdecl
operator delete(void *p) NOEXCEPT;
operator delete(void *p) noexcept;

void __cdecl
operator delete[](void *p) NOEXCEPT;
operator delete[](void *p) noexcept;

#ifdef _DEBUG_IMPL
HRESULT _OutOfMemory(LPCSTR szFile, int iLine);
Expand Down Expand Up @@ -3728,8 +3728,8 @@ extern const CExecutable executable;

void * __cdecl operator new(size_t n, const CExecutable&);
void * __cdecl operator new[](size_t n, const CExecutable&);
void * __cdecl operator new(size_t n, const CExecutable&, const NoThrow&);
void * __cdecl operator new[](size_t n, const CExecutable&, const NoThrow&);
void * __cdecl operator new(size_t n, const CExecutable&, const std::nothrow_t&) noexcept;
void * __cdecl operator new[](size_t n, const CExecutable&, const std::nothrow_t&) noexcept;


//
Expand Down
38 changes: 10 additions & 28 deletions src/coreclr/utilcode/clrhost_nodependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,8 @@ ClrDebugState *CLRInitDebugState()

#endif //defined(_DEBUG_IMPL) && defined(ENABLE_CONTRACTS_IMPL)

const NoThrow nothrow = { 0 };

#if defined(HAS_ADDRESS_SANITIZER) || defined(DACCESS_COMPILE)
// use standard heap functions for address sanitizer
#else

// use standard heap functions for AddressSanitizer and for the DAC build.
#if !defined(HAS_ADDRESS_SANITIZER) && !defined(DACCESS_COMPILE)
#ifdef _DEBUG
#ifdef TARGET_X86
#define OS_HEAP_ALIGN 8
Expand All @@ -221,7 +217,7 @@ const NoThrow nothrow = { 0 };
static HANDLE g_hProcessHeap;
#endif

FORCEINLINE void* ClrMalloc(size_t size)
static FORCEINLINE void* ClrMalloc(size_t size)
{
STATIC_CONTRACT_NOTHROW;

Expand Down Expand Up @@ -339,14 +335,9 @@ operator new[](size_t n)
return result;
};

#endif // HAS_ADDRESS_SANITIZER || DACCESS_COMPILE

void * __cdecl operator new(size_t n, const NoThrow&) NOEXCEPT
void * __cdecl operator new(size_t n, const std::nothrow_t&) noexcept
{
#if defined(HAS_ADDRESS_SANITIZER) || defined(DACCESS_COMPILE)
// use standard heap functions for address sanitizer (which doesn't provide for NoThrow)
void * result = operator new(n);
#else
STATIC_CONTRACT_NOTHROW;
STATIC_CONTRACT_GC_NOTRIGGER;
STATIC_CONTRACT_FAULT;
Expand All @@ -355,17 +346,12 @@ void * __cdecl operator new(size_t n, const NoThrow&) NOEXCEPT
INCONTRACT(_ASSERTE(!ARE_FAULTS_FORBIDDEN()));

void* result = ClrMalloc(n);
#endif // HAS_ADDRESS_SANITIZER || DACCESS_COMPILE
TRASH_LASTERROR;
return result;
}

void * __cdecl operator new[](size_t n, const NoThrow&) NOEXCEPT
void * __cdecl operator new[](size_t n, const std::nothrow_t&) noexcept
{
#if defined(HAS_ADDRESS_SANITIZER) || defined(DACCESS_COMPILE)
// use standard heap functions for address sanitizer (which doesn't provide for NoThrow)
void * result = operator new[](n);
#else
STATIC_CONTRACT_NOTHROW;
STATIC_CONTRACT_GC_NOTRIGGER;
STATIC_CONTRACT_FAULT;
Expand All @@ -374,16 +360,12 @@ void * __cdecl operator new[](size_t n, const NoThrow&) NOEXCEPT
INCONTRACT(_ASSERTE(!ARE_FAULTS_FORBIDDEN()));

void* result = ClrMalloc(n);
#endif // HAS_ADDRESS_SANITIZER || DACCESS_COMPILE
TRASH_LASTERROR;
return result;
}

#if defined(HAS_ADDRESS_SANITIZER) || defined(DACCESS_COMPILE)
// use standard heap functions for address sanitizer
#else
void __cdecl
operator delete(void *p) NOEXCEPT
operator delete(void *p) noexcept
{
STATIC_CONTRACT_NOTHROW;
STATIC_CONTRACT_GC_NOTRIGGER;
Expand All @@ -395,7 +377,7 @@ operator delete(void *p) NOEXCEPT
}

void __cdecl
operator delete[](void *p) NOEXCEPT
operator delete[](void *p) noexcept
{
STATIC_CONTRACT_NOTHROW;
STATIC_CONTRACT_GC_NOTRIGGER;
Expand All @@ -405,7 +387,7 @@ operator delete[](void *p) NOEXCEPT
TRASH_LASTERROR;
}

#endif // HAS_ADDRESS_SANITIZER || DACCESS_COMPILE
#endif // !HAS_ADDRESS_SANITIZER && !DACCESS_COMPILE

/* ------------------------------------------------------------------------ *
* New operator overloading for the executable heap
Expand Down Expand Up @@ -494,7 +476,7 @@ void * __cdecl operator new[](size_t n, const CExecutable&)
return result;
}

void * __cdecl operator new(size_t n, const CExecutable&, const NoThrow&)
void * __cdecl operator new(size_t n, const CExecutable&, const std::nothrow_t&) noexcept
{
STATIC_CONTRACT_NOTHROW;
STATIC_CONTRACT_GC_NOTRIGGER;
Expand All @@ -511,7 +493,7 @@ void * __cdecl operator new(size_t n, const CExecutable&, const NoThrow&)
return result;
}

void * __cdecl operator new[](size_t n, const CExecutable&, const NoThrow&)
void * __cdecl operator new[](size_t n, const CExecutable&, const std::nothrow_t&) noexcept
{
STATIC_CONTRACT_NOTHROW;
STATIC_CONTRACT_GC_NOTRIGGER;
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/utilcode/stresslog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ void* StressLog::AllocMemoryMapped(size_t n)
return nullptr;
}

void* __cdecl ThreadStressLog::operator new(size_t n, const NoThrow&) NOEXCEPT
void* __cdecl ThreadStressLog::operator new(size_t n, const std::nothrow_t&) noexcept
{
if (StressLogChunk::s_memoryMapped)
return StressLog::AllocMemoryMapped(n);
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/vm/stackingallocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ void * __cdecl operator new[](size_t n, StackingAllocator * alloc)
return retval;
}

void * __cdecl operator new(size_t n, StackingAllocator * alloc, const NoThrow&) throw()
void * __cdecl operator new(size_t n, StackingAllocator * alloc, const std::nothrow_t&) noexcept
{
STATIC_CONTRACT_NOTHROW;
STATIC_CONTRACT_FAULT;
Expand All @@ -412,7 +412,7 @@ void * __cdecl operator new(size_t n, StackingAllocator * alloc, const NoThrow&)
return alloc->UnsafeAllocNoThrow((unsigned)n);
}

void * __cdecl operator new[](size_t n, StackingAllocator * alloc, const NoThrow&) throw()
void * __cdecl operator new[](size_t n, StackingAllocator * alloc, const std::nothrow_t&) noexcept
{
STATIC_CONTRACT_NOTHROW;
STATIC_CONTRACT_FAULT;
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/vm/stackingallocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ class StackingAllocatorHolder

void * __cdecl operator new(size_t n, StackingAllocator *alloc);
void * __cdecl operator new[](size_t n, StackingAllocator *alloc);
void * __cdecl operator new(size_t n, StackingAllocator *alloc, const NoThrow&) throw();
void * __cdecl operator new[](size_t n, StackingAllocator *alloc, const NoThrow&) throw();
void * __cdecl operator new(size_t n, StackingAllocator *alloc, const std::nothrow_t&) noexcept;
void * __cdecl operator new[](size_t n, StackingAllocator *alloc, const std::nothrow_t&) noexcept;

#ifdef _MSC_VER
#pragma warning(pop)
Expand Down

0 comments on commit 12312c2

Please sign in to comment.