Skip to content

Conversation

@laanwj
Copy link
Member

@laanwj laanwj commented Aug 21, 2014

100% code movement, no functional changes.
Split up util.cpp/h into:

  • string utilities (hex, base32, base64): no internal dependencies, no dependency on boost (apart from foreach)
  • money utilities (parsemoney, formatmoney)
  • time utilities (gettime*, sleep, format date):
  • and the rest (logging, argument parsing, config file parsing)

The latter is basically the environment and OS handling, and is stripped of all utility functions, so we may want to rename it to something else than util.cpp/h for clarity (@TheBlueMatt suggested osinterface).

Some unused functions have been completely removed, some functions of limited use that are only used in one place have been moved where they are used (see commits).

Breaks dependency of sha256.cpp on all the things pulled in by util. This makes many include-time dependencies explicit, which before were 'inherited' from include files.

@theuni
Copy link
Member

theuni commented Aug 21, 2014

Looks great, I'm verifying the c/p now. Several dependencies on boost could be dropped, I assume you're leaving that for a follow-up?

@theuni
Copy link
Member

theuni commented Aug 21, 2014

Verfied the code movement with c/p, all is clean with 2 exceptions. I'm only mentioning these for the sake of being thorough, I assume they're harmless.

GetTimeMicros and MilliSleep have moved from inline->non-inline. I have no clue if they actually ended up being inlined for real when compiled before, but if so, that may mean a functional change here due to the timing/precision involved.

That aside, ACK.

@laanwj
Copy link
Member Author

laanwj commented Aug 22, 2014

If you see any further dependencies on boost - especially includes in headers - that can be removed let me know. This has the overall effect of including less boost headers per compilation unit which means faster compile times.

And indeed: GetTimeMillis/Micros are no longer inline because they pull in a compile-time dependency on boost::posix_time. Having them implemented in utiltime.cpp means that the boost usage is at least isolated. It could theoretically affect timings - but what's one extra function call in microseconds, who knows what boost::posixtime::* is doing for awful stuff internally. To reliably benchmark small times one should use CPU performance counters (and yes, inlined :-). But IIRC we only benchmark larger time-spans.

@laanwj laanwj force-pushed the 2014_08_core_print_2 branch from 04db80f to d9e45ae Compare August 22, 2014 07:29
@laanwj
Copy link
Member Author

laanwj commented Aug 22, 2014

PASSED! Hah, take that @BitcoinPullTester (for some reason the pulltester environment requires some more explicit #includes of boost/thread.hpp, so had to add those one by one, sorry for the spam)

@theuni
Copy link
Member

theuni commented Aug 22, 2014

@laanwj re: inlines, sounds good.

As for the boost deps, I'm not sure if there are others, but I noticed this one right away in utilstring.cpp

bool IsHex(const string& str)
{
 BOOST_FOREACH(char c, str)
 {
 if (HexDigit(c) < 0)

->

bool IsHex(const string& str)
{
 for(std::string::const_iterator c(str.begin()); c != str.end(); ++c)
 {
 if (HexDigit(*c) < 0)

That would mean dropping boost completely for that object.

@laanwj
Copy link
Member Author

laanwj commented Aug 23, 2014

@theuni I thought about that, although I like keeping FOREACH, so that they can be easily replaced when the time for c++11 comes. boost/foreach.hpp is header-only.

@TheBlueMatt
Copy link
Contributor

I havent verified the c/p yet (will do that after squash before merge), but you've definitely got my conceptual ACK. I might consider changing utilmoney to uilmoneystr or just moneystr, utilstring to utilstrencodings or something and splitting the new util up further into something like arguments/env and logging (but that may be better in a separate pull because some of it isnt clear).

Copy link
Member

Choose a reason for hiding this comment

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

2x version.h?

@sipa
Copy link
Member

sipa commented Aug 24, 2014

Untested ACK; I didn't verify it to be move-only.

@laanwj
Copy link
Member Author

laanwj commented Aug 25, 2014

@TheBlueMatt I'm not going to do any further splitting in this pull. Those renames sound fine to me though.

@laanwj laanwj force-pushed the 2014_08_core_print_2 branch from ea0f29e to e084db7 Compare August 25, 2014 09:22
@TheBlueMatt
Copy link
Contributor

ut (but verified cp) ACK

@jgarzik
Copy link
Contributor

jgarzik commented Aug 25, 2014

ut ACK

"utilstrencodings" is a lame name. utilstrcode or strutil ?

@sipa
Copy link
Member

sipa commented Aug 25, 2014

Untested ACK, but verified move-only.

I will refrain from joining the filename bikeshedding.

@laanwj
Copy link
Member Author

laanwj commented Aug 26, 2014

@jgarzik It was just utilstring, then I renamed it after @TheBlueMatt complained about the name once already. I won't keep renaming them. Go fight it out with him first..

@TheBlueMatt
Copy link
Contributor

@jgarzik now its bikeshedding, I dont care either way, it was just a suggestion.

laanwj added 10 commits August 26, 2014 13:25
Now that we no longer use the median filter to keep track of
the number of blocks of peers, that's the only place it is used.
Put the THREAD_* and PRIO_ constants in compat.h.
Breaks compile-time dependency of wallet.h on util.
Eventually these should end up in `money.h` after monetary
amounts are typedef'ed, but at least they don't belong in `util.h`.
Split up util.cpp/h into:

- string utilities (hex, base32, base64): no internal dependencies, no dependency on boost (apart from foreach)
- money utilities (parsesmoney, formatmoney)
- time utilities (gettime*, sleep, format date):
- and the rest (logging, argument parsing, config file parsing)

The latter is basically the environment and OS handling,
and is stripped of all utility functions, so we may want to
rename it to something else than util.cpp/h for clarity (Matt suggested
osinterface).

Breaks dependency of sha256.cpp on all the things pulled in by util.
@laanwj laanwj force-pushed the 2014_08_core_print_2 branch from e084db7 to ad49c25 Compare August 26, 2014 11:25
@BitcoinPullTester
Copy link

Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/p4748_ad49c256c33bfe4088fd3c7ecb7d28cb81a8fc70/ for binaries and test log.
This test script verifies pulls every time they are updated. It, however, dies sometimes and fails to test properly. If you are waiting on a test, please check timestamps to verify that the test.log is moving at http://jenkins.bluematt.me/pull-tester/current/
Contact BlueMatt on freenode if something looks broken.

@sipa
Copy link
Member

sipa commented Aug 26, 2014

Merging, as this will likely be outdated soon otherwise.

File renames can easily be done later if necessary.

@sipa sipa merged commit ad49c25 into bitcoin:master Aug 26, 2014
sipa added a commit that referenced this pull request Aug 26, 2014
ad49c25 Split up util.cpp/h (Wladimir J. van der Laan)
f841aa2 Move `COIN` and `CENT` to core.h (Wladimir J. van der Laan)
6e5fd00 Move `*Version()` functions to version.h/cpp (Wladimir J. van der Laan)
b4aa769 Move `S_I*` constants and `MSG_NOSIGNAL` to compat.h (Wladimir J. van der Laan)
af8297c Move functions in wallet.h to implementation file (Wladimir J. van der Laan)
651480c move functions in main and net to implementation files (Wladimir J. van der Laan)
610a8c0 Move SetThreadPriority implementation to util.cpp instead of the header (Wladimir J. van der Laan)
f780e65 Remove unused function `ByteReverse` from util.h (Wladimir J. van der Laan)
121d6ad Remove unused `alignup` function from util.h (Wladimir J. van der Laan)
d1e26d4 Move CMedianFilter to timedata.cpp (Wladimir J. van der Laan)
laanwj added a commit to laanwj/bitcoin that referenced this pull request Jun 27, 2016
Updates `tinyformat.h` to commit
c42f/tinyformat@3a33bbf upstream.

Makes sure that our local changes are kept:

- bitcoin#3767 1b8fd35 Make tinyformat errors raise an exception instead of assert()ing
- bitcoin#4735 9b6d4c5 Move strprintf define to tinyformat.h
- bitcoin#4748 6e5fd00 include stdexcept (for std::exception)
- bitcoin#8000 9eaa0af force USE_VARIADIC_TEMPLATES
- Add `std::string format(const std::string &fmt...` added this
  at the time, as we want to be able to do `strprintf(_(...), ...)`

Inspired by bitcoin#8264.
@laanwj laanwj mentioned this pull request Jun 27, 2016
zkbot pushed a commit to zcash/zcash that referenced this pull request Oct 25, 2016
util: Update tinyformat

Updates `tinyformat.h` to commit
c42f/tinyformat@3a33bbf upstream.

Makes sure that our local changes are kept:

- bitcoin/bitcoin#3767 1b8fd35 Make tinyformat errors raise an exception instead of assert()ing
- bitcoin/bitcoin#4735 9b6d4c5 Move strprintf define to tinyformat.h
- bitcoin/bitcoin#4748 6e5fd00 include stdexcept (for std::exception)
- bitcoin/bitcoin#8000 9eaa0af force USE_VARIADIC_TEMPLATES
- Add `std::string format(const std::string &fmt...` added this
  at the time, as we want to be able to do `strprintf(_(...), ...)`

Inspired by bitcoin/bitcoin#8264.

For Zcash: ref #1349
protonn pushed a commit to argentumproject/argentum that referenced this pull request May 7, 2017
Updates `tinyformat.h` to commit
c42f/tinyformat@3a33bbf upstream.

Makes sure that our local changes are kept:

- bitcoin#3767 1b8fd35 Make tinyformat errors raise an exception instead of assert()ing
- bitcoin#4735 9b6d4c5 Move strprintf define to tinyformat.h
- bitcoin#4748 6e5fd00 include stdexcept (for std::exception)
- bitcoin#8000 9eaa0af force USE_VARIADIC_TEMPLATES
- Add `std::string format(const std::string &fmt...` added this
  at the time, as we want to be able to do `strprintf(_(...), ...)`

Inspired by bitcoin#8264.
lateminer pushed a commit to lateminer/bitcoin that referenced this pull request Jan 3, 2019
Updates `tinyformat.h` to commit
c42f/tinyformat@3a33bbf upstream.

Makes sure that our local changes are kept:

- bitcoin#3767 1b8fd35 Make tinyformat errors raise an exception instead of assert()ing
- bitcoin#4735 9b6d4c5 Move strprintf define to tinyformat.h
- bitcoin#4748 6e5fd00 include stdexcept (for std::exception)
- bitcoin#8000 9eaa0af force USE_VARIADIC_TEMPLATES
- Add `std::string format(const std::string &fmt...` added this
  at the time, as we want to be able to do `strprintf(_(...), ...)`

Inspired by bitcoin#8264.
@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.

6 participants