-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(parse_size): Add cross-platform total_physical_memory implementat… #9653
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
base: main
Are you sure you want to change the base?
fix(parse_size): Add cross-platform total_physical_memory implementat… #9653
Conversation
401a9fe to
8fae6fc
Compare
|
GNU testsuite comparison: |
80fa255 to
34d1ef3
Compare
|
GNU testsuite comparison: |
34d1ef3 to
f57d398
Compare
|
GNU testsuite comparison: |
|
LGTM for FreeBSD and OpenBSD to get "Total physical memory" via |
sylvestre
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this patch has a lot of duplication, could you please have a look? thanks
f57d398 to
6c0f36a
Compare
|
GNU testsuite comparison: |
…ions - Implements total_physical_memory() for macOS (hw.memsize) - Implements total_physical_memory() for FreeBSD (hw.physmem) - Implements total_physical_memory() for OpenBSD (hw.physmem) - Implements total_physical_memory() for NetBSD (hw.physmem64) - Enables 'sort -S 50%' to work on all BSD-based platforms - Updates tests to include percentage buffer sizes for BSD platforms Fixes uutils#7257
6c0f36a to
67839ab
Compare
|
GNU testsuite comparison: |
Replace subprocess-based sysctl calls with native libc::sysctl() syscalls for macOS, FreeBSD, OpenBSD, and NetBSD to fix test_buffer_sizes failure in CI environments. The previous implementation spawned sysctl subprocesses which could fail in sandboxed GitHub Actions runners. The native approach is more reliable, performant, and includes subprocess fallback for robustness. Fixes percentage-based buffer size parsing (e.g., sort -S 10%)
67839ab to
e104905
Compare
|
GNU testsuite comparison: |
- Fix clippy::borrow-as-ptr lint error in parse_size.rs by using raw pointer syntax - Fix macOS uptime test regex to accept integer load averages without decimals Fixes OpenBSD and macOS CI test failures in PR uutils#9653
The bsd_sysctl_memory() subprocess fallback was inheriting parent's stdin, causing commands like sort to hang when receiving EOF. This broke the GNU tty-eof test which expects immediate exit on Ctrl+D. Fix: Configure subprocess stdin/stdout/stderr to prevent fd inheritance: - stdin: Stdio::null() (no input needed) - stdout: Stdio::piped() (capture output) - stderr: Stdio::null() (suppress errors) Fixes GNU test: tests/tty/tty-eof
|
GNU testsuite comparison: |
…gile configurations Addresses PR uutils#9653 review feedback about 'fragile commands' by implementing fail-fast validation in Parser builder pattern. Changes: - Add ParserBuilderError enum with 8 validation error variants - Refactor builder methods to return Result<&mut Self, ParserBuilderError> - Implement comprehensive unit validation (57 valid units including k/m/g/t) - Add cross-validation between builder settings (default_unit vs allow_list) - Detect conflicts (b_byte_count with 'b' unit, '%' with size units) - Update all call sites (sort, du, df, od) to handle new error types - Fix invalid '%' unit in sort's parse_byte_count allow_list Benefits: - Configuration errors detected immediately (not during parsing) - Clear error messages listing invalid/conflicting settings - Maintains backward compatibility through explicit error reporting Files modified: - src/uucore/src/lib/features/parser/parse_size.rs (core implementation) - src/uu/sort/src/sort.rs (error handling + fix invalid '%') - src/uu/du/src/du.rs (error handling) - src/uu/df/src/df.rs (error handling) - src/uu/od/src/od.rs (error handling)
…gile configurations Addresses PR uutils#9653 review feedback about 'fragile commands' by implementing fail-fast validation in Parser builder pattern. Changes: - Add ParserBuilderError enum with 8 validation error variants - Refactor builder methods to return Result<&mut Self, ParserBuilderError> - Implement comprehensive unit validation (57 valid units including k/m/g/t) - Add cross-validation between builder settings (default_unit vs allow_list) - Detect conflicts (b_byte_count with 'b' unit, '%' with size units) - Update all call sites (sort, du, df, od) to handle new error types - Fix invalid '%' unit in sort's parse_byte_count allow_list Benefits: - Configuration errors detected immediately (not during parsing) - Clear error messages listing invalid/conflicting settings - Maintains backward compatibility through explicit error reporting Files modified: - src/uucore/src/lib/features/parser/parse_size.rs (core implementation) - src/uu/sort/src/sort.rs (error handling + fix invalid '%') - src/uu/du/src/du.rs (error handling) - src/uu/df/src/df.rs (error handling) - src/uu/od/src/od.rs (error handling)
…gile configurations Addresses PR uutils#9653 review feedback about 'fragile commands' by implementing fail-fast validation in Parser builder pattern. Changes: - Add ParserBuilderError enum with 8 validation error variants - Refactor builder methods to return Result<&mut Self, ParserBuilderError> - Implement comprehensive unit validation (57 valid units including k/m/g/t) - Add cross-validation between builder settings (default_unit vs allow_list) - Detect conflicts (b_byte_count with 'b' unit, '%' with size units) - Update all call sites (sort, du, df, od) to handle new error types - Fix invalid '%' unit in sort's parse_byte_count allow_list Benefits: - Configuration errors detected immediately (not during parsing) - Clear error messages listing invalid/conflicting settings - Maintains backward compatibility through explicit error reporting Files modified: - src/uucore/src/lib/features/parser/parse_size.rs (core implementation) - src/uu/sort/src/sort.rs (error handling + fix invalid '%') - src/uu/du/src/du.rs (error handling) - src/uu/df/src/df.rs (error handling) - src/uu/od/src/od.rs (error handling)
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
OpenBSD has stricter clippy linting that requires dereferencing &&str before calling to_string() to use the fast str specialization instead of the slower blanket impl.
|
GNU testsuite comparison: |
…cation - Added '%' to sort's buffer-size allow_list for Unix-like systems - Removed overly strict validation that prevented '%' from being mixed with other size units in the same allow_list - The '%' suffix triggers special handling for percentage of physical memory, but other units remain valid in the same configuration
|
GNU testsuite comparison: |
Move 'use nix::libc' to module level for BSD platforms to fix macOS compilation error where libc::c_int was referenced in function signature before the import was in scope. Also removed duplicate use statements from individual functions.
|
GNU testsuite comparison: |
Implements
total_physical_memory()for macOS, FreeBSD, OpenBSD, and NetBSD using platform-specificsysctlcommands. Enablessort -S 50%to work on all BSD-based systems.Fixes #7257