-
Notifications
You must be signed in to change notification settings - Fork 3k
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
m_option: don't overlap UPDATE and M_OPT constant values #15457
Open
guidocella
wants to merge
3
commits into
mpv-player:master
Choose a base branch
from
guidocella:option-constants
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -423,62 +423,44 @@ struct m_option { | |
|
||
char *format_file_size(int64_t size); | ||
|
||
// The following are also part of the M_OPT_* flags, and are used to update | ||
// certain groups of options. | ||
#define UPDATE_TERM (1 << 0) // terminal options | ||
#define UPDATE_SUB_FILT (1 << 1) // subtitle filter options | ||
#define UPDATE_OSD (1 << 2) // related to OSD rendering | ||
#define UPDATE_BUILTIN_SCRIPTS (1 << 3) // osc/ytdl/stats | ||
#define UPDATE_IMGPAR (1 << 4) // video image params overrides | ||
#define UPDATE_INPUT (1 << 5) // mostly --input-* options | ||
#define UPDATE_AUDIO (1 << 6) // --audio-channels etc. | ||
#define UPDATE_PRIORITY (1 << 7) // --priority (Windows-only) | ||
#define UPDATE_SCREENSAVER (1 << 8) // --stop-screensaver | ||
#define UPDATE_VOL (1 << 9) // softvol related options | ||
#define UPDATE_LAVFI_COMPLEX (1 << 10) // --lavfi-complex | ||
#define UPDATE_HWDEC (1 << 11) // --hwdec | ||
#define UPDATE_DVB_PROG (1 << 12) // some --dvbin-... | ||
#define UPDATE_SUB_HARD (1 << 13) // subtitle opts. that need full reinit | ||
#define UPDATE_SUB_EXTS (1 << 14) // update internal list of sub exts | ||
#define UPDATE_VIDEO (1 << 15) // force redraw if needed | ||
#define UPDATE_VO (1 << 16) // reinit the VO | ||
#define UPDATE_CLIPBOARD (1 << 17) // reinit the clipboard | ||
#define UPDATE_OPT_LAST (1 << 17) | ||
|
||
// All bits between of UPDATE_ flags | ||
#define UPDATE_OPTS_MASK ((UPDATE_OPT_LAST << 1) - 1) | ||
|
||
// The option is forbidden in config files. | ||
#define M_OPT_NOCFG (1 << 30) | ||
|
||
// The option should be set during command line pre-parsing | ||
#define M_OPT_PRE_PARSE (1 << 29) | ||
|
||
// The option expects a file name (or a list of file names) | ||
#define M_OPT_FILE (1 << 28) | ||
|
||
// Do not add as property. | ||
#define M_OPT_NOPROP (1 << 27) | ||
|
||
// Enable special semantics for some options when parsing the string "help". | ||
#define M_OPT_HAVE_HELP (1 << 26) | ||
|
||
// type_float/type_double: string "default" is parsed as NaN (and reverse) | ||
#define M_OPT_DEFAULT_NAN (1 << 25) | ||
|
||
// type time: string "no" maps to MP_NOPTS_VALUE (if unset, NOPTS is rejected) | ||
// and | ||
// parsing: "--no-opt" is parsed as "--opt=no" | ||
#define M_OPT_ALLOW_NO (1 << 24) | ||
|
||
// type channels: disallow "auto" (still accept ""), limit list to at most 1 item. | ||
#define M_OPT_CHANNELS_LIMITED (1 << 23) | ||
|
||
// type_float/type_double: controls if pretty print should trim trailing zeros | ||
#define M_OPT_FIXED_LEN_PRINT (1 << 22) | ||
|
||
// Like M_OPT_TYPE_OPTIONAL_PARAM. | ||
#define M_OPT_OPTIONAL_PARAM (1 << 21) | ||
enum option_flags { | ||
// The following are also part of the M_OPT_* flags, and are used to update | ||
// certain groups of options. | ||
UPDATE_TERM = (1 << 0), // terminal options | ||
UPDATE_SUB_FILT = (1 << 1), // subtitle filter options | ||
UPDATE_OSD = (1 << 2), // related to OSD rendering | ||
UPDATE_BUILTIN_SCRIPTS = (1 << 3), // osc/ytdl/stats | ||
UPDATE_IMGPAR = (1 << 4), // video image params overrides | ||
UPDATE_INPUT = (1 << 5), // mostly --input-* options | ||
UPDATE_AUDIO = (1 << 6), // --audio-channels etc. | ||
UPDATE_PRIORITY = (1 << 7), // --priority (Windows-only) | ||
UPDATE_SCREENSAVER = (1 << 8), // --stop-screensaver | ||
UPDATE_VOL = (1 << 9), // softvol related options | ||
UPDATE_LAVFI_COMPLEX = (1 << 10), // --lavfi-complex | ||
UPDATE_HWDEC = (1 << 11), // --hwdec | ||
UPDATE_DVB_PROG = (1 << 12), // some --dvbin-... | ||
UPDATE_SUB_HARD = (1 << 13), // subtitle opts. that need full reinit | ||
UPDATE_SUB_EXTS = (1 << 14), // update internal list of sub exts | ||
UPDATE_VIDEO = (1 << 15), // force redraw if needed | ||
UPDATE_VO = (1 << 16), // reinit the VO | ||
UPDATE_CLIPBOARD = (1 << 17), // reinit the clipboard | ||
UPDATE_OPT_LAST = (1 << 17), | ||
|
||
M_OPT_NOCFG = (1 << 30), // The option is forbidden in config files. | ||
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. Now that the type has been changed to 64 bits, those should be moved up. |
||
M_OPT_PRE_PARSE = (1 << 29), // The option should be set during command line pre-parsing | ||
M_OPT_FILE = (1 << 28), // The option expects a file name (or a list of file names) | ||
M_OPT_NOPROP = (1 << 27), // Do not add as property. | ||
M_OPT_HAVE_HELP = (1 << 26), // Enable special semantics for some options when parsing the string "help". | ||
|
||
M_OPT_DEFAULT_NAN = (1 << 25), // type_float/type_double: string "default" is parsed as NaN (and reverse) | ||
M_OPT_ALLOW_NO = (1 << 24), // type time: string "no" maps to MP_NOPTS_VALUE (if unset, NOPTS is rejected) | ||
// and parsing: "--no-opt" is parsed as "--opt=no" | ||
M_OPT_CHANNELS_LIMITED = (1 << 23), // type channels: disallow "auto" (still accept ""), limit list to at most 1 item. | ||
M_OPT_FIXED_LEN_PRINT = (1 << 22), // type_float/type_double: controls if pretty print should trim trailing zeros | ||
M_OPT_OPTIONAL_PARAM = (1 << 21), // Like M_OPT_TYPE_OPTIONAL_PARAM. | ||
}; | ||
|
||
#define UPDATE_OPTS_MASK ((UPDATE_OPT_LAST << 1) - 1) | ||
|
||
static_assert(!(UPDATE_OPTS_MASK & M_OPT_OPTIONAL_PARAM), ""); | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 this shouldn't use enum here. I consider a value of enum type can only be one of the defined exact value instead of some OR'd values.
If you want to group flags you can add a comment at the beginning of this section like the "These flags are used to describe special parser capabilities or behavior." for the next section below.
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.
It was kasper's preference to use enum. I think it's more readable without all the #define and don't see a problem OR'ing constants as long as the OR'd variables are int64_t instead of the enum type.
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.
For me it is more easily recognizable, what flags are grouped together, but I approved previous version, as it was looking nice too. Frankly I would leave the enum conversion to separate commit, if not PR, to not mix it with real fixes that are being made in this 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.
ok but that sounds easy to get wrong, no?
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.
It's not like it doesn't work if the variable is of the enum type, it just makes more sense to use int if the value is not one of the enum constants. Also even this example in Microsoft's docs does it and even assigns the OR'd constants to
Days
variables: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/enum#enumeration-types-as-bit-flagsThere 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 wouldn't take MS documentation as the benchmark of correctness. There are many code examples from them that don't even work.
In fact, C++ enum classes are strongly typed and won't allow such usage, just like enum in most non-C programming languages.