diff --git a/.gitignore b/.gitignore index 737b076b7a..43f8eb1d72 100644 --- a/.gitignore +++ b/.gitignore @@ -58,7 +58,7 @@ libconftest.dylib* .dirstamp .libs .*.swp -*.*~* +*~ *.bak *.rej *.orig diff --git a/build-aux/m4/ax_boost_base.m4 b/build-aux/m4/ax_boost_base.m4 index 2ae33f7140..7aac53c815 100644 --- a/build-aux/m4/ax_boost_base.m4 +++ b/build-aux/m4/ax_boost_base.m4 @@ -11,7 +11,7 @@ # Test for the Boost C++ libraries of a particular version (or newer) # # If no path to the installed boost library is given the macro searchs -# under /usr, /usr/local, /opt and /opt/local and evaluates the +# under /usr, /usr/local, /opt, /opt/local and /opt/homebrew and evaluates the # $BOOST_ROOT environment variable. Further documentation is available at # . # @@ -151,7 +151,7 @@ AC_DEFUN([_AX_BOOST_BASE_RUNDETECT],[ else search_libsubdirs="$multiarch_libsubdir $libsubdirs" fi - for _AX_BOOST_BASE_boost_path_tmp in /usr /usr/local /opt /opt/local ; do + for _AX_BOOST_BASE_boost_path_tmp in /usr /usr/local /opt /opt/local /opt/homebrew/; do if test -d "$_AX_BOOST_BASE_boost_path_tmp/include/boost" && test -r "$_AX_BOOST_BASE_boost_path_tmp/include/boost" ; then for libsubdir in $search_libsubdirs ; do if ls "$_AX_BOOST_BASE_boost_path_tmp/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi @@ -227,7 +227,7 @@ AC_DEFUN([_AX_BOOST_BASE_RUNDETECT],[ fi else if test "x$cross_compiling" != "xyes" ; then - for _AX_BOOST_BASE_boost_path in /usr /usr/local /opt /opt/local ; do + for _AX_BOOST_BASE_boost_path in /usr /usr/local /opt /opt/local /opt/homebrew ; do if test -d "$_AX_BOOST_BASE_boost_path" && test -r "$_AX_BOOST_BASE_boost_path" ; then for i in `ls -d $_AX_BOOST_BASE_boost_path/include/boost-* 2>/dev/null`; do _version_tmp=`echo $i | sed "s#$_AX_BOOST_BASE_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'` diff --git a/depends/hosts/linux.mk b/depends/hosts/linux.mk index 602206d634..99434c90d5 100644 --- a/depends/hosts/linux.mk +++ b/depends/hosts/linux.mk @@ -7,7 +7,7 @@ linux_release_CXXFLAGS=$(linux_release_CFLAGS) linux_debug_CFLAGS=-O1 linux_debug_CXXFLAGS=$(linux_debug_CFLAGS) -linux_debug_CPPFLAGS=-D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC +linux_debug_CPPFLAGS=-D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_LIBCPP_DEBUG=1 ifeq (86,$(findstring 86,$(build_arch))) i686_linux_CC=gcc -m32 diff --git a/src/httpserver.cpp b/src/httpserver.cpp index 7119a67142..0c56d43070 100644 --- a/src/httpserver.cpp +++ b/src/httpserver.cpp @@ -74,12 +74,11 @@ template class WorkQueue { private: - /** Mutex protects entire object */ Mutex cs; - std::condition_variable cond; - std::deque> queue; - bool running; - size_t maxDepth; + std::condition_variable cond GUARDED_BY(cs); + std::deque> queue GUARDED_BY(cs); + bool running GUARDED_BY(cs); + const size_t maxDepth; public: explicit WorkQueue(size_t _maxDepth) : running(true), @@ -95,7 +94,7 @@ public: bool Enqueue(WorkItem* item) { LOCK(cs); - if (queue.size() >= maxDepth) { + if (!running || queue.size() >= maxDepth) { return false; } queue.emplace_back(std::unique_ptr(item)); @@ -111,7 +110,7 @@ public: WAIT_LOCK(cs, lock); while (running && queue.empty()) cond.wait(lock); - if (!running) + if (!running && queue.empty()) break; i = std::move(queue.front()); queue.pop_front(); @@ -469,8 +468,6 @@ void StopHTTPServer() thread.join(); } g_thread_http_workers.clear(); - delete workQueue; - workQueue = nullptr; } // Unlisten sockets, these are what make the event loop running, which means // that after this and all connections are closed the event loop will quit. @@ -490,6 +487,10 @@ void StopHTTPServer() event_base_free(eventBase); eventBase = nullptr; } + if (workQueue) { + delete workQueue; + workQueue = nullptr; + } LogPrint(BCLog::HTTP, "Stopped HTTP server\n"); } diff --git a/src/netaddress.cpp b/src/netaddress.cpp index 2a42147cc8..8c4ff4a2af 100644 --- a/src/netaddress.cpp +++ b/src/netaddress.cpp @@ -501,6 +501,11 @@ enum Network CNetAddr::GetNetwork() const return m_net; } +static std::string IPv4ToString(Span a) +{ + return strprintf("%u.%u.%u.%u", a[0], a[1], a[2], a[3]); +} + static std::string IPv6ToString(Span a) { assert(a.size() == ADDR_IPV6_SIZE); @@ -521,6 +526,7 @@ std::string CNetAddr::ToStringIP(bool fUseGetnameinfo) const { switch (m_net) { case NET_IPV4: + return IPv4ToString(m_addr); case NET_IPV6: { if (fUseGetnameinfo) { CService serv(*this, 0); @@ -533,9 +539,6 @@ std::string CNetAddr::ToStringIP(bool fUseGetnameinfo) const return std::string(name); } } - if (m_net == NET_IPV4) { - return strprintf("%u.%u.%u.%u", m_addr[0], m_addr[1], m_addr[2], m_addr[3]); - } return IPv6ToString(m_addr); } case NET_ONION: diff --git a/src/qt/android/.gitignore b/src/qt/android/.gitignore new file mode 100644 index 0000000000..74cf42f934 --- /dev/null +++ b/src/qt/android/.gitignore @@ -0,0 +1,9 @@ +/.gradle +/build +/gradle/wrapper +/gradlew* +/libs +/res/layout +/res/values* +/src/org/kde +/src/org/qtproject diff --git a/src/streams.h b/src/streams.h index 1dc30901ce..866cdef762 100644 --- a/src/streams.h +++ b/src/streams.h @@ -174,7 +174,7 @@ public: } template - VectorReader& operator>>(T& obj) + VectorReader& operator>>(T&& obj) { // Unserialize from this stream ::Unserialize(*this, obj); diff --git a/src/test/streams_tests.cpp b/src/test/streams_tests.cpp index 435fc1905b..34e0c587ed 100644 --- a/src/test/streams_tests.cpp +++ b/src/test/streams_tests.cpp @@ -114,6 +114,17 @@ BOOST_AUTO_TEST_CASE(streams_vector_reader) BOOST_CHECK_THROW(reader >> d, std::ios_base::failure); } +BOOST_AUTO_TEST_CASE(streams_vector_reader_rvalue) +{ + std::vector data{0x82, 0xa7, 0x31}; + VectorReader reader(SER_NETWORK, INIT_PROTO_VERSION, data, /* pos= */ 0); + uint32_t varint = 0; + // Deserialize into r-value + reader >> VARINT(varint); + BOOST_CHECK_EQUAL(varint, 54321); + BOOST_CHECK(reader.empty()); +} + BOOST_AUTO_TEST_CASE(bitstream_reader_writer) { CDataStream data(SER_NETWORK, INIT_PROTO_VERSION); diff --git a/src/util/strencodings.cpp b/src/util/strencodings.cpp index 47456440ed..f3339934b8 100644 --- a/src/util/strencodings.cpp +++ b/src/util/strencodings.cpp @@ -606,14 +606,15 @@ bool ParseHDKeypath(const std::string& keypath_str, std::vector& keypa std::string HexStr(const Span s) { - std::string rv; + std::string rv(s.size() * 2, '\0'); static constexpr char hexmap[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; - rv.reserve(s.size() * 2); - for (uint8_t v: s) { - rv.push_back(hexmap[v >> 4]); - rv.push_back(hexmap[v & 15]); + auto it = rv.begin(); + for (uint8_t v : s) { + *it++ = hexmap[v >> 4]; + *it++ = hexmap[v & 15]; } + assert(it == rv.end()); return rv; } diff --git a/test/functional/test_framework/netutil.py b/test/functional/test_framework/netutil.py index 195ec1c5e8..0bac633008 100644 --- a/test/functional/test_framework/netutil.py +++ b/test/functional/test_framework/netutil.py @@ -151,7 +151,7 @@ def test_ipv6_local(): have_ipv6 = True try: s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) - s.connect(('::1', 0)) + s.connect(('::1', 1)) except socket.error: have_ipv6 = False return have_ipv6