Kaydet (Commit) 2386a92c authored tarafından Michael Stahl's avatar Michael Stahl

pyuno: set up fake command line in getComponentContext()

Easy to trigger the assert in osl_getCommandArgCount(), just
run instdir/*/program/python and "import unohelper".

Avoid that by setting up a fake command line, hopefully
nobody expects to be able to give relevant args to python...

Change-Id: I0df6c23d6ecbb3c2bce81a9d5bcecdcb1729ddbb
üst d703c8f6
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <osl/module.hxx> #include <osl/module.hxx>
#include <osl/thread.h> #include <osl/thread.h>
#include <osl/process.h>
#include <osl/file.hxx> #include <osl/file.hxx>
#include <typelib/typedescription.hxx> #include <typelib/typedescription.hxx>
...@@ -260,6 +261,13 @@ static PyObject* getComponentContext( ...@@ -260,6 +261,13 @@ static PyObject* getComponentContext(
} }
else else
{ {
// 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);
OUString iniFile; OUString iniFile;
if( path.isEmpty() ) if( path.isEmpty() )
{ {
......
...@@ -176,7 +176,7 @@ sal_uInt32 SAL_CALL osl_getCommandArgCount (void) ...@@ -176,7 +176,7 @@ sal_uInt32 SAL_CALL osl_getCommandArgCount (void)
sal_uInt32 result = 0; sal_uInt32 result = 0;
pthread_mutex_lock (&(g_command_args.m_mutex)); pthread_mutex_lock (&(g_command_args.m_mutex));
SAL_WARN_IF (g_command_args.m_nCount == 0, "sal.osl", "osl_setCommandArgs() not called before calling osl_getCommandArgCount()"); assert (g_command_args.m_nCount != 0);
if (g_command_args.m_nCount > 0) if (g_command_args.m_nCount > 0)
result = g_command_args.m_nCount - 1; result = g_command_args.m_nCount - 1;
pthread_mutex_unlock (&(g_command_args.m_mutex)); pthread_mutex_unlock (&(g_command_args.m_mutex));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment