Skip to content

Conversation

@jtimon
Copy link
Contributor

@jtimon jtimon commented Jan 9, 2017

Continues #9243 by @TheBlueMatt
Introduce an ArgsManager class encapsulating cs_args, mapArgs and mapMultiArgs.

To reduce disruption, the used functions are kept as wrapers. The wrapers can be removed later, see jtimon/bitcoin@0.13-args-class...jtimon:0.13-args-remove-wrapers for the less disruptive ones to remove.

@TheBlueMatt
Copy link
Contributor

TheBlueMatt commented Jan 9, 2017 via email

@jtimon
Copy link
Contributor Author

jtimon commented Jan 9, 2017

Yes, we discussed it in #9243, but that this seems approximately what was discussed previously is still very useful, thanks.

What concerns me more of the current code is the fact that the methods IsArgSet, GetArg, GetBoolArg and ArgsAt aren't const, because they need to LOCK(cs_args);. The first "solution" that comes to mind is to make a superclass with just these methods (but they remain non-const).

@dcousens
Copy link
Contributor

dcousens commented Jan 11, 2017

concept ACK 👍 , will review again when able, once-over utACK 8a96939

bool IsArgSet(const std::string& strArg)
const std::vector<std::string>& ArgsManager::ArgsAt(const std::string& strArg) const
{
return mapMultiArgs.at(strArg);
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 assume this should get LOCK(cs_args); too? If so, the method can't be const.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, it also cant return a reference, needs to make a copy.

@jtimon
Copy link
Contributor Author

jtimon commented Jan 31, 2017

Needed rebase.

@jtimon
Copy link
Contributor Author

jtimon commented Mar 23, 2017

Needed rebase (due to "Refactor: Remove using namespace " PRs).

@laanwj
Copy link
Member

laanwj commented Mar 24, 2017

Concept ACK, seems a move in the right direction.

@sipa
Copy link
Member

sipa commented Mar 24, 2017

utACK c67209128a114e3260ab93c3e8a63b1b23663b34

@TheBlueMatt
Copy link
Contributor

TheBlueMatt commented Mar 25, 2017 via email

Copy link
Contributor

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

Switching mapMultiArgs.count() to argsGlobal.IsArgSet makes a few things incorrect, because the SoftSetArgs stuff doesn't update mapMultiArgs but does update mapArgs. I think the correct solution here is to keep mapMultiArgs and mapArgs consistent (@luke-jr also needed that for the multiwallet pull), though that does mean ArgsAt needs to return a copy and not a reference (which I think is OK - arg usage doesn't need to be fast).

src/httprpc.cpp Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: kill the > 0 here?

@jtimon
Copy link
Contributor Author

jtimon commented Mar 28, 2017

Switching mapMultiArgs.count() to argsGlobal.IsArgSet makes a few things incorrect, because the SoftSetArgs stuff doesn't update mapMultiArgs but does update mapArgs.

Maybe a solution could be to use argsGlobal.IsArgsAt().size() > 0 in those cases?
I mean, I think in all those cases will just try to loop through an empty vector (ie do nothing) inside the if clause, but I haven't made sure of that. I could go through them and maybe replace some BOOST_FOREACH for C++ fors while at it.
Never mind, it seems mapMultiArgs.count("-bind") is not like that, but could be fixed with argsGlobal.IsArgsAt().size() > 0
By "making mapMultiArgs and mapArg" I assume you just mean redundantly setting to mapMultiArgs in ArgsManager::SoftSetArg too as it is done in ArgsManager::ArgsAt. Perhaps that is simpler and easier to reason about.

Thoughts?

@TheBlueMatt
Copy link
Contributor

I'd prefer to just fix the issue - I think its super strange that SoftSetArg, etc dont keep mapMultiArgs and mapArgs consistent.

@jtimon
Copy link
Contributor Author

jtimon commented Mar 29, 2017

Fixed nits. Also removed a bunch of BOOST_FOREACH for free in the commit that introduces ArgsManager::ArgsAt().

@jtimon jtimon force-pushed the 0.13-args-class branch 2 times, most recently from 4396063 to 5c18d51 Compare March 29, 2017 21:24
@jtimon
Copy link
Contributor Author

jtimon commented Mar 29, 2017

Fixed nit.

@jtimon
Copy link
Contributor Author

jtimon commented Apr 4, 2017

Needed rebase.

@JeremyRubin
Copy link
Contributor

put my review of this code on the wrong PR. #10119 (comment)

@theuni
Copy link
Member

theuni commented May 9, 2017

utACK f19f5b5

@jtimon
Copy link
Contributor Author

jtimon commented May 9, 2017

Sorry, just pushed again changing the history as @TheBlueMatt suggested.
78da882 should be equivalent to f19f5b5

@ryanofsky
Copy link
Contributor

utACK 78da882. Confirmed no diff since previous review, just mapMultiArgs commit history change.

@laanwj
Copy link
Member

laanwj commented May 15, 2017

utACK 78da882

@laanwj laanwj merged commit 78da882 into bitcoin:master May 15, 2017
laanwj added a commit that referenced this pull request May 15, 2017
…pArgs and mapMultiArgs

78da882 Util: Small improvements in gArgs usage (Jorge Timón)
5292245 Util: Put mapMultiArgs inside ArgsManager (Jorge Timón)
b3cbd55 scripted-diff: Util: Encapsulate mapMultiArgs behind gArgs (Jorge Timón)
f2957ce Util: Create ArgsManager class... (Jorge Timón)

Tree-SHA512: 7d58250da440ad0f41745f46ab6021d6ecbb292035cab3d86fb08ce6bd822df604ac31b3ded6fd6914f7cfd12ba531cbc06a76eb500f629627f47ae6ac8350a7
@jtimon jtimon deleted the 0.13-args-class branch May 18, 2017 20:25
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 22, 2019
…rgs, mapArgs and mapMultiArgs

78da882 Util: Small improvements in gArgs usage (Jorge Timón)
5292245 Util: Put mapMultiArgs inside ArgsManager (Jorge Timón)
b3cbd55 scripted-diff: Util: Encapsulate mapMultiArgs behind gArgs (Jorge Timón)
f2957ce Util: Create ArgsManager class... (Jorge Timón)

Tree-SHA512: 7d58250da440ad0f41745f46ab6021d6ecbb292035cab3d86fb08ce6bd822df604ac31b3ded6fd6914f7cfd12ba531cbc06a76eb500f629627f47ae6ac8350a7

add ForceRemoveArg and ForceSetMultiArg to ArgsManager class

Signed-off-by: Pasta <[email protected]>

add static inlines for ForceSetMultiArgs and ForceRemoveArg

Signed-off-by: Pasta <[email protected]>

both void

Signed-off-by: Pasta <[email protected]>

use gArgs, dash code

Signed-off-by: Pasta <[email protected]>

revert a bit

Signed-off-by: Pasta <[email protected]>

adj

Signed-off-by: Pasta <[email protected]>

use gArgs

Signed-off-by: Pasta <[email protected]>

remove '_'

Signed-off-by: Pasta <[email protected]>
furszy added a commit to PIVX-Project/PIVX that referenced this pull request Oct 28, 2020
4709ff8 remove now unused gArgs wrappers (Fuzzbawls)
cc40f8d Manual prep for gArg wrapper removal (Fuzzbawls)
b3c843c scripted-diff: stop using the gArgs wrappers (Fuzzbawls)
5ce3844 Migrate g_logger fields to gArgs (Fuzzbawls)
72a6f56 Track negated arguments in the argument paser. (Fuzzbawls)
3142e1b Add additional tests for GetBoolArg() (Fuzzbawls)
4aef2f3 Fix constness of ArgsManager methods (Fuzzbawls)
13fd27d Fix indentation after 'Remove redundant calls to gArgs.IsArgSet()' (Fuzzbawls)
a4114f3 Util: Remove redundant calls to gArgs.IsArgSet() (Fuzzbawls)
92e7227 Util: Small improvements in gArgs usage (Fuzzbawls)
a8b26e7 Util: Put mapMultiArgs inside ArgsManager (Fuzzbawls)
d2f2e25 scripted-diff: Util: Encapsulate mapMultiArgs behind gArgs (Fuzzbawls)
b2abc59 Util: Create ArgsManager class... (Fuzzbawls)
8c4d9c5 Add a ForceSetArg method for testing (Fuzzbawls)
59d6529 Lock mapArgs/mapMultiArgs access in util (Fuzzbawls)
f7f2689 Un-expose mapArgs from util.h (Fuzzbawls)
7894b07 Get rid of mapArgs direct access in ZMQ construction (Matt Corallo)
b28789f Introduce (and use) an IsArgSet accessor method (Fuzzbawls)
4d8ecf9 Fix non-const mapMultiArgs[] access after init. (Fuzzbawls)
391388d Remove arguments to ReadConfigFile (Fuzzbawls)

Pull request description:

  This is a cumulation of several upstream backports surrounding the argument parsing code.

  Included here are the following upstream PRs:
  - bitcoin#9243
  - bitcoin#9494
  - bitcoin#10118
  - bitcoin#10901
  - bitcoin#12713
  - bitcoin#10607

  I've also refactored the global logging argument parsing to match, as that was an "out-of-order" PR that was previously backported to match our previous state.

ACKs for top commit:
  random-zebra:
    utACK 4709ff8
  furszy:
    cool encapsulation, utACK 4709ff8 and merging

Tree-SHA512: 74c8dc1b2280b726eff44855e9908f3563d4ef6493f296ebfafe240ac6470bc45cbc75baac614ed59dfda9e1377b7da7d47a695dfc05e364cada2468bb99a258
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants