Making our exported Regexp type a pointer breaks code that expects to be
able to take its address and call methods on the result.
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
Now that we ensure Regexp can't be copied, remove this
incorrect attempt to avoid the (correct and relevant) warning.
This partially reverts #14664 .
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
The "once" field and "regexp" need to be maintained
together; it's not OK to make two copies of a delayed
Regexp{} that point to a shared once, because the second
user won't see the initialized regexp pointer.
So:
- Turn the public Regexp type into a pointer to a struct,
so that it is not copied by value.
- To make that possible without MOSTLY breaking the existing
API, make it an alias to an internal struct.
- That also has the side effect of making it impossible for external
callers to do Regexp{}, without calling regexp.Delayed,
which is quite a good thing (BUT AN API BREAK).
- Use the noLock struct copy&pasted throughout the Go standard
library to ensure that we don't copy the struct without
noticing.
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
gofumpt is a superset of gofmt, enabling some more code formatting
rules.
This commit is brought to you by
gofumpt -w .
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
It is never a good idea to copy a mutex.
Fix this warning from govet:
> pkg/regexp/regexp.go:26:9: copylocks: return copies lock value: github.com/containers/storage/pkg/regexp.Regexp contains sync.Once contains sync.Mutex (govet)
> return re
> ^
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
The new Reexp structure, will handle the initialization of regexp
and then will do the MustCompile within a sync.Once field.
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>