Skip to content

Commit

Permalink
Remove CoreCLR PAL's InternalNew/Delete and just use new/delete with …
Browse files Browse the repository at this point in the history
…std::nothrow (dotnet#109659)
  • Loading branch information
jkoritzinsky authored Nov 12, 2024
1 parent 37188fc commit 524d217
Show file tree
Hide file tree
Showing 31 changed files with 36 additions and 150 deletions.
1 change: 0 additions & 1 deletion src/coreclr/pal/src/debug/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ SET_DEFAULT_DEBUG_CHANNEL(DEBUG); // some headers have code with asserts, so do
#include "pal/context.h"
#include "pal/debug.h"
#include "pal/environ.h"
#include "pal/malloc.hpp"
#include "pal/module.h"
#include "pal/stackstring.hpp"
#include "pal/virtual.h"
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/pal/src/exception/machexception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ SET_DEFAULT_DEBUG_CHANNEL(EXCEPT); // some headers have code with asserts, so do
#include "pal/init.h"
#include "pal/utils.h"
#include "pal/context.h"
#include "pal/malloc.hpp"
#include "pal/process.h"
#include "pal/virtual.h"
#include "pal/map.hpp"
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/pal/src/exception/machmessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Module Name:
#include "config.h"
#include "pal/dbgmsg.h"
#include "pal/environ.h"
#include "pal/malloc.hpp"
#include "pal/thread.hpp"
#include "machmessage.h"

Expand Down
1 change: 0 additions & 1 deletion src/coreclr/pal/src/exception/seh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ Module Name:
#include "pal/debug.h"
#include "pal/init.h"
#include "pal/process.h"
#include "pal/malloc.hpp"
#include "pal/signal.hpp"
#include "pal/virtual.h"

Expand Down
1 change: 0 additions & 1 deletion src/coreclr/pal/src/file/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ SET_DEFAULT_DEBUG_CHANNEL(FILE); // some headers have code with asserts, so do t

#include "pal/thread.hpp"
#include "pal/file.hpp"
#include "pal/malloc.hpp"
#include "pal/stackstring.hpp"

#include "pal/palinternal.h"
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/pal/src/file/find.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Revision History:
--*/

#include "pal/thread.hpp"
#include "pal/malloc.hpp"
#include "pal/file.hpp"
#include "pal/stackstring.hpp"

Expand Down
1 change: 0 additions & 1 deletion src/coreclr/pal/src/file/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Revision History:
#include "pal/palinternal.h"
#include "pal/dbgmsg.h"
#include "pal/file.h"
#include "pal/malloc.hpp"
#include "pal/stackstring.hpp"

#include <errno.h>
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/pal/src/handlemgr/handlemgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Module Name:
#include "pal/thread.hpp"
#include "pal/handlemgr.hpp"
#include "pal/cs.hpp"
#include "pal/malloc.hpp"
#include "pal/dbgmsg.h"

using namespace CorUnix;
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/pal/src/include/pal/handlemgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ Module Name:
#include "corunix.hpp"
#include "cs.hpp"
#include "pal/thread.hpp"
#include "pal/malloc.hpp"


/* Pseudo handles constant for current thread and process */
Expand Down
80 changes: 0 additions & 80 deletions src/coreclr/pal/src/include/pal/malloc.hpp

This file was deleted.

8 changes: 4 additions & 4 deletions src/coreclr/pal/src/include/pal/synchcache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Module Name:
#define _SYNCH_CACHE_H_

#include "pal/thread.hpp"
#include "pal/malloc.hpp"
#include <new>

namespace CorUnix
{
Expand Down Expand Up @@ -116,7 +116,7 @@ namespace CorUnix

for (j=i;j<n;j++)
{
pvObjRaw = (void *) InternalNew<USynchCacheStackNode>();
pvObjRaw = (void *) new(std::nothrow) USynchCacheStackNode();
if (NULL == pvObjRaw)
break;
#ifdef _DEBUG
Expand Down Expand Up @@ -159,7 +159,7 @@ namespace CorUnix
}
else
{
InternalDelete((char *)pNode);
delete (char *)pNode;
}
Unlock(pthrCurrent);
}
Expand All @@ -184,7 +184,7 @@ namespace CorUnix
{
pTemp = pNode;
pNode = pNode->next;
InternalDelete((char *)pTemp);
delete (char *)pTemp;
}
}
};
Expand Down
8 changes: 0 additions & 8 deletions src/coreclr/pal/src/include/pal/threadsusp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ Module Name:
// Need this ifdef since this header is included by .c files so they can use the diagnostic function.
#ifdef __cplusplus

// Note: do not include malloc.hpp from this header. The template InternalDelete
// needs to know the layout of class CPalThread, which includes a member of type
// CThreadSuspensionInfo, which is defined later in this header, and it is not
// yet known at this point.
// If any future change should bring this issue back, the circular dependency can
// be further broken by making the InternalDelete's CPalThread argument a
// templatized argument, so that type checking on it takes place only at
// instantiation time.
#include "pal/threadinfo.hpp"
#include "pal/thread.hpp"
#include "pal/mutex.hpp"
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/pal/src/init/pal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ Initialize(

// The gSharedFilesPath is allocated dynamically so its destructor does not get
// called unexpectedly during cleanup
gSharedFilesPath = InternalNew<PathCharString>();
gSharedFilesPath = new(std::nothrow) PathCharString();
if (gSharedFilesPath == nullptr)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
Expand Down Expand Up @@ -482,7 +482,7 @@ Initialize(
// Initialize the object manager
//

pshmom = InternalNew<CSharedMemoryObjectManager>();
pshmom = new(std::nothrow) CSharedMemoryObjectManager();
if (nullptr == pshmom)
{
ERROR("Unable to allocate new object manager\n");
Expand All @@ -494,7 +494,7 @@ Initialize(
if (NO_ERROR != palError)
{
ERROR("object manager initialization failed!\n");
InternalDelete(pshmom);
delete pshmom;
goto CLEANUP1b;
}

Expand Down
1 change: 0 additions & 1 deletion src/coreclr/pal/src/loader/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Module Name:
SET_DEFAULT_DEBUG_CHANNEL(LOADER); // some headers have code with asserts, so do this first

#include "pal/thread.hpp"
#include "pal/malloc.hpp"
#include "pal/file.hpp"
#include "pal/palinternal.h"
#include "pal/module.h"
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/pal/src/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ Module Name:
#include "pal/map.hpp"
#include "pal/thread.hpp"
#include "pal/file.hpp"
#include "pal/malloc.hpp"

#include <stddef.h>
#include <sys/stat.h>
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/pal/src/map/virtual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ SET_DEFAULT_DEBUG_CHANNEL(VIRTUAL); // some headers have code with asserts, so d

#include "pal/thread.hpp"
#include "pal/cs.hpp"
#include "pal/malloc.hpp"
#include "pal/file.hpp"
#include "pal/seh.hpp"
#include "pal/virtual.h"
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/pal/src/misc/dbgmsg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Module Name:
/* PAL headers */

#include "pal/thread.hpp"
#include "pal/malloc.hpp"
#include "pal/file.hpp"

#include "config.h"
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/pal/src/misc/environ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Revision History:
#include "pal/critsect.h"
#include "pal/dbgmsg.h"
#include "pal/environ.h"
#include "pal/malloc.hpp"

#if HAVE_CRT_EXTERNS_H
#include <crt_externs.h>
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/pal/src/misc/strutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Module Name:

#include "pal/corunix.hpp"
#include "pal/thread.hpp"
#include "pal/malloc.hpp"
#include "pal/dbgmsg.h"

SET_DEFAULT_DEBUG_CHANNEL(PAL);
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/pal/src/misc/tracepointprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Revision History:
#include "pal/file.h"
#include "pal/process.h"
#include "pal/module.h"
#include "pal/malloc.hpp"
#include "pal/stackstring.hpp"

#include <errno.h>
Expand Down
3 changes: 1 addition & 2 deletions src/coreclr/pal/src/objmgr/palobjbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Module Name:
--*/

#include "palobjbase.hpp"
#include "pal/malloc.hpp"
#include "pal/dbgmsg.h"

SET_DEFAULT_DEBUG_CHANNEL(PAL);
Expand Down Expand Up @@ -323,7 +322,7 @@ CPalObjectBase::ReleaseReference(
(*m_pot->GetProcessLocalDataCleanupRoutine())(pthr, static_cast<IPalObject*>(this));
}

InternalDelete(this);
delete this;

pthr->ReleaseThreadReference();
}
Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/pal/src/objmgr/palobjbase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ namespace CorUnix

class CPalObjectBase : public IPalObject
{
template <class T> friend void InternalDelete(T *p);

protected:

LONG m_lRefCount;
Expand Down
3 changes: 1 addition & 2 deletions src/coreclr/pal/src/objmgr/shmobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Module Name:
--*/

#include "shmobject.hpp"
#include "pal/malloc.hpp"
#include "pal/cs.hpp"
#include "pal/dbgmsg.h"

Expand Down Expand Up @@ -527,7 +526,7 @@ CSharedMemoryObject::CleanupForProcessShutdown(
m_pthrCleanup = pthr;
pthr->AddThreadReference();

InternalDelete(this);
delete this;

pthr->ReleaseThreadReference();

Expand Down
4 changes: 0 additions & 4 deletions src/coreclr/pal/src/objmgr/shmobject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ namespace CorUnix

class CSharedMemoryObject : public CPalObjectBase
{
template <class T> friend void InternalDelete(T *p);

protected:

//
Expand Down Expand Up @@ -298,8 +296,6 @@ namespace CorUnix

class CSharedMemoryWaitableObject : public CSharedMemoryObject
{
template <class T> friend void InternalDelete(T *p);

protected:

VOID *m_pvSynchData;
Expand Down
8 changes: 4 additions & 4 deletions src/coreclr/pal/src/objmgr/shmobjectmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ CSharedMemoryObjectManager::AllocateObject(

if (CObjectType::WaitableObject == pot->GetSynchronizationSupport())
{
pshmobj = InternalNew<CSharedMemoryWaitableObject>(pot, &m_csListLock);
pshmobj = new(std::nothrow) CSharedMemoryWaitableObject(pot, &m_csListLock);
}
else
{
pshmobj = InternalNew<CSharedMemoryObject>(pot, &m_csListLock);
pshmobj = new(std::nothrow) CSharedMemoryObject(pot, &m_csListLock);
}

if (NULL != pshmobj)
Expand Down Expand Up @@ -1025,15 +1025,15 @@ CSharedMemoryObjectManager::ImportSharedObjectIntoProcess(

if (CObjectType::WaitableObject == pot->GetSynchronizationSupport())
{
pshmobj = InternalNew<CSharedMemoryWaitableObject>(pot,
pshmobj = new(std::nothrow) CSharedMemoryWaitableObject(pot,
&m_csListLock,
shmSharedObjectData,
psmod,
fAddRefSharedData);
}
else
{
pshmobj = InternalNew<CSharedMemoryObject>(pot,
pshmobj = new(std::nothrow) CSharedMemoryObject(pot,
&m_csListLock,
shmSharedObjectData,
psmod,
Expand Down
Loading

0 comments on commit 524d217

Please sign in to comment.