Commit Graph

7 Commits

Author SHA1 Message Date
Nalin Dahyabhai 7d87965738 pkg/regexp: make sure that &Regexp implements the interfaces
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>
2023-06-27 11:23:17 -04:00
Miloslav Trmač ba08716caa Embed Regexp.once directly into the owner again
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>
2023-06-09 01:25:23 +02:00
Miloslav Trmač f2dfc33f1a Ensure regexp.Regexp can't be copied by value
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>
2023-06-09 01:25:23 +02:00
Kir Kolyshkin a4d8f720a2 Format sources with gofumpt
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>
2023-05-26 16:17:31 -07:00
Kir Kolyshkin 7003de8a1a pkg/regex: fix copying mutex
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>
2023-05-25 18:52:05 -07:00
Daniel J Walsh 0ee26255cd
Run codespell on codebase
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2023-02-09 12:27:59 -05:00
Daniel J Walsh b4f7b119c9
Create pkg/regexp to better handle init regex
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>
2023-01-12 13:19:47 -05:00