From 847e87e71e7056132f4d4e27c6cf60c43384edcf Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Wed, 1 Jul 2026 10:27:01 -0400 Subject: [PATCH] Fall back to iterative brace removal because I suspect regex version is too slow. Further tidying of ci. --- .github/workflows/main.yml | 17 ++++++++++++++--- lib/cmock_header_parser.rb | 12 ++++-------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index df1e235..dfc6579 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -51,11 +51,17 @@ jobs: gem install bundler bundle install - - name: Run Ruby Unit Tests and Style Check + - name: Run Ruby Unit Tests env: NO_COLOR: ${{ matrix.os == 'windows-latest' && '1' || '' }} run: | - cd test && rake test:unit style:check + cd test && rake test:unit + + - name: Run Style Check + env: + NO_COLOR: ${{ matrix.os == 'windows-latest' && '1' || '' }} + run: | + cd test && rake style:check # Job: C compilation and system tests — only needs to run on one Ruby version per OS, # since the generated C code and runtime behavior don't vary with the Ruby version. @@ -102,7 +108,12 @@ jobs: - name: Run System Tests env: NO_COLOR: ${{ matrix.os == 'windows-latest' && '1' || '' }} - run: cd test && rake test:system test:examples + run: cd test && rake test:system + + - name: Run Examples + env: + NO_COLOR: ${{ matrix.os == 'windows-latest' && '1' || '' }} + run: cd test && rake test:examples # Job: Valgrind memory-leak check (Linux/gcc_64 only, latest Ruby) valgrind: diff --git a/lib/cmock_header_parser.rb b/lib/cmock_header_parser.rb index b2fd69b..42ed862 100644 --- a/lib/cmock_header_parser.rb +++ b/lib/cmock_header_parser.rb @@ -118,15 +118,11 @@ class CMockHeaderParser def remove_nested_pairs_of_braces(source) # remove nested pairs of braces because no function declarations will be inside of them (leave outer pair for function definition detection) - if RUBY_VERSION.split('.')[0].to_i > 1 - # we assign a string first because (no joke) if Ruby 1.9.3 sees this line as a regex, it will crash. - r = '\\{([^\\{\\}]*|\\g<0>)*\\}' - source.gsub!(/#{r}/m, '{ }') - else - while source.gsub!(/\{[^{}]*\{[^{}]*\}[^{}]*\}/m, '{ }') - end + # Use iterative approach for all Ruby versions: the recursive regex \{([^\{\}]*|\g<0>)*\} + # is exponential on unbalanced brace inputs (catastrophic backtracking on Ruby < 3.2). + while source.gsub!(/\{[^{}]*\{[^{}]*\}[^{}]*\}/m, '{ }') + # Keep doing it! end - source end