diff options
Diffstat (limited to 'binaryurp')
-rw-r--r-- | binaryurp/CppunitTest_binaryurp_test-cache.mk | 2 | ||||
-rw-r--r-- | binaryurp/CppunitTest_binaryurp_test-unmarshal.mk | 2 | ||||
-rw-r--r-- | binaryurp/Library_binaryurp.mk | 4 | ||||
-rw-r--r-- | binaryurp/qa/test-cache.cxx | 20 | ||||
-rw-r--r-- | binaryurp/source/binaryany.cxx | 2 | ||||
-rw-r--r-- | binaryurp/source/binaryurp.component | 2 | ||||
-rw-r--r-- | binaryurp/source/bridge.cxx | 94 | ||||
-rw-r--r-- | binaryurp/source/bridge.hxx | 11 | ||||
-rw-r--r-- | binaryurp/source/bridgefactory.cxx | 17 | ||||
-rw-r--r-- | binaryurp/source/incomingreply.hxx | 9 | ||||
-rw-r--r-- | binaryurp/source/incomingrequest.cxx | 21 | ||||
-rw-r--r-- | binaryurp/source/incomingrequest.hxx | 18 | ||||
-rw-r--r-- | binaryurp/source/outgoingrequest.hxx | 9 | ||||
-rw-r--r-- | binaryurp/source/outgoingrequests.cxx | 7 | ||||
-rw-r--r-- | binaryurp/source/outgoingrequests.hxx | 5 | ||||
-rw-r--r-- | binaryurp/source/proxy.cxx | 9 | ||||
-rw-r--r-- | binaryurp/source/proxy.hxx | 4 | ||||
-rw-r--r-- | binaryurp/source/reader.cxx | 11 | ||||
-rw-r--r-- | binaryurp/source/unmarshal.cxx | 5 | ||||
-rw-r--r-- | binaryurp/source/unmarshal.hxx | 2 | ||||
-rw-r--r-- | binaryurp/source/writer.cxx | 49 | ||||
-rw-r--r-- | binaryurp/source/writer.hxx | 46 |
22 files changed, 173 insertions, 176 deletions
diff --git a/binaryurp/CppunitTest_binaryurp_test-cache.mk b/binaryurp/CppunitTest_binaryurp_test-cache.mk index 97f5b78f081d..50f3d1b4c02d 100644 --- a/binaryurp/CppunitTest_binaryurp_test-cache.mk +++ b/binaryurp/CppunitTest_binaryurp_test-cache.mk @@ -9,8 +9,6 @@ $(eval $(call gb_CppunitTest_CppunitTest,binaryurp_test-cache)) -$(eval $(call gb_CppunitTest_use_external,binaryurp_test-cache,boost_headers)) - $(eval $(call gb_CppunitTest_use_libraries,binaryurp_test-cache,\ sal \ )) diff --git a/binaryurp/CppunitTest_binaryurp_test-unmarshal.mk b/binaryurp/CppunitTest_binaryurp_test-unmarshal.mk index 11c70f5b9db0..03823614e99e 100644 --- a/binaryurp/CppunitTest_binaryurp_test-unmarshal.mk +++ b/binaryurp/CppunitTest_binaryurp_test-unmarshal.mk @@ -9,8 +9,6 @@ $(eval $(call gb_CppunitTest_CppunitTest,binaryurp_test-unmarshal)) -$(eval $(call gb_CppunitTest_use_external,binaryurp_test-unmarshal,boost_headers)) - $(eval $(call gb_CppunitTest_use_libraries,binaryurp_test-unmarshal,\ cppu \ cppuhelper \ diff --git a/binaryurp/Library_binaryurp.mk b/binaryurp/Library_binaryurp.mk index 51efc35a5375..74205c9e66a2 100644 --- a/binaryurp/Library_binaryurp.mk +++ b/binaryurp/Library_binaryurp.mk @@ -9,12 +9,10 @@ $(eval $(call gb_Library_Library,binaryurp)) -$(eval $(call gb_Library_set_componentfile,binaryurp,binaryurp/source/binaryurp)) +$(eval $(call gb_Library_set_componentfile,binaryurp,binaryurp/source/binaryurp,ure/services)) $(eval $(call gb_Library_use_udk_api,binaryurp)) -$(eval $(call gb_Library_use_external,binaryurp,boost_headers)) - $(eval $(call gb_Library_use_libraries,binaryurp,\ cppu \ cppuhelper \ diff --git a/binaryurp/qa/test-cache.cxx b/binaryurp/qa/test-cache.cxx index 989b103e2e90..c4696f78395f 100644 --- a/binaryurp/qa/test-cache.cxx +++ b/binaryurp/qa/test-cache.cxx @@ -17,6 +17,10 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <sal/config.h> + +#include <cstddef> + #include <sal/types.h> #include <cppunit/TestAssert.h> #include <cppunit/TestFixture.h> @@ -39,13 +43,13 @@ private: // cf. jurt/test/com/sun/star/lib/uno/protocols/urp/Cache_Test.java: void Test::testNothingLostFromLruList() { int a[8]; - for (int i = 0; i != int(SAL_N_ELEMENTS(a)); ++i) { - for (int j = 0; j != i; ++j) { + for (std::size_t i = 0; i != std::size(a); ++i) { + for (std::size_t j = 0; j != i; ++j) { a[j] = 0; } for (;;) { binaryurp::Cache< int > c(4); - for (int k = 0; k != i; ++k) { + for (std::size_t k = 0; k != i; ++k) { bool f; c.add(a[k], &f); } @@ -53,15 +57,15 @@ void Test::testNothingLostFromLruList() { CPPUNIT_ASSERT_EQUAL( 6, c.add(-1, &f) + c.add(-2, &f) + c.add(-3, &f) + c.add(-4, &f)); - int j = i - 1; - while (j >= 0 && a[j] == 3) { + std::size_t j = i; + while (j != 0 && a[j - 1] == 3) { --j; } - if (j < 0) { + if (j == 0) { break; } - ++a[j]; - for (int k = j + 1; k != i; ++k) { + ++a[j - 1]; + for (std::size_t k = j; k != i; ++k) { a[k] = 0; } } diff --git a/binaryurp/source/binaryany.cxx b/binaryurp/source/binaryany.cxx index 17db2f3775ef..7f6e14a6fb35 100644 --- a/binaryurp/source/binaryany.cxx +++ b/binaryurp/source/binaryany.cxx @@ -32,7 +32,7 @@ namespace binaryurp { namespace { -// Cf. com::sun::star::uno::detail::moveAnyInternals in +// Cf. com::sun::star::uno::Any move ctor in // include/com/sun/star/uno/Any.hxx: void moveInternals(uno_Any & from, uno_Any & to) { uno_any_construct(&to, nullptr, nullptr, nullptr); diff --git a/binaryurp/source/binaryurp.component b/binaryurp/source/binaryurp.component index e2581c76411e..b5b0f4da102f 100644 --- a/binaryurp/source/binaryurp.component +++ b/binaryurp/source/binaryurp.component @@ -20,7 +20,7 @@ <component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@" xmlns="http://openoffice.org/2010/uno-components"> <implementation name="com.sun.star.comp.bridge.BridgeFactory" - constructor="com_sun_star_comp_bridge_BridgeFactory_get_implementation"> + constructor="com_sun_star_comp_bridge_BridgeFactory_get_implementation" single-instance="true"> <service name="com.sun.star.bridge.BridgeFactory"/> </implementation> </component> diff --git a/binaryurp/source/bridge.cxx b/binaryurp/source/bridge.cxx index 007e7e9440df..068649cc3b4b 100644 --- a/binaryurp/source/bridge.cxx +++ b/binaryurp/source/bridge.cxx @@ -24,6 +24,7 @@ #include <cstddef> #include <limits> #include <memory> +#include <utility> #include <vector> #include <com/sun/star/bridge/InvalidProtocolChangeException.hpp> @@ -74,7 +75,7 @@ namespace { sal_Int32 random() { sal_Int32 n; rtlRandomPool pool = rtl_random_createPool(); - rtl_random_getBytes(pool, &n, sizeof n); + (void)rtl_random_getBytes(pool, &n, sizeof n); rtl_random_destroyPool(pool); return n; } @@ -129,7 +130,7 @@ AttachThread::~AttachThread() { class PopOutgoingRequest { public: PopOutgoingRequest( - OutgoingRequests & requests, rtl::ByteSequence const & tid, + OutgoingRequests & requests, rtl::ByteSequence tid, OutgoingRequest const & request); ~PopOutgoingRequest(); @@ -146,9 +147,9 @@ private: }; PopOutgoingRequest::PopOutgoingRequest( - OutgoingRequests & requests, rtl::ByteSequence const & tid, + OutgoingRequests & requests, rtl::ByteSequence tid, OutgoingRequest const & request): - requests_(requests), tid_(tid), cleared_(false) + requests_(requests), tid_(std::move(tid)), cleared_(false) { requests_.push(tid_, request); } @@ -172,11 +173,11 @@ struct Bridge::SubStub { }; Bridge::Bridge( - rtl::Reference< BridgeFactory > const & factory, OUString const & name, + rtl::Reference< BridgeFactory > const & factory, OUString name, css::uno::Reference< css::connection::XConnection > const & connection, - css::uno::Reference< css::bridge::XInstanceProvider > const & provider): - factory_(factory), name_(name), connection_(connection), - provider_(provider), + css::uno::Reference< css::bridge::XInstanceProvider > provider): + factory_(factory), name_(std::move(name)), connection_(connection), + provider_(std::move(provider)), binaryUno_(UNO_LB_UNO), cppToBinaryMapping_(CPPU_CURRENT_LANGUAGE_BINDING_NAME, UNO_LB_UNO), binaryToCppMapping_(UNO_LB_UNO, CPPU_CURRENT_LANGUAGE_BINDING_NAME), @@ -201,13 +202,14 @@ Bridge::Bridge( throw css::uno::RuntimeException("URP: no C++ UNO mapping"); } passive_.set(); + // coverity[uninit_member] - random_ is set in due course by the reader_ thread's state machine } void Bridge::start() { rtl::Reference r(new Reader(this)); rtl::Reference w(new Writer(this)); { - osl::MutexGuard g(mutex_); + std::lock_guard g(mutex_); assert( state_ == STATE_INITIAL && threadPool_ == nullptr && !writer_.is() && !reader_.is()); @@ -237,7 +239,7 @@ void Bridge::terminate(bool final) { bool joinW; Listeners ls; { - osl::ClearableMutexGuard g(mutex_); + std::unique_lock g(mutex_); switch (state_) { case STATE_INITIAL: // via ~Bridge -> dispose -> terminate case STATE_FINAL: @@ -246,10 +248,10 @@ void Bridge::terminate(bool final) { break; case STATE_TERMINATED: if (final) { - g.clear(); + g.unlock(); terminated_.wait(); { - osl::MutexGuard g2(mutex_); + std::lock_guard g2(mutex_); tp = threadPool_; threadPool_ = nullptr; if (reader_.is()) { @@ -309,7 +311,7 @@ void Bridge::terminate(bool final) { uno_threadpool_dispose(tp); Stubs s; { - osl::MutexGuard g(mutex_); + std::lock_guard g(mutex_); s.swap(stubs_); } for (auto & stub : s) @@ -330,7 +332,7 @@ void Bridge::terminate(bool final) { try { listener->disposing( css::lang::EventObject( - static_cast< cppu::OWeakObject * >(this))); + getXWeak())); } catch (const css::uno::RuntimeException & e) { SAL_WARN("binaryurp", "caught " << e); } @@ -340,7 +342,7 @@ void Bridge::terminate(bool final) { uno_threadpool_destroy(tp); } { - osl::MutexGuard g(mutex_); + std::lock_guard g(mutex_); if (final) { threadPool_ = nullptr; } @@ -361,14 +363,14 @@ BinaryAny Bridge::mapCppToBinaryAny(css::uno::Any const & cppAny) { } uno_ThreadPool Bridge::getThreadPool() { - osl::MutexGuard g(mutex_); + std::lock_guard g(mutex_); checkDisposed(); assert(threadPool_ != nullptr); return threadPool_; } rtl::Reference< Writer > Bridge::getWriter() { - osl::MutexGuard g(mutex_); + std::lock_guard g(mutex_); checkDisposed(); assert(writer_.is()); return writer_; @@ -392,7 +394,7 @@ css::uno::UnoInterfaceReference Bridge::registerIncomingInterface( } else { obj.set(new Proxy(this, oid, type), SAL_NO_ACQUIRE); { - osl::MutexGuard g(mutex_); + std::lock_guard g(mutex_); assert(proxies_ < std::numeric_limits< std::size_t >::max()); ++proxies_; } @@ -419,7 +421,7 @@ OUString Bridge::registerOutgoingInterface( if (!Proxy::isProxy(this, object, &oid)) { binaryUno_.get()->pExtEnv->getObjectIdentifier( binaryUno_.get()->pExtEnv, &oid.pData, object.get()); - osl::MutexGuard g(mutex_); + std::lock_guard g(mutex_); Stubs::iterator i(stubs_.find(oid)); Stub newStub; Stub * stub = i == stubs_.end() ? &newStub : &i->second; @@ -458,7 +460,7 @@ css::uno::UnoInterfaceReference Bridge::findStub( OUString const & oid, css::uno::TypeDescription const & type) { assert(!oid.isEmpty() && type.is()); - osl::MutexGuard g(mutex_); + std::lock_guard g(mutex_); Stubs::iterator i(stubs_.find(oid)); if (i != stubs_.end()) { Stub::iterator j(i->second.find(type)); @@ -484,7 +486,7 @@ void Bridge::releaseStub( css::uno::UnoInterfaceReference obj; bool unused; { - osl::MutexGuard g(mutex_); + std::lock_guard g(mutex_); Stubs::iterator i(stubs_.find(oid)); if (i == stubs_.end()) { throw css::uno::RuntimeException("URP: release unknown stub"); @@ -538,7 +540,7 @@ void Bridge::freeProxy(Proxy & proxy) { } bool unused; { - osl::MutexGuard g(mutex_); + std::lock_guard g(mutex_); assert(proxies_ > 0); --proxies_; unused = becameUnused(); @@ -547,7 +549,7 @@ void Bridge::freeProxy(Proxy & proxy) { } void Bridge::incrementCalls(bool normalCall) noexcept { - osl::MutexGuard g(mutex_); + std::lock_guard g(mutex_); assert(calls_ < std::numeric_limits< std::size_t >::max()); ++calls_; normalCall_ |= normalCall; @@ -556,7 +558,7 @@ void Bridge::incrementCalls(bool normalCall) noexcept { void Bridge::decrementCalls() { bool unused; { - osl::MutexGuard g(mutex_); + std::lock_guard g(mutex_); assert(calls_ > 0); --calls_; unused = becameUnused(); @@ -565,7 +567,7 @@ void Bridge::decrementCalls() { } void Bridge::incrementActiveCalls() noexcept { - osl::MutexGuard g(mutex_); + std::lock_guard g(mutex_); assert( activeCalls_ <= calls_ && activeCalls_ < std::numeric_limits< std::size_t >::max()); @@ -574,7 +576,7 @@ void Bridge::incrementActiveCalls() noexcept { } void Bridge::decrementActiveCalls() noexcept { - osl::MutexGuard g(mutex_); + std::lock_guard g(mutex_); assert(activeCalls_ <= calls_ && activeCalls_ > 0); --activeCalls_; if (activeCalls_ == 0) { @@ -584,7 +586,7 @@ void Bridge::decrementActiveCalls() noexcept { bool Bridge::makeCall( OUString const & oid, css::uno::TypeDescription const & member, - bool setter, std::vector< BinaryAny > const & inArguments, + bool setter, std::vector< BinaryAny >&& inArguments, BinaryAny * returnValue, std::vector< BinaryAny > * outArguments) { std::unique_ptr< IncomingReply > resp; @@ -596,7 +598,7 @@ bool Bridge::makeCall( OutgoingRequest(OutgoingRequest::KIND_NORMAL, member, setter)); sendRequest( att.getTid(), oid, css::uno::TypeDescription(), member, - inArguments); + std::move(inArguments)); pop.clear(); incrementCalls(true); incrementActiveCalls(); @@ -610,7 +612,7 @@ bool Bridge::makeCall( { throw css::lang::DisposedException( "Binary URP bridge disposed during call", - static_cast< cppu::OWeakObject * >(this)); + getXWeak()); } *returnValue = resp->returnValue; if (!resp->exception) { @@ -673,7 +675,7 @@ void Bridge::handleRequestChangeReply( if (n != exp) { throw css::uno::RuntimeException( "URP: requestChange reply with unexpected return value received", - static_cast< cppu::OWeakObject * >(this)); + getXWeak()); } decrementCalls(); switch (exp) { @@ -756,7 +758,7 @@ void Bridge::handleRequestChangeRequest( default: throw css::uno::RuntimeException( "URP: unexpected requestChange request received", - static_cast< cppu::OWeakObject * >(this)); + getXWeak()); } } @@ -770,7 +772,7 @@ void Bridge::handleCommitChangeRequest( css::uno::Sequence< css::bridge::ProtocolProperty > s; [[maybe_unused]] bool ok = (mapBinaryToCppAny(inArguments[0]) >>= s); assert(ok); - for (const auto & pp : std::as_const(s)) { + for (const auto & pp : s) { if (pp.Name == "CurrentContext") { bCcMode = true; } else { @@ -807,7 +809,7 @@ void Bridge::handleCommitChangeRequest( default: throw css::uno::RuntimeException( "URP: unexpected commitChange request received", - static_cast< cppu::OWeakObject * >(this)); + getXWeak()); } } @@ -824,19 +826,19 @@ bool Bridge::isProtocolPropertiesRequest( } void Bridge::setCurrentContextMode() { - osl::MutexGuard g(mutex_); + std::lock_guard g(mutex_); currentContextMode_ = true; } bool Bridge::isCurrentContextMode() { - osl::MutexGuard g(mutex_); + std::lock_guard g(mutex_); return currentContextMode_; } Bridge::~Bridge() { #if OSL_DEBUG_LEVEL > 0 { - osl::MutexGuard g(mutex_); + std::lock_guard g(mutex_); SAL_WARN_IF( state_ == STATE_STARTED || state_ == STATE_TERMINATED, "binaryurp", "undisposed bridge \"" << name_ <<"\" in state " << state_ @@ -852,7 +854,7 @@ css::uno::Reference< css::uno::XInterface > Bridge::getInstance( if (sInstanceName.isEmpty()) { throw css::uno::RuntimeException( "XBridge::getInstance sInstanceName must be non-empty", - static_cast< cppu::OWeakObject * >(this)); + getXWeak()); } for (sal_Int32 i = 0; i != sInstanceName.getLength(); ++i) { if (sInstanceName[i] > 0x7F) { @@ -873,7 +875,7 @@ css::uno::Reference< css::uno::XInterface > Bridge::getInstance( sInstanceName, css::uno::TypeDescription( "com.sun.star.uno.XInterface::queryInterface"), - false, inArgs, &ret, &outArgs); + false, std::move(inArgs), &ret, &outArgs); throwException(bExc, ret); auto const t = ret.getType(); if (t.get()->eTypeClass == typelib_TypeClass_VOID) { @@ -925,7 +927,7 @@ void Bridge::addEventListener( { assert(xListener.is()); { - osl::MutexGuard g(mutex_); + std::lock_guard g(mutex_); assert(state_ != STATE_INITIAL); if (state_ == STATE_STARTED) { listeners_.push_back(xListener); @@ -933,13 +935,13 @@ void Bridge::addEventListener( } } xListener->disposing( - css::lang::EventObject(static_cast< cppu::OWeakObject * >(this))); + css::lang::EventObject(getXWeak())); } void Bridge::removeEventListener( css::uno::Reference< css::lang::XEventListener > const & aListener) { - osl::MutexGuard g(mutex_); + std::lock_guard g(mutex_); Listeners::iterator i( std::find(listeners_.begin(), listeners_.end(), aListener)); if (i != listeners_.end()) { @@ -950,7 +952,7 @@ void Bridge::removeEventListener( void Bridge::sendCommitChangeRequest() { assert(mode_ == MODE_REQUESTED || mode_ == MODE_REPLY_1); css::uno::Sequence< css::bridge::ProtocolProperty > s(1); - s[0].Name = "CurrentContext"; + s.getArray()[0].Name = "CurrentContext"; std::vector< BinaryAny > a { mapCppToBinaryAny(css::uno::Any(s)) }; sendProtPropRequest(OutgoingRequest::KIND_COMMIT_CHANGE, a); } @@ -991,7 +993,7 @@ void Bridge::makeReleaseCall( // its own: static auto const tid = [] { static sal_Int8 const id[] = {'r', 'e', 'l', 'e', 'a', 's', 'e', 'h', 'a', 'c', 'k'}; - return rtl::ByteSequence(id, SAL_N_ELEMENTS(id)); + return rtl::ByteSequence(id, std::size(id)); }(); sendRequest( tid, oid, type, @@ -1003,9 +1005,9 @@ void Bridge::sendRequest( rtl::ByteSequence const & tid, OUString const & oid, css::uno::TypeDescription const & type, css::uno::TypeDescription const & member, - std::vector< BinaryAny > const & inArguments) + std::vector< BinaryAny >&& inArguments) { - getWriter()->queueRequest(tid, oid, type, member, inArguments); + getWriter()->queueRequest(tid, oid, type, member, std::move(inArguments)); } void Bridge::throwException(bool exception, BinaryAny const & value) { @@ -1043,7 +1045,7 @@ void Bridge::checkDisposed() { if (state_ != STATE_STARTED) { throw css::lang::DisposedException( "Binary URP bridge already disposed", - static_cast< cppu::OWeakObject * >(this)); + getXWeak()); } } diff --git a/binaryurp/source/bridge.hxx b/binaryurp/source/bridge.hxx index e0d5ce39b671..9da6640fa126 100644 --- a/binaryurp/source/bridge.hxx +++ b/binaryurp/source/bridge.hxx @@ -23,6 +23,7 @@ #include <cstddef> #include <map> +#include <mutex> #include <vector> #include <com/sun/star/bridge/XBridge.hpp> @@ -70,11 +71,11 @@ class Bridge: public: Bridge( rtl::Reference< BridgeFactory > const & factory, - OUString const & name, + OUString name, com::sun::star::uno::Reference< com::sun::star::connection::XConnection > const & connection, com::sun::star::uno::Reference< - com::sun::star::bridge::XInstanceProvider > const & provider); + com::sun::star::bridge::XInstanceProvider > provider); void start(); @@ -132,7 +133,7 @@ public: bool makeCall( OUString const & oid, com::sun::star::uno::TypeDescription const & member, bool setter, - std::vector< BinaryAny > const & inArguments, BinaryAny * returnValue, + std::vector< BinaryAny >&& inArguments, BinaryAny * returnValue, std::vector< BinaryAny > * outArguments); // Only called from reader_ thread: @@ -204,7 +205,7 @@ private: rtl::ByteSequence const & tid, OUString const & oid, com::sun::star::uno::TypeDescription const & type, com::sun::star::uno::TypeDescription const & member, - std::vector< BinaryAny > const & inArguments); + std::vector< BinaryAny >&& inArguments); void throwException(bool exception, BinaryAny const & value); @@ -257,7 +258,7 @@ private: // decrementActiveCalls, without an intervening exception osl::Condition terminated_; - osl::Mutex mutex_; + std::mutex mutex_; State state_; Listeners listeners_; uno_ThreadPool threadPool_; diff --git a/binaryurp/source/bridgefactory.cxx b/binaryurp/source/bridgefactory.cxx index d2fef4383c06..cd43fe592b0e 100644 --- a/binaryurp/source/bridgefactory.cxx +++ b/binaryurp/source/bridgefactory.cxx @@ -49,7 +49,7 @@ void BridgeFactory::removeBridge( osl::MutexGuard g(m_aMutex); if (n.isEmpty()) { - unnamed_.erase(std::remove(unnamed_.begin(), unnamed_.end(), bridge), unnamed_.end()); + std::erase(unnamed_, bridge); } else { @@ -93,17 +93,17 @@ css::uno::Reference< css::bridge::XBridge > BridgeFactory::createBridge( if (rBHelper.bDisposed) { throw css::lang::DisposedException( "BridgeFactory disposed", - static_cast< cppu::OWeakObject * >(this)); + getXWeak()); } if (named_.find(sName) != named_.end()) { throw css::bridge::BridgeExistsException( - sName, static_cast< cppu::OWeakObject * >(this)); + sName, getXWeak()); } if (sProtocol != "urp" || !aConnection.is()) { throw css::lang::IllegalArgumentException( ("BridgeFactory::createBridge: sProtocol != urp ||" " aConnection == null"), - static_cast< cppu::OWeakObject * >(this), -1); + getXWeak(), -1); } b.set(new Bridge(this, sName, aConnection, anInstanceProvider)); if (sName.isEmpty()) { @@ -131,22 +131,23 @@ BridgeFactory::getExistingBridges() { if (unnamed_.size() > SAL_MAX_INT32) { throw css::uno::RuntimeException( "BridgeFactory::getExistingBridges: too many", - static_cast< cppu::OWeakObject * >(this)); + getXWeak()); } sal_Int32 n = static_cast< sal_Int32 >(unnamed_.size()); if (named_.size() > o3tl::make_unsigned(SAL_MAX_INT32 - n)) { throw css::uno::RuntimeException( "BridgeFactory::getExistingBridges: too many", - static_cast< cppu::OWeakObject * >(this)); + getXWeak()); } n = static_cast< sal_Int32 >(n + named_.size()); css::uno::Sequence< css::uno::Reference< css::bridge::XBridge > > s(n); + auto r = asNonConstRange(s); sal_Int32 i = 0; for (auto const& item : unnamed_) - s[i++] = item; + r[i++] = item; for (auto const& item : named_) - s[i++] = item.second; + r[i++] = item.second; return s; } diff --git a/binaryurp/source/incomingreply.hxx b/binaryurp/source/incomingreply.hxx index b1ff6cb4d2eb..c2f5353fff4c 100644 --- a/binaryurp/source/incomingreply.hxx +++ b/binaryurp/source/incomingreply.hxx @@ -21,6 +21,7 @@ #include <sal/config.h> +#include <utility> #include <vector> #include "binaryany.hxx" @@ -33,10 +34,10 @@ private: IncomingReply& operator=(const IncomingReply&) = delete; public: IncomingReply( - bool theException, BinaryAny const & theReturnValue, - std::vector< BinaryAny > const & theOutArguments): - exception(theException), returnValue(theReturnValue), - outArguments(theOutArguments) + bool theException, BinaryAny theReturnValue, + std::vector< BinaryAny >&& theOutArguments): + exception(theException), returnValue(std::move(theReturnValue)), + outArguments(std::move(theOutArguments)) {} bool exception; diff --git a/binaryurp/source/incomingrequest.cxx b/binaryurp/source/incomingrequest.cxx index eed6f7cb8466..6f4107693b73 100644 --- a/binaryurp/source/incomingrequest.cxx +++ b/binaryurp/source/incomingrequest.cxx @@ -20,6 +20,7 @@ #include <sal/config.h> #include <cassert> +#include <utility> #include <vector> #include <com/sun/star/bridge/XInstanceProvider.hpp> @@ -43,16 +44,16 @@ namespace binaryurp { IncomingRequest::IncomingRequest( - rtl::Reference< Bridge > const & bridge, rtl::ByteSequence const & tid, - OUString const & oid, css::uno::UnoInterfaceReference const & object, - css::uno::TypeDescription const & type, sal_uInt16 functionId, + rtl::Reference< Bridge > const & bridge, rtl::ByteSequence tid, + OUString oid, css::uno::UnoInterfaceReference object, + css::uno::TypeDescription type, sal_uInt16 functionId, bool synchronous, css::uno::TypeDescription const & member, bool setter, - std::vector< BinaryAny > const & inArguments, bool currentContextMode, - css::uno::UnoInterfaceReference const & currentContext): - bridge_(bridge), tid_(tid), oid_(oid), object_(object), type_(type), - functionId_(functionId), synchronous_(synchronous), member_(member), - setter_(setter), inArguments_(inArguments), - currentContextMode_(currentContextMode), currentContext_(currentContext) + std::vector< BinaryAny >&& inArguments, bool currentContextMode, + css::uno::UnoInterfaceReference currentContext): + bridge_(bridge), tid_(std::move(tid)), oid_(std::move(oid)), object_(std::move(object)), type_(std::move(type)), + member_(member), currentContext_(std::move(currentContext)), + inArguments_(std::move(inArguments)), functionId_(functionId), + synchronous_(synchronous), setter_(setter), currentContextMode_(currentContextMode) { assert(bridge.is()); assert(member.is()); @@ -98,7 +99,7 @@ void IncomingRequest::execute() const { bridge_->decrementActiveCalls(); try { bridge_->getWriter()->queueReply( - tid_, member_, setter_, isExc, ret, outArgs, false); + tid_, member_, setter_, isExc, ret, std::move(outArgs), false); return; } catch (const css::uno::RuntimeException & e) { SAL_INFO("binaryurp", "caught " << e); diff --git a/binaryurp/source/incomingrequest.hxx b/binaryurp/source/incomingrequest.hxx index f85171b15a93..faff4f5a5c0c 100644 --- a/binaryurp/source/incomingrequest.hxx +++ b/binaryurp/source/incomingrequest.hxx @@ -43,14 +43,14 @@ private: IncomingRequest& operator=(const IncomingRequest&) = delete; public: IncomingRequest( - rtl::Reference< Bridge > const & bridge, rtl::ByteSequence const & tid, - OUString const & oid, - com::sun::star::uno::UnoInterfaceReference const & object, - com::sun::star::uno::TypeDescription const & type, + rtl::Reference< Bridge > const & bridge, rtl::ByteSequence tid, + OUString oid, + com::sun::star::uno::UnoInterfaceReference object, + com::sun::star::uno::TypeDescription type, sal_uInt16 functionId, bool synchronous, com::sun::star::uno::TypeDescription const & member, bool setter, - std::vector< BinaryAny > const & inArguments, bool currentContextMode, - com::sun::star::uno::UnoInterfaceReference const & currentContext); + std::vector< BinaryAny >&& inArguments, bool currentContextMode, + com::sun::star::uno::UnoInterfaceReference currentContext); ~IncomingRequest(); @@ -65,13 +65,13 @@ private: OUString oid_; // initial object queryInterface; release com::sun::star::uno::UnoInterfaceReference object_; com::sun::star::uno::TypeDescription type_; + com::sun::star::uno::TypeDescription member_; + com::sun::star::uno::UnoInterfaceReference currentContext_; + std::vector< BinaryAny > inArguments_; sal_uInt16 functionId_; bool synchronous_; - com::sun::star::uno::TypeDescription member_; bool setter_; - std::vector< BinaryAny > inArguments_; bool currentContextMode_; - com::sun::star::uno::UnoInterfaceReference currentContext_; }; } diff --git a/binaryurp/source/outgoingrequest.hxx b/binaryurp/source/outgoingrequest.hxx index f5abda34a302..efa673eac781 100644 --- a/binaryurp/source/outgoingrequest.hxx +++ b/binaryurp/source/outgoingrequest.hxx @@ -22,6 +22,7 @@ #include <sal/config.h> #include <typelib/typedescription.hxx> +#include <utility> namespace binaryurp { @@ -29,15 +30,15 @@ struct OutgoingRequest { enum Kind { KIND_NORMAL, KIND_REQUEST_CHANGE, KIND_COMMIT_CHANGE }; OutgoingRequest( - Kind theKind, com::sun::star::uno::TypeDescription const & theMember, + Kind theKind, com::sun::star::uno::TypeDescription theMember, bool theSetter): - kind(theKind), member(theMember), setter(theSetter) + member(std::move(theMember)), kind(theKind), setter(theSetter) {} - Kind kind; - com::sun::star::uno::TypeDescription member; + Kind kind; + bool setter; }; diff --git a/binaryurp/source/outgoingrequests.cxx b/binaryurp/source/outgoingrequests.cxx index 859aa8b9270d..3cdc80e82bb2 100644 --- a/binaryurp/source/outgoingrequests.cxx +++ b/binaryurp/source/outgoingrequests.cxx @@ -23,7 +23,6 @@ #include <com/sun/star/uno/RuntimeException.hpp> #include <rtl/byteseq.hxx> -#include <osl/mutex.hxx> #include "lessoperators.hxx" #include "outgoingrequest.hxx" @@ -38,12 +37,12 @@ OutgoingRequests::~OutgoingRequests() {} void OutgoingRequests::push( rtl::ByteSequence const & tid, OutgoingRequest const & request) { - osl::MutexGuard g(mutex_); + std::scoped_lock g(mutex_); map_[tid].push_back(request); } OutgoingRequest OutgoingRequests::top(rtl::ByteSequence const & tid) { - osl::MutexGuard g(mutex_); + std::scoped_lock g(mutex_); Map::iterator i(map_.find(tid)); if (i == map_.end()) { throw css::uno::RuntimeException( @@ -54,7 +53,7 @@ OutgoingRequest OutgoingRequests::top(rtl::ByteSequence const & tid) { } void OutgoingRequests::pop(rtl::ByteSequence const & tid) noexcept { - osl::MutexGuard g(mutex_); + std::scoped_lock g(mutex_); Map::iterator i(map_.find(tid)); assert(i != map_.end()); i->second.pop_back(); diff --git a/binaryurp/source/outgoingrequests.hxx b/binaryurp/source/outgoingrequests.hxx index 294119693d02..698b6db9e417 100644 --- a/binaryurp/source/outgoingrequests.hxx +++ b/binaryurp/source/outgoingrequests.hxx @@ -22,10 +22,9 @@ #include <sal/config.h> #include <map> +#include <mutex> #include <vector> -#include <osl/mutex.hxx> - namespace binaryurp { struct OutgoingRequest; @@ -56,7 +55,7 @@ private: typedef std::map<rtl::ByteSequence, std::vector<OutgoingRequest>> Map; - osl::Mutex mutex_; + std::mutex mutex_; Map map_; }; } diff --git a/binaryurp/source/proxy.cxx b/binaryurp/source/proxy.cxx index 0e5a92b68f9e..49705e06aa89 100644 --- a/binaryurp/source/proxy.cxx +++ b/binaryurp/source/proxy.cxx @@ -21,6 +21,7 @@ #include <cassert> #include <exception> +#include <utility> #include <vector> #include <cppuhelper/exc_hlp.hxx> @@ -64,9 +65,9 @@ extern "C" void proxy_dispatchInterface( } Proxy::Proxy( - rtl::Reference< Bridge > const & bridge, OUString const & oid, - css::uno::TypeDescription const & type): - bridge_(bridge), oid_(oid), type_(type), references_(1) + rtl::Reference< Bridge > const & bridge, OUString oid, + css::uno::TypeDescription type): + bridge_(bridge), oid_(std::move(oid)), type_(std::move(type)), references_(1) { assert(bridge.is()); acquire = &proxy_acquireInterface; @@ -169,7 +170,7 @@ void Proxy::do_dispatch_throw( oid_, css::uno::TypeDescription( const_cast< typelib_TypeDescription * >(member)), - bSetter, inArgs, &ret, &outArgs)) + bSetter, std::move(inArgs), &ret, &outArgs)) { assert(ret.getType().get()->eTypeClass == typelib_TypeClass_EXCEPTION); uno_any_construct( diff --git a/binaryurp/source/proxy.hxx b/binaryurp/source/proxy.hxx index cf9e1262a8c3..4e1fa3656ecc 100644 --- a/binaryurp/source/proxy.hxx +++ b/binaryurp/source/proxy.hxx @@ -39,8 +39,8 @@ namespace binaryurp { class Proxy: public uno_Interface { public: Proxy( - rtl::Reference< Bridge > const & bridge, OUString const & oid, - com::sun::star::uno::TypeDescription const & type); + rtl::Reference< Bridge > const & bridge, OUString oid, + com::sun::star::uno::TypeDescription type); const OUString& getOid() const { return oid_;} diff --git a/binaryurp/source/reader.cxx b/binaryurp/source/reader.cxx index b11b77ffe658..393d8312e43a 100644 --- a/binaryurp/source/reader.cxx +++ b/binaryurp/source/reader.cxx @@ -35,6 +35,7 @@ #include <com/sun/star/uno/XCurrentContext.hpp> #include <com/sun/star/uno/XInterface.hpp> #include <cppu/unotype.hxx> +#include <o3tl/safeint.hxx> #include <rtl/byteseq.h> #include <rtl/ustring.hxx> #include <sal/log.hxx> @@ -70,11 +71,11 @@ css::uno::Sequence< sal_Int8 > read( if (n == 0 && eofOk) { return css::uno::Sequence< sal_Int8 >(); } - if (n != static_cast< sal_Int32 >(size)) { + if (o3tl::make_unsigned(n) != size) { throw css::io::IOException( "binaryurp::Reader: premature end of input"); } - assert(buf.getLength() == static_cast< sal_Int32 >(size)); + assert(o3tl::make_unsigned(buf.getLength()) == size); return buf; } @@ -330,13 +331,14 @@ void Reader::readMessage(Unmarshal & unmarshal) { std::unique_ptr< IncomingRequest > req( new IncomingRequest( bridge_, tid, oid, obj, type, functionId, synchronous, memberTd, - bSetter, inArgs, ccMode, cc)); + bSetter, std::move(inArgs), ccMode, cc)); if (synchronous) { bridge_->incrementActiveCalls(); } uno_threadpool_putJob( bridge_->getThreadPool(), tid.getHandle(), req.get(), &request, !synchronous); + // coverity[leaked_storage] - "request" destroys req when executed req.release(); } } @@ -441,10 +443,11 @@ void Reader::readReplyMessage(Unmarshal & unmarshal, sal_uInt8 flags1) { case OutgoingRequest::KIND_NORMAL: { std::unique_ptr< IncomingReply > resp( - new IncomingReply(exc, ret, outArgs)); + new IncomingReply(exc, ret, std::move(outArgs))); uno_threadpool_putJob( bridge_->getThreadPool(), tid.getHandle(), resp.get(), nullptr, false); + // coverity[leaked_storage] - "Bridge::makeCall" destroys resp when received resp.release(); break; } diff --git a/binaryurp/source/unmarshal.cxx b/binaryurp/source/unmarshal.cxx index 4263edf8c91c..7d943d37b704 100644 --- a/binaryurp/source/unmarshal.cxx +++ b/binaryurp/source/unmarshal.cxx @@ -22,6 +22,7 @@ #include <cassert> #include <cstdlib> #include <new> +#include <utility> #include <vector> #include <com/sun/star/io/IOException.hpp> @@ -90,9 +91,9 @@ std::vector< BinaryAny >::iterator copyMemberValues( } Unmarshal::Unmarshal( - rtl::Reference< Bridge > const & bridge, ReaderState & state, + rtl::Reference< Bridge > bridge, ReaderState & state, css::uno::Sequence< sal_Int8 > const & buffer): - bridge_(bridge), state_(state), buffer_(buffer) + bridge_(std::move(bridge)), state_(state), buffer_(buffer) { data_ = reinterpret_cast< sal_uInt8 const * >(buffer_.getConstArray()); end_ = data_ + buffer_.getLength(); diff --git a/binaryurp/source/unmarshal.hxx b/binaryurp/source/unmarshal.hxx index c5b91eebb07a..1972c30d0e74 100644 --- a/binaryurp/source/unmarshal.hxx +++ b/binaryurp/source/unmarshal.hxx @@ -40,7 +40,7 @@ namespace binaryurp { class Unmarshal { public: Unmarshal( - rtl::Reference< Bridge > const & bridge, ReaderState & state, + rtl::Reference< Bridge > bridge, ReaderState & state, com::sun::star::uno::Sequence< sal_Int8 > const & buffer); ~Unmarshal(); diff --git a/binaryurp/source/writer.cxx b/binaryurp/source/writer.cxx index 585f375d7a58..539d8a2c532f 100644 --- a/binaryurp/source/writer.cxx +++ b/binaryurp/source/writer.cxx @@ -24,6 +24,7 @@ #include <cstring> #include <exception> #include <limits> +#include <utility> #include <vector> #include <com/sun/star/connection/XConnection.hpp> @@ -31,7 +32,6 @@ #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> #include <com/sun/star/uno/XCurrentContext.hpp> #include <cppuhelper/exc_hlp.hxx> -#include <osl/mutex.hxx> #include <sal/log.hxx> #include <uno/dispatcher.hxx> @@ -51,25 +51,26 @@ Writer::Item::Item() {} Writer::Item::Item( - rtl::ByteSequence const & theTid, OUString const & theOid, - css::uno::TypeDescription const & theType, - css::uno::TypeDescription const & theMember, - std::vector< BinaryAny > const & inArguments, - css::uno::UnoInterfaceReference const & theCurrentContext): - request(true), tid(theTid), oid(theOid), type(theType), member(theMember), - setter(false), arguments(inArguments), exception(false), - currentContext(theCurrentContext), setCurrentContextMode(false) + rtl::ByteSequence theTid, OUString theOid, + css::uno::TypeDescription theType, + css::uno::TypeDescription theMember, + std::vector< BinaryAny >&& inArguments, + css::uno::UnoInterfaceReference theCurrentContext): + tid(std::move(theTid)), oid(std::move(theOid)), type(std::move(theType)), member(std::move(theMember)), + currentContext(std::move(theCurrentContext)), arguments(std::move(inArguments)), + request(true), setter(false), exception(false), setCurrentContextMode(false) {} Writer::Item::Item( - rtl::ByteSequence const & theTid, - css::uno::TypeDescription const & theMember, bool theSetter, - bool theException, BinaryAny const & theReturnValue, - std::vector< BinaryAny > const & outArguments, + rtl::ByteSequence theTid, + css::uno::TypeDescription theMember, bool theSetter, + bool theException, BinaryAny theReturnValue, + std::vector< BinaryAny >&& outArguments, bool theSetCurrentContextMode): - request(false), tid(theTid), member(theMember), setter(theSetter), - arguments(outArguments), exception(theException), - returnValue(theReturnValue), setCurrentContextMode(theSetCurrentContextMode) + tid(std::move(theTid)), member(std::move(theMember)), + returnValue(std::move(theReturnValue)), arguments(std::move(outArguments)), + request(false), setter(theSetter), + exception(theException), setCurrentContextMode(theSetCurrentContextMode) {} Writer::Writer(rtl::Reference< Bridge > const & bridge): @@ -104,11 +105,11 @@ void Writer::queueRequest( rtl::ByteSequence const & tid, OUString const & oid, css::uno::TypeDescription const & type, css::uno::TypeDescription const & member, - std::vector< BinaryAny > const & inArguments) + std::vector< BinaryAny >&& inArguments) { css::uno::UnoInterfaceReference cc(current_context::get()); - osl::MutexGuard g(mutex_); - queue_.emplace_back(tid, oid, type, member, inArguments, cc); + std::lock_guard g(mutex_); + queue_.emplace_back(tid, oid, type, member, std::move(inArguments), cc); items_.set(); } @@ -116,11 +117,11 @@ void Writer::queueReply( rtl::ByteSequence const & tid, com::sun::star::uno::TypeDescription const & member, bool setter, bool exception, BinaryAny const & returnValue, - std::vector< BinaryAny > const & outArguments, bool setCurrentContextMode) + std::vector< BinaryAny >&& outArguments, bool setCurrentContextMode) { - osl::MutexGuard g(mutex_); + std::lock_guard g(mutex_); queue_.emplace_back( - tid, member, setter, exception, returnValue, outArguments, + tid, member, setter, exception, returnValue, std::move(outArguments), setCurrentContextMode); items_.set(); } @@ -134,7 +135,7 @@ void Writer::unblock() { void Writer::stop() { { - osl::MutexGuard g(mutex_); + std::lock_guard g(mutex_); stop_ = true; } unblocked_.set(); @@ -150,7 +151,7 @@ void Writer::execute() { items_.wait(); Item item; { - osl::MutexGuard g(mutex_); + std::lock_guard g(mutex_); if (stop_) { return; } diff --git a/binaryurp/source/writer.hxx b/binaryurp/source/writer.hxx index 8a6f60de0d03..e2061502a015 100644 --- a/binaryurp/source/writer.hxx +++ b/binaryurp/source/writer.hxx @@ -22,10 +22,10 @@ #include <sal/config.h> #include <deque> +#include <mutex> #include <vector> #include <osl/conditn.hxx> -#include <osl/mutex.hxx> #include <rtl/byteseq.hxx> #include <rtl/ref.hxx> #include <rtl/ustring.hxx> @@ -66,13 +66,13 @@ public: rtl::ByteSequence const & tid, OUString const & oid, com::sun::star::uno::TypeDescription const & type, com::sun::star::uno::TypeDescription const & member, - std::vector< BinaryAny > const & inArguments); + std::vector< BinaryAny >&& inArguments); void queueReply( rtl::ByteSequence const & tid, com::sun::star::uno::TypeDescription const & member, bool setter, bool exception, BinaryAny const & returnValue, - std::vector< BinaryAny > const & outArguments, + std::vector< BinaryAny >&& outArguments, bool setCurrentContextMode); void unblock(); @@ -104,42 +104,30 @@ private: // Request: Item( - rtl::ByteSequence const & theTid, OUString const & theOid, - com::sun::star::uno::TypeDescription const & theType, - com::sun::star::uno::TypeDescription const & theMember, - std::vector< BinaryAny > const & inArguments, - com::sun::star::uno::UnoInterfaceReference const & - theCurrentContext); + rtl::ByteSequence theTid, OUString theOid, + com::sun::star::uno::TypeDescription theType, + com::sun::star::uno::TypeDescription theMember, + std::vector< BinaryAny >&& inArguments, + com::sun::star::uno::UnoInterfaceReference theCurrentContext); // Reply: Item( - rtl::ByteSequence const & theTid, - com::sun::star::uno::TypeDescription const & theMember, - bool theSetter, bool theException, BinaryAny const & theReturnValue, - std::vector< BinaryAny > const & outArguments, + rtl::ByteSequence theTid, + com::sun::star::uno::TypeDescription theMember, + bool theSetter, bool theException, BinaryAny theReturnValue, + std::vector< BinaryAny >&& outArguments, bool theSetCurrentContextMode); - bool request; - rtl::ByteSequence tid; // request + reply - OUString oid; // request - com::sun::star::uno::TypeDescription type; // request - com::sun::star::uno::TypeDescription member; // request + reply - + com::sun::star::uno::UnoInterfaceReference currentContext; // request + BinaryAny returnValue; // reply + std::vector< BinaryAny > arguments; // request: inArguments; reply: outArguments + bool request; bool setter; // reply - - std::vector< BinaryAny > arguments; - // request: inArguments; reply: outArguments - bool exception; // reply - - BinaryAny returnValue; // reply - - com::sun::star::uno::UnoInterfaceReference currentContext; // request - bool setCurrentContextMode; // reply }; @@ -152,7 +140,7 @@ private: osl::Condition unblocked_; osl::Condition items_; - osl::Mutex mutex_; + std::mutex mutex_; std::deque< Item > queue_; bool stop_; }; |