Skip to content

Minimal std/os #2571

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

Closed
daurnimator opened this issue May 28, 2019 · 3 comments
Closed

Minimal std/os #2571

daurnimator opened this issue May 28, 2019 · 3 comments
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@daurnimator
Copy link
Contributor

daurnimator commented May 28, 2019

I understand your general preference @daurnimator to move stuff out of std/os.zig. I'd like to handle that proposal separately. I think there is something to it, but I also think that the premise of this PR as it stands is sound. The comment at the top says:

// This file contains thin wrappers around OS-specific APIs, with these
// specific goals in mind:
// * Convert "errno"-style error codes into Zig errors.
// * When null-terminated byte buffers are required, provide APIs which accept
//   slices as well as APIs which accept null-terminated byte buffers. Same goes
//   for UTF-16LE encoding.
// * Where operating systems share APIs, e.g. POSIX, these thin wrappers provide
//   cross platform abstracting.
// * When there exists a corresponding libc function and linking libc, the libc
//   implementation is used. Exceptions are made for known buggy areas of libc.
//   On Linux libc can be side-stepped by using `std.os.linux` directly.
// * For Windows, this file represents the API that libc would provide for
//   Windows. For thin wrappers around Windows-specific APIs, see `std.os.windows`.
// Note: The Zig standard library does not support POSIX thread cancellation, and
// in general EINTR is handled by trying again.

In particular 3 of these points apply to nanosleep:

  • nanosleep is a libc function, available on linux, freebsd, macos, netbsd, and probably more. os.nanosleep provides cross platform abstraction over these.
  • on linux when not linking libc, os.nanosleep provides abstraction over calling the libc version or the linux syscall directly.
  • the possible error of nanosleep is converted to void meaning that it cannot fail (by adding "spurious wakeups are possible" to the documented behavior)

On the other hand, the decision to make it work for Windows is questionable. nanosleep is not a Windows API function, either directly or in msvcrt. os.nanosleep could have Windows support removed and that logic can go directly in std.time.sleep, and become simpler. That's probably a good idea.

Originally posted by @andrewrk in #2527

@andrewrk andrewrk added proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. standard library This issue involves writing Zig code for the standard library. labels May 28, 2019
@andrewrk andrewrk added this to the 0.6.0 milestone May 28, 2019
@andrewrk
Copy link
Member

The nanosleep changes mentioned above are in master branch.

Can you make a small proof of concept PR to explain what you want to do? As it stands this proposal would not be enough for me to accept.

@andrewrk
Copy link
Member

andrewrk commented Jan 5, 2020

It's not clear to me what's being proposed here

@andrewrk andrewrk closed this as completed Jan 5, 2020
@daurnimator
Copy link
Contributor Author

I guess one outcome of this issue could be a better definition of what makes it into std/os.zig:

  • is it any functionality that appears in at least two operating systems?
  • is it any API in any OS? (e.g. currently memfd_create is in there and it's linux only)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

No branches or pull requests

2 participants