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

various: upgrade option flags to uint64_t #15457

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

guidocella
Copy link
Contributor

UPDATE_CLIPBOARD currently has the same value as M_OPT_DEFAULT_NAN, so increment all constants after UPDATE_OPT_LAST. But increment them by 5 so we can add a few more UPDATE flags without either forgetting to increase them like in e1d30c4, or having to increase them each time like in a5937ac.

options/m_option.h Outdated Show resolved Hide resolved
options/m_option.h Outdated Show resolved Hide resolved
options/m_option.h Outdated Show resolved Hide resolved
options/m_option.h Outdated Show resolved Hide resolved
@guidocella guidocella force-pushed the option-constants branch 2 times, most recently from 049dcf7 to 0939db8 Compare December 8, 2024 12:56
options/m_option.h Outdated Show resolved Hide resolved
options/m_option.h Outdated Show resolved Hide resolved
@guidocella guidocella force-pushed the option-constants branch 2 times, most recently from 1ff9a1f to 0fb6d24 Compare December 8, 2024 13:38

// Like M_OPT_TYPE_OPTIONAL_PARAM.
#define M_OPT_OPTIONAL_PARAM (1 << 30)
#define M_OPT_OPTIONAL_PARAM (UINT64_C(1) << 63)
Copy link
Contributor

@kasper93 kasper93 Dec 8, 2024

Choose a reason for hiding this comment

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

Could we start from 63 and count down? So we can add new flags here instead of before NAN one.

So NAN would be 64, ALLOW_NO, would be 62 and so on.

Copy link
Contributor

@kasper93 kasper93 Dec 8, 2024

Choose a reason for hiding this comment

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

And after last flag we can add static_assert(UPDATE_OPT_LAST < M_OPT_OPTIONAL_PARAM), so it is easily visible requirement.

Copy link

github-actions bot commented Dec 8, 2024

Download the artifacts for this pull request:

Windows
macOS

@guidocella guidocella force-pushed the option-constants branch 2 times, most recently from 64aed6c to 78a995e Compare December 8, 2024 14:38
// 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_DEFAULT_NAN = (1 << 5),
M_OPT_ALLOW_NO = (1 << 6),
Copy link
Contributor

@na-na-hi na-na-hi Dec 8, 2024

Choose a reason for hiding this comment

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

Forgot the comment for M_OPT_ALLOW_NO.

UPDATE_IMGPAR = (1 << 14), // video image params overrides
UPDATE_INPUT = (1 << 15), // mostly --input-* options
UPDATE_AUDIO = (1 << 16), // --audio-channels etc.
UPDATE_PRIORITY = (1 << 17), // --priority (1Windows-only)
Copy link
Contributor

Choose a reason for hiding this comment

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

1Windows-only

#define UPDATE_OPT_LAST (1 << 26)

// All bits between _FIRST and _LAST (inclusive)
enum option_flags {
Copy link
Contributor

@na-na-hi na-na-hi Dec 8, 2024

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Member

Choose a reason for hiding this comment

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

as the OR'd variables are int64_t instead of the enum type.

ok but that sounds easy to get wrong, no?

Copy link
Contributor Author

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-flags

Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

If this is controversial we can leave it as defines, I don't mind either way, it's just a values.

@kasper93
Copy link
Contributor

Needs rebase.

UPDATE_CLIPBOARD = (1 << 17), // reinit the clipboard
UPDATE_OPT_LAST = (1 << 17),

M_OPT_NOCFG = (1 << 30), // The option is forbidden in config files.
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

@kasper93 kasper93 added the priority:on-ice may be revisited later label Jan 5, 2025
@kasper93
Copy link
Contributor

kasper93 commented Jan 5, 2025

I think we can wait with this PR until next time we add new flag.

@Dudemanguy
Copy link
Member

#15456 adds a new flag so I think this is probably relevant again?

@guidocella
Copy link
Contributor Author

That was the motivation of this PR, but 2 more flags can be added after UPDATE_DEMUXER before having to convert flags to 64 bit.

@guidocella guidocella changed the title m_option: don't overlap UPDATE and M_OPT constant values various: upgrade option flags to uint64_t Jan 28, 2025
@guidocella
Copy link
Contributor Author

As the 2 remaining flags just got added tihs is now necessary to add more.

@Dudemanguy Dudemanguy removed the priority:on-ice may be revisited later label Jan 28, 2025
enum option_flags {
// The following are also part of the M_OPT_* flags, and are used to update
// certain groups of options.
UPDATE_TERM = (UINT64_C(1) << 0), // terminal options
Copy link
Contributor

Choose a reason for hiding this comment

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

parentheses are not needed if we use enum

UPDATE_OPT_LAST = (UINT64_C(1) << 20),

// The option is forbidden in config files.
M_OPT_NOCFG = (UINT64_C(1) << 61),
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we suppose to use uint64_t, top value can be << 63

#define UPDATE_OPT_LAST (1 << 26)

// All bits between _FIRST and _LAST (inclusive)
enum option_flags {
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is controversial we can leave it as defines, I don't mind either way, it's just a values.

@kasper93
Copy link
Contributor

kasper93 commented Jan 28, 2025

It still fails on win32 build.

EDIT: enum won't work on Windows, by default size deduction is disabled and enums are always int. See for more info https://learn.microsoft.com/en-us/cpp/build/reference/zc-enumtypes

@kasper93
Copy link
Contributor

kasper93 commented Jan 31, 2025

This has to be updated too:

assert(!(subopts->change_flags & ~(unsigned)UPDATE_OPTS_MASK));

Copy link
Member

@sfan5 sfan5 left a comment

Choose a reason for hiding this comment

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

lgtm

options/m_config_core.c Outdated Show resolved Hide resolved
So that more UPDATE flags can be added.

change_flags in m_config_core.h was already uint64_t.

Co-authored-by: Kacper Michajłow <[email protected]>
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.

5 participants