Skip to content

Commit 0118adc

Browse files
committed
Added global variable to control panics
1 parent af7e799 commit 0118adc

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

regex.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ var (
5555
ErrInvalidRegex = errors.NewKind("the given regular expression is invalid")
5656
)
5757

58+
// ShouldPanic determines whether the finalizer will panic if it finds a Regex that has not been closed.
59+
var ShouldPanic bool = true
60+
5861
// RegexFlags are flags to define the behavior of the regular expression. Use OR (|) to combine flags. All flag values
5962
// were taken directly from ICU.
6063
type RegexFlags uint32
@@ -161,7 +164,7 @@ func CreateRegex(stringBufferInBytes uint32) Regex {
161164
// by GC, this finalizer ensures that regexes are being used as efficiently as possible by maximizing pool rotations.
162165
// Hopefully, this would be caught during development and not in production.
163166
runtime.SetFinalizer(pr, func(pr *privateRegex) {
164-
if pr.mod != nil {
167+
if pr.mod != nil && ShouldPanic {
165168
panic("Finalizer found a Regex that was never closed")
166169
}
167170
})

0 commit comments

Comments
 (0)