-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Implement System for Win32 #6972
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
Merged
RX14
merged 14 commits into
crystal-lang:master
from
neatorobito:markrjr/windows_system
Dec 17, 2018
Merged
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
aa43722
Working hostname and cpu count on win32.
neatorobito 077b2dd
Remove API links and run format tool.
neatorobito 6df9883
Use wide string variant, GetNativeSysInfo, and other PR comment fixes.
neatorobito b9b5904
Uses retry_wstr_buffer and other also removes unnecessary constants.
neatorobito 808e56c
Removed redundancy in libc function definition.
neatorobito 8be0008
Ran format tool.
neatorobito ba46dd9
Update specs for Windows and check flags.
neatorobito a6e6737
Revert part of system_soec and change conditional block for system.
neatorobito ef48f4c
Formatting tool.
neatorobito 60d8a2b
Re-add shell_cpus.
neatorobito 0d7683a
Flag changes for system.
neatorobito 4a2742d
Add indentation.
2c59c80
Switch from to_u, remove space, remove shell_cpus, and revert comments.
neatorobito 3fca8ec
Conditionally define shell_cpus.
neatorobito File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| require "c/sysinfoapi" | ||
|
|
||
| module Crystal::System | ||
| def self.cpu_count | ||
| LibC.GetNativeSystemInfo(out system_info) | ||
| system_info.dwNumberOfProcessors | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| require "c/sysinfoapi" | ||
|
|
||
| module Crystal::System | ||
| def self.hostname | ||
| retry_wstr_buffer do |buffer, small_buf| | ||
| name_size = buffer.size.to_u | ||
neatorobito marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if LibC.GetComputerNameExW(LibC::COMPUTER_NAME_FORMAT::ComputerNameDnsHostname, buffer, pointerof(name_size)) != 0 | ||
| break String.from_utf16(buffer[0, name_size]) | ||
| elsif small_buf && name_size > 0 | ||
| next name_size | ||
| else | ||
| raise WinError.new("GetComputerNameExW") | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| require "c/winnt" | ||
| require "c/win_def" | ||
| require "c/int_safe" | ||
|
|
||
| lib LibC | ||
| fun GetNativeSystemInfo(system_info : SYSTEM_INFO*) | ||
|
|
||
| struct PROCESSOR_INFO | ||
| wProcessorArchitecture : WORD | ||
| wReserved : WORD | ||
| end | ||
|
|
||
| union OEM_PROCESSOR_INFO | ||
| dwOemId : DWORD | ||
| processorInfo : PROCESSOR_INFO | ||
| end | ||
|
|
||
| struct SYSTEM_INFO | ||
| oemProcessorInfo : OEM_PROCESSOR_INFO | ||
| dwPageSize : DWORD | ||
| lpMinimumApplicationAddress : Void* | ||
| lpMaximumApplicationAddress : Void* | ||
| dwActiveProcessorMask : DWORD* | ||
| dwNumberOfProcessors : DWORD | ||
| dwProcessorType : DWORD | ||
| dwAllocationGranularity : DWORD | ||
| wProcessorLevel : WORD | ||
| wProcessorRevision : WORD | ||
| end | ||
|
|
||
| fun GetComputerNameExW(computer_name_format : COMPUTER_NAME_FORMAT, | ||
| machine_name : LPWSTR, | ||
| machine_name_size : DWORD*) : BOOLEAN | ||
|
|
||
| enum COMPUTER_NAME_FORMAT | ||
| ComputerNameNetBIOS | ||
| ComputerNameDnsHostname | ||
neatorobito marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ComputerNameDnsDomain | ||
| ComputerNameDnsFullyQualified | ||
| ComputerNamePhysicalNetBIOS | ||
| ComputerNamePhysicalDnsHostname | ||
| ComputerNamePhysicalDomain | ||
| ComputerNamePhysicalDnsFullyQualified | ||
| end | ||
| end | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.