Skip to content
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

[upstream_utils] Upgrade Sleipnir to avoid pool allocator crash on Windows #6821

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions upstream_utils/update_sleipnir.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
def main():
upstream_root = clone_repo(
"https://github.com/SleipnirGroup/Sleipnir",
# main on 2024-07-05
"b90f89d343379dd8dc88f22e0462eb7b59006b2c",
# main on 2024-07-09
"b6ffa2d4fdb99cab1bf79491f715a6a9a86633b5",
shallow=False,
)
wpilib_root = get_repo_root()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@

namespace sleipnir::detail {

// The global pool allocator uses a thread-local static pool resource, which
// isn't guaranteed to be initialized properly across DLL boundaries on Windows
#ifdef _WIN32
inline constexpr bool kUsePoolAllocator = false;
#else
inline constexpr bool kUsePoolAllocator = true;
#endif

struct SLEIPNIR_DLLEXPORT Expression;

inline void IntrusiveSharedPtrIncRefCount(Expression* expr);
Expand All @@ -38,8 +46,12 @@ using ExpressionPtr = IntrusiveSharedPtr<Expression>;
*/
template <typename... Args>
static ExpressionPtr MakeExpressionPtr(Args&&... args) {
return AllocateIntrusiveShared<Expression>(GlobalPoolAllocator<Expression>(),
std::forward<Args>(args)...);
if constexpr (kUsePoolAllocator) {
return AllocateIntrusiveShared<Expression>(
GlobalPoolAllocator<Expression>(), std::forward<Args>(args)...);
} else {
return MakeIntrusiveShared<Expression>(std::forward<Args>(args)...);
}
}

/**
Expand Down Expand Up @@ -437,9 +449,11 @@ inline void IntrusiveSharedPtrDecRefCount(Expression* expr) {

// Not calling the destructor here is safe because it only decrements
// refcounts, which was already done above.
auto alloc = GlobalPoolAllocator<Expression>();
std::allocator_traits<decltype(alloc)>::deallocate(alloc, elem,
sizeof(Expression));
if constexpr (kUsePoolAllocator) {
auto alloc = GlobalPoolAllocator<Expression>();
std::allocator_traits<decltype(alloc)>::deallocate(alloc, elem,
sizeof(Expression));
}
}
}
}
Expand Down
Loading