- Document FreeBSD quirk.
- Fix FreeBSD build: Cast to
intto allowstd::minto work under FreeBSD.
Context: #9598 (comment)
int to allow std::min to work under FreeBSD.Context: #9598 (comment)
So this was originally applied in #2695:
When compiling on FreeBSD, the calculation here returns an unsigned int. This causes a compile-time error with std::min, which cannot compare signed with unsigned integers. This pull inserts an explicit cast, treating the calculated value as signed, keeping the compiler happy.
Then reverted in #9598 to:
Improve readability by removing redundant casts to same type (on all platforms)
Now we're re-adding (int) again but only for FreeBSD.
I've just built master (3f398d7) successfully on a FreeBSD 11.1 VM, so I'm curious to know which version of FreeBSD this is broken on?
Regardless of the above, the current patch doesn't compile:
fvisibility=hidden -c -o libbitcoin_server_a-init.o `test -f 'init.cpp' || echo './'`init.cpp
init.cpp:969:2: error: invalid preprocessing directive #fi
#fi
^~
init.cpp:964:0: error: unterminated #else
#if defined(__FreeBSD__) || defined(__DragonFly__)
make[2]: *** [libbitcoin_server_a-init.o] Error 1
Makefile:5817: recipe for target 'libbitcoin_server_a-init.o' failed
960 | @@ -961,7 +961,12 @@ bool AppInitParameterInteraction() 961 | nMaxConnections = std::max(nUserMaxConnections, 0); 962 | 963 | // Trim requested connection counts, to fit into system limitations 964 | +#if defined(__FreeBSD__) || defined(__DragonFly__) 965 | + // See #2695: Explictly cast to int to allow std::min to work under FreeBSD 966 | + nMaxConnections = std::max(std::min(nMaxConnections, (int)(FD_SETSIZE - nBind - MIN_CORE_FILEDESCRIPTORS - MAX_ADDNODE_CONNECTIONS)), 0); 967 | +#else 968 | nMaxConnections = std::max(std::min(nMaxConnections, FD_SETSIZE - nBind - MIN_CORE_FILEDESCRIPTORS - MAX_ADDNODE_CONNECTIONS), 0); 969 | +#fi
This is not bash script :)
@fanquake @ken2812221 Sorry about the bashism :-) Not fixed!
If this is fixed in FreeBSD 11.1 I'm not sure we have a problem to solve :-)
Closing this temporarily while waiting for input from @anton48.
If we can reproduce under FreeBSD 11.1 I'll re-open.
@practicalswift @fanquake the source of the problem is not a version of FreeBSD itself, but version of clang. currently there are two production versions of FreeBSD: 11.1 and 10.4. former contains clang 4, latter clang 3.4. "new" code in init.cpp can be compiled with clang 4, but not with 3.4. @practicalswift your patch with "if defined(FreeBSD)" works for me at 10.3, 10.4 and 11.1.
Agree with @fanquake.
Having different code for each platform makes testing a nightmare. Btw. I believe you can specify the function template you want to call with std::min<type>(a,b)
@fanquake @MarcoFalke Thanks for reviewing. Feedback addressed. Please re-review :-) @anton48 Can you confirm that the updated version works as expected for you?
@practicalswift by updated version you mean nMaxConnections = std::max(std::min<int>(nMaxConnections, FD_SETSIZE - nBind - MIN_CORE_FILEDESCRIPTORS - MAX_ADDNODE_CONNECTIONS), 0);? yes, it can be compiled without errors on FreeBSD (tested on 10 and 11 versions).
@anton48 Yes, that's the new version. Thanks for confirming.
The cast to int was only recently removed in master and I believe it only fails on FreeBSD 10, not 11.
utACK 629a47a1543a6e77cbf9c73917e2e419669b04df
utACK 629a47a1543a6e77cbf9c73917e2e419669b04df
utACK 629a47a for fixing the FreeBSD 10.x build. As noted above, the issue comes from Clang 3.4