liquid5-c 5.1.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.
- checksums.yaml +4 -4
- data/ext/liquid_c/liquid.c +8 -2
- data/ext/liquid_c/native_parser.c +30 -29
- data/ext/liquid_c/raw.c +25 -9
- data/lib/liquid/c/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f8fe27b1445a1a680e822545c3967ae4d331acf66ce5911e9c41d81ebda5ff80
|
|
4
|
+
data.tar.gz: b95747806f4083341fc6d4b3be688bae01ac6671389ba930a4c8e6c0f12fa98f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1dde35e40af620813a4ad6eefdabf2fe9c5f50c5efcffeb435164441c2b811abc8257f965d61804cfb63e2642b60a4875b12a397ed2dee8d0b4496c68c07954f
|
|
7
|
+
data.tar.gz: c5bb753b3fe8d7489fc3f0b0b9216541010e6b2b2a431888efb9e0ad5cb7b3dfcd6387dcac1d5b287bf962431b47991baa3224231f8e8e23e07e6d033fe31f83
|
data/ext/liquid_c/liquid.c
CHANGED
|
@@ -121,8 +121,14 @@ __attribute__((noreturn)) void raise_non_utf8_encoding_error(VALUE string, const
|
|
|
121
121
|
// after switching Ruby versions) would corrupt memory instead of failing.
|
|
122
122
|
static void check_abi(void)
|
|
123
123
|
{
|
|
124
|
-
|
|
125
|
-
|
|
124
|
+
char platform[256];
|
|
125
|
+
char version[32];
|
|
126
|
+
VALUE platform_string = rb_const_get(rb_cObject, rb_intern("RUBY_PLATFORM"));
|
|
127
|
+
Check_Type(platform_string, T_STRING);
|
|
128
|
+
snprintf(platform, sizeof(platform), "%.*s", (int)RSTRING_LEN(platform_string), RSTRING_PTR(platform_string));
|
|
129
|
+
VALUE version_string = rb_const_get(rb_cObject, rb_intern("RUBY_VERSION"));
|
|
130
|
+
Check_Type(version_string, T_STRING);
|
|
131
|
+
snprintf(version, sizeof(version), "%.*s", (int)RSTRING_LEN(version_string), RSTRING_PTR(version_string));
|
|
126
132
|
int major = 0, minor = 0;
|
|
127
133
|
sscanf(version, "%d.%d", &major, &minor);
|
|
128
134
|
if (major != RUBY_API_VERSION_MAJOR || minor != RUBY_API_VERSION_MINOR || strcmp(platform, RUBY_PLATFORM) != 0) {
|
|
@@ -75,11 +75,11 @@ static VALUE native_capture_constant(VALUE owner, const char *name)
|
|
|
75
75
|
return rb_const_get_at(owner, id);
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
typedef struct { VALUE owner; ID method; bool public_call; } primitive_guard_t;
|
|
78
|
+
typedef struct { const VALUE *owner; ID method; bool public_call; } primitive_guard_t;
|
|
79
79
|
static primitive_guard_t primitive_guards[96];
|
|
80
80
|
static size_t primitive_guard_count;
|
|
81
81
|
|
|
82
|
-
static void native_guard_primitive(VALUE owner, const char *method)
|
|
82
|
+
static void native_guard_primitive(const VALUE *owner, const char *method)
|
|
83
83
|
{
|
|
84
84
|
if (primitive_guard_count >= sizeof(primitive_guards) / sizeof(primitive_guards[0]))
|
|
85
85
|
rb_raise(rb_eRuntimeError, "too many native primitive guards");
|
|
@@ -93,8 +93,9 @@ static bool native_primitives_standard(bool check_visibility)
|
|
|
93
93
|
{
|
|
94
94
|
for (size_t i = 0; i < primitive_guard_count; i++) {
|
|
95
95
|
const primitive_guard_t *guard = &primitive_guards[i];
|
|
96
|
-
|
|
97
|
-
if (
|
|
96
|
+
VALUE owner = *guard->owner;
|
|
97
|
+
if (!liquid_method_basic_definition_p(owner, guard->method)) return false;
|
|
98
|
+
if (check_visibility && guard->public_call && rb_method_boundp(owner, guard->method, 3) != 1) return false;
|
|
98
99
|
}
|
|
99
100
|
return true;
|
|
100
101
|
}
|
|
@@ -1186,34 +1187,34 @@ void liquid_define_native_parser(void)
|
|
|
1186
1187
|
RB_GC_GUARD(unbound);
|
|
1187
1188
|
}
|
|
1188
1189
|
const char *strings[] = { "strip", "start_with?", "end_with?", "scan", "match", "to_f", "[]", "freeze", "=~", "<<", "==", "byteslice", "length", "dup", "initialize_copy", "initialize_dup", "hash", "eql?" };
|
|
1189
|
-
for (size_t i = 0; i < sizeof(strings) / sizeof(strings[0]); i++) native_guard_primitive(rb_cString, strings[i]);
|
|
1190
|
+
for (size_t i = 0; i < sizeof(strings) / sizeof(strings[0]); i++) native_guard_primitive(&rb_cString, strings[i]);
|
|
1190
1191
|
const char *arrays[] = { "all?", "each_with_index", "push", "reverse_each", "shift", "each_index", "[]", "[]=", "<<", "include?", "each", "size", "==" };
|
|
1191
|
-
for (size_t i = 0; i < sizeof(arrays) / sizeof(arrays[0]); i++) native_guard_primitive(rb_cArray, arrays[i]);
|
|
1192
|
-
native_guard_primitive(cLiquidVariableLookup, "freeze");
|
|
1193
|
-
native_guard_primitive(cLiquidRangeLookup, "freeze");
|
|
1194
|
-
native_guard_primitive(rb_cRange, "freeze");
|
|
1195
|
-
native_guard_primitive(rb_cHash, "[]");
|
|
1196
|
-
native_guard_primitive(rb_cHash, "[]=");
|
|
1197
|
-
native_guard_primitive(rb_cHash, "key?");
|
|
1198
|
-
native_guard_primitive(rb_cHash, "each");
|
|
1199
|
-
native_guard_primitive(rb_cHash, "size");
|
|
1200
|
-
native_guard_primitive(rb_cInteger, "<<");
|
|
1201
|
-
native_guard_primitive(rb_cInteger, "|");
|
|
1202
|
-
native_guard_primitive(rb_cInteger, "&");
|
|
1203
|
-
native_guard_primitive(rb_cInteger, "<=>");
|
|
1204
|
-
native_guard_primitive(rb_cInteger, "freeze");
|
|
1205
|
-
native_guard_primitive(rb_cFloat, "freeze");
|
|
1206
|
-
native_guard_primitive(rb_cNilClass, "==");
|
|
1207
|
-
native_guard_primitive(rb_cRegexp, "===");
|
|
1208
|
-
native_guard_primitive(rb_cRegexp, "match?");
|
|
1209
|
-
native_guard_primitive(native_condition_class, "send");
|
|
1210
|
-
native_guard_primitive(rb_cMatch, "[]");
|
|
1211
|
-
native_guard_primitive(rb_cObject, "is_a?");
|
|
1212
|
-
native_guard_primitive(rb_cObject, "freeze");
|
|
1192
|
+
for (size_t i = 0; i < sizeof(arrays) / sizeof(arrays[0]); i++) native_guard_primitive(&rb_cArray, arrays[i]);
|
|
1193
|
+
native_guard_primitive(&cLiquidVariableLookup, "freeze");
|
|
1194
|
+
native_guard_primitive(&cLiquidRangeLookup, "freeze");
|
|
1195
|
+
native_guard_primitive(&rb_cRange, "freeze");
|
|
1196
|
+
native_guard_primitive(&rb_cHash, "[]");
|
|
1197
|
+
native_guard_primitive(&rb_cHash, "[]=");
|
|
1198
|
+
native_guard_primitive(&rb_cHash, "key?");
|
|
1199
|
+
native_guard_primitive(&rb_cHash, "each");
|
|
1200
|
+
native_guard_primitive(&rb_cHash, "size");
|
|
1201
|
+
native_guard_primitive(&rb_cInteger, "<<");
|
|
1202
|
+
native_guard_primitive(&rb_cInteger, "|");
|
|
1203
|
+
native_guard_primitive(&rb_cInteger, "&");
|
|
1204
|
+
native_guard_primitive(&rb_cInteger, "<=>");
|
|
1205
|
+
native_guard_primitive(&rb_cInteger, "freeze");
|
|
1206
|
+
native_guard_primitive(&rb_cFloat, "freeze");
|
|
1207
|
+
native_guard_primitive(&rb_cNilClass, "==");
|
|
1208
|
+
native_guard_primitive(&rb_cRegexp, "===");
|
|
1209
|
+
native_guard_primitive(&rb_cRegexp, "match?");
|
|
1210
|
+
native_guard_primitive(&native_condition_class, "send");
|
|
1211
|
+
native_guard_primitive(&rb_cMatch, "[]");
|
|
1212
|
+
native_guard_primitive(&rb_cObject, "is_a?");
|
|
1213
|
+
native_guard_primitive(&rb_cObject, "freeze");
|
|
1213
1214
|
const char *integers[] = { "+", "-", "==", "!=", "<", ">", ">=" };
|
|
1214
|
-
for (size_t i = 0; i < sizeof(integers) / sizeof(integers[0]); i++) native_guard_primitive(rb_cInteger, integers[i]);
|
|
1215
|
+
for (size_t i = 0; i < sizeof(integers) / sizeof(integers[0]); i++) native_guard_primitive(&rb_cInteger, integers[i]);
|
|
1215
1216
|
const char *symbols[] = { "==", "!=", "===" };
|
|
1216
|
-
for (size_t i = 0; i < sizeof(symbols) / sizeof(symbols[0]); i++) native_guard_primitive(rb_cSymbol, symbols[i]);
|
|
1217
|
+
for (size_t i = 0; i < sizeof(symbols) / sizeof(symbols[0]); i++) native_guard_primitive(&rb_cSymbol, symbols[i]);
|
|
1217
1218
|
id_string_scanner = rb_intern("@string_scanner");
|
|
1218
1219
|
id_new_native = rb_intern("new");
|
|
1219
1220
|
id_allocate_native = rb_intern("allocate");
|
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,
|
|
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
|
-
|
|
112
|
-
|
|
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
|
-
|
|
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
|
|
data/lib/liquid/c/version.rb
CHANGED
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.1.
|
|
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-
|
|
13
|
+
date: 2026-11-25 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: liquid
|
|
@@ -115,7 +115,7 @@ licenses:
|
|
|
115
115
|
- MIT
|
|
116
116
|
metadata:
|
|
117
117
|
allowed_push_host: https://rubygems.org
|
|
118
|
-
source_code_uri: https://github.com/VladimirIvanin/liquid-c/tree/v5.1.
|
|
118
|
+
source_code_uri: https://github.com/VladimirIvanin/liquid-c/tree/v5.1.1
|
|
119
119
|
post_install_message:
|
|
120
120
|
rdoc_options: []
|
|
121
121
|
require_paths:
|