From 4192ecd7ad13544582bef02884d1bfa053dad468 Mon Sep 17 00:00:00 2001 From: Quinton Miller Date: Thu, 9 Feb 2023 22:41:18 +0800 Subject: [PATCH 1/2] Do not use `@[ThreadLocal]` for PCRE2's JIT stack --- src/regex/pcre2.cr | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/regex/pcre2.cr b/src/regex/pcre2.cr index 08b823083086..b0f24733860f 100644 --- a/src/regex/pcre2.cr +++ b/src/regex/pcre2.cr @@ -141,13 +141,12 @@ module Regex::PCRE2 # # Only a single `match` function can run per thread at any given time, so there # can't be any concurrent access to the JIT stack. - @[ThreadLocal] - class_getter jit_stack : LibPCRE2::JITStack do - jit_stack = LibPCRE2.jit_stack_create(32_768, 1_048_576, Regex::PCRE2.general_context) - if jit_stack.null? - raise "Error allocating JIT stack" + @@jit_stack = Crystal::ThreadLocalValue(LibPCRE2::JITStack).new + + def self.jit_stack + @@jit_stack.get do + LibPCRE2.jit_stack_create(32_768, 1_048_576, general_context) || raise "Error allocating JIT stack" end - jit_stack end private def match_data(str, byte_index, options) From 94bdb82d039e29a94527f96db17028f18bb419c1 Mon Sep 17 00:00:00 2001 From: Quinton Miller Date: Fri, 10 Feb 2023 00:43:47 +0800 Subject: [PATCH 2/2] fix windows compilation --- src/regex/pcre2.cr | 1 + 1 file changed, 1 insertion(+) diff --git a/src/regex/pcre2.cr b/src/regex/pcre2.cr index b0f24733860f..14b64e72546d 100644 --- a/src/regex/pcre2.cr +++ b/src/regex/pcre2.cr @@ -1,4 +1,5 @@ require "./lib_pcre2" +require "crystal/thread_local_value" # :nodoc: module Regex::PCRE2