File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change 1818#include " struct_smart_holder.h"
1919
2020#include < atomic>
21+ #include < cstdint>
2122#include < exception>
23+ #include < limits>
2224#include < mutex>
2325#include < thread>
2426
@@ -274,8 +276,10 @@ struct internals {
274276 registered_exception_translators.push_front (&translate_exception);
275277#ifdef Py_GIL_DISABLED
276278 // Scale proportional to the number of cores. 2x is a heuristic to reduce contention.
277- auto num_shards
278- = static_cast <size_t >(round_up_to_next_pow2 (2 * std::thread::hardware_concurrency ()));
279+ // Make sure the number isn't unreasonable by limiting it to 16 bits (65K)
280+ auto num_shards = static_cast <std::uint16_t >(
281+ std::min<std::size_t >(round_up_to_next_pow2 (2 * std::thread::hardware_concurrency ()),
282+ std::numeric_limits<std::uint16_t >::max ()));
279283 if (num_shards == 0 ) {
280284 num_shards = 1 ;
281285 }
You can’t perform that action at this time.
0 commit comments