-
Notifications
You must be signed in to change notification settings - Fork 648
Fix default -m delimiter for note ACL #2410
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -101,14 +101,8 @@ class OptionValue | |||||||
| public: | ||||||||
| typedef Value value_type; | ||||||||
|
|
||||||||
| // TODO: Some callers use .value without checking whether the option is | ||||||||
| // enabled(), accessing the (default-initialized or customized) default | ||||||||
| // value that way. This trick will stop working if we add valued options | ||||||||
| // that can be disabled (e.g., --with-foo=x --without-foo). To support such | ||||||||
| // options, store the default value separately and provide value accessor. | ||||||||
|
|
||||||||
| OptionValue(): value {} {} | ||||||||
| explicit OptionValue(const Value &aValue): value(aValue) {} | ||||||||
| OptionValue(): explicitOrDefaultValue {} {} | ||||||||
| explicit OptionValue(const Value &aValue): explicitOrDefaultValue(aValue) {} | ||||||||
|
|
||||||||
| /// whether the option is explicitly turned "on" (with or without a value) | ||||||||
| bool enabled() const { return configured && !disabled; } | ||||||||
|
|
@@ -117,11 +111,19 @@ class OptionValue | |||||||
| /// go back to the default-initialized state | ||||||||
| void reset() { *this = OptionValue<Value>(); } | ||||||||
|
|
||||||||
| Value value; ///< final value storage, possibly after conversions | ||||||||
| const Value *value() const { return enabled() ? &explicitOrDefaultValue : nullptr; }; ///< accessor | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am against the suggestion in this change request because it contains arguably misleading caller instructions (where no instructions are necessary at all) and because the suggested wording implies that a caller has access to multiple option values. I do agree that "accessor" is also problematic and posted a change request with a specific replacement suggestion.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no change from the implications created by the member naming ( "AorB" ) except to clarify that hidden
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Alex suggested the following comment for this method: and for the variable description: In my opinion, this covers the three possible semantic meanings quite well.
ankor2023 marked this conversation as resolved.
Outdated
|
||||||||
| void setValue(const Value &aValue){ explicitOrDefaultValue = aValue; }; | ||||||||
|
|
||||||||
| bool configured = false; ///< whether the option was present in squid.conf | ||||||||
| /* flags for configured options */ | ||||||||
| bool disabled = false; ///< whether the option was turned off | ||||||||
| bool valued = false; ///< whether a configured option had a value | ||||||||
|
|
||||||||
| private: | ||||||||
| /// Final value storage, possibly after conversions. | ||||||||
|
ankor2023 marked this conversation as resolved.
Outdated
|
||||||||
| /// When `valued` is true, this is an explicitly set value. | ||||||||
| /// Otherwise, this is the default value. | ||||||||
| Value explicitOrDefaultValue; | ||||||||
| }; | ||||||||
|
|
||||||||
| /// a type-specific Option (e.g., a boolean --toggle or -m=SBuf) | ||||||||
|
|
@@ -191,8 +193,8 @@ class TypedOption: public Option | |||||||
| } | ||||||||
|
|
||||||||
| private: | ||||||||
| void import(const SBuf &rawValue) const { recipient_->value = rawValue; } | ||||||||
| void printValue(std::ostream &os) const { os << recipient_->value; } | ||||||||
| void import(const SBuf &rawValue) const { recipient_->setValue(rawValue); } | ||||||||
| void printValue(std::ostream &os) const { os << *recipient_->value(); } | ||||||||
|
|
||||||||
| // The "mutable" specifier demarcates set-once Option kind/behavior from the | ||||||||
| // ever-changing recipient of the actual admin-configured option value. | ||||||||
|
|
||||||||
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 you are adding this
ifstatement "just in case", please do not add it. It is the caller's responsibility to check that the value exists as it is not possible to print a non-existing value correctly. This method can (and probably should) assert (usingAssure()) that the value exists.Otherwise, please discuss what caller(s) prompted you to add this
ifstatement.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.
@rousskov
I assumed this method could be used for debugging purposes. In this case, as I understand it, the calling procedure might not know whether the internal variable has been set.
Refactor it to the following, then?
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 do not think that is a valid assumption in this case. Debugging code should use higher-level methods that handle non-existent values correctly.
If you really insist. FWIW, my recommendation for this method in this PR is to just add
()to get this code to compile. This PR is not about improving other aspects of this method, and the proposed assertion is not related to the primary PR changes.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.
Sorry, the above recommendation was based on my incorrect assumption that the official code already dereferenced the value pointer. I was wrong. Yes, please refactor as you suggested as the next step.
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.
@rousskov
Done.