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

Support empty IpcSharedMemory #335

Merged
merged 3 commits into from
May 31, 2024
Merged

Conversation

sagudev
Copy link
Member

@sagudev sagudev commented May 4, 2024

#334 made more simple.

Fixes #268.

@sagudev sagudev mentioned this pull request May 4, 2024
3 tasks
@sagudev sagudev requested a review from mrobinson May 13, 2024 07:32
Comment on lines 630 to +636
pub fn from_bytes(bytes: &[u8]) -> IpcSharedMemory {
IpcSharedMemory {
os_shared_memory: OsIpcSharedMemory::from_bytes(bytes),
if bytes.is_empty() {
IpcSharedMemory::empty()
} else {
IpcSharedMemory {
os_shared_memory: Some(OsIpcSharedMemory::from_bytes(bytes)),
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be made even simpler by having this return Option<IpcSharedMemory>, much like ptr::NonNull? Then calling code would explicitly need to handle when the shared memory is empty. It feels like it should be an error to try to create an empty shared memory segment -- as it's kinda useless.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would made uses more verbose (most of the time there would be Some value so a lot of None values would be unreachable) and I feel this would complicate things for consumers. There is also no way in rust to tell that slice is at least length of 1, so consumers would still need to handle len=0 cases, even if they get Some. Also this would be breaking change and I tried to avoided that.

Empty buffer also has meaning (receiver was woken with empty message).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is that this API needs to change anyway. Creating a shared memory segment can fail (see the manpage for shm_open for instance). ipc-channels is pretending like it cannot fail and it will panic if a failure does occur. When creating IPC channels, this reality is acknowledged, because channel() returns a Result. Not doing the same here feels like a bit of a lie. Many programs will want to handle failure gracefully.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, but I think better error handling should be done as in separate PR. This PR just makes current API works as expected.

@sagudev sagudev added this pull request to the merge queue May 31, 2024
Merged via the queue into servo:main with commit d8b7f32 May 31, 2024
16 checks passed
SomeoneToIgnore referenced this pull request in zed-industries/zed Aug 1, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [ipc-channel](https://github.com/servo/ipc-channel) | dependencies |
patch | `0.18.0` -> `0.18.2` |

---

### Release Notes

<details>
<summary>servo/ipc-channel (ipc-channel)</summary>

###
[`v0.18.2`](https://github.com/servo/ipc-channel/releases/tag/v0.18.2)

[Compare
Source](https://github.com/servo/ipc-channel/compare/v0.18.1...v0.18.2)

Changes:

-   Upgraded to version `1.0` of `mio`

###
[`v0.18.1`](https://github.com/servo/ipc-channel/releases/tag/v0.18.1)

[Compare
Source](https://github.com/servo/ipc-channel/compare/v0.18.0...v0.18.1)

Includes
[https://github.com/servo/ipc-channel/pull/335](https://github.com/servo/ipc-channel/pull/335)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 3pm on Wednesday" in timezone
America/New_York, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

Release Notes:

- N/A

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40NDAuNyIsInVwZGF0ZWRJblZlciI6IjM3LjQ0MC43IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
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

Successfully merging this pull request may close these issues.

macos::OsIpcSharedMemory::from_bytes aborts if passed an empty slice
2 participants