Perils of purpose UNO environments
Michael Stahl
mstahl at redhat.com
Wed Feb 24 14:12:20 UTC 2016
On 24.02.2016 10:08, Stephan Bergmann wrote:
> (This shows why
> comphelper::getProcessComponentContext is a convenient but dumb idea.)
indeed, like all mutable global state.
>> diff --git a/comphelper/source/processfactory/processfactory.cxx b/comphelper/source/processfactory/processfactory.cxx
>> index 211067a..d7ca3af 100644
>> --- a/comphelper/source/processfactory/processfactory.cxx
>> +++ b/comphelper/source/processfactory/processfactory.cxx
>> @@ -18,6 +18,7 @@
>> */
>>
>> #include <osl/mutex.hxx>
>> +#include <uno/environment.hxx>
>> #include <comphelper/processfactory.hxx>
>> #include <com/sun/star/lang/XMultiServiceFactory.hpp>
>>
>> @@ -52,11 +53,17 @@ Reference< XMultiServiceFactory > localProcessFactory( const Reference< XMultiSe
>>
>> void setProcessServiceFactory(const Reference< XMultiServiceFactory >& xSMgr)
>> {
>> +css::uno::Environment env(css::uno::Environment::getCurrent());
>> +assert(env.is());
>> +assert(env.getTypeName() == CPPU_CURRENT_LANGUAGE_BINDING_NAME);
>> localProcessFactory( xSMgr, true );
>> }
>>
>> Reference< XMultiServiceFactory > getProcessServiceFactory()
>> {
>> +css::uno::Environment env(css::uno::Environment::getCurrent());
>> +assert(env.is());
>> +assert(env.getTypeName() == CPPU_CURRENT_LANGUAGE_BINDING_NAME);
>> Reference< XMultiServiceFactory> xReturn;
>> xReturn = localProcessFactory( xReturn, false );
>> if ( !xReturn.is() )
>
> could catch cases where it erroneously gets called from within a purpose
> environment. Then again, purpose environments are rare enough in
> practice, and I only found a single problematic
> <https://cgit.freedesktop.org/libreoffice/core/commit/?id=9610a5aebd3ffdf76bcb734c633b5f88b78ad4dd>
> "Use passed-in context instead of
> comphelper::getProcessComponentContext()" when running "make check" with
> that patch enabled. So it might not be worth it to commit that.
well that's what we have *today* - who knows what will be added (or
"cleaned up") in the future, better add the asserts.
More information about the LibreOffice
mailing list