Skip to content

Commit

Permalink
Added global variable to control panics
Browse files Browse the repository at this point in the history
  • Loading branch information
Hydrocharged committed Sep 16, 2024
1 parent af7e799 commit 0118adc
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion regex.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ var (
ErrInvalidRegex = errors.NewKind("the given regular expression is invalid")
)

// ShouldPanic determines whether the finalizer will panic if it finds a Regex that has not been closed.
var ShouldPanic bool = true

// RegexFlags are flags to define the behavior of the regular expression. Use OR (|) to combine flags. All flag values
// were taken directly from ICU.
type RegexFlags uint32
Expand Down Expand Up @@ -161,7 +164,7 @@ func CreateRegex(stringBufferInBytes uint32) Regex {
// by GC, this finalizer ensures that regexes are being used as efficiently as possible by maximizing pool rotations.
// Hopefully, this would be caught during development and not in production.
runtime.SetFinalizer(pr, func(pr *privateRegex) {
if pr.mod != nil {
if pr.mod != nil && ShouldPanic {
panic("Finalizer found a Regex that was never closed")
}
})
Expand Down

0 comments on commit 0118adc

Please sign in to comment.