Skip to content

Commit 7ceca47

Browse files
committed
fixup! PCRE2: use System::ThreadLocal for the JITStack and MatchData
1 parent 369a777 commit 7ceca47

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/regex/pcre2.cr

+7-7
Original file line numberDiff line numberDiff line change
@@ -232,17 +232,17 @@ module Regex::PCRE2
232232
LibPCRE2.jit_stack_free(jit_stack)
233233
end
234234

235-
@@match_datas = Crystal::System::ThreadLocal(LibPCRE2::MatchData*).new do |match_data|
235+
@@match_data = Crystal::System::ThreadLocal(LibPCRE2::MatchData*).new do |match_data|
236236
LibPCRE2.match_data_free(match_data)
237237
end
238238

239239
class_getter match_context : LibPCRE2::MatchContext* do
240240
match_context = LibPCRE2.match_context_create(nil)
241-
LibPCRE2.jit_stack_assign(match_context, ->(_data) {
242-
@@jit_stack.get do
243-
LibPCRE2.jit_stack_create(32_768, 1_048_576, nil) || raise "Error allocating JIT stack"
244-
end
245-
}, nil)
241+
LibPCRE2.jit_stack_assign(match_context, ->(data) {
242+
# we must pass @@jit_stack through the data argument to avoid a segfault
243+
jit_stack = data.as(Crystal::System::ThreadLocal(LibPCRE2::JITStack*)*)
244+
jit_stack.value.get { LibPCRE2.jit_stack_create(32_768, 1_048_576, nil) || raise "Error allocating JIT stack" }
245+
}, pointerof(@@jit_stack))
246246
match_context
247247
end
248248

@@ -251,7 +251,7 @@ module Regex::PCRE2
251251
end
252252

253253
private def match_data(str, byte_index, options)
254-
match_data = @@match_datas.get { LibPCRE2.match_data_create(65_535, nil) }
254+
match_data = @@match_data.get { LibPCRE2.match_data_create(65_535, nil) }
255255
match_count = LibPCRE2.match(@re, str, str.bytesize, byte_index, pcre2_match_options(options), match_data, PCRE2.match_context)
256256

257257
if match_count < 0

0 commit comments

Comments
 (0)