diff --git a/.github/workflows/liquid.yml b/.github/workflows/liquid.yml index bbd17139..717c4fd8 100644 --- a/.github/workflows/liquid.yml +++ b/.github/workflows/liquid.yml @@ -7,7 +7,6 @@ jobs: strategy: matrix: include: - - { ruby: '2.7', allowed-failure: false } - { ruby: '3.0', allowed-failure: false } - { ruby: '3.1', allowed-failure: false } - { ruby: '3.2', allowed-failure: false } @@ -44,7 +43,6 @@ jobs: - uses: actions/checkout@v2 - uses: ruby/setup-ruby@v1 with: - ruby-version: 3.3 bundler-cache: true - run: sudo apt-get install -y valgrind - run: bundle exec rake test:valgrind diff --git a/.gitignore b/.gitignore index 2934b7fe..b91fb243 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ *.gem *.rbc -Gemfile.lock pkg tmp *.o diff --git a/.rubocop.yml b/.rubocop.yml index a8a66735..42284bc9 100755 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,7 +4,6 @@ inherit_gem: require: rubocop-performance AllCops: - TargetRubyVersion: 2.5 Exclude: - 'vendor/bundle/**/*' - 'tmp/**/*' diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 00000000..15a27998 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +3.3.0 diff --git a/Gemfile b/Gemfile index 2aa3686b..c99748af 100755 --- a/Gemfile +++ b/Gemfile @@ -11,9 +11,9 @@ gem "liquid", github: "Shopify/liquid", ref: "master" group :test do gem "base64", require: false # for older rubocop on Ruby 3.4 - gem "rubocop", "~> 1.24.1", require: false + gem "rubocop", "~> 1.61.0", require: false gem "rubocop-performance", "~> 1.13.2", require: false - gem "rubocop-shopify", "~> 2.4.0", require: false + gem "rubocop-shopify", "~> 2.15.1", require: false gem "spy", "0.4.1" gem "benchmark-ips" gem "ruby_memcheck" diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 00000000..8dfbd358 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,85 @@ +GIT + remote: https://github.com/Shopify/liquid.git + revision: 0b9318222bcc09681e52fd5b8e70262274e673bf + ref: master + specs: + liquid (5.4.0) + +PATH + remote: . + specs: + liquid-c (4.2.0) + liquid (>= 5.0.1) + +GEM + remote: https://rubygems.org/ + specs: + ast (2.4.2) + base64 (0.2.0) + benchmark-ips (2.13.0) + byebug (11.1.3) + json (2.7.2) + language_server-protocol (3.17.0.3) + mini_portile2 (2.8.5) + minitest (5.22.3) + nokogiri (1.16.3) + mini_portile2 (~> 2.8.2) + racc (~> 1.4) + parallel (1.24.0) + parser (3.3.0.5) + ast (~> 2.4.1) + racc + racc (1.7.3) + rainbow (3.1.1) + rake (13.2.1) + rake-compiler (1.2.7) + rake + regexp_parser (2.9.0) + rexml (3.2.6) + rubocop (1.61.0) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.30.0, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.31.2) + parser (>= 3.3.0.4) + rubocop-performance (1.13.3) + rubocop (>= 1.7.0, < 2.0) + rubocop-ast (>= 0.4.0) + rubocop-shopify (2.15.1) + rubocop (~> 1.51) + ruby-progressbar (1.13.0) + ruby_memcheck (2.3.0) + nokogiri + spy (0.4.1) + stackprof (0.2.26) + unicode-display_width (2.5.0) + +PLATFORMS + ruby + +DEPENDENCIES + base64 + benchmark-ips + bundler (>= 1.5) + byebug + liquid! + liquid-c! + minitest + rake + rake-compiler + rubocop (~> 1.61.0) + rubocop-performance (~> 1.13.2) + rubocop-shopify (~> 2.15.1) + ruby_memcheck + spy (= 0.4.1) + stackprof + +BUNDLED WITH + 2.4.22 diff --git a/ext/liquid_c/extconf.rb b/ext/liquid_c/extconf.rb index a4ebe1a5..1faf8747 100755 --- a/ext/liquid_c/extconf.rb +++ b/ext/liquid_c/extconf.rb @@ -22,5 +22,5 @@ have_func "rb_hash_bulk_insert" -$warnflags&.gsub!(/-Wdeclaration-after-statement/, "") +$warnflags&.gsub!("-Wdeclaration-after-statement", "") create_makefile("liquid_c") diff --git a/lib/liquid/c.rb b/lib/liquid/c.rb index 259c7d8f..eba53435 100644 --- a/lib/liquid/c.rb +++ b/lib/liquid/c.rb @@ -13,15 +13,17 @@ def render(context) module Liquid BlockBody.class_eval do - def self.c_rescue_render_node(context, output, line_number, exc, blank_tag) - # There seems to be a MRI ruby bug with how the rb_rescue C function, - # where $! gets set for its rescue callback, but it doesn't stay set - # after a nested exception is raised and handled as is the case in - # Liquid::Context#internal_error. This isn't a problem for plain ruby code, - # so use a ruby rescue block to have setup $! properly. - raise(exc) - rescue => exc - rescue_render_node(context, output, line_number, exc, blank_tag) + class << self + def c_rescue_render_node(context, output, line_number, exc, blank_tag) + # There seems to be a MRI ruby bug with how the rb_rescue C function, + # where $! gets set for its rescue callback, but it doesn't stay set + # after a nested exception is raised and handled as is the case in + # Liquid::Context#internal_error. This isn't a problem for plain ruby code, + # so use a ruby rescue block to have setup $! properly. + raise(exc) + rescue => exc + rescue_render_node(context, output, line_number, exc, blank_tag) + end end end end @@ -100,6 +102,7 @@ def liquid_c_nodes_disabled? # provide the `disable_liquid_c_nodes` option to enable the Ruby AST to be produced # so the profiler can use it on future runs. return @liquid_c_nodes_disabled if defined?(@liquid_c_nodes_disabled) + @liquid_c_nodes_disabled = !Liquid::C.enabled || @template_options[:profile] || @template_options[:disable_liquid_c_nodes] || self.class.liquid_c_nodes_disabled end @@ -234,15 +237,17 @@ def c_parse_evaluate(expression) end Liquid::ResourceLimits.class_eval do - def self.new(limits) - if Liquid::C.enabled - Liquid::C::ResourceLimits.new( - limits[:render_length_limit], - limits[:render_score_limit], - limits[:assign_score_limit] - ) - else - super + class << self + def new(limits) + if Liquid::C.enabled + Liquid::C::ResourceLimits.new( + limits[:render_length_limit], + limits[:render_score_limit], + limits[:assign_score_limit], + ) + else + super + end end end end diff --git a/liquid-c.gemspec b/liquid-c.gemspec index ba5e353e..8dfa40ab 100755 --- a/liquid-c.gemspec +++ b/liquid-c.gemspec @@ -1,8 +1,6 @@ # coding: utf-8 # frozen_string_literal: true -# rubocop:disable Gemspec/RubyVersionGlobalsUsage - lib = File.expand_path("../lib", __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require "liquid/c/version" @@ -19,10 +17,9 @@ Gem::Specification.new do |spec| spec.extensions = ["ext/liquid_c/extconf.rb"] spec.files = %x(git ls-files -z).split("\x0") spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } - spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] - spec.required_ruby_version = ">= 2.5.0" + spec.required_ruby_version = ">= 3.0.0" spec.metadata["allowed_push_host"] = "https://rubygems.org" @@ -32,5 +29,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency("minitest") spec.add_development_dependency("rake") spec.add_development_dependency("rake-compiler") - spec.add_development_dependency("stackprof") if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.1.0") + spec.add_development_dependency("stackprof") if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.1.0") # rubocop:disable Gemspec/RubyVersionGlobalsUsage end diff --git a/performance/c_profile.rb b/performance/c_profile.rb index 49e5ad9b..8fe8a143 100644 --- a/performance/c_profile.rb +++ b/performance/c_profile.rb @@ -10,6 +10,7 @@ unless TASK_NAMES.include?(task_name) raise "Unsupported task '#{task_name}' (must be one of #{TASK_NAMES})" end + task = ThemeRunner.new.method(task_name) runner_id = fork do diff --git a/test/unit/block_test.rb b/test/unit/block_test.rb index 8f0a8892..cf3e512a 100644 --- a/test/unit/block_test.rb +++ b/test/unit/block_test.rb @@ -78,8 +78,8 @@ def test_disassemble 0x0000: write_raw("raw") 0x0005: render_variable_rescue(line_number: 2) 0x0009: find_static_var("var") - 0x000c: push_const(\"none\") - 0x000f: push_const(\"allow_false\") + 0x000c: push_const("none") + 0x000f: push_const("allow_false") 0x0012: push_true 0x0013: hash_new(1) 0x0015: builtin_filter(name: :default, num_args: 3) @@ -97,6 +97,7 @@ def test_exception_renderer_exception if exc == original_error raise(handler_error) end + exc end template = Liquid::Template.parse("{% assign x = raise_error %}") diff --git a/test/unit/raw_test.rb b/test/unit/raw_test.rb index 8f7a2442..3103d08d 100644 --- a/test/unit/raw_test.rb +++ b/test/unit/raw_test.rb @@ -25,7 +25,7 @@ def test_derived_class assert_equal( "", output, - "Template: #{template}" + "Template: #{template}", ) end end @@ -76,10 +76,10 @@ def test_does_not_allow_nbsp_in_tag_delimiter ].each do |bad_delimiter| exception = assert_raises( Liquid::SyntaxError, - "#{bad_delimiter.inspect} did not raise Liquid::SyntaxError" + "#{bad_delimiter.inspect} did not raise Liquid::SyntaxError", ) do Liquid::Template.parse( - "{% raw %}body#{bad_delimiter}" + "{% raw %}body#{bad_delimiter}", ) end diff --git a/test/unit/variable_test.rb b/test/unit/variable_test.rb index aa0bb14e..09a15f33 100644 --- a/test/unit/variable_test.rb +++ b/test/unit/variable_test.rb @@ -160,7 +160,7 @@ def test_write_object_with_broken_to_s end assert_equal( "VariableTest::StringConvertible#to_s returned a non-String convertible value of type Integer", - exc.message + exc.message, ) end @@ -264,7 +264,7 @@ def test_encoding_error_message_with_multi_byte_characters end assert_equal( "Liquid syntax error: Unexpected character \u00A0 in \"{{\u00a0}}\"", - exc.message + exc.message, ) # 3 byte character @@ -273,7 +273,7 @@ def test_encoding_error_message_with_multi_byte_characters end assert_equal( "Liquid syntax error: Unexpected character \u3042 in \"{{\u3042}}\"", - exc.message + exc.message, ) # 4 byte character @@ -282,7 +282,7 @@ def test_encoding_error_message_with_multi_byte_characters end assert_equal( "Liquid syntax error: Unexpected character \u{1F600} in \"{{\u{1F600}}}\"", - exc.message + exc.message, ) end