Skip to content
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

Merged
merged 2 commits into from
Feb 24, 2024
Merged

Support JSON Marshal/Unmarshal #77

merged 2 commits into from
Feb 24, 2024

Conversation

hunshcn
Copy link
Contributor

@hunshcn hunshcn commented Jan 11, 2024

resolve #76

Copy link
Owner

@dlclark dlclark left a 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()
Copy link
Owner

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping @dlclark

Copy link
Owner

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
Copy link
Owner

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)
Copy link
Owner

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.

Copy link
Contributor Author

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?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That could work.

regexp_test.go Show resolved Hide resolved
@hunshcn hunshcn requested a review from dlclark January 24, 2024 07:44
Copy link
Owner

@dlclark dlclark left a 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()
Copy link
Owner

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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That could work.

@hunshcn
Copy link
Contributor Author

hunshcn commented Feb 22, 2024

ready to go

Copy link
Owner

@dlclark dlclark left a 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.

regexp.go Show resolved Hide resolved
@dlclark dlclark merged commit 05e6ac2 into dlclark:master Feb 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FR: support Marshal/Unmarshal
2 participants