[Libreoffice-commits] .: sw/inc sw/source
Stephan Bergmann
sbergmann at kemper.freedesktop.org
Thu Oct 6 00:32:06 PDT 2011
sw/inc/init.hxx | 24 ++++++++++++++++-
sw/inc/shellio.hxx | 3 --
sw/inc/swdll.hxx | 4 ++
sw/source/filter/basflt/fltini.cxx | 50 ++++++++++++++++++++-----------------
sw/source/ui/app/swdll.cxx | 15 +++++++++--
sw/source/ui/app/swdllimpl.hxx | 14 +++++++++-
6 files changed, 80 insertions(+), 30 deletions(-)
New commits:
commit 06fdd1585d59b2580e8e35bba8a3295bbda28c6e
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Thu Oct 6 09:28:20 2011 +0200
Ensure msword lib has not yet been unloaded when aReaderWriter pReaders are destroyed.
...as some may use code exported from msword lib. The newly introduced sw::Filters
class can still be improved, bundling what is currently exported through various channels
from fltini.cxx. Also, the code is still not thread safe.
diff --git a/sw/inc/init.hxx b/sw/inc/init.hxx
index 42f5406..daad12c 100644
--- a/sw/inc/init.hxx
+++ b/sw/inc/init.hxx
@@ -28,13 +28,33 @@
#ifndef _INIT_HXX
#define _INIT_HXX
+#include "sal/config.h"
+
+#include "boost/noncopyable.hpp"
+#include "osl/module.h"
+#include "osl/module.hxx"
+
class ViewShell;
void _InitCore(); // bastyp/init.cxx
void _FinitCore();
-void _InitFilter(); // basflt/fltini.cxx
-void _FinitFilter();
+namespace sw {
+
+// basflt/fltini.cxx
+class Filters: private boost::noncopyable {
+public:
+ Filters();
+
+ ~Filters();
+
+ oslGenericFunction GetMswordLibSymbol( const char *pSymbol );
+
+private:
+ osl::Module msword_;
+};
+
+}
// layout/newfrm.cxx
void _FrmInit();
diff --git a/sw/inc/shellio.hxx b/sw/inc/shellio.hxx
index 14eaf0e..d915bb2 100644
--- a/sw/inc/shellio.hxx
+++ b/sw/inc/shellio.hxx
@@ -369,9 +369,6 @@ public:
// BEGIN source/filter/basflt/fltini.cxx
-extern void _InitFilter();
-extern void _FinitFilter();
-
extern SwRead ReadAscii, /*ReadSwg, ReadSw3, */ReadHTML, ReadXML;
SW_DLLPUBLIC SwRead SwGetReaderXML();
diff --git a/sw/inc/swdll.hxx b/sw/inc/swdll.hxx
index 868682e..154f670 100644
--- a/sw/inc/swdll.hxx
+++ b/sw/inc/swdll.hxx
@@ -31,6 +31,8 @@
#include <sfx2/sfxdefs.hxx>
#include <sfx2/module.hxx>
+namespace sw { class Filters; }
+
/**
* This class is a wrapper for a Load-On-Demand-DLL. One instance
* per SfxApplication will be created for the runtime of
@@ -39,6 +41,8 @@
namespace SwGlobals
{
void ensure();
+
+ sw::Filters & getFilters();
}
#endif
diff --git a/sw/source/filter/basflt/fltini.cxx b/sw/source/filter/basflt/fltini.cxx
index 7f83ff1..a7bfa29 100644
--- a/sw/source/filter/basflt/fltini.cxx
+++ b/sw/source/filter/basflt/fltini.cxx
@@ -54,6 +54,7 @@
#include <wdocsh.hxx>
#include <fltini.hxx>
#include <hints.hxx>
+#include <init.hxx>
#include <frmatr.hxx>
#include <fmtfsize.hxx>
#include <swtable.hxx>
@@ -134,7 +135,15 @@ inline void _SetFltPtr( sal_uInt16 rPos, SwRead pReader )
aReaderWriter[ rPos ].pReader = pReader;
}
-void _InitFilter()
+namespace {
+
+extern "C" { static void SAL_CALL thisModule() {} }
+
+}
+
+namespace sw {
+
+Filters::Filters()
{
_SetFltPtr( READER_WRITER_BAS, (ReadAscii = new AsciiReader) );
_SetFltPtr( READER_WRITER_HTML, (ReadHTML = new HTMLReader) );
@@ -144,7 +153,7 @@ void _InitFilter()
_SetFltPtr( READER_WRITER_TEXT, ReadAscii );
}
-void _FinitFilter()
+Filters::~Filters()
{
// die Reader vernichten
for( sal_uInt16 n = 0; n < MAXFILTER; ++n )
@@ -155,6 +164,17 @@ void _FinitFilter()
}
}
+oslGenericFunction Filters::GetMswordLibSymbol( const char *pSymbol )
+{
+ static ::rtl::OUString aLibName( RTL_CONSTASCII_USTRINGPARAM( SVLIBRARY( "msword" ) ) );
+ if (!msword_.is())
+ SvLibrary::LoadModule( msword_, aLibName, &thisModule, SAL_LOADMODULE_GLOBAL | SAL_LOADMODULE_LAZY );
+ if (msword_.is())
+ return msword_.getFunctionSymbol( ::rtl::OUString::createFromAscii( pSymbol ) );
+ return NULL;
+}
+
+}
namespace SwReaderWriter {
@@ -807,23 +827,9 @@ void SwAsciiOptions::WriteUserData( String& rStr )
rStr += ',';
}
-extern "C" { static void SAL_CALL thisModule() {} }
-
-static oslGenericFunction GetMswordLibSymbol( const char *pSymbol )
-{
- static ::osl::Module aModule;
- static sal_Bool bLoaded = sal_False;
- static ::rtl::OUString aLibName( RTL_CONSTASCII_USTRINGPARAM( SVLIBRARY( "msword" ) ) );
- if (!bLoaded)
- bLoaded = SvLibrary::LoadModule( aModule, aLibName, &thisModule, SAL_LOADMODULE_GLOBAL | SAL_LOADMODULE_LAZY );
- if (bLoaded)
- return aModule.getFunctionSymbol( ::rtl::OUString::createFromAscii( pSymbol ) );
- return NULL;
-}
-
Reader* GetRTFReader()
{
- FnGetReader pFunction = reinterpret_cast<FnGetReader>( GetMswordLibSymbol( "ImportRTF" ) );
+ FnGetReader pFunction = reinterpret_cast<FnGetReader>( SwGlobals::getFilters().GetMswordLibSymbol( "ImportRTF" ) );
if ( pFunction )
return (*pFunction)();
@@ -833,7 +839,7 @@ Reader* GetRTFReader()
void GetRTFWriter( const String& rFltName, const String& rBaseURL, WriterRef& xRet )
{
- FnGetWriter pFunction = reinterpret_cast<FnGetWriter>( GetMswordLibSymbol( "ExportRTF" ) );
+ FnGetWriter pFunction = reinterpret_cast<FnGetWriter>( SwGlobals::getFilters().GetMswordLibSymbol( "ExportRTF" ) );
if ( pFunction )
(*pFunction)( rFltName, rBaseURL, xRet );
@@ -843,7 +849,7 @@ void GetRTFWriter( const String& rFltName, const String& rBaseURL, WriterRef& xR
Reader* GetWW8Reader()
{
- FnGetReader pFunction = reinterpret_cast<FnGetReader>( GetMswordLibSymbol( "ImportDOC" ) );
+ FnGetReader pFunction = reinterpret_cast<FnGetReader>( SwGlobals::getFilters().GetMswordLibSymbol( "ImportDOC" ) );
if ( pFunction )
return (*pFunction)();
@@ -853,7 +859,7 @@ Reader* GetWW8Reader()
void GetWW8Writer( const String& rFltName, const String& rBaseURL, WriterRef& xRet )
{
- FnGetWriter pFunction = reinterpret_cast<FnGetWriter>( GetMswordLibSymbol( "ExportDOC" ) );
+ FnGetWriter pFunction = reinterpret_cast<FnGetWriter>( SwGlobals::getFilters().GetMswordLibSymbol( "ExportDOC" ) );
if ( pFunction )
(*pFunction)( rFltName, rBaseURL, xRet );
@@ -866,7 +872,7 @@ typedef sal_uLong ( __LOADONCALLAPI *GetSaveWarning )( SfxObjectShell& );
sal_uLong SaveOrDelMSVBAStorage( SfxObjectShell& rDoc, SotStorage& rStor, sal_Bool bSaveInto, const String& rStorageName )
{
- SaveOrDel pFunction = reinterpret_cast<SaveOrDel>( GetMswordLibSymbol( "SaveOrDelMSVBAStorage_ww8" ) );
+ SaveOrDel pFunction = reinterpret_cast<SaveOrDel>( SwGlobals::getFilters().GetMswordLibSymbol( "SaveOrDelMSVBAStorage_ww8" ) );
if( pFunction )
return pFunction( rDoc, rStor, bSaveInto, rStorageName );
return ERRCODE_NONE;
@@ -874,7 +880,7 @@ sal_uLong SaveOrDelMSVBAStorage( SfxObjectShell& rDoc, SotStorage& rStor, sal_Bo
sal_uLong GetSaveWarningOfMSVBAStorage( SfxObjectShell &rDocS )
{
- GetSaveWarning pFunction = reinterpret_cast<GetSaveWarning>( GetMswordLibSymbol( "GetSaveWarningOfMSVBAStorage_ww8" ) );
+ GetSaveWarning pFunction = reinterpret_cast<GetSaveWarning>( SwGlobals::getFilters().GetMswordLibSymbol( "GetSaveWarningOfMSVBAStorage_ww8" ) );
if( pFunction )
return pFunction( rDocS );
return ERRCODE_NONE;
diff --git a/sw/source/ui/app/swdll.cxx b/sw/source/ui/app/swdll.cxx
index ff22a1c..9a9b43e 100644
--- a/sw/source/ui/app/swdll.cxx
+++ b/sw/source/ui/app/swdll.cxx
@@ -78,6 +78,11 @@ namespace SwGlobals
{
theSwDLLInstance::get();
}
+
+ sw::Filters & getFilters()
+ {
+ return theSwDLLInstance::get().get()->getFilters();
+ }
}
SwDLL::SwDLL()
@@ -126,7 +131,7 @@ SwDLL::SwDLL()
// Initialisation of Statics
::_InitCore();
- ::_InitFilter();
+ filters_.reset(new sw::Filters);
::_InitUI();
pModule->InitAttrPool();
@@ -148,7 +153,7 @@ SwDLL::~SwDLL()
SW_MOD()->RemoveAttrPool();
::_FinitUI();
- ::_FinitFilter();
+ filters_.reset();
::_FinitCore();
// sign out Objekt-Factory
SdrObjFactory::RemoveMakeObjectHdl(LINK(&aSwObjectFactory, SwObjectFactory, MakeObject ));
@@ -160,4 +165,10 @@ SwDLL::~SwDLL()
#endif
}
+sw::Filters & SwDLL::getFilters()
+{
+ OSL_ASSERT(filters_);
+ return *filters_.get();
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/ui/app/swdllimpl.hxx b/sw/source/ui/app/swdllimpl.hxx
index 7472436..1f7c17e 100644
--- a/sw/source/ui/app/swdllimpl.hxx
+++ b/sw/source/ui/app/swdllimpl.hxx
@@ -28,7 +28,14 @@
#ifndef SWDLL_IMPL_INCLUDE
#define SWDLL_IMPL_INCLUDE
-class SwDLL
+#include "sal/config.h"
+
+#include "boost/noncopyable.hpp"
+#include "boost/scoped_ptr.hpp"
+
+namespace sw { class Filters; }
+
+class SwDLL: private boost::noncopyable
{
public:
static void RegisterFactories();
@@ -37,6 +44,11 @@ public:
SwDLL();
~SwDLL();
+
+ sw::Filters & getFilters();
+
+private:
+ boost::scoped_ptr< sw::Filters > filters_;
};
#endif
More information about the Libreoffice-commits
mailing list