Skip to content

Conversation

@kallewoof
Copy link
Contributor

@kallewoof kallewoof commented Dec 16, 2016

Uses built-in byte swap if available (Apple) and if bswap_XX is undefined.

Defers to pre-defined version if found (e.g. protobuf). For protobuf case, the definitions are identical and thus include order should not affect results.

Fixes compilation errors on recent Mac OS X with QT client enabled.

Replaces #9361

@fanquake fanquake added the macOS label Dec 16, 2016
@laanwj
Copy link
Member

laanwj commented Dec 16, 2016

Yes, this looks better, thanks

Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer moving this one to the qt unit tests, instead of adding a qt-specific unit test to the core unit tests.

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 moved this into a new "CompatTests" test suite in the QT tests.

@theuni
Copy link
Member

theuni commented Dec 16, 2016

Hmm, is it really necessary to have the system-specific bswaps anymore? Since we require a modern compiler, these are likely to be detected/optimized automatically anyway.

Test file: https://gist.github.com/theuni/deb0b97c31890bd0a06a65dd3cb51822
compiled with gcc/clang: c++ -std=c++11 -O2 -c -o bswapcomp.o bswap.cpp

Results: https://gist.github.com/theuni/508b69da908be1e52bbdd0b7a135c318

On x86-64, I see no difference for osx+clang, linux+clang, linux+gcc.

doesn't look like it's worth bothering to me, or is there some platform that would be more likely to be a discrepancy?

@kallewoof
Copy link
Contributor Author

kallewoof commented Dec 16, 2016

@theuni So you think it's better to basically #undef and #define them always for consistency?

Edit: I meant to say that since we want the same thing to happen no matter which include order is taken, we might as well just redefine them each time on our own side.

@theuni
Copy link
Member

theuni commented Dec 17, 2016

@kallewoof I was suggesting just skipping the platform includes (byteswap.h/OSByteOrder.h), skipping the use of any system implementations, and renaming bswap_foo -> int_bswap_foo to avoid collisions.

Need others to chime in first though.

@kallewoof
Copy link
Contributor Author

FWIW I like the idea personally.

@kallewoof kallewoof force-pushed the macosx-qt-build-fix2 branch 2 times, most recently from 1f8c454 to 609eb65 Compare December 17, 2016 01:29
…ined.

Defers to pre-defined version if found (e.g. protobuf). For protobuf case, the definitions are identical and thus include order should not affect results.
@theuni
Copy link
Member

theuni commented Dec 17, 2016

utACK 815f414 for the sake of fixing the build.

Dropping the system includes (or alternatively autoconfing this) can come as a next step if it's agreed upon.

@laanwj
Copy link
Member

laanwj commented Dec 19, 2016

Hmm, is it really necessary to have the system-specific bswaps anymore? Since we require a modern compiler, these are likely to be detected/optimized automatically anyway.

If there are bswap primitives, I think we should use them. This is used internally in the serialization as well as crypto operations, so performance here (if there is a compiler where it makes sense) does matter.
If you want to prove for every compiler, architecture combo in existence that this doesn't matter, fine. But if not, I'd prefer to keep using system primitives if available.

@laanwj
Copy link
Member

laanwj commented Dec 19, 2016

utACK 815f414, let's just fix this to fix the build, I think we've been through enough shed-painting here.

@laanwj laanwj merged commit 815f414 into bitcoin:master Dec 19, 2016
laanwj added a commit that referenced this pull request Dec 19, 2016
…defer

815f414 Uses built-in byte swap if available (Apple) and if bswap_XX is undefined. (Karl-Johan Alm)
@kallewoof kallewoof deleted the macosx-qt-build-fix2 branch December 19, 2016 07:30
@droark
Copy link
Contributor

droark commented Feb 1, 2017

FYI, I backported this to 0.13. I noticed it when trying to compile the Elements Alpha refresh.

laanwj pushed a commit that referenced this pull request Feb 1, 2017
…ined.

Defers to pre-defined version if found (e.g. protobuf). For protobuf case, the definitions are identical and thus include order should not affect results.

Github-Pull: #9366
Rebased-From: 815f414
sickpig referenced this pull request in sickpig/BitcoinUnlimited Feb 28, 2017
…defer

815f414 Uses built-in byte swap if available (Apple) and if bswap_XX is undefined. (Karl-Johan Alm)
gandrewstone referenced this pull request in BitcoinUnlimited/BitcoinUnlimited Mar 1, 2017
Fix macosx build (backport core #9169 and #9366)
fanquake added a commit to fanquake/bitcoin that referenced this pull request Oct 24, 2019
This was originally added in bitcoin#9366 to fix the gui build, as
Protobuf would also define these macros. Now that we're no-longer
using Protobuf, remove the additional check.
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Oct 28, 2019
This was originally added in bitcoin#9366 to fix the gui build, as
Protobuf would also define these macros. Now that we're no-longer
using Protobuf, remove the additional check.
str4d pushed a commit to str4d/zcash that referenced this pull request Jul 30, 2020
-BEGIN VERIFY SCRIPT-
sed -i 's/__APPLE__/MAC_OSX/g' src/compat/byteswap.h src/util.cpp
-END VERIFY SCRIPT-

Zcash: Excludes byteswap.h change as we don't have bitcoin/bitcoin#9366.
sidhujag pushed a commit to syscoin-core/syscoin that referenced this pull request Nov 10, 2020
This was originally added in bitcoin#9366 to fix the gui build, as
Protobuf would also define these macros. Now that we're no-longer
using Protobuf, remove the additional check.
fanquake added a commit to fanquake/bitcoin that referenced this pull request Mar 29, 2021
These were added as part of bitcoin#9366 to fix issues with Protobuf.

Now that we no-longer use Protobuf, there's no reason to maintain a
duplicate set of byteswap tests for qt.
maflcko pushed a commit to maflcko/bitcoin-core that referenced this pull request Mar 29, 2021
9ac86bc test: remove qt byteswap compattests (fanquake)

Pull request description:

  These were added as part of bitcoin#9366 when with fixing issues with Protobuf.

  Now that we no-longer use Protobuf, there's no reason to maintain a duplicate set of byteswap tests in the qt tests. Our other set of byteswap tests are here: https://github.com/bitcoin/bitcoin/blob/master/src/test/bswap_tests.cpp.

ACKs for top commit:
  laanwj:
    Code review ACK 9ac86bc

Tree-SHA512: 72ba131a5f8fbd9fdbbc4e1f95baa794496c960b12e0271700c632c6511b7e1b331e8db07a201838b4d56b2aeeb43d4de4e10265ea07ab14241307fa14d3342e
Fuzzbawls pushed a commit to Fuzzbawls/PIVX that referenced this pull request Apr 17, 2021
This was originally added in bitcoin#9366 to fix the gui build, as
Protobuf would also define these macros. Now that we're no-longer
using Protobuf, remove the additional check.
@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.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants