Kaydet (Commit) 12fa9ece authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Avoid global static data

...that (indirectly) allocates memory via rtl/alloc.h, thereby causing the
rtl_cache_wsupdate_init thread to be spawned before main, as on Mac OS X that
would interfere with the code in sal_detail_initialize to close all file
descriptors >= 3 -- on Mac OS X the pthreads implementation makes use of KQUEUE
file descriptors.

* This commit removes enough global static data to make ui-preview work again on
Mac OS X (where it crashed at startup when the main thread closed the KQUEUE fd
used by pthreads implementation threads).  gengal uses further static data (at
least from module sb), so needs further clean-up.

* Avoiding global static instances derived from class Application required the
introduction of vcl/vclmain.hxx.

* That the vcl library was linked against the static vclmain library (which only
provides an implementation of main) appears to me to be a historic relic (all
executables should either include a SAL_IMPLEMENT_MAIN or link against vclmain),
so I removed that.

Change-Id: I048aa616208cb3a1b9bd8dcc3b729ba1665729bd
üst 4be8c320
......@@ -67,8 +67,6 @@ namespace
struct s_threadMap : public rtl::Static< ThreadMap, s_threadMap > {};
}
static rtl::OUString s_uno_envDcp(RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO));
static void s_setCurrent(uno_Environment * pEnv)
{
oslThreadIdentifier threadId = osl_getThreadIdentifier(NULL);
......@@ -128,8 +126,10 @@ extern "C" CPPU_DLLPUBLIC void SAL_CALL uno_getCurrentEnvironment(uno_Environmen
(*ppEnv)->acquire(*ppEnv);
}
else
uno_getEnvironment(ppEnv, s_uno_envDcp.pData, NULL);
{
rtl::OUString uno_envDcp(UNO_LB_UNO);
uno_getEnvironment(ppEnv, uno_envDcp.pData, NULL);
}
}
}
......@@ -196,7 +196,7 @@ static int s_getNextEnv(uno_Environment ** ppEnv, uno_Environment * pCurrEnv, un
if (!nextPurpose.isEmpty())
{
rtl::OUString next_envDcp(s_uno_envDcp);
rtl::OUString next_envDcp(UNO_LB_UNO);
next_envDcp += nextPurpose;
uno_getEnvironment(ppEnv, next_envDcp.pData, NULL);
......@@ -355,7 +355,7 @@ CPPU_DLLPUBLIC int SAL_CALL uno_Environment_isValid(uno_Environment * pEnv, rtl_
int result = 1;
rtl::OUString typeName(cppu::EnvDcp::getTypeName(pEnv->pTypeName));
if (typeName.equals(s_uno_envDcp))
if (typeName == UNO_LB_UNO)
{
cppu::Enterable * pEnterable = reinterpret_cast<cppu::Enterable *>(pEnv->pReserved);
if (pEnterable)
......@@ -363,7 +363,7 @@ CPPU_DLLPUBLIC int SAL_CALL uno_Environment_isValid(uno_Environment * pEnv, rtl_
}
else
{
rtl::OUString envDcp(s_uno_envDcp);
rtl::OUString envDcp(UNO_LB_UNO);
envDcp += cppu::EnvDcp::getPurpose(pEnv->pTypeName);
uno::Environment env(envDcp);
......
......@@ -21,6 +21,7 @@
#include <unistd.h>
#include "vcl/svapp.hxx"
#include "vcl/vclmain.hxx"
#include "vcl/wrkwin.hxx"
#include "vcl/unowrap.hxx"
......@@ -53,7 +54,10 @@ public:
static rtl::OUString ReadStringHook( const rtl::OUString& );
};
MyApp aMyApp;
void vclmain::createApplication()
{
static MyApp aMyApp;
}
rtl::OUString MyApp::ReadStringHook( const rtl::OUString& rStr )
{
......
......@@ -47,6 +47,7 @@
#include <tools/urlobj.hxx>
#include <tools/fsys.hxx>
#include <vcl/vclmain.hxx>
#include <vcl/window.hxx>
#include <vcl/svapp.hxx>
#include <vcl/font.hxx>
......@@ -261,6 +262,9 @@ int GalApp::Main()
return EXIT_SUCCESS;
}
GalApp aGalApp;
void vclmain::createApplication()
{
static GalApp aGalApp;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -51,29 +51,27 @@ using rtl::OUString;
namespace
{
OUString const sData = "org.openoffice.UserProfile/Data";
// vOptionNames[] -- names of the user option entries
// The order corresponds to the #define USER_OPT_* list in useroptions.hxx.
OUString const vOptionNames[] = {
OUString("l"), // USER_OPT_CITY
OUString("o"), // USER_OPT_COMPANY
OUString("c"), // USER_OPT_COUNTRY
OUString("mail"), // USER_OPT_EMAIL
OUString("facsimiletelephonenumber"), // USER_OPT_FAX
OUString("givenname"), // USER_OPT_FIRSTNAME
OUString("sn"), // USER_OPT_LASTNAME
OUString("position"), // USER_OPT_POSITION
OUString("st"), // USER_OPT_STATE
OUString("street"), // USER_OPT_STREET
OUString("homephone"), // USER_OPT_TELEPHONEHOME
OUString("telephonenumber"), // USER_OPT_TELEPHONEWORK
OUString("title"), // USER_OPT_TITLE
OUString("initials"), // USER_OPT_ID
OUString("postalcode"), // USER_OPT_ZIP
OUString("fathersname"), // USER_OPT_FATHERSNAME
OUString("apartment"), // USER_OPT_APARTMENT
OUString("customernumber") // USER_OPT_CUSTOMERNUMBER
char const * const vOptionNames[] = {
"l", // USER_OPT_CITY
"o", // USER_OPT_COMPANY
"c", // USER_OPT_COUNTRY
"mail", // USER_OPT_EMAIL
"facsimiletelephonenumber", // USER_OPT_FAX
"givenname", // USER_OPT_FIRSTNAME
"sn", // USER_OPT_LASTNAME
"position", // USER_OPT_POSITION
"st", // USER_OPT_STATE
"street", // USER_OPT_STREET
"homephone", // USER_OPT_TELEPHONEHOME
"telephonenumber", // USER_OPT_TELEPHONEWORK
"title", // USER_OPT_TITLE
"initials", // USER_OPT_ID
"postalcode", // USER_OPT_ZIP
"fathersname", // USER_OPT_FATHERSNAME
"apartment", // USER_OPT_APARTMENT
"customernumber" // USER_OPT_CUSTOMERNUMBER
};
const sal_uInt16 nOptionNameCount = SAL_N_ELEMENTS(vOptionNames);
......@@ -147,7 +145,7 @@ SvtUserOptions::Impl::Impl() :
m_xCfg = uno::Reference<container::XNameAccess>(
comphelper::ConfigurationHelper::openConfig(
comphelper::getProcessComponentContext(),
sData,
"org.openoffice.UserProfile/Data",
comphelper::ConfigurationHelper::E_STANDARD
),
uno::UNO_QUERY
......@@ -180,7 +178,7 @@ OUString SvtUserOptions::Impl::GetToken (sal_uInt16 nToken) const
try
{
if (m_xData.is())
m_xData->getPropertyValue(vOptionNames[nToken]) >>= sToken;
m_xData->getPropertyValue(OUString::createFromAscii(vOptionNames[nToken])) >>= sToken;
}
catch (uno::Exception const& ex)
{
......@@ -201,7 +199,7 @@ void SvtUserOptions::Impl::SetToken (sal_uInt16 nToken, OUString const& sToken)
try
{
if (m_xData.is())
m_xData->setPropertyValue(vOptionNames[nToken], uno::makeAny(sToken));
m_xData->setPropertyValue(OUString::createFromAscii(vOptionNames[nToken]), uno::makeAny(sToken));
comphelper::ConfigurationHelper::flush(m_xCfg);
}
catch (uno::Exception const& ex)
......@@ -240,7 +238,7 @@ sal_Bool SvtUserOptions::Impl::IsTokenReadonly (sal_uInt16 nToken) const
{
uno::Reference<beans::XPropertySet> xData(m_xCfg, uno::UNO_QUERY);
uno::Reference<beans::XPropertySetInfo> xInfo = xData->getPropertySetInfo();
beans::Property aProp = xInfo->getPropertyByName(vOptionNames[nToken]);
beans::Property aProp = xInfo->getPropertyByName(OUString::createFromAscii(vOptionNames[nToken]));
return ((aProp.Attributes & beans::PropertyAttribute::READONLY) ==
beans::PropertyAttribute::READONLY);
}
......
......@@ -661,12 +661,6 @@ $(eval $(call gb_Library_add_ldflags,vcl,\
endif
endif
ifneq ($(OS),IOS)
$(eval $(call gb_Library_use_static_libraries,vcl,\
vclmain \
))
endif
# Runtime dependency for unit-tests
$(call gb_LinkTarget_get_target,$(call gb_Library_get_linktargetname,vcl)) :| \
$(call gb_AllLangResTarget_get_target,vcl)
......
......@@ -156,6 +156,7 @@ $(eval $(call gb_Package_add_file,vcl_inc,inc/vcl/unohelp.hxx,vcl/unohelp.hxx))
$(eval $(call gb_Package_add_file,vcl_inc,inc/vcl/unowrap.hxx,vcl/unowrap.hxx))
$(eval $(call gb_Package_add_file,vcl_inc,inc/vcl/vclenum.hxx,vcl/vclenum.hxx))
$(eval $(call gb_Package_add_file,vcl_inc,inc/vcl/vclevent.hxx,vcl/vclevent.hxx))
$(eval $(call gb_Package_add_file,vcl_inc,inc/vcl/vclmain.hxx,vcl/vclmain.hxx))
$(eval $(call gb_Package_add_file,vcl_inc,inc/vcl/vclmedit.hxx,vcl/vclmedit.hxx))
$(eval $(call gb_Package_add_file,vcl_inc,inc/vcl/virdev.hxx,vcl/virdev.hxx))
$(eval $(call gb_Package_add_file,vcl_inc,inc/vcl/waitobj.hxx,vcl/waitobj.hxx))
......
......@@ -48,16 +48,13 @@ using ::rtl::OString;
namespace // private
{
const Type CPPUTYPE_SEQINT8 = getCppuType((Sequence<sal_Int8>*)0);
const Type CPPUTYPE_OUSTRING = getCppuType( (OUString*)0 );
/* Determine whether or not a DataFlavor is valid.
*/
bool isValidFlavor(const DataFlavor& aFlavor)
{
size_t len = aFlavor.MimeType.getLength();
Type dtype = aFlavor.DataType;
return ((len > 0) && ((dtype == CPPUTYPE_SEQINT8) || (dtype == CPPUTYPE_OUSTRING)));
return ((len > 0) && ((dtype == getCppuType((Sequence<sal_Int8>*)0)) || (dtype == getCppuType( (OUString*)0 ))));
}
NSString* PBTYPE_SODX = @"application/x-openoffice-objectdescriptor-xml;windows_formatname=\"Star Object Descriptor (XML)\"";
......@@ -92,7 +89,7 @@ namespace // private
NSString* SystemFlavor;
const char* OOoFlavor;
const char* HumanPresentableName;
Type DataType;
bool DataTypeOUString; // sequence<byte> otherwise
};
// NSPICTPboardType is deprecated in 10.6 and later
......@@ -113,23 +110,23 @@ namespace // private
*/
FlavorMap flavorMap[] =
{
{ NSStringPboardType, "text/plain;charset=utf-16", "Unicode Text (UTF-16)", CPPUTYPE_OUSTRING },
{ NSRTFPboardType, "text/richtext", "Rich Text Format", CPPUTYPE_SEQINT8 },
{ NSTIFFPboardType, "image/bmp", "Windows Bitmap", CPPUTYPE_SEQINT8 },
{ NSPICTPboardType, "image/bmp", "Windows Bitmap", CPPUTYPE_SEQINT8 },
{ NSHTMLPboardType, "text/html", "Plain Html", CPPUTYPE_SEQINT8 },
{ NSFilenamesPboardType, "application/x-openoffice-filelist;windows_formatname=\"FileList\"", "FileList", CPPUTYPE_SEQINT8 },
{ PBTYPE_SESX, FLAVOR_SESX, "Star Embed Source (XML)", CPPUTYPE_SEQINT8 },
{ PBTYPE_SLSDX, FLAVOR_SLSDX, "Star Link Source Descriptor (XML)", CPPUTYPE_SEQINT8 },
{ PBTYPE_ESX, FLAVOR_ESX, "Star Embed Source (XML)", CPPUTYPE_SEQINT8 },
{ PBTYPE_LSX, FLAVOR_LSX, "Star Link Source (XML)", CPPUTYPE_SEQINT8 },
{ PBTYPE_EOX, FLAVOR_EOX, "Star Embedded Object (XML)", CPPUTYPE_SEQINT8 },
{ PBTYPE_SVXB, FLAVOR_SVXB, "SVXB (StarView Bitmap/Animation", CPPUTYPE_SEQINT8 },
{ PBTYPE_GDIMF, FLAVOR_GDIMF, "GDIMetaFile", CPPUTYPE_SEQINT8 },
{ PBTYPE_WMF, FLAVOR_WMF, "Windows MetaFile", CPPUTYPE_SEQINT8 },
{ PBTYPE_EMF, FLAVOR_EMF, "Windows Enhanced MetaFile", CPPUTYPE_SEQINT8 },
{ PBTYPE_SODX, FLAVOR_SODX, "Star Object Descriptor (XML)", CPPUTYPE_SEQINT8 },
{ PBTYPE_DUMMY_INTERNAL, FLAVOR_DUMMY_INTERNAL, "internal data",CPPUTYPE_SEQINT8 }
{ NSStringPboardType, "text/plain;charset=utf-16", "Unicode Text (UTF-16)", true },
{ NSRTFPboardType, "text/richtext", "Rich Text Format", false },
{ NSTIFFPboardType, "image/bmp", "Windows Bitmap", false },
{ NSPICTPboardType, "image/bmp", "Windows Bitmap", false },
{ NSHTMLPboardType, "text/html", "Plain Html", false },
{ NSFilenamesPboardType, "application/x-openoffice-filelist;windows_formatname=\"FileList\"", "FileList", false },
{ PBTYPE_SESX, FLAVOR_SESX, "Star Embed Source (XML)", false },
{ PBTYPE_SLSDX, FLAVOR_SLSDX, "Star Link Source Descriptor (XML)", false },
{ PBTYPE_ESX, FLAVOR_ESX, "Star Embed Source (XML)", false },
{ PBTYPE_LSX, FLAVOR_LSX, "Star Link Source (XML)", false },
{ PBTYPE_EOX, FLAVOR_EOX, "Star Embedded Object (XML)", false },
{ PBTYPE_SVXB, FLAVOR_SVXB, "SVXB (StarView Bitmap/Animation", false },
{ PBTYPE_GDIMF, FLAVOR_GDIMF, "GDIMetaFile", false },
{ PBTYPE_WMF, FLAVOR_WMF, "Windows MetaFile", false },
{ PBTYPE_EMF, FLAVOR_EMF, "Windows Enhanced MetaFile", false },
{ PBTYPE_SODX, FLAVOR_SODX, "Star Object Descriptor (XML)", false },
{ PBTYPE_DUMMY_INTERNAL, FLAVOR_DUMMY_INTERNAL, "internal data",false }
};
......@@ -138,12 +135,12 @@ namespace // private
inline bool isByteSequenceType(const Type& theType)
{
return (theType == CPPUTYPE_SEQINT8);
return (theType == getCppuType((Sequence<sal_Int8>*)0));
}
inline bool isOUStringType(const Type& theType)
{
return (theType == CPPUTYPE_OUSTRING);
return (theType == getCppuType( (OUString*)0 ));
}
} // namespace private
......@@ -519,7 +516,7 @@ DataFlavor DataFlavorMapper::systemToOpenOfficeFlavor(NSString* systemDataFlavor
{
oOOFlavor.MimeType = OUString::createFromAscii(flavorMap[i].OOoFlavor);
oOOFlavor.HumanPresentableName = OUString(RTL_CONSTASCII_USTRINGPARAM(flavorMap[i].HumanPresentableName));
oOOFlavor.DataType = flavorMap[i].DataType;
oOOFlavor.DataType = flavorMap[i].DataTypeOUString ? getCppuType( (OUString*)0 ) : getCppuType((Sequence<sal_Int8>*)0);
return oOOFlavor;
}
} // for
......
......@@ -34,16 +34,13 @@ using namespace com::sun::star::container;
using ::rtl::OUString;
const Type CPPUTYPE_SEQINT8 = getCppuType((Sequence<sal_Int8>*)0);
const Type CPPUTYPE_OUSTRING = getCppuType((OUString*)0);
namespace // private
{
bool isValidFlavor( const DataFlavor& aFlavor )
{
size_t len = aFlavor.MimeType.getLength();
Type dtype = aFlavor.DataType;
return ((len > 0) && ((dtype == CPPUTYPE_SEQINT8) || (dtype == CPPUTYPE_OUSTRING)));
return ((len > 0) && ((dtype == getCppuType((Sequence<sal_Int8>*)0)) || (dtype == getCppuType((OUString*)0))));
}
} // namespace private
......@@ -106,7 +103,7 @@ Any SAL_CALL OSXTransferable::getTransferData( const DataFlavor& aFlavor )
bool OSXTransferable::isUnicodeText(const DataFlavor& flavor)
{
return (flavor.DataType == CPPUTYPE_OUSTRING);
return (flavor.DataType == getCppuType((OUString*)0));
}
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef INCLUDED_VCL_VCLMAIN_HXX
#define INCLUDED_VCL_VCLMAIN_HXX
#include "sal/config.h"
namespace vclmain {
// Function called from vclmain's implementation of main, needs to be
// implemented by the application and needs to instantiate a (static, derived)
// instance of Application (where the Application constructor takes care to link
// that instance to ImplSVData.mpApp):
void createApplication();
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -32,16 +32,13 @@ using namespace com::sun::star::container;
using ::rtl::OUString;
const Type CPPUTYPE_SEQINT8 = getCppuType((Sequence<sal_Int8>*)0);
const Type CPPUTYPE_OUSTRING = getCppuType((OUString*)0);
namespace // private
{
bool isValidFlavor( const DataFlavor& aFlavor )
{
size_t len = aFlavor.MimeType.getLength();
Type dtype = aFlavor.DataType;
return ((len > 0) && ((dtype == CPPUTYPE_SEQINT8) || (dtype == CPPUTYPE_OUSTRING)));
return ((len > 0) && ((dtype == getCppuType((Sequence<sal_Int8>*)0)) || (dtype == getCppuType((OUString*)0))));
}
} // namespace private
......@@ -82,7 +79,7 @@ Any SAL_CALL iOSTransferable::getTransferData( const DataFlavor& aFlavor )
bool iOSTransferable::isUnicodeText(const DataFlavor& flavor)
{
return (flavor.DataType == CPPUTYPE_OUSTRING);
return (flavor.DataType == getCppuType((OUString*)0));
}
......
......@@ -23,11 +23,13 @@
#include "sal/main.h"
#include "tools/extendapplicationenvironment.hxx"
#include "vcl/vclmain.hxx"
#include "salinst.hxx"
SAL_IMPLEMENT_MAIN() {
tools::extendApplicationEnvironment();
vclmain::createApplication();
return SVMain();
}
......
......@@ -18,6 +18,7 @@
#include <vcl/dialog.hxx>
#include <vcl/help.hxx>
#include <vcl/svapp.hxx>
#include <vcl/vclmain.hxx>
class UIPreviewApp : public Application
{
......@@ -88,6 +89,9 @@ int UIPreviewApp::Main()
return EXIT_SUCCESS;
}
UIPreviewApp aApp;
void vclmain::createApplication()
{
static UIPreviewApp aApp;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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