Skip to content

Fix comments parsing in dedup_headers#425

Merged
bwoebi merged 1 commit intomainfrom
bob/fix-dedup-headers-comments
May 13, 2024
Merged

Fix comments parsing in dedup_headers#425
bwoebi merged 1 commit intomainfrom
bob/fix-dedup-headers-comments

Conversation

@bwoebi
Copy link
Copy Markdown
Contributor

@bwoebi bwoebi commented May 12, 2024

After d3f8544 it broke cbindgen generation in dd-trace-php.

The previous /**.*?*/ parsing would match from a comment to the next typedef fulfilling the criteria, instead of matching just the comment itself.

This is fixed by matching against /**([^*]|*[^/])**/, where the */ sequence is disallowed within a comment. (Also saves us from needing the ungreedy match.)

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 65.51%. Comparing base (b94f25c) to head (ddbfd7b).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #425      +/-   ##
==========================================
+ Coverage   65.36%   65.51%   +0.14%     
==========================================
  Files         184      184              
  Lines       22503    22568      +65     
==========================================
+ Hits        14710    14785      +75     
+ Misses       7793     7783      -10     
Components Coverage Δ
crashtracker 20.31% <ø> (ø)
data-pipeline 51.45% <ø> (ø)
data-pipeline-ffi 0.00% <ø> (ø)
ddcommon 81.23% <ø> (ø)
ddcommon-ffi 74.93% <ø> (ø)
ddtelemetry 53.72% <ø> (ø)
ipc 81.27% <ø> (ø)
profiling 76.89% <ø> (ø)
profiling-ffi 60.05% <ø> (ø)
serverless 0.00% <ø> (ø)
sidecar 29.37% <ø> (ø)
sidecar-ffi 0.00% <ø> (ø)
spawn-worker 54.98% <ø> (ø)
trace-mini-agent 69.12% <ø> (ø)
trace-normalization 97.79% <ø> (ø)
trace-obfuscation 95.74% <ø> (ø)
trace-protobuf 25.64% <ø> (ø)
trace-utils 68.85% <ø> (ø)

Comment thread tools/src/bin/dedup_headers.rs Outdated
fn collect_definitions(header: &str) -> Vec<regex::Match<'_>> {
lazy_static::lazy_static! {
static ref HEADER_TYPE_DECL_RE: Regex = RegexBuilder::new(r"^(/\*\*.*?\*/\n)?(#define [a-zA-Z_0-9]+ [^\n]+|typedef (struct|enum) [a-zA-Z_0-9]+ +(\{.*?\} )?[a-zA-Z_0-9]+;)\n+")
static ref HEADER_TYPE_DECL_RE: Regex = RegexBuilder::new(r"^(/\*\*([^*]|\*[^/])*\*/\n)?(#define [a-zA-Z_0-9]+ [^\n]+|typedef (struct|enum) [a-zA-Z_0-9]+ +(\{.*?\} )?[a-zA-Z_0-9]+;)\n+")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we add some tests for these things? To me it's not clear what assumptions can/should be made about the comments we are matching against. This new pattern has problems with comments ending in **/ and will not stop there. Is that an issue?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, it's not an issue, but trivial to fix, added a + there.

@bwoebi bwoebi force-pushed the bob/fix-dedup-headers-comments branch 2 times, most recently from 9615023 to add7895 Compare May 13, 2024 11:09
The previous /\*\*.*?\*/ parsing would match from a comment to the next typedef fulfilling the criteria, instead of matching just the comment itself.

This is fixed by matching against /\*\*([^*]|\*+[^*/])*\*+/, where the */ sequence is disallowed within a comment. (Also saves us from needing the ungreedy match.)

Signed-off-by: Bob Weinand <[email protected]>
@bwoebi bwoebi force-pushed the bob/fix-dedup-headers-comments branch from add7895 to ddbfd7b Compare May 13, 2024 11:11
assert_eq!(matches.len(), 1);
assert_eq!(
matches[0].as_str(),
r"typedef struct ddog_Vec_U8 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So a comment that has a **/ comment end inside it is completely discarded, which is probably fine, since it's not a well formed comment anyway.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's just a test that it doesn't malfunction completely.

@bwoebi bwoebi merged commit 428d8d6 into main May 13, 2024
@bwoebi bwoebi deleted the bob/fix-dedup-headers-comments branch May 13, 2024 13:38
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.

3 participants