liquid5-c 5.0.0 → 5.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,48 +2,7 @@
2
2
  #include "mri_compat.h"
3
3
  #include "context.h"
4
4
 
5
- #ifdef HAVE_RB_CALLABLE_METHOD_ENTRY
6
- static VALUE identity_entries[8];
7
- static bool identity_registered;
8
- static VALUE register_identity_methods(VALUE self, VALUE enabled)
9
- {
10
- Check_Type(enabled, T_ARRAY);
11
- if (RARRAY_LEN(enabled) != 8) rb_raise(rb_eArgError, "invalid identity method flags");
12
- if (identity_registered) rb_raise(rb_eRuntimeError, "identity methods already registered");
13
- VALUE owners[] = { rb_cString, rb_cArray, rb_cHash, rb_cNumeric, rb_cRange,
14
- rb_cTrueClass, rb_cFalseClass, rb_cNilClass };
15
- for (long i = 0; i < 8; i++) {
16
- identity_entries[i] = RTEST(RARRAY_AREF(enabled, i)) ?
17
- liquid_method_entry(owners[i], id_to_liquid) : 0;
18
- rb_gc_register_address(&identity_entries[i]);
19
- }
20
- identity_registered = true;
21
- return Qnil;
22
- }
23
-
24
- VALUE liquid_value_to_liquid(VALUE value)
25
- {
26
- int index;
27
- switch (TYPE(value)) {
28
- case T_STRING: index = 0; break;
29
- case T_ARRAY: index = 1; break;
30
- case T_HASH: index = 2; break;
31
- case T_FIXNUM: case T_BIGNUM: case T_FLOAT: index = 3; break;
32
- case T_STRUCT: index = rb_obj_is_kind_of(value, rb_cRange) ? 4 : -1; break;
33
- case T_TRUE: index = 5; break;
34
- case T_FALSE: index = 6; break;
35
- case T_NIL: index = 7; break;
36
- default: index = -1; break;
37
- }
38
- if (index >= 0 && identity_entries[index] && identity_entries[index] ==
39
- liquid_method_entry(CLASS_OF(value), id_to_liquid)) return value;
40
- return rb_funcall(value, id_to_liquid, 0);
41
- }
42
- #endif
43
5
 
44
6
  void liquid_define_native_values(void)
45
7
  {
46
- #ifdef HAVE_RB_CALLABLE_METHOD_ENTRY
47
- rb_define_singleton_method(mLiquidC, "native_register_identity_methods", register_identity_methods, 1);
48
- #endif
49
8
  }
data/ext/liquid_c/raw.c CHANGED
@@ -88,11 +88,19 @@ static VALUE raw_parse_method(VALUE self, VALUE tokens)
88
88
 
89
89
  VALUE block_delimiter = rb_funcall(self, id_block_delimiter, 0);
90
90
  Check_Type(block_delimiter, T_STRING);
91
- char *block_delimiter_str = RSTRING_PTR(block_delimiter);
92
91
  long block_delimiter_len = RSTRING_LEN(block_delimiter);
92
+ // tokenizer_next may compact this string when line numbers are enabled.
93
+ VALUE delimiter_buffer = 0;
94
+ const char *block_delimiter_bytes = "";
95
+ if (block_delimiter_len > 0) {
96
+ char *bytes = ALLOCV_N(char, delimiter_buffer, block_delimiter_len);
97
+ memcpy(bytes, RSTRING_PTR(block_delimiter), (size_t)block_delimiter_len);
98
+ block_delimiter_bytes = bytes;
99
+ }
93
100
 
94
101
  const char *body = NULL;
95
102
  long body_len = 0;
103
+ bool found_delimiter = false;
96
104
 
97
105
  while (true) {
98
106
  tokenizer_next(tokenizer, &token);
@@ -105,21 +113,29 @@ static VALUE raw_parse_method(VALUE self, VALUE tokens)
105
113
 
106
114
  if (match_full_token_possibly_invalid(&token, &match)
107
115
  && match.delimiter_len == block_delimiter_len
108
- && memcmp(match.delimiter_start, block_delimiter_str, block_delimiter_len) == 0) {
116
+ && memcmp(match.delimiter_start, block_delimiter_bytes, (size_t)block_delimiter_len) == 0) {
109
117
  tokenizer->lstrip_flag = token.len_full >= 3 && token.str_full[token.len_full - 3] == '-';
110
118
  body_len += match.body_len;
111
- VALUE body_str = rb_enc_str_new(body, body_len, utf8_encoding);
112
- rb_ivar_set(self, id_ivar_body, body_str);
113
- if (RBASIC_CLASS(self) == cLiquidRaw) {
114
- tokenizer->raw_tag_body = body_str;
115
- }
116
- return Qnil;
119
+ found_delimiter = true;
120
+ break;
117
121
  }
118
122
 
119
123
  body_len += token.len_full;
120
124
  }
121
125
 
122
- rb_funcall(self, id_raise_tag_never_closed, 1, rb_funcall(self, id_block_name, 0));
126
+ RB_GC_GUARD(block_delimiter);
127
+ ALLOCV_END(delimiter_buffer);
128
+
129
+ if (!found_delimiter) {
130
+ rb_funcall(self, id_raise_tag_never_closed, 1, rb_funcall(self, id_block_name, 0));
131
+ return Qnil;
132
+ }
133
+
134
+ VALUE body_str = rb_enc_str_new(body, body_len, utf8_encoding);
135
+ rb_ivar_set(self, id_ivar_body, body_str);
136
+ if (RBASIC_CLASS(self) == cLiquidRaw) {
137
+ tokenizer->raw_tag_body = body_str;
138
+ }
123
139
  return Qnil;
124
140
  }
125
141
 
@@ -131,6 +147,7 @@ void liquid_define_raw(void)
131
147
  id_ivar_body = rb_intern("@body");
132
148
 
133
149
  cLiquidRaw = rb_const_get(mLiquid, rb_intern("Raw"));
150
+ rb_global_variable(&cLiquidRaw);
134
151
 
135
152
  rb_define_method(cLiquidRaw, "c_parse", raw_parse_method, 1);
136
153
  }
@@ -106,47 +106,10 @@ module Liquid
106
106
  (mutable_table ? value == special_tokens : value.is_a?(Module) || value.frozen?)
107
107
  [owner, name, value, standard, mutable_table ? value.dup.freeze : nil].freeze
108
108
  end.freeze
109
- GUARD_SPECS = GUARDS.map do |owner, name, *_|
110
- receiver = if owner == Liquid::ParseContext
111
- 1
112
- elsif owner == StringScanner
113
- 2
114
- elsif owner == Liquid::Variable
115
- 3
116
- else
117
- 0
118
- end
119
- [owner, name, receiver, false, nil, nil, ![:initialize, :lax_parse_filter_expressions].include?(name)].freeze
120
- end.concat(CONSTRUCTORS.map { |klass, name, _| [klass.singleton_class, name, 0, false, nil, nil, true].freeze })
121
- .concat(CONSTANT_GUARDS.map do |owner, name, value, _standard, snapshot|
122
- [owner, name, 0, true, snapshot, value, false].freeze
123
- end).freeze
124
109
  STANDARD_GUARDS = GUARDS.all?(&:last) && CONSTANT_GUARDS.all? { |guard| guard[3] } &&
125
110
  CONSTRUCTORS.all? do |_klass, name, method|
126
111
  method.source_location.nil? && method.owner == Class && method.original_name == name
127
112
  end
128
- # MRI 3.2's public counter counts registered IC sites. Warm and retain
129
- # one actual Ruby constant reader per guarded name: changes then invalidate
130
- # the epoch even when the native parser never executes the Ruby lexer.
131
- # Method identities and mutable table slots are NOT cached.
132
- CONSTANT_WATCHERS = if STANDARD_GUARDS && RUBY_ENGINE == "ruby" && RUBY_VERSION.start_with?("3.2.") &&
133
- Liquid::C.respond_to?(:native_constant_watchers_supported?) &&
134
- Liquid::C.native_constant_watchers_supported?(RubyVM)
135
- unchanged = true
136
- evaluator = Module.instance_method(:module_eval)
137
- readers = CONSTANT_GUARDS.map do |owner, name, expected, *_|
138
- reader = evaluator.bind_call(owner, "-> { #{name} }", __FILE__, __LINE__)
139
- unchanged &&= reader.call.equal?(expected)
140
- reader.freeze
141
- end
142
- unchanged ? readers.freeze : nil
143
- end
144
- NATIVE_GUARDS = if Liquid::C.respond_to?(:native_try_parse_variable) && STANDARD_GUARDS && CONSTANT_WATCHERS
145
- watchers = ENV["LIQUID_C_NATIVE_CONST_CACHE"] == "false" ? nil : CONSTANT_WATCHERS
146
- Liquid::C.native_parser_register_guards(GUARD_SPECS, watchers, RubyVM)
147
- else
148
- false
149
- end
150
113
 
151
114
  class << self
152
115
  def parse(markup, context, variable = nil)
@@ -154,16 +117,9 @@ module Liquid
154
117
  return record(context, :disabled) if ENV["LIQUID_C_NATIVE_PARSER"] == "false"
155
118
  return record(context, :disabled) unless Liquid::C.instance_variable_get(:@enabled)
156
119
 
157
- if NATIVE_GUARDS && variable
158
- result = Liquid::C.native_try_parse_variable(markup, context, variable)
159
- if result.equal?(false) && compatible?(context, variable)
160
- result = Liquid::C.native_try_parse_variable(markup, context, variable)
161
- end
162
- return result || nil
163
- end
164
120
  return record(context, :disabled) if context.instance_variable_get(:@liquid_c_nodes_disabled)
165
121
  return record(context, :hooks) if variable && !variable.instance_of?(Liquid::Variable)
166
- return record(context, :guard_cost) unless NATIVE_GUARDS || Liquid::C.native_frontend_candidate?(markup)
122
+ return record(context, :guard_cost) unless Liquid::C.native_frontend_candidate?(markup)
167
123
  return record(context, :hooks) unless compatible?(context, variable)
168
124
  return record(context, :disabled) if context.liquid_c_nodes_disabled?
169
125
  return record(context, :mode) unless [:lax, :warn, :strict].include?(context.error_mode)
@@ -186,7 +142,7 @@ module Liquid
186
142
 
187
143
  def tag_payload(markup, context, kind)
188
144
  return if ENV["LIQUID_C_NATIVE_TAGS"] == "false"
189
- return unless NATIVE_GUARDS || Liquid::C.native_frontend_candidate?(markup)
145
+ return unless Liquid::C.native_frontend_candidate?(markup)
190
146
  return unless compatible?(context)
191
147
  return if context.liquid_c_nodes_disabled?
192
148
  return unless context.error_mode == :strict && compatible?(context)
@@ -213,7 +169,6 @@ module Liquid
213
169
  def compatible?(context, variable = nil)
214
170
  return false unless context.instance_of?(Liquid::ParseContext)
215
171
  return false unless STANDARD_GUARDS
216
- return true if NATIVE_GUARDS && Liquid::C.native_parser_methods_compatible?(context, variable)
217
172
  return false unless CONSTANT_GUARDS.all? do |owner, name, value, standard, snapshot|
218
173
  standard && Liquid::C.native_constant_matches?(owner, name, value, snapshot)
219
174
  end
@@ -245,11 +200,7 @@ module Liquid
245
200
  Liquid::C.native_public_method?(target, name)) && target.method(name).unbind == method
246
201
  end
247
202
 
248
- return true unless NATIVE_GUARDS
249
-
250
- watchers = ENV["LIQUID_C_NATIVE_CONST_CACHE"] == "false" ? nil : CONSTANT_WATCHERS
251
- Liquid::C.native_parser_register_guards(GUARD_SPECS, watchers, RubyVM)
252
- Liquid::C.native_parser_methods_compatible?(context, variable)
203
+ true
253
204
  end
254
205
 
255
206
  def record(context, reason)
@@ -60,7 +60,7 @@ module Liquid
60
60
  return if ENV["LIQUID_C_NATIVE_TAGS"] == "false" || context.instance_variable_get(:@error_mode) != :strict
61
61
  return unless Liquid::C.instance_variable_get(:@enabled)
62
62
  return if context.instance_variable_get(:@liquid_c_nodes_disabled)
63
- return unless NativeParser::NATIVE_GUARDS || Liquid::C.native_frontend_candidate?(markup)
63
+ return unless Liquid::C.native_frontend_candidate?(markup)
64
64
  return unless compatible?(object, kind)
65
65
 
66
66
  result = NativeParser.tag_payload(markup, context, kind)
@@ -69,35 +69,6 @@ module Liquid
69
69
  result
70
70
  end
71
71
  end
72
-
73
- original_if = Liquid::If.instance_method(:strict_parse)
74
- if NativeParser::NATIVE_GUARDS && original_if.owner == Liquid::If && original_if.original_name == :strict_parse &&
75
- original_if.source_location&.first == File.join(root, "tags", "if.rb")
76
- Liquid::C.native_install_header_parser(original_if, false)
77
- end
78
-
79
- original_for = Liquid::For.instance_method(:strict_parse)
80
- if NativeParser::NATIVE_GUARDS && original_for.owner == Liquid::For &&
81
- original_for.original_name == :strict_parse &&
82
- original_for.source_location&.first == File.join(root, "tags", "for.rb")
83
- Liquid::C.native_install_header_parser(original_for, true)
84
- end
85
-
86
- original_context = Liquid::ParserSwitching.instance_method(:strict_parse_with_error_context)
87
- if NativeParser::NATIVE_GUARDS && original_context.owner == Liquid::ParserSwitching &&
88
- original_context.original_name == :strict_parse_with_error_context &&
89
- original_context.source_location&.first == File.join(root, "parser_switching.rb")
90
- Liquid::C.native_install_strict_context
91
- end
92
-
93
- # Case's legacy fragment matcher deliberately remains responsible for
94
- # choosing the fragment. Its permissive semantics differ from Parser.
95
- original_case = Liquid::Case.instance_method(:parse_expression)
96
- if NativeParser::NATIVE_GUARDS && original_case.owner == Liquid::Tag &&
97
- original_case.original_name == :parse_expression &&
98
- original_case.source_location&.first == File.join(root, "tag.rb")
99
- Liquid::C.native_install_case_parser
100
- end
101
72
  end
102
73
  end
103
74
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Liquid
4
4
  module C
5
- VERSION = "5.0.0"
5
+ VERSION = "5.1.1"
6
6
  end
7
7
  end
data/lib/liquid/c.rb CHANGED
@@ -372,8 +372,6 @@ end
372
372
 
373
373
  require "liquid/c/native_parser"
374
374
  require "liquid/c/native_tags"
375
- require "liquid/c/native_values"
376
375
 
377
376
  # Parsing during require retains the original path until guards are ready.
378
377
  Liquid::C.native_enable_variable_frontend
379
- require "liquid/c/native_compiler"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: liquid5-c
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0
4
+ version: 5.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Li
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2026-11-24 00:00:00.000000000 Z
13
+ date: 2026-11-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: liquid
@@ -107,17 +107,15 @@ files:
107
107
  - ext/liquid_c/vm_assembler_pool.h
108
108
  - lib/liquid/c.rb
109
109
  - lib/liquid/c/compile_ext.rb
110
- - lib/liquid/c/native_compiler.rb
111
110
  - lib/liquid/c/native_parser.rb
112
111
  - lib/liquid/c/native_tags.rb
113
- - lib/liquid/c/native_values.rb
114
112
  - lib/liquid/c/version.rb
115
113
  homepage: https://github.com/VladimirIvanin/liquid-c
116
114
  licenses:
117
115
  - MIT
118
116
  metadata:
119
117
  allowed_push_host: https://rubygems.org
120
- source_code_uri: https://github.com/VladimirIvanin/liquid-c/tree/v5.0.0
118
+ source_code_uri: https://github.com/VladimirIvanin/liquid-c/tree/v5.1.1
121
119
  post_install_message:
122
120
  rdoc_options: []
123
121
  require_paths:
@@ -126,7 +124,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
124
  requirements:
127
125
  - - ">="
128
126
  - !ruby/object:Gem::Version
129
- version: 3.0.0
127
+ version: 3.2.0
130
128
  required_rubygems_version: !ruby/object:Gem::Requirement
131
129
  requirements:
132
130
  - - ">="
@@ -1,262 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- if Liquid::C.respond_to?(:native_register_compiler)
4
- Liquid::If.class_eval do
5
- private
6
-
7
- def liquid_c_finish_parse
8
- @blocks.reverse_each do |block|
9
- block.attachment.remove_blank_strings if blank?
10
- block.attachment.freeze
11
- end
12
- end
13
- end
14
- Liquid::For.class_eval do
15
- private
16
-
17
- def liquid_c_finish_parse
18
- if blank?
19
- @else_block&.remove_blank_strings
20
- @for_block.remove_blank_strings
21
- end
22
- @else_block&.freeze
23
- @for_block.freeze
24
- end
25
- end
26
- source_root = File.join(Gem.loaded_specs.fetch("liquid").full_gem_path, "lib", "liquid")
27
- library_root = File.expand_path("..", __dir__)
28
- context_method = Liquid::ParserSwitching.instance_method(:strict2_parse_with_error_context)
29
- expected_context_owner = context_method.owner == Liquid::ParserSwitching
30
- if expected_context_owner && context_method.original_name == :strict2_parse_with_error_context &&
31
- context_method.source_location&.first == File.join(source_root, "parser_switching.rb")
32
- Liquid::C.native_install_compiler_context
33
- end
34
- specifications = {
35
- Liquid::Variable.singleton_class => [:c_parse],
36
- Liquid::C::BlockBody.singleton_class => [:new, :allocate],
37
- Liquid::Condition.singleton_class => [:new, :allocate, :parse_expression],
38
- Liquid::ElseCondition.singleton_class => [:new, :allocate],
39
- Liquid::Variable => [
40
- :initialize,
41
- :strict_parse,
42
- :lax_parse,
43
- :c_compilable?,
44
- :compile_evaluate,
45
- :filters,
46
- :strict_parse_with_error_mode_fallback,
47
- :strict_parse_with_error_context,
48
- :strict2_mode?,
49
- ],
50
- Liquid::ParseContext => [:line_number, :depth, :depth=, :new_block_body, :environment],
51
- Liquid::Tag => [:initialize, :parse, :parse_context, :line_number, :options],
52
- Liquid::Tag.singleton_class => [:parse],
53
- Liquid::Block => [:initialize, :new_body, :parse_body, :block_name, :block_delimiter, :blank?],
54
- Liquid::Assign => [:initialize, :parse, :strict_parse, :strict2_parse, :lax_parse, :blank?],
55
- Liquid::Assign.singleton_class => [:parse],
56
- Liquid::Capture => [
57
- :initialize, :parse, :strict_parse, :strict2_parse, :lax_parse, :blank?, :unknown_tag, :raise_tag_never_closed,
58
- ],
59
- Liquid::Capture.singleton_class => [:parse],
60
- Liquid::Include => [
61
- :initialize, :parse, :strict_parse, :strict2_parse, :lax_parse, :blank?, :safe_parse_expression, :parse_context,
62
- ],
63
- Liquid::Include.singleton_class => [:parse],
64
- Liquid::If => [
65
- :initialize,
66
- :parse,
67
- :push_block,
68
- :unknown_tag,
69
- :strict_parse,
70
- :strict2_parse,
71
- :parse_binary_comparisons,
72
- :parse_comparison,
73
- :parse_expression,
74
- ],
75
- Liquid::Unless => [
76
- :initialize,
77
- :parse,
78
- :push_block,
79
- :unknown_tag,
80
- :strict_parse,
81
- :strict2_parse,
82
- :parse_binary_comparisons,
83
- :parse_comparison,
84
- :parse_expression,
85
- ],
86
- Liquid::For => [
87
- :initialize,
88
- :parse,
89
- :unknown_tag,
90
- :strict_parse,
91
- :strict2_parse,
92
- :set_attribute,
93
- :parse_expression,
94
- ],
95
- Liquid::If.singleton_class => [:parse],
96
- Liquid::Unless.singleton_class => [:parse],
97
- Liquid::For.singleton_class => [:parse],
98
- Liquid::Condition => [:initialize, :and, :or, :attach, :attachment],
99
- Liquid::ElseCondition => [:initialize, :attach, :attachment],
100
- Liquid::Environment => [:tag_for_name],
101
- Liquid::ParserSwitching => [:strict2_parse_with_error_context],
102
- Liquid::VariableLookup => [:compile_evaluate, :name, :lookups],
103
- Liquid::RangeLookup => [:compile_evaluate],
104
- Liquid::C::BlockBody => [
105
- :add_evaluate_expression,
106
- :add_find_variable,
107
- :add_lookup_guard,
108
- :patch_lookup_guard,
109
- :add_lookup_command,
110
- :add_lookup_key,
111
- :add_new_int_range,
112
- :add_hash_new,
113
- :add_filter,
114
- :initialize,
115
- :parse,
116
- :freeze,
117
- :remove_blank_strings,
118
- :blank?,
119
- ],
120
- }
121
- switching = [:parse_with_selected_parser, :strict_parse_with_error_context, :strict2_parse_with_error_context]
122
- inherited = [:new_body, :parse_body, :block_name, :block_delimiter, :blank?, :parse_context, :line_number, :options]
123
- [Liquid::If, Liquid::Unless, Liquid::For].each { |klass| specifications[klass].concat(inherited + switching) }
124
- specifications[Liquid::Include].concat(switching + [:line_number, :options])
125
- specifications[Liquid::Capture].concat((inherited + switching).reject { |name| name == :blank? })
126
- specifications[Liquid::Assign].concat(switching)
127
- standard = Liquid::C::NativeParser::NATIVE_GUARDS
128
- standard &&= Liquid::Tag.method(:new).unbind == Class.instance_method(:new)
129
- control_owners = [
130
- Liquid::Assign,
131
- Liquid::Assign.singleton_class,
132
- Liquid::Capture,
133
- Liquid::Capture.singleton_class,
134
- Liquid::Include,
135
- Liquid::Include.singleton_class,
136
- Liquid::Tag,
137
- Liquid::Tag.singleton_class,
138
- Liquid::Block,
139
- Liquid::If,
140
- Liquid::Unless,
141
- Liquid::For,
142
- Liquid::If.singleton_class,
143
- Liquid::Unless.singleton_class,
144
- Liquid::For.singleton_class,
145
- Liquid::Condition,
146
- Liquid::Condition.singleton_class,
147
- Liquid::ElseCondition,
148
- Liquid::ElseCondition.singleton_class,
149
- Liquid::C::BlockBody.singleton_class,
150
- ]
151
- guards = specifications.flat_map do |owner, names|
152
- names.map do |name|
153
- method = owner.instance_method(name)
154
- location = method.source_location&.first
155
- builtin_constructor = [:new, :allocate].include?(name) &&
156
- [
157
- Liquid::C::BlockBody.singleton_class,
158
- Liquid::Condition.singleton_class,
159
- Liquid::ElseCondition.singleton_class,
160
- ].include?(owner)
161
- expected_owner = if builtin_constructor
162
- Class
163
- elsif (switching + [:strict_parse_with_error_mode_fallback, :strict2_mode?]).include?(name)
164
- Liquid::ParserSwitching
165
- elsif inherited.include?(name) && [Liquid::If, Liquid::Unless, Liquid::For].include?(owner)
166
- [:parse_context, :line_number, :options].include?(name) ? Liquid::Tag : Liquid::Block
167
- elsif owner == Liquid::Include && [:blank?, :safe_parse_expression, :line_number, :options].include?(name)
168
- Liquid::Tag
169
- elsif owner == Liquid::Capture && [:parse, :unknown_tag, :raise_tag_never_closed].include?(name)
170
- Liquid::Block
171
- elsif owner == Liquid::Capture && inherited.include?(name) && name != :blank?
172
- [:parse_context, :line_number, :options].include?(name) ? Liquid::Tag : Liquid::Block
173
- elsif owner == Liquid::Assign && name == :parse
174
- Liquid::Tag
175
- elsif owner == Liquid::Unless
176
- Liquid::If
177
- elsif owner == Liquid::For && name == :parse_expression
178
- Liquid::Tag
179
- elsif owner == Liquid::ElseCondition
180
- Liquid::Condition
181
- elsif [
182
- Liquid::If.singleton_class,
183
- Liquid::Unless.singleton_class,
184
- Liquid::For.singleton_class,
185
- Liquid::Assign.singleton_class,
186
- Liquid::Capture.singleton_class,
187
- Liquid::Include.singleton_class,
188
- ].include?(owner)
189
- Liquid::Tag.singleton_class
190
- else
191
- owner
192
- end
193
- expected_name = name == :options ? :parse_context : name
194
- standard &&= method.owner == expected_owner && method.original_name == expected_name &&
195
- (if owner == Liquid::C::BlockBody || builtin_constructor || [
196
- :strict_parse_with_error_context,
197
- :strict2_parse_with_error_context,
198
- ].include?(name)
199
- location.nil?
200
- else
201
- location && (location.start_with?(source_root + "/") || location.start_with?(library_root + "/"))
202
- end)
203
- control = control_owners.include?(owner) ||
204
- owner == Liquid::ParseContext && [:depth, :depth=, :new_block_body].include?(name) ||
205
- owner == Liquid::C::BlockBody && [:initialize, :parse, :freeze, :remove_blank_strings, :blank?].include?(name)
206
- [owner, name, control].freeze
207
- end
208
- end
209
- constants = [
210
- *[
211
- :Block, :Tag, :If, :For, :Unless, :Condition, :ElseCondition, :Environment, :Assign, :Capture, :Include,
212
- ].map do |name|
213
- [Liquid, name]
214
- end,
215
- [Liquid::Assign, :Syntax],
216
- [Liquid::Include, :FOR],
217
- [Liquid::Block, :MAX_DEPTH],
218
- [Liquid::If, :ELSE_TAG_NAMES],
219
- [Liquid::C, :BlockBody],
220
- ].map do |owner, name|
221
- location = owner.const_source_location(name)&.first
222
- native_class = owner == Liquid::C && name == :BlockBody &&
223
- $LOADED_FEATURES.any? { |path| path == location && path.end_with?("/liquid_c.so", "/liquid_c.bundle") }
224
- standard &&= native_class || location && location.start_with?(source_root + "/", library_root + "/")
225
- [owner, name, owner.const_get(name, false)].freeze
226
- end.freeze
227
- ancestor_prefixes = [
228
- [Liquid::Assign, [Liquid::Assign, Liquid::Tag]],
229
- [Liquid::Capture, [Liquid::Capture, Liquid::Block, Liquid::Tag]],
230
- [Liquid::Include, [Liquid::Tag::Disableable, Liquid::Include, Liquid::Tag]],
231
- [Liquid::If, [Liquid::If, Liquid::Block, Liquid::Tag]],
232
- [Liquid::Unless, [Liquid::Unless, Liquid::If, Liquid::Block, Liquid::Tag]],
233
- [Liquid::For, [Liquid::For, Liquid::Block, Liquid::Tag]],
234
- [Liquid::C::BlockBody, [Liquid::C::BlockBody, Object]],
235
- ].map do |klass, prefix|
236
- standard &&= klass.ancestors.first(prefix.size) == prefix
237
- prefix = klass.ancestors
238
- [klass, prefix.freeze].freeze
239
- end.freeze
240
- constant_watchers = if Liquid::C::NativeParser::CONSTANT_WATCHERS
241
- evaluator = Module.instance_method(:module_eval)
242
- constants.map do |owner, name, expected|
243
- reader = evaluator.bind_call(owner, "-> { #{name} }", __FILE__, __LINE__)
244
- standard &&= reader.call.equal?(expected)
245
- reader.freeze
246
- end.freeze
247
- end
248
- Liquid::C.native_register_control(
249
- [Liquid::If.instance_method(:liquid_c_finish_parse), Liquid::For.instance_method(:liquid_c_finish_parse)].freeze,
250
- constants,
251
- ancestor_prefixes,
252
- constant_watchers,
253
- )
254
- [:render, :render_to_output_buffer, :render_obj_to_output].each do |name|
255
- method = Liquid::Variable.instance_method(name)
256
- standard &&= method.owner == Liquid::Variable && method.source_location.nil? && method.original_name == :"c_#{name}"
257
- end
258
- Liquid::C.native_register_compiler(guards.freeze, standard)
259
-
260
- end
261
-
262
- Liquid::C.private_constant(:VariablePlaceholder)
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- if Liquid::C.respond_to?(:native_register_identity_methods)
4
- source = File.join(Gem.loaded_specs.fetch("liquid").full_gem_path, "lib", "liquid", "extensions.rb")
5
- flags = [String, Array, Hash, Numeric, Range, TrueClass, FalseClass, NilClass].map do |klass|
6
- ENV["LIQUID_C_IDENTITY_VALUES"] != "false" && klass.instance_method(:to_liquid).source_location&.first == source
7
- end
8
- Liquid::C.native_register_identity_methods(flags)
9
- end