-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support JSON Marshal/Unmarshal #77
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see comments. Also please add documentation to the README.md about the requirement to use inline-options when marshaling/unmarshaling.
Thanks!
regexp.go
Outdated
if err != nil { | ||
return err | ||
} | ||
re.muRun.Lock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why lock and unlock the runner pool?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the variable value of the struct is changed while the runner is running, it can cause some unexpected results
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ping @dlclark
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I don't think the framework regexp version of this function is safe to do while a regexp may be running. Is there a use case where you'd need to Unmarshal into a running regex?
regexp.go
Outdated
} | ||
re.muRun.Lock() | ||
defer re.muRun.Unlock() | ||
re.pattern = newRE.pattern |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer the more elegant *re = *newRE
style copy, so lets change Regexp.muRun
to a pointer (and update Compile
) so we can copy the struct with go vet warnings.
regexp.go
Outdated
// UnmarshalText implements [encoding.TextUnmarshaler] by calling | ||
// [Compile] on the encoded value. | ||
func (re *Regexp) UnmarshalText(text []byte) error { | ||
newRE, err := Compile(string(text), re.options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the options should be 0 here since there's no real valid way to set re.options
anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also thinking about this. Is it possible to provide a global flag, such as DefaultUnmarshalOptions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That could work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've left several comments for changes in various parts. Those need to be addressed before this can be accepted.
regexp.go
Outdated
if err != nil { | ||
return err | ||
} | ||
re.muRun.Lock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I don't think the framework regexp version of this function is safe to do while a regexp may be running. Is there a use case where you'd need to Unmarshal into a running regex?
regexp.go
Outdated
// UnmarshalText implements [encoding.TextUnmarshaler] by calling | ||
// [Compile] on the encoded value. | ||
func (re *Regexp) UnmarshalText(text []byte) error { | ||
newRE, err := Compile(string(text), re.options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That could work.
ready to go |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're so close, one small nit and we're good.
resolve #76