Skip to content

Commit e6575d2

Browse files
Fix System.cpu_count to return Int32 (#16648)
`Int32` is the default number type, and stdlib APIs should usually return that. Before, the return type of `System.cpu_count` was platform-specific and might have been anything between `Int32`, `Int64` or `UInt32` which makes it difficult to use in portable applications.
1 parent 710d9a5 commit e6575d2

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

spec/std/system_spec.cr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ describe System do
2323
`getconf _NPROCESSORS_ONLN 2>/dev/null || nproc --all 2>/dev/null || grep -sc '^processor' /proc/cpuinfo || sysctl -n hw.ncpu 2>/dev/null`.to_i
2424
{% end %}
2525
cpu_count = System.cpu_count
26+
cpu_count.should be_a(Int32)
2627
cpu_count.should eq(shell_cpus)
2728
end
2829
end

src/system.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module System
1919
# ```
2020
# System.cpu_count # => 4
2121
# ```
22-
def self.cpu_count : Int
23-
Crystal::System.cpu_count
22+
def self.cpu_count : Int32
23+
Crystal::System.cpu_count.to_i32!
2424
end
2525
end

0 commit comments

Comments
 (0)