[Libreoffice-commits] core.git: pyuno/source sal/osl

Michael Stahl mstahl at redhat.com
Thu Oct 10 05:39:05 PDT 2013


 pyuno/source/module/pyuno_module.cxx |    5 +----
 sal/osl/unx/process_impl.cxx         |   19 ++++++++++++++++---
 sal/osl/w32/process.cxx              |    8 ++++----
 3 files changed, 21 insertions(+), 11 deletions(-)

New commits:
commit 1acaa577b67158c060d2f57414f7aea86504a489
Author: Michael Stahl <mstahl at redhat.com>
Date:   Thu Oct 10 13:47:18 2013 +0200

    sal: add special handling of argc==0 to osl_setCommandArgs()
    
    ... to set up a fake command line.  This is used from pyuno, when
    invoked from the "python" executable as "import uno".
    
    On WNT there is an API to get the actual command line, so just use that
    even in the "fake" case; on UNX just fake something up.
    
    Just for the record the whole osl_setCommandArgs() is called exactly once
    assumption should work out _unless_ there is a program that uses SAL_MAIN
    _and_ does a python-level "import uno" _before_ it wants to create a
    python-based UNO service (via pyuno_loader::CreateInstance), since
    pyuno already takes care to call Runtime::initialize() at most once.
    
    Change-Id: Ifd23de733ea3e6b694d46ab039b6aa4fd3e7fc1b
    Signed-off-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/pyuno/source/module/pyuno_module.cxx b/pyuno/source/module/pyuno_module.cxx
index e34b675..718759f 100644
--- a/pyuno/source/module/pyuno_module.cxx
+++ b/pyuno/source/module/pyuno_module.cxx
@@ -263,10 +263,7 @@ static PyObject* getComponentContext(
         {
             // cppu::defaultBootstrap_InitialComponentContext expects
             // command line arguments to be present
-            static char * argv [1];
-            argv[0] = strdup(
-                "this is just a fake and cheap imitation of a command line");
-            osl_setCommandArgs(1, argv);
+            osl_setCommandArgs(0, 0); // fake it
 
             OUString iniFile;
             if( path.isEmpty() )
diff --git a/sal/osl/unx/process_impl.cxx b/sal/osl/unx/process_impl.cxx
index 00766cc..6d1694d 100644
--- a/sal/osl/unx/process_impl.cxx
+++ b/sal/osl/unx/process_impl.cxx
@@ -208,13 +208,26 @@ oslProcessError SAL_CALL osl_getCommandArg (sal_uInt32 nArg, rtl_uString ** strC
  **************************************/
 void SAL_CALL osl_setCommandArgs (int argc, char ** argv)
 {
-    OSL_ASSERT(argc > 0);
+    // special case for argc == 0: set up fake command line
+    int nArgs(argc ? argc : 1);
     pthread_mutex_lock (&(g_command_args.m_mutex));
     assert (g_command_args.m_nCount == 0);
     if (g_command_args.m_nCount == 0)
     {
-        rtl_uString** ppArgs = (rtl_uString**)rtl_allocateZeroMemory (argc * sizeof(rtl_uString*));
-        if (ppArgs != 0)
+        rtl_uString** ppArgs =
+            (rtl_uString**)rtl_allocateZeroMemory(nArgs * sizeof(rtl_uString*));
+        if (ppArgs != 0 && argc == 0)
+        {
+            // special case: set up fake command line
+            char const*const arg =
+                "this is just a fake and cheap imitation of a command line";
+            rtl_string2UString(&ppArgs[0],
+                arg, rtl_str_getLength(arg), RTL_TEXTENCODING_ASCII_US,
+                OSTRING_TO_OUSTRING_CVTFLAGS);
+            g_command_args.m_nCount = nArgs;
+            g_command_args.m_ppArgs = ppArgs;
+        }
+        else if (ppArgs != 0)
         {
             rtl_TextEncoding encoding = osl_getThreadTextEncoding();
             for (int i = 0; i < argc; i++)
diff --git a/sal/osl/w32/process.cxx b/sal/osl/w32/process.cxx
index 920e77d..6d55249 100644
--- a/sal/osl/w32/process.cxx
+++ b/sal/osl/w32/process.cxx
@@ -261,14 +261,14 @@ static struct CommandArgs_Impl g_command_args =
 #endif
 static rtl_uString ** osl_createCommandArgs_Impl (int argc, char **)
 {
+    int nArgs(0);
+    LPWSTR *wargv = CommandLineToArgvW( GetCommandLineW(), &nArgs );
+    assert(argc == nArgs || argc == 0 /* special case - faked */);
     rtl_uString ** ppArgs =
-        (rtl_uString**)rtl_allocateZeroMemory (argc * sizeof(rtl_uString*));
+        (rtl_uString**)rtl_allocateZeroMemory(nArgs * sizeof(rtl_uString*));
     if (ppArgs != 0)
     {
         int i;
-        int nArgs;
-        LPWSTR *wargv = CommandLineToArgvW( GetCommandLineW(), &nArgs );
-        OSL_ASSERT( nArgs == argc );
         for (i = 0; i < nArgs; i++)
         {
             /* Convert to unicode */


More information about the Libreoffice-commits mailing list