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.
This commit is contained in:
Stephan Bergmann
2011-10-06 09:28:20 +02:00
parent 8529da0851
commit 06fdd1585d
6 changed files with 80 additions and 30 deletions

View File

@@ -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();

View File

@@ -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();

View File

@@ -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

View File

@@ -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;

View File

@@ -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: */

View File

@@ -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