Kaydet (Commit) 2ad716f4 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Revert "pyuno: set up fake command line in getComponentContext()"

This reverts commit 2386a92c and its follow-ups
1acaa577 "sal: add special handling of argc==0
to osl_setCommandArgs()" and 01f27b5e "sal: fix
osl_setCommandArgs() on WNT."

The situation that osl_getCommandArgCount is called without a prior call to
osl_setCommandArgs should be considered as harmless and can legitimately not
only happen in the pyuno case discussed in the reverted commits, but also in
case binary UNO is bootstrapped from within a Java process, as happens in
test-javanative in ure/source/uretest/Makefile.

Change-Id: I2829db390e37dfe5daeda33a4c0659b7d35e565a
üst d8266cfc
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
#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>
...@@ -250,10 +249,6 @@ static PyObject* getComponentContext( ...@@ -250,10 +249,6 @@ static PyObject* getComponentContext(
} }
else else
{ {
// cppu::defaultBootstrap_InitialComponentContext expects
// command line arguments to be present
osl_setCommandArgs(0, 0); // fake it
OUString iniFile; OUString iniFile;
if( path.isEmpty() ) if( path.isEmpty() )
{ {
......
...@@ -164,7 +164,7 @@ sal_uInt32 SAL_CALL osl_getCommandArgCount (void) ...@@ -164,7 +164,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));
assert (g_command_args.m_nCount != 0); SAL_WARN_IF (g_command_args.m_nCount == 0, "sal.osl", "osl_setCommandArgs() not called before calling osl_getCommandArgCount()");
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));
...@@ -204,26 +204,13 @@ int SAL_CALL osl_areCommandArgsSet (void) ...@@ -204,26 +204,13 @@ int SAL_CALL osl_areCommandArgsSet (void)
**************************************/ **************************************/
void SAL_CALL osl_setCommandArgs (int argc, char ** argv) void SAL_CALL osl_setCommandArgs (int argc, char ** argv)
{ {
// special case for argc == 0: set up fake command line OSL_ASSERT(argc > 0);
int nArgs(argc ? argc : 1);
pthread_mutex_lock (&(g_command_args.m_mutex)); pthread_mutex_lock (&(g_command_args.m_mutex));
assert (g_command_args.m_nCount == 0); assert (g_command_args.m_nCount == 0);
if (g_command_args.m_nCount == 0) if (g_command_args.m_nCount == 0)
{ {
rtl_uString** ppArgs = rtl_uString** ppArgs = (rtl_uString**)rtl_allocateZeroMemory (argc * sizeof(rtl_uString*));
(rtl_uString**)rtl_allocateZeroMemory(nArgs * sizeof(rtl_uString*)); if (ppArgs != 0)
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(); rtl_TextEncoding encoding = osl_getThreadTextEncoding();
for (int i = 0; i < argc; i++) for (int i = 0; i < argc; i++)
......
...@@ -259,20 +259,16 @@ static struct CommandArgs_Impl g_command_args = ...@@ -259,20 +259,16 @@ static struct CommandArgs_Impl g_command_args =
#pragma warning( push ) #pragma warning( push )
#pragma warning( disable: 4100 ) #pragma warning( disable: 4100 )
#endif #endif
static rtl_uString ** osl_createCommandArgs_Impl (int & argc, char **) static rtl_uString ** osl_createCommandArgs_Impl (int argc, char **)
{ {
int nArgs(0);
LPWSTR *wargv = CommandLineToArgvW( GetCommandLineW(), &nArgs );
if (argc != nArgs)
{
assert(argc == 0 /* special case - faked */);
argc = nArgs;
}
rtl_uString ** ppArgs = rtl_uString ** ppArgs =
(rtl_uString**)rtl_allocateZeroMemory(nArgs * sizeof(rtl_uString*)); (rtl_uString**)rtl_allocateZeroMemory (argc * sizeof(rtl_uString*));
if (ppArgs != 0) if (ppArgs != 0)
{ {
int i; int i;
int nArgs;
LPWSTR *wargv = CommandLineToArgvW( GetCommandLineW(), &nArgs );
OSL_ASSERT( nArgs == argc );
for (i = 0; i < nArgs; i++) for (i = 0; i < nArgs; i++)
{ {
/* Convert to unicode */ /* Convert to unicode */
...@@ -385,6 +381,7 @@ int SAL_CALL osl_areCommandArgsSet(void) ...@@ -385,6 +381,7 @@ int SAL_CALL osl_areCommandArgsSet(void)
void SAL_CALL osl_setCommandArgs (int argc, char ** argv) void SAL_CALL osl_setCommandArgs (int argc, char ** argv)
{ {
OSL_ASSERT(argc > 0);
osl_acquireMutex (*osl_getGlobalMutex()); osl_acquireMutex (*osl_getGlobalMutex());
if (g_command_args.m_nCount == 0) if (g_command_args.m_nCount == 0)
{ {
......
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