diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-04-03 10:43:38 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-04-03 11:37:36 +0200 |
commit | 50abf47628ad20c3104149a900313f62c34bac9f (patch) | |
tree | e778aad20c10374a518e4dfe8d96b99222e3582a /pyuno/source | |
parent | 8666dfecbaac69b9dc9a9c23a05654d847608907 (diff) |
loplugin:flatten in pyuno
Change-Id: I6074463579f1ffc18f5683a3c4b109402b650f9a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91613
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'pyuno/source')
-rw-r--r-- | pyuno/source/loader/pyuno_loader.cxx | 82 | ||||
-rw-r--r-- | pyuno/source/module/pyuno_module.cxx | 26 | ||||
-rw-r--r-- | pyuno/source/module/pyuno_runtime.cxx | 60 | ||||
-rw-r--r-- | pyuno/source/module/pyuno_util.cxx | 54 |
4 files changed, 111 insertions, 111 deletions
diff --git a/pyuno/source/loader/pyuno_loader.cxx b/pyuno/source/loader/pyuno_loader.cxx index b2a89749b98d..c7b7b7289b86 100644 --- a/pyuno/source/loader/pyuno_loader.cxx +++ b/pyuno/source/loader/pyuno_loader.cxx @@ -180,62 +180,62 @@ namespace { struct PythonInit { PythonInit() { - if (! Py_IsInitialized()) // may be inited by getComponentContext() already - { - OUString pythonPath; - OUString pythonHome; - OUString path( "$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("pythonloader.uno" )); - rtl::Bootstrap::expandMacros(path); //TODO: detect failure - rtl::Bootstrap bootstrap(path); + if ( Py_IsInitialized()) // may be inited by getComponentContext() already + return; - // look for pythonhome - bootstrap.getFrom( "PYUNO_LOADER_PYTHONHOME", pythonHome ); - bootstrap.getFrom( "PYUNO_LOADER_PYTHONPATH", pythonPath ); + OUString pythonPath; + OUString pythonHome; + OUString path( "$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("pythonloader.uno" )); + rtl::Bootstrap::expandMacros(path); //TODO: detect failure + rtl::Bootstrap bootstrap(path); - // pythonhome+pythonpath must be set before Py_Initialize(), otherwise there appear warning on the console - // sadly, there is no api for setting the pythonpath, we have to use the environment variable - if( !pythonHome.isEmpty() ) - setPythonHome( pythonHome ); + // look for pythonhome + bootstrap.getFrom( "PYUNO_LOADER_PYTHONHOME", pythonHome ); + bootstrap.getFrom( "PYUNO_LOADER_PYTHONPATH", pythonPath ); - if( !pythonPath.isEmpty() ) - prependPythonPath( pythonPath ); + // pythonhome+pythonpath must be set before Py_Initialize(), otherwise there appear warning on the console + // sadly, there is no api for setting the pythonpath, we have to use the environment variable + if( !pythonHome.isEmpty() ) + setPythonHome( pythonHome ); + + if( !pythonPath.isEmpty() ) + prependPythonPath( pythonPath ); #ifdef _WIN32 - //extend PATH under windows to include the branddir/program so ssl libs will be found - //for use by terminal mailmerge dependency _ssl.pyd - OUString sEnvName("PATH"); - OUString sPath; - osl_getEnvironment(sEnvName.pData, &sPath.pData); - OUString sBrandLocation("$BRAND_BASE_DIR/program"); - rtl::Bootstrap::expandMacros(sBrandLocation); - osl::FileBase::getSystemPathFromFileURL(sBrandLocation, sBrandLocation); - sPath = OUStringBuffer(sPath). - append(static_cast<sal_Unicode>(SAL_PATHSEPARATOR)). - append(sBrandLocation).makeStringAndClear(); - osl_setEnvironment(sEnvName.pData, sPath.pData); + //extend PATH under windows to include the branddir/program so ssl libs will be found + //for use by terminal mailmerge dependency _ssl.pyd + OUString sEnvName("PATH"); + OUString sPath; + osl_getEnvironment(sEnvName.pData, &sPath.pData); + OUString sBrandLocation("$BRAND_BASE_DIR/program"); + rtl::Bootstrap::expandMacros(sBrandLocation); + osl::FileBase::getSystemPathFromFileURL(sBrandLocation, sBrandLocation); + sPath = OUStringBuffer(sPath). + append(static_cast<sal_Unicode>(SAL_PATHSEPARATOR)). + append(sBrandLocation).makeStringAndClear(); + osl_setEnvironment(sEnvName.pData, sPath.pData); #endif #if PY_MAJOR_VERSION >= 3 - PyImport_AppendInittab( "pyuno", PyInit_pyuno ); + PyImport_AppendInittab( "pyuno", PyInit_pyuno ); #else - PyImport_AppendInittab( (char*)"pyuno", initpyuno ); + PyImport_AppendInittab( (char*)"pyuno", initpyuno ); #endif #if HAVE_FEATURE_READONLY_INSTALLSET - Py_DontWriteBytecodeFlag = 1; + Py_DontWriteBytecodeFlag = 1; #endif - // initialize python - Py_Initialize(); - PyEval_InitThreads(); + // initialize python + Py_Initialize(); + PyEval_InitThreads(); - PyThreadState *tstate = PyThreadState_Get(); - PyEval_ReleaseThread( tstate ); - // This tstate is never used again, so delete it here. - // This prevents an assertion in PyThreadState_Swap on the - // PyThreadAttach below. - PyThreadState_Delete(tstate); - } + PyThreadState *tstate = PyThreadState_Get(); + PyEval_ReleaseThread( tstate ); + // This tstate is never used again, so delete it here. + // This prevents an assertion in PyThreadState_Swap on the + // PyThreadAttach below. + PyThreadState_Delete(tstate); } }; diff --git a/pyuno/source/module/pyuno_module.cxx b/pyuno/source/module/pyuno_module.cxx index 1eb6b0e38428..4abe28b84539 100644 --- a/pyuno/source/module/pyuno_module.cxx +++ b/pyuno/source/module/pyuno_module.cxx @@ -179,21 +179,21 @@ void fillStruct( inv->setValue( rMemberName, a ); } } - if ( PyTuple_Size( initializer ) > 0 ) + if ( PyTuple_Size( initializer ) <= 0 ) + return; + + // Allow partial initialisation when only keyword arguments are given + for ( int i = 0; i < nMembers ; ++i) { - // Allow partial initialisation when only keyword arguments are given - for ( int i = 0; i < nMembers ; ++i) + const OUString memberName (pCompType->ppMemberNames[i]); + if ( ! state.isInitialised( memberName ) ) { - const OUString memberName (pCompType->ppMemberNames[i]); - if ( ! state.isInitialised( memberName ) ) - { - OUString buf = "pyuno._createUnoStructHelper: member '" + - memberName + - "' of struct type '" + - OUString::unacquired(&pCompType->aBase.pTypeName) + - "' not given a value."; - throw RuntimeException(buf); - } + OUString buf = "pyuno._createUnoStructHelper: member '" + + memberName + + "' of struct type '" + + OUString::unacquired(&pCompType->aBase.pTypeName) + + "' not given a value."; + throw RuntimeException(buf); } } } diff --git a/pyuno/source/module/pyuno_runtime.cxx b/pyuno/source/module/pyuno_runtime.cxx index 5182f57ab201..9b6eb22d4e06 100644 --- a/pyuno/source/module/pyuno_runtime.cxx +++ b/pyuno/source/module/pyuno_runtime.cxx @@ -217,39 +217,39 @@ static void readLoggingConfig( sal_Int32 *pLevel, FILE **ppFile ) OUStringToOString( str, RTL_TEXTENCODING_UTF8 ).getStr() ); } } - if( *pLevel > LogLevel::NONE ) - { + if( *pLevel <= LogLevel::NONE ) + return; + + *ppFile = stdout; + if( !bootstrapHandle.getFrom( "PYUNO_LOGTARGET", str ) ) + return; + + if ( str == "stdout" ) *ppFile = stdout; - if( bootstrapHandle.getFrom( "PYUNO_LOGTARGET", str ) ) + else if ( str == "stderr" ) + *ppFile = stderr; + else + { + oslProcessInfo data; + data.Size = sizeof( data ); + osl_getProcessInfo( + nullptr , osl_Process_IDENTIFIER , &data ); + osl_getSystemPathFromFileURL( str.pData, &str.pData); + OString o = OUStringToOString( str, osl_getThreadTextEncoding() ); + o += "."; + o += OString::number( data.Ident ); + + *ppFile = fopen( o.getStr() , "w" ); + if ( *ppFile ) { - if ( str == "stdout" ) - *ppFile = stdout; - else if ( str == "stderr" ) - *ppFile = stderr; - else - { - oslProcessInfo data; - data.Size = sizeof( data ); - osl_getProcessInfo( - nullptr , osl_Process_IDENTIFIER , &data ); - osl_getSystemPathFromFileURL( str.pData, &str.pData); - OString o = OUStringToOString( str, osl_getThreadTextEncoding() ); - o += "."; - o += OString::number( data.Ident ); - - *ppFile = fopen( o.getStr() , "w" ); - if ( *ppFile ) - { - // do not buffer (useful if e.g. analyzing a crash) - setvbuf( *ppFile, nullptr, _IONBF, 0 ); - } - else - { - fprintf( stderr, "couldn't create file %s\n", - OUStringToOString( str, RTL_TEXTENCODING_UTF8 ).getStr() ); + // do not buffer (useful if e.g. analyzing a crash) + setvbuf( *ppFile, nullptr, _IONBF, 0 ); + } + else + { + fprintf( stderr, "couldn't create file %s\n", + OUStringToOString( str, RTL_TEXTENCODING_UTF8 ).getStr() ); - } - } } } } diff --git a/pyuno/source/module/pyuno_util.cxx b/pyuno/source/module/pyuno_util.cxx index f75533d47fdb..f1eebff90345 100644 --- a/pyuno/source/module/pyuno_util.cxx +++ b/pyuno/source/module/pyuno_util.cxx @@ -112,33 +112,33 @@ void log( RuntimeCargo * cargo, sal_Int32 level, const OUString &logString ) void log( RuntimeCargo * cargo, sal_Int32 level, const char *str ) { - if( isLog( cargo, level ) ) - { - static const char *strLevel[] = { "NONE", "CALL", "ARGS" }; - - TimeValue systemTime; - TimeValue localTime; - oslDateTime localDateTime; - - osl_getSystemTime( &systemTime ); - osl_getLocalTimeFromSystemTime( &systemTime, &localTime ); - osl_getDateTimeFromTimeValue( &localTime, &localDateTime ); - - fprintf( cargo->logFile, - "%4i-%02i-%02i %02i:%02i:%02i,%03lu [%s,tid %ld]: %s\n", - localDateTime.Year, - localDateTime.Month, - localDateTime.Day, - localDateTime.Hours, - localDateTime.Minutes, - localDateTime.Seconds, - sal::static_int_cast< unsigned long >( - localDateTime.NanoSeconds/1000000), - strLevel[level], - sal::static_int_cast< long >( - static_cast<sal_Int32>(osl::Thread::getCurrentIdentifier())), - str ); - } + if( !isLog( cargo, level ) ) + return; + + static const char *strLevel[] = { "NONE", "CALL", "ARGS" }; + + TimeValue systemTime; + TimeValue localTime; + oslDateTime localDateTime; + + osl_getSystemTime( &systemTime ); + osl_getLocalTimeFromSystemTime( &systemTime, &localTime ); + osl_getDateTimeFromTimeValue( &localTime, &localDateTime ); + + fprintf( cargo->logFile, + "%4i-%02i-%02i %02i:%02i:%02i,%03lu [%s,tid %ld]: %s\n", + localDateTime.Year, + localDateTime.Month, + localDateTime.Day, + localDateTime.Hours, + localDateTime.Minutes, + localDateTime.Seconds, + sal::static_int_cast< unsigned long >( + localDateTime.NanoSeconds/1000000), + strLevel[level], + sal::static_int_cast< long >( + static_cast<sal_Int32>(osl::Thread::getCurrentIdentifier())), + str ); } namespace { |