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
Use system allocator for containers on macOS (bypassing Unity's allocator) #2900
Conversation
There are many intentional uses of the c99 designator initialization syntax in the codebase.
This is necessary for the macOS alloc code to compile. The change in error_analysis_test.cpp is necessary because a non-Principia function is called which returns a ::std::vector. I'm not sure why the friend std::pair in discrete_trajectory.cpp needs full qualification.
Specifically, force include magic/malloc_allocator.hpp on macOS builds via clang argument.
FWIW, this PR generally looks good. We'll do a more thorough review over the week-end. Expect nits, but nothing earth-shattering. |
@@ -87,6 +87,7 @@ SHARED_ARGS := \ | |||
-Wall -Wpedantic \ | |||
-Wno-char-subscripts \ | |||
-Wno-gnu-anonymous-struct \ | |||
-Wno-c99-extensions \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just out of curiosity, which warning does this suppress?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
./astronomy/orbital_elements_body.hpp:165:10: warning: designated initializers
are a C99 feature [-Wc99-extensions]
{.t = time,
^~~~~~~~~
./astronomy/orbital_elements_body.hpp:166:10: warning: designated initializers
are a C99 feature [-Wc99-extensions]
.a = *osculating_elements.semimajor_axis,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./astronomy/orbital_elements_body.hpp:167:10: warning: designated initializers
are a C99 feature [-Wc99-extensions]
.h = e * Sin(ϖ),
^~~~~~~~~~~~~~~
…and so on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right, these are C++20 whereas the flags say 1z=17.
magic/malloc_allocator.hpp
Outdated
@@ -0,0 +1,110 @@ | |||
// This file contains two things: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Among other things, the magic
directly is going to interact poorly with VS. I would organize things differently here:
- A file
base/malloc_allocator.hpp
that declares and defines the classMallocAllocator
in namespaceprincipia::base
. This one is not magic in any way, and should be included in the usual manner. - A file
base/macos_allocator_replacement.hpp
that has all the stuff declared inprincipia::std
. This is the one that is magically included. For safety, it should have preprocessor directives that ensure that it's never pulled for other platforms:
#if !OS_MACOSX
#error Only include for macOS
#endif
... all the rest ...
You'll need to include base/macros.hpp
in that second file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Split principia::std into a separate file. Disabled principia::std for non-macOS builds.
First part of a two-part fix for #2899.
This change causes STL containers (std::vector and the like) to use the native system allocator on macOS instead of the Unity-provided allocator.
It does this by defining an allocator which avoids using of
new
anddelete
, and then creating aliases tostd::vector
and friends in theprincipia::std
namespace using the new allocator. The header file containing this change is included via compiler argument, so this change is almost entirely transparent to the rest of the codebase (I had to add full qualification in two places).