Skip to content

Commit

Permalink
Review comments
Browse files Browse the repository at this point in the history
Signed-off-by: John Nunley <[email protected]>
  • Loading branch information
notgull committed Oct 7, 2023
1 parent 5f5f020 commit f705e9a
Show file tree
Hide file tree
Showing 41 changed files with 719 additions and 669 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

env:
CARGO_TERM_COLOR: always
MOST_FEATURES: all-extensions cursor image tracing tracing-subscriber/env-filter
MOST_FEATURES: all-extensions cursor extra-traits image tracing tracing-subscriber/env-filter
# According to code coverage changes, sometimes $XENVIRONMENT is set and
# sometimes not. Try to make this consistent to stabilise coverage reports.
# Example: https://app.codecov.io/gh/psychon/x11rb/compare/726/changes
Expand Down Expand Up @@ -60,6 +60,12 @@ jobs:
- name: clippy x11rb without features
run: cargo clippy -p x11rb --all-targets -- -D warnings ${{ matrix.clippy_args }}

- name: clippy x11rb without default features
run: cargo clippy -p x11rb --all-targets -- -D warnings ${{ matrix.clippy_args }} --no-default-features

- name: clippy x11rb-protocol with request parsing
run: cargo clippy -p x11rb-protocol --all-targets -- -D warnings ${{ matrix.clippy_args }} --features request-parsing

- name: clippy x11rb with allow-unsafe-code but without dl-libxcb
run: cargo clippy -p x11rb --all-targets --features "allow-unsafe-code" -- -D warnings ${{ matrix.clippy_args }}

Expand Down
2 changes: 1 addition & 1 deletion generator/src/generator/namespace/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ fn emit_request_struct(
);
outln!(
out,
"#[cfg(feature = \"extra-traits\")]"
"#[cfg(feature = \"request-parsing\")]"
);
if gathered.has_fds() {
outln!(
Expand Down
4 changes: 4 additions & 0 deletions generator/src/generator/namespace/switch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,10 @@ fn emit_switch_try_parse(
)
})
.collect::<Vec<_>>();
outln!(
out.indent(),
"#[cfg_attr(not(feature = \"request-parsing\"), allow(dead_code))]"
);
outln!(
out.indent(),
"fn try_parse(value: &[u8], {}) -> Result<(Self, &[u8]), ParseError> {{",
Expand Down
2 changes: 1 addition & 1 deletion generator/src/generator/requests_replies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ pub(super) fn generate(out: &mut Output, module: &xcbdefs::Module, mut enum_case
out,
"#[allow(clippy::cognitive_complexity, clippy::single_match)]"
);
outln!(out, "#[cfg(feature = \"extra-traits\")]");
outln!(out, "#[cfg(feature = \"request-parsing\")]");
outln!(out, "pub fn parse(");
out.indented(|out| {
outln!(out, "header: RequestHeader,");
Expand Down
1 change: 1 addition & 0 deletions x11rb-async/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ all-extensions = [
"xvmc"
]

# Enable extra traits on protocol types.
extra-traits = ["x11rb-protocol/extra-traits"]

composite = ["x11rb-protocol/composite", "xfixes"]
Expand Down
5 changes: 5 additions & 0 deletions x11rb-protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ std = []
# Enable extra traits for the X11 types
extra-traits = []

# Enable parsing for requests.
#
# This adds a lot of extra code that isn't used in the common case.
request-parsing = []

# Enable utility functions in `x11rb::resource_manager` for querying the
# resource databases.
resource_manager = ["std"]
Expand Down
2 changes: 1 addition & 1 deletion x11rb-protocol/src/protocol/bigreq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl EnableRequest {
([request0.into()], vec![])
}
/// Parse this request given its header, its body, and any fds that go along with it
#[cfg(feature = "extra-traits")]
#[cfg(feature = "request-parsing")]
pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
if header.minor_opcode != ENABLE_REQUEST {
return Err(ParseError::InvalidValue);
Expand Down
18 changes: 9 additions & 9 deletions x11rb-protocol/src/protocol/composite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl QueryVersionRequest {
([request0.into()], vec![])
}
/// Parse this request given its header, its body, and any fds that go along with it
#[cfg(feature = "extra-traits")]
#[cfg(feature = "request-parsing")]
pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
if header.minor_opcode != QUERY_VERSION_REQUEST {
return Err(ParseError::InvalidValue);
Expand Down Expand Up @@ -333,7 +333,7 @@ impl RedirectWindowRequest {
([request0.into()], vec![])
}
/// Parse this request given its header, its body, and any fds that go along with it
#[cfg(feature = "extra-traits")]
#[cfg(feature = "request-parsing")]
pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
if header.minor_opcode != REDIRECT_WINDOW_REQUEST {
return Err(ParseError::InvalidValue);
Expand Down Expand Up @@ -417,7 +417,7 @@ impl RedirectSubwindowsRequest {
([request0.into()], vec![])
}
/// Parse this request given its header, its body, and any fds that go along with it
#[cfg(feature = "extra-traits")]
#[cfg(feature = "request-parsing")]
pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
if header.minor_opcode != REDIRECT_SUBWINDOWS_REQUEST {
return Err(ParseError::InvalidValue);
Expand Down Expand Up @@ -499,7 +499,7 @@ impl UnredirectWindowRequest {
([request0.into()], vec![])
}
/// Parse this request given its header, its body, and any fds that go along with it
#[cfg(feature = "extra-traits")]
#[cfg(feature = "request-parsing")]
pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
if header.minor_opcode != UNREDIRECT_WINDOW_REQUEST {
return Err(ParseError::InvalidValue);
Expand Down Expand Up @@ -581,7 +581,7 @@ impl UnredirectSubwindowsRequest {
([request0.into()], vec![])
}
/// Parse this request given its header, its body, and any fds that go along with it
#[cfg(feature = "extra-traits")]
#[cfg(feature = "request-parsing")]
pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
if header.minor_opcode != UNREDIRECT_SUBWINDOWS_REQUEST {
return Err(ParseError::InvalidValue);
Expand Down Expand Up @@ -652,7 +652,7 @@ impl CreateRegionFromBorderClipRequest {
([request0.into()], vec![])
}
/// Parse this request given its header, its body, and any fds that go along with it
#[cfg(feature = "extra-traits")]
#[cfg(feature = "request-parsing")]
pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
if header.minor_opcode != CREATE_REGION_FROM_BORDER_CLIP_REQUEST {
return Err(ParseError::InvalidValue);
Expand Down Expand Up @@ -721,7 +721,7 @@ impl NameWindowPixmapRequest {
([request0.into()], vec![])
}
/// Parse this request given its header, its body, and any fds that go along with it
#[cfg(feature = "extra-traits")]
#[cfg(feature = "request-parsing")]
pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
if header.minor_opcode != NAME_WINDOW_PIXMAP_REQUEST {
return Err(ParseError::InvalidValue);
Expand Down Expand Up @@ -784,7 +784,7 @@ impl GetOverlayWindowRequest {
([request0.into()], vec![])
}
/// Parse this request given its header, its body, and any fds that go along with it
#[cfg(feature = "extra-traits")]
#[cfg(feature = "request-parsing")]
pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
if header.minor_opcode != GET_OVERLAY_WINDOW_REQUEST {
return Err(ParseError::InvalidValue);
Expand Down Expand Up @@ -933,7 +933,7 @@ impl ReleaseOverlayWindowRequest {
([request0.into()], vec![])
}
/// Parse this request given its header, its body, and any fds that go along with it
#[cfg(feature = "extra-traits")]
#[cfg(feature = "request-parsing")]
pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
if header.minor_opcode != RELEASE_OVERLAY_WINDOW_REQUEST {
return Err(ParseError::InvalidValue);
Expand Down
10 changes: 5 additions & 5 deletions x11rb-protocol/src/protocol/damage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl QueryVersionRequest {
([request0.into()], vec![])
}
/// Parse this request given its header, its body, and any fds that go along with it
#[cfg(feature = "extra-traits")]
#[cfg(feature = "request-parsing")]
pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
if header.minor_opcode != QUERY_VERSION_REQUEST {
return Err(ParseError::InvalidValue);
Expand Down Expand Up @@ -367,7 +367,7 @@ impl CreateRequest {
([request0.into()], vec![])
}
/// Parse this request given its header, its body, and any fds that go along with it
#[cfg(feature = "extra-traits")]
#[cfg(feature = "request-parsing")]
pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
if header.minor_opcode != CREATE_REQUEST {
return Err(ParseError::InvalidValue);
Expand Down Expand Up @@ -442,7 +442,7 @@ impl DestroyRequest {
([request0.into()], vec![])
}
/// Parse this request given its header, its body, and any fds that go along with it
#[cfg(feature = "extra-traits")]
#[cfg(feature = "request-parsing")]
pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
if header.minor_opcode != DESTROY_REQUEST {
return Err(ParseError::InvalidValue);
Expand Down Expand Up @@ -524,7 +524,7 @@ impl SubtractRequest {
([request0.into()], vec![])
}
/// Parse this request given its header, its body, and any fds that go along with it
#[cfg(feature = "extra-traits")]
#[cfg(feature = "request-parsing")]
pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
if header.minor_opcode != SUBTRACT_REQUEST {
return Err(ParseError::InvalidValue);
Expand Down Expand Up @@ -604,7 +604,7 @@ impl AddRequest {
([request0.into()], vec![])
}
/// Parse this request given its header, its body, and any fds that go along with it
#[cfg(feature = "extra-traits")]
#[cfg(feature = "request-parsing")]
pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
if header.minor_opcode != ADD_REQUEST {
return Err(ParseError::InvalidValue);
Expand Down
16 changes: 8 additions & 8 deletions x11rb-protocol/src/protocol/dbe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ impl QueryVersionRequest {
([request0.into()], vec![])
}
/// Parse this request given its header, its body, and any fds that go along with it
#[cfg(feature = "extra-traits")]
#[cfg(feature = "request-parsing")]
pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
if header.minor_opcode != QUERY_VERSION_REQUEST {
return Err(ParseError::InvalidValue);
Expand Down Expand Up @@ -517,7 +517,7 @@ impl AllocateBackBufferRequest {
([request0.into()], vec![])
}
/// Parse this request given its header, its body, and any fds that go along with it
#[cfg(feature = "extra-traits")]
#[cfg(feature = "request-parsing")]
pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
if header.minor_opcode != ALLOCATE_BACK_BUFFER_REQUEST {
return Err(ParseError::InvalidValue);
Expand Down Expand Up @@ -590,7 +590,7 @@ impl DeallocateBackBufferRequest {
([request0.into()], vec![])
}
/// Parse this request given its header, its body, and any fds that go along with it
#[cfg(feature = "extra-traits")]
#[cfg(feature = "request-parsing")]
pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
if header.minor_opcode != DEALLOCATE_BACK_BUFFER_REQUEST {
return Err(ParseError::InvalidValue);
Expand Down Expand Up @@ -663,7 +663,7 @@ impl<'input> SwapBuffersRequest<'input> {
([request0.into(), actions_bytes.into(), padding0.into()], vec![])
}
/// Parse this request given its header, its body, and any fds that go along with it
#[cfg(feature = "extra-traits")]
#[cfg(feature = "request-parsing")]
pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
if header.minor_opcode != SWAP_BUFFERS_REQUEST {
return Err(ParseError::InvalidValue);
Expand Down Expand Up @@ -727,7 +727,7 @@ impl BeginIdiomRequest {
([request0.into()], vec![])
}
/// Parse this request given its header, its body, and any fds that go along with it
#[cfg(feature = "extra-traits")]
#[cfg(feature = "request-parsing")]
pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
if header.minor_opcode != BEGIN_IDIOM_REQUEST {
return Err(ParseError::InvalidValue);
Expand Down Expand Up @@ -780,7 +780,7 @@ impl EndIdiomRequest {
([request0.into()], vec![])
}
/// Parse this request given its header, its body, and any fds that go along with it
#[cfg(feature = "extra-traits")]
#[cfg(feature = "request-parsing")]
pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
if header.minor_opcode != END_IDIOM_REQUEST {
return Err(ParseError::InvalidValue);
Expand Down Expand Up @@ -845,7 +845,7 @@ impl<'input> GetVisualInfoRequest<'input> {
([request0.into(), drawables_bytes.into(), padding0.into()], vec![])
}
/// Parse this request given its header, its body, and any fds that go along with it
#[cfg(feature = "extra-traits")]
#[cfg(feature = "request-parsing")]
pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
if header.minor_opcode != GET_VISUAL_INFO_REQUEST {
return Err(ParseError::InvalidValue);
Expand Down Expand Up @@ -992,7 +992,7 @@ impl GetBackBufferAttributesRequest {
([request0.into()], vec![])
}
/// Parse this request given its header, its body, and any fds that go along with it
#[cfg(feature = "extra-traits")]
#[cfg(feature = "request-parsing")]
pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
if header.minor_opcode != GET_BACK_BUFFER_ATTRIBUTES_REQUEST {
return Err(ParseError::InvalidValue);
Expand Down
18 changes: 9 additions & 9 deletions x11rb-protocol/src/protocol/dpms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl GetVersionRequest {
([request0.into()], vec![])
}
/// Parse this request given its header, its body, and any fds that go along with it
#[cfg(feature = "extra-traits")]
#[cfg(feature = "request-parsing")]
pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
if header.minor_opcode != GET_VERSION_REQUEST {
return Err(ParseError::InvalidValue);
Expand Down Expand Up @@ -200,7 +200,7 @@ impl CapableRequest {
([request0.into()], vec![])
}
/// Parse this request given its header, its body, and any fds that go along with it
#[cfg(feature = "extra-traits")]
#[cfg(feature = "request-parsing")]
pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
if header.minor_opcode != CAPABLE_REQUEST {
return Err(ParseError::InvalidValue);
Expand Down Expand Up @@ -340,7 +340,7 @@ impl GetTimeoutsRequest {
([request0.into()], vec![])
}
/// Parse this request given its header, its body, and any fds that go along with it
#[cfg(feature = "extra-traits")]
#[cfg(feature = "request-parsing")]
pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
if header.minor_opcode != GET_TIMEOUTS_REQUEST {
return Err(ParseError::InvalidValue);
Expand Down Expand Up @@ -503,7 +503,7 @@ impl SetTimeoutsRequest {
([request0.into()], vec![])
}
/// Parse this request given its header, its body, and any fds that go along with it
#[cfg(feature = "extra-traits")]
#[cfg(feature = "request-parsing")]
pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
if header.minor_opcode != SET_TIMEOUTS_REQUEST {
return Err(ParseError::InvalidValue);
Expand Down Expand Up @@ -561,7 +561,7 @@ impl EnableRequest {
([request0.into()], vec![])
}
/// Parse this request given its header, its body, and any fds that go along with it
#[cfg(feature = "extra-traits")]
#[cfg(feature = "request-parsing")]
pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
if header.minor_opcode != ENABLE_REQUEST {
return Err(ParseError::InvalidValue);
Expand Down Expand Up @@ -613,7 +613,7 @@ impl DisableRequest {
([request0.into()], vec![])
}
/// Parse this request given its header, its body, and any fds that go along with it
#[cfg(feature = "extra-traits")]
#[cfg(feature = "request-parsing")]
pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
if header.minor_opcode != DISABLE_REQUEST {
return Err(ParseError::InvalidValue);
Expand Down Expand Up @@ -729,7 +729,7 @@ impl ForceLevelRequest {
([request0.into()], vec![])
}
/// Parse this request given its header, its body, and any fds that go along with it
#[cfg(feature = "extra-traits")]
#[cfg(feature = "request-parsing")]
pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
if header.minor_opcode != FORCE_LEVEL_REQUEST {
return Err(ParseError::InvalidValue);
Expand Down Expand Up @@ -784,7 +784,7 @@ impl InfoRequest {
([request0.into()], vec![])
}
/// Parse this request given its header, its body, and any fds that go along with it
#[cfg(feature = "extra-traits")]
#[cfg(feature = "request-parsing")]
pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
if header.minor_opcode != INFO_REQUEST {
return Err(ParseError::InvalidValue);
Expand Down Expand Up @@ -982,7 +982,7 @@ impl SelectInputRequest {
([request0.into()], vec![])
}
/// Parse this request given its header, its body, and any fds that go along with it
#[cfg(feature = "extra-traits")]
#[cfg(feature = "request-parsing")]
pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
if header.minor_opcode != SELECT_INPUT_REQUEST {
return Err(ParseError::InvalidValue);
Expand Down
Loading

0 comments on commit f705e9a

Please sign in to comment.