Skip to content

Conversation

@Schamper
Copy link
Member

Fixes #125

@codecov
Copy link

codecov bot commented Jul 22, 2025

Codecov Report

❌ Patch coverage is 97.82609% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 92.95%. Comparing base (01afa28) to head (0e2918c).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
dissect/cstruct/parser.py 97.82% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #135      +/-   ##
==========================================
+ Coverage   92.74%   92.95%   +0.21%     
==========================================
  Files          21       21              
  Lines        2384     2427      +43     
==========================================
+ Hits         2211     2256      +45     
+ Misses        173      171       -2     
Flag Coverage Δ
unittests 92.95% <97.82%> (+0.21%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@andkae
Copy link
Contributor

andkae commented Jul 24, 2025

HI schamper, thanks for the changes. It still not work on my end, what is a little bit strange. But if i modify the regexp:

From:

TOK.add(r"#ifndef\s+(?P<name>[^\s]+)\s*(?=\s)", "IFNDEF")

To:

TOK.add(r"#ifndef\s+(?P<name>[^\s]+)\s*", "IFNDEF")

Then runs my example.

ChatGPT explains in that way:
This pattern breakdown is:

  • #ifndef: Matches the literal text #ifndef.
  • \s+: Matches one or more whitespace characters following the #ifndef.
  • (?P[^\s]+): Named capturing group name that matches and captures one or more non-whitespace characters (the identifier).
  • \s*: Matches zero or more whitespace characters following the identifier, making it optional.

This version will correctly match #ifndef __MYGUARD whether or not there is a space after __MYGUARD.

@Schamper
Copy link
Member Author

I just tab-completed those patterns from Copilot so I'm blaming AI 😄. Changed it.

@andkae
Copy link
Contributor

andkae commented Jul 24, 2025

Another hint, if i run python3.9 -m pytest i recieved some error:

================================================= test session starts ==================================================
platform linux -- Python 3.9.5, pytest-8.4.1, pluggy-1.6.0
rootdir: /home/ubuntu/Desktop/guard
collected 515 items                                                                                                    

dissect.cstruct/tests/test_align.py ................                                                             [  3%]
dissect.cstruct/tests/test_annotations.py ...................................................................... [ 16%]
..................                                                                                               [ 20%]
dissect.cstruct/tests/test_basic.py ........F..............................                                      [ 27%]
dissect.cstruct/tests/test_bitbuffer.py .                                                                        [ 27%]
dissect.cstruct/tests/test_bitfield.py ....................                                                      [ 31%]
dissect.cstruct/tests/test_compiler.py ....................                                                      [ 35%]
dissect.cstruct/tests/test_ctypes.py .......                                                                     [ 37%]
dissect.cstruct/tests/test_expression.py ....................................................................... [ 50%]
                                                                                                                 [ 50%]
dissect.cstruct/tests/test_parser.py ............                                                                [ 53%]
dissect.cstruct/tests/test_tools_stubgen.py ............F..                                                      [ 56%]
dissect.cstruct/tests/test_types_base.py ......                                                                  [ 57%]
dissect.cstruct/tests/test_types_char.py ......                                                                  [ 58%]
dissect.cstruct/tests/test_types_custom.py ...                                                                   [ 59%]
dissect.cstruct/tests/test_types_enum.py ............................                                            [ 64%]
dissect.cstruct/tests/test_types_flag.py .................                                                       [ 67%]
dissect.cstruct/tests/test_types_int.py ...........................                                              [ 73%]
dissect.cstruct/tests/test_types_leb128.py .............                                                         [ 75%]
dissect.cstruct/tests/test_types_packed.py ...............                                                       [ 78%]
dissect.cstruct/tests/test_types_pointer.py ..............                                                       [ 81%]
dissect.cstruct/tests/test_types_structure.py .............................................                      [ 89%]
dissect.cstruct/tests/test_types_union.py ..........................                                             [ 94%]
dissect.cstruct/tests/test_types_void.py .......                                                                 [ 96%]
dissect.cstruct/tests/test_types_wchar.py ..........                                                             [ 98%]
dissect.cstruct/tests/test_utils.py .........                                                                    [100%]

@Schamper
Copy link
Member Author

Fixed.

@andkae
Copy link
Contributor

andkae commented Jul 24, 2025

With cda868c it looks really good, it can handle define guards and also all unit tests.

Great work :) Thanks

Copy link
Contributor

@Miauwkeru Miauwkeru left a comment

Choose a reason for hiding this comment

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

I did found a condition where I expected the parser to break, but it just continued

    #ifndef __HELP
    #define __HELP
    #ifndef __MY_CONST
    struct test {
        uint32 a;
    };
    #endif

Is it an idea to check the length of self._conditionals and _conditional_depth at the end of the parsing, to see whether the conditionals where actually closed.

@Schamper Schamper requested a review from Miauwkeru July 31, 2025 13:12
@Schamper Schamper merged commit bbbb86e into main Jul 31, 2025
25 checks passed
@Schamper Schamper deleted the add-conditionals branch July 31, 2025 14:22
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.

Support handling #define guard

4 participants