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 18
18
#include " struct_smart_holder.h"
19
19
20
20
#include < atomic>
21
+ #include < cstdint>
21
22
#include < exception>
23
+ #include < limits>
22
24
#include < mutex>
23
25
#include < thread>
24
26
@@ -274,8 +276,10 @@ struct internals {
274
276
registered_exception_translators.push_front (&translate_exception);
275
277
#ifdef Py_GIL_DISABLED
276
278
// 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 ()));
279
283
if (num_shards == 0 ) {
280
284
num_shards = 1 ;
281
285
}
You can’t perform that action at this time.
0 commit comments