Skip to content
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

librustuv: avoid using the magic number -1 for offset #17433

Closed
nodakai opened this issue Sep 22, 2014 · 1 comment
Closed

librustuv: avoid using the magic number -1 for offset #17433

nodakai opened this issue Sep 22, 2014 · 1 comment

Comments

@nodakai
Copy link
Contributor

nodakai commented Sep 22, 2014

The signature of uv_fs_read() is

UV_EXTERN int uv_fs_read(uv_loop_t* loop, uv_fs_t* req, uv_file file,
    void* buf, size_t length, int64_t offset, uv_fs_cb cb);

and when we pass -1 as offset, libuv discards it in favor of the intrinsic file offset.

  if (offset != -1) {
    memset(&overlapped, 0, sizeof overlapped);

    offset_.QuadPart = offset;
    overlapped.Offset = offset_.LowPart;
    overlapped.OffsetHigh = offset_.HighPart;

    overlapped_ptr = &overlapped;
  } else {
    overlapped_ptr = NULL;
  }
static ssize_t uv__fs_read(uv_fs_t* req) {
  if (req->off < 0)
    return read(req->file, req->buf, req->len);
  else
    return pread(req->file, req->buf, req->len, req->off);
}

(The same goes for write operations.)

Such an interface design is fine for libuv itself, but librustuv should present more meaningful interface such as offset: Option<u64>. Note that the role of the magic number -1 is documented nowhere in libuv (sample codes in the uvbook use it without any explanations.) That pretty much means the users of libuv are expected to go through its implementation code in C. But all the developers of Rust don't need to do so.

@thestinger
Copy link
Contributor

libuv was removed as part of #17325 so this is no longer an issue for this repository

lnicola pushed a commit to lnicola/rust that referenced this issue Jun 23, 2024
These are not currently documented and could cause users to think
that their rust-analyzer configuration is broken.

Partially addresses rust-lang#17433.
lnicola pushed a commit to lnicola/rust that referenced this issue Jun 23, 2024
…rs, r=Veykril

docs: document omission heuristics for parameter inlay hints

These are not currently documented and could cause users to think that their rust-analyzer configuration is broken.

Partially addresses rust-lang#17433.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants