From 99fa6e2090d08a41f15d1c3f59b546568a4859a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Sun, 18 Sep 2022 22:07:21 +0200 Subject: [PATCH 1/2] Avoid free call in interpreted mode This is a workaround for an interpreter bug (#12495) and basically restores the status before #12456. --- src/regex.cr | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/regex.cr b/src/regex.cr index 6ed5891fb921..dd7682902766 100644 --- a/src/regex.cr +++ b/src/regex.cr @@ -262,7 +262,9 @@ class Regex raise ArgumentError.new("#{String.new(errptr)} at #{erroffset}") if @re.null? @extra = LibPCRE.study(@re, LibPCRE::STUDY_JIT_COMPILE, out studyerrptr) if @extra.null? && studyerrptr - LibPCRE.free.call @re.as(Void*) + {% unless flag?(:interpreter) %} + LibPCRE.free.call @re.as(Void*) + {% end %} raise ArgumentError.new("#{String.new(studyerrptr)}") end LibPCRE.full_info(@re, nil, LibPCRE::INFO_CAPTURECOUNT, out @captures) @@ -270,7 +272,9 @@ class Regex def finalize LibPCRE.free_study @extra - LibPCRE.free.call @re.as(Void*) + {% unless flag?(:interpreter) %} + LibPCRE.free.call @re.as(Void*) + {% end %} end # Determines Regex's source validity. If it is, `nil` is returned. @@ -283,7 +287,9 @@ class Regex def self.error?(source) : String? re = LibPCRE.compile(source, (Options::UTF_8 | Options::NO_UTF8_CHECK | Options::DUPNAMES), out errptr, out erroffset, nil) if re - LibPCRE.free.call re.as(Void*) + {% unless flag?(:interpreter) %} + LibPCRE.free.call re.as(Void*) + {% end %} nil else "#{String.new(errptr)} at #{erroffset}" From fbada574ca9ae9fdb472d999109cd6bebd411bba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Sun, 18 Sep 2022 22:45:23 +0200 Subject: [PATCH 2/2] Fix typo --- src/regex.cr | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/regex.cr b/src/regex.cr index dd7682902766..b3ccd7bf0bec 100644 --- a/src/regex.cr +++ b/src/regex.cr @@ -262,7 +262,7 @@ class Regex raise ArgumentError.new("#{String.new(errptr)} at #{erroffset}") if @re.null? @extra = LibPCRE.study(@re, LibPCRE::STUDY_JIT_COMPILE, out studyerrptr) if @extra.null? && studyerrptr - {% unless flag?(:interpreter) %} + {% unless flag?(:interpreted) %} LibPCRE.free.call @re.as(Void*) {% end %} raise ArgumentError.new("#{String.new(studyerrptr)}") @@ -272,7 +272,7 @@ class Regex def finalize LibPCRE.free_study @extra - {% unless flag?(:interpreter) %} + {% unless flag?(:interpreted) %} LibPCRE.free.call @re.as(Void*) {% end %} end @@ -287,7 +287,7 @@ class Regex def self.error?(source) : String? re = LibPCRE.compile(source, (Options::UTF_8 | Options::NO_UTF8_CHECK | Options::DUPNAMES), out errptr, out erroffset, nil) if re - {% unless flag?(:interpreter) %} + {% unless flag?(:interpreted) %} LibPCRE.free.call re.as(Void*) {% end %} nil