@@ -232,17 +232,17 @@ module Regex::PCRE2
232
232
LibPCRE2 .jit_stack_free(jit_stack)
233
233
end
234
234
235
- @@match_datas = Crystal ::System ::ThreadLocal (LibPCRE2 ::MatchData * ).new do |match_data |
235
+ @@match_data = Crystal ::System ::ThreadLocal (LibPCRE2 ::MatchData * ).new do |match_data |
236
236
LibPCRE2 .match_data_free(match_data)
237
237
end
238
238
239
239
class_getter match_context : LibPCRE2 ::MatchContext * do
240
240
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 ) )
246
246
match_context
247
247
end
248
248
@@ -251,7 +251,7 @@ module Regex::PCRE2
251
251
end
252
252
253
253
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 ) }
255
255
match_count = LibPCRE2 .match(@re , str, str.bytesize, byte_index, pcre2 _match_options(options), match_data, PCRE2 .match_context)
256
256
257
257
if match_count < 0
0 commit comments