Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Remove unsafe code in gateway #1042

Merged
merged 2 commits into from
Jul 20, 2021
Merged

Remove unsafe code in gateway #1042

merged 2 commits into from
Jul 20, 2021

Conversation

zeylahellyer
Copy link
Member

@zeylahellyer zeylahellyer commented Jul 18, 2021

Remove unsafe code in the gateway crate. Its use of unsafe was to accommodate simd-json, but can be removed by instead continuously working with the mutable buffer rather than going from bytes -> str -> bytes again.

This also adds #![deny(unsafe_code)] to all crates that weren't already marked with it.

Remove unsafe code in the `gateway` crate's use of `unsafe` to
accommodate `simd-json`, by instead continuously working with the
mutable buffer directly instead of going from bytes -> str -> bytes
again.

This also adds `#![deny(unsafe_code)]` to all crates that weren't
already marked with it.

Signed-off-by: Zeyla Hellyer <zeyla@hellyer.dev>
@zeylahellyer zeylahellyer added c-all Affects all crates or the project as a whole t-refactor Refactors APIs or code. labels Jul 18, 2021
Signed-off-by: Zeyla Hellyer <zeyla@hellyer.dev>
@vilgotf
Copy link
Member

vilgotf commented Jul 18, 2021

Shouldn't this be #![forbid(unsafe_code)]?

@zeylahellyer
Copy link
Member Author

Shouldn't this be #![forbid(unsafe_code)]?

It doesn't really matter either way. The difference is that with deny you can allow usage on particular items, while forbid won't allow you to allow usage anywhere. Since we have a PR process, if there's ever unsafe code that's submitted then we can review whether it's necessary or not. For consistency and simplicity I think it's easier to just combine it into the denial list.

@7596ff 7596ff merged commit 1ebb89a into twilight-rs:main Jul 20, 2021
@zeylahellyer zeylahellyer deleted the refactor/gateway/remove-unsafe-code branch July 21, 2021 01:56
tbnritzdoge pushed a commit to tbnritzdoge/twilight that referenced this pull request Jul 22, 2021
Remove unsafe code in the `gateway` crate's use of `unsafe` to
accommodate `simd-json`, by instead continuously working with the
mutable buffer directly instead of going from bytes -> str -> bytes
again.

This also adds `#![deny(unsafe_code)]` to all crates that weren't
already marked with it.
7596ff added a commit that referenced this pull request Jul 24, 2021
Changes

`#![deny(unsafe_code)]` has been added, ensuring no unsafe code exists
in the crate ([#1042] - [@zeylahellyer]).

[#1042]: #1042

[@zeylahellyer]: https://github.com/zeylahellyer
7596ff added a commit that referenced this pull request Jul 24, 2021
Changes

`#![deny(unsafe_code)]` has been added, ensuring no unsafe code exists
in the crate ([#1042] - [@zeylahellyer]).

[#1042]: #1042

[@zeylahellyer]: https://github.com/zeylahellyer
7596ff added a commit that referenced this pull request Jul 24, 2021
Additions

Add `EventTypeFlags` constants with categories of flags that are
equivalent to their Intents counterpart. For example, the new
`EventTypeFlags::GUILD_BANS` associated constant includes the `BAN_ADD`
and `BAN_REMOVE` event type flags.

The following categories have been added ([#1049] - [@vilgotf]):

- `DIRECT_MESSAGES`
- `DIRECT_MESSAGE_REACTIONS`
- `DIRECT_MESSAGE_TYPING`
- `GUILDS`
- `GUILD_BANS`
- `GUILD_EMOJIS`
- `GUILD_INTEGRATIONS`
- `GUILD_INVITES`
- `GUILD_MEMBERS`
- `GUILD_MESSAGES`
- `GUILD_MESSAGE_REACTIONS`
- `GUILD_MESSAGE_TYPING`
- `GUILD_PRESENCES`
- `GUILD_VOICE_STATES`
- `GUILD_WEBHOOKS`

Changes

`#![deny(unsafe_code)]` has been added, ensuring no unsafe code exists
in the crate. To comply with this, while using the `simd-json` feature,
the mutable buffer is directly used instead of casting from bytes -> str
-> bytes ([#1042] - [@zeylahellyer]).

[#1042]: #1042
[#1049]: #1049

[@vilgotf]: https://github.com/vilgotf
[@zeylahellyer]: https://github.com/zeylahellyer
7596ff added a commit that referenced this pull request Jul 24, 2021
Changes

`#![deny(unsafe_code)]` has been added, ensuring no unsafe code exists
in the crate ([#1042] - [@zeylahellyer]).

[#1042]: #1042

[@zeylahellyer]: https://github.com/zeylahellyer
7596ff added a commit that referenced this pull request Jul 24, 2021
Changes

`#![deny(unsafe_code)]` has been added, ensuring no unsafe code exists
in the crate ([#1042] - [@zeylahellyer]).

Fixes

The `JSON` body is now actually serialized on the `update_channel` route
([#1051] - [@Learath2]).

[#1042]: #1042
[#1051]: #1051

[@Learath2]: https://github.com/Learath2
[@zeylahellyer]: https://github.com/zeylahellyer
7596ff added a commit that referenced this pull request Jul 24, 2021
Changes

`#![deny(unsafe_code)]` has been added, ensuring no unsafe code exists
in the crate ([#1042] - [@zeylahellyer]).

[#1042]: #1042

[@zeylahellyer]: https://github.com/zeylahellyer
7596ff added a commit that referenced this pull request Jul 24, 2021
Changes

`#![deny(unsafe_code)]` has been added, ensuring no unsafe code exists
in the crate ([#1042] - [@zeylahellyer]).

[#1042]: #1042

[@zeylahellyer]: https://github.com/zeylahellyer
7596ff added a commit that referenced this pull request Jul 24, 2021
Changes

`#![deny(unsafe_code)]` has been added, ensuring no unsafe code exists
in the crate ([#1042] - [@zeylahellyer]).

[#1042]: #1042

[@zeylahellyer]: https://github.com/zeylahellyer
zeylahellyer pushed a commit to twilight-rs/command-parser that referenced this pull request Apr 15, 2022
Changes

`#![deny(unsafe_code)]` has been added, ensuring no unsafe code exists
in the crate ([#1042] - [@zeylahellyer]).

[#1042]: twilight-rs/twilight#1042

[@zeylahellyer]: https://github.com/zeylahellyer
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
c-all Affects all crates or the project as a whole t-refactor Refactors APIs or code.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants