Skip to content

Sidetables should not use operator new or operator delete. #58459

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

Merged

Conversation

grynspan
Copy link
Contributor

Sidetables should not use operator new or operator delete. This change switches them over to swift_cxx_newObject() and swift_cxx_deleteObject() which wrap swift_slowAlloc() and swift_slowDealloc() respectively.

Why is this important? Because these operators can be overridden globally by code in other modules. Imagine a game that has a custom memory allocator (a common scenario!) The developers of this game may want to have all C++ allocations go through their custom allocator. Now, what happens if they implement the guts of this allocator in Swift (in whole or in part)? Well… better hope you never need to allocate a sidetable while you're in there.

@grynspan
Copy link
Contributor Author

@swift-ci please test

@@ -1329,6 +1330,9 @@ class HeapObjectSideTableEntry {
#endif
{ }

void *operator new(size_t) = delete;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might have to pull these lines out, but the idea is to catch any errant uses of new or delete on this type.

@grynspan grynspan force-pushed the jgrynspan/avoid-operator-new-for-sidetables branch 2 times, most recently from 4f1476a to 32fc8c0 Compare April 27, 2022 18:06
@grynspan
Copy link
Contributor Author

@swift-ci please test

@grynspan grynspan force-pushed the jgrynspan/avoid-operator-new-for-sidetables branch from 32fc8c0 to 0fdad9e Compare April 28, 2022 16:50
@grynspan
Copy link
Contributor Author

@swift-ci please test

@grynspan grynspan requested a review from zoecarver April 28, 2022 16:56
@grynspan grynspan force-pushed the jgrynspan/avoid-operator-new-for-sidetables branch from 0fdad9e to 19e954f Compare April 28, 2022 17:47
@grynspan grynspan changed the title [WIP] Sidetables should not use operator new or operator delete. Sidetables should not use operator new or operator delete. Apr 28, 2022
@grynspan
Copy link
Contributor Author

@swift-ci please test

@grynspan grynspan requested a review from mikeash April 28, 2022 18:47
@zoecarver
Copy link
Contributor

I don't know this part of the codebase very well, but it seems reasonable. Thanks Jonathan.

@grynspan grynspan self-assigned this Apr 28, 2022
@grynspan grynspan merged commit 320872c into swiftlang:main Apr 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants