connectivity/source/drivers/kab/KConnection.cxx |   35 +++++++++++------------
 connectivity/source/drivers/kab/KConnection.hxx |   20 ++++++++-----
 connectivity/source/drivers/kab/KDriver.cxx     |   36 ++++++++++--------------
 connectivity/source/drivers/kab/KDriver.hxx     |   13 ++++----
 connectivity/source/drivers/kab/KStatement.cxx  |    2 -
 5 files changed, 54 insertions(+), 52 deletions(-)

New commits:
commit 6a319aa381a1ab704a6c523198baccca021918bd
Author: Stephan Bergmann <sberg...@redhat.com>
Date:   Fri Feb 27 16:35:01 2015 +0100

    Clean up interface between kab and kabdrv libs
    
    ...to not need to see the KDriver class from the outer kab wrapper in the 
inner
    kabdrv, and the KConnection class from the inner kabdrv in the outer kab
    wrapper, which caused false positives from -fsanitize=vptr.
    
    Change-Id: Ifae4c837ba4da660df0928b50de5114d567e5d9c

diff --git a/connectivity/source/drivers/kab/KConnection.cxx 
b/connectivity/source/drivers/kab/KConnection.cxx
index e98ee24..1938336 100644
--- a/connectivity/source/drivers/kab/KConnection.cxx
+++ b/connectivity/source/drivers/kab/KConnection.cxx
@@ -22,7 +22,6 @@
 #include "KDatabaseMetaData.hxx"
 #include "KStatement.hxx"
 #include "KPreparedStatement.hxx"
-#include "KDriver.hxx"
 #include "KCatalog.hxx"
 #include <com/sun/star/sdbc/ColumnValue.hpp>
 #include <com/sun/star/sdbc/TransactionIsolation.hpp>
@@ -37,23 +36,20 @@ using namespace com::sun::star::sdbcx;
 
 IMPLEMENT_SERVICE_INFO(KabConnection, 
"com.sun.star.sdbc.drivers.KabConnection", "com.sun.star.sdbc.Connection")
 
-KabConnection::KabConnection(KabDriver* _pDriver)
+KabConnection::KabConnection(
+    css::uno::Reference<css::uno::XComponentContext> const & componentContext,
+    css::uno::Reference<css::sdbc::XDriver> const & driver)
          : OMetaConnection_BASE(m_aMutex),
-         OSubComponent<KabConnection, 
KabConnection_BASE>((::cppu::OWeakObject*)_pDriver, this),
+         OSubComponent<KabConnection, KabConnection_BASE>(driver, this),
          m_xMetaData(NULL),
          m_pAddressBook(NULL),
-         m_pDriver(_pDriver)
-{
-    m_pDriver->acquire();
-}
+         m_xComponentContext(componentContext)
+{}
 
 KabConnection::~KabConnection()
 {
     if (!isClosed())
         close();
-
-    m_pDriver->release();
-    m_pDriver = NULL;
 }
 
 void SAL_CALL KabConnection::release() throw()
@@ -61,15 +57,15 @@ void SAL_CALL KabConnection::release() throw()
     relase_ChildImpl();
 }
 
-void KabConnection::construct(const OUString&, const Sequence< PropertyValue 
>&) throw(SQLException)
+//TODO: is doing this after the ctor, and the manual ref counting really
+// necessary?
+void KabConnection::construct()
 {
     osl_atomic_increment( &m_refCount );
 
     // create a KDE address book object
     m_pAddressBook = KABC::StdAddressBook::self();
     KABC::StdAddressBook::setAutomaticSave(false);
-// perhaps we should analyze the URL to know whether the addressbook is local, 
over LDAP, etc...
-// perhaps we should get some user and password information from "info" 
properties
 
     osl_atomic_decrement( &m_refCount );
 }
@@ -309,12 +305,15 @@ Reference< XTablesSupplier > SAL_CALL 
KabConnection::createCatalog()
     return m_pAddressBook;
 }
 
-extern "C" SAL_DLLPUBLIC_EXPORT void*  SAL_CALL createKabConnection( void* 
_pDriver )
+extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
+createKabConnection(
+    css::uno::Reference<css::uno::XComponentContext> const & componentContext,
+    css::uno::Reference<css::sdbc::XDriver> const & driver)
 {
-    KabConnection* pConnection = new KabConnection( static_cast< KabDriver* >( 
_pDriver ) );
-    // by definition, the pointer crossing library boundaries as void ptr is 
acquired once
-    pConnection->acquire();
-    return pConnection;
+    rtl::Reference<KabConnection> con(
+        new KabConnection(componentContext, driver));
+    con->construct();
+    return cppu::acquire(con.get());
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/connectivity/source/drivers/kab/KConnection.hxx 
b/connectivity/source/drivers/kab/KConnection.hxx
index 848dce4..aeb6b3f 100644
--- a/connectivity/source/drivers/kab/KConnection.hxx
+++ b/connectivity/source/drivers/kab/KConnection.hxx
@@ -37,6 +37,9 @@ namespace KABC
     class StdAddressBook;
     class AddressBook;
 }
+namespace com { namespace sun { namespace star { namespace sdbc {
+    class XDriver;
+} } } }
 
 namespace connectivity
 {
@@ -48,8 +51,6 @@ namespace connectivity
                                                 
::com::sun::star::lang::XServiceInfo
                                             > OMetaConnection_BASE;
 
-        class KabDriver;
-
         typedef OMetaConnection_BASE                KabConnection_BASE; // 
implements basics and text encoding
         typedef std::vector< ::com::sun::star::uno::WeakReferenceHelper > 
OWeakRefArray;
 
@@ -69,14 +70,17 @@ namespace connectivity
                                                                     // for 
this Connection
 
             ::KABC::StdAddressBook*                 m_pAddressBook; // the 
address book
-            KabDriver*                              m_pDriver;      // pointer 
to the owning driver object
+            css::uno::Reference<css::uno::XComponentContext> 
m_xComponentContext;
             ::com::sun::star::uno::Reference< 
::com::sun::star::sdbcx::XTablesSupplier>
                                                     m_xCatalog;     // needed 
for the SQL interpreter
 
         public:
-            virtual void construct( const OUString& url,const 
::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& 
info) throw(::com::sun::star::sdbc::SQLException);
+            void construct();
 
-            KabConnection(KabDriver* _pDriver);
+            KabConnection(
+                css::uno::Reference<css::uno::XComponentContext> const &
+                    componentContext,
+                css::uno::Reference<css::sdbc::XDriver> const & driver);
             virtual ~KabConnection();
 
             void closeAllStatements () throw( 
::com::sun::star::sdbc::SQLException);
@@ -120,8 +124,10 @@ namespace connectivity
             // needed for the SQL interpreter
             ::com::sun::star::uno::Reference< 
::com::sun::star::sdbcx::XTablesSupplier > SAL_CALL createCatalog();
 
-            // accessors
-            inline KabDriver*           getDriver()         const { return 
m_pDriver;}
+            css::uno::Reference<css::uno::XComponentContext>
+            getComponentContext() const
+            { return m_xComponentContext; }
+
                    ::KABC::AddressBook* getAddressBook()    const;
         };
     }
diff --git a/connectivity/source/drivers/kab/KDriver.cxx 
b/connectivity/source/drivers/kab/KDriver.cxx
index e13bbac..582e85e 100644
--- a/connectivity/source/drivers/kab/KDriver.cxx
+++ b/connectivity/source/drivers/kab/KDriver.cxx
@@ -17,12 +17,15 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+#include <sal/config.h>
+
+#include <cassert>
 
 #include "KDriver.hxx"
 #include "KDEInit.h"
-#include "KConnection.hxx"
 #include <rtl/strbuf.hxx>
 
+#include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/configuration/theDefaultProvider.hpp>
 #include <com/sun/star/sdb/SQLContext.hpp>
 #include <com/sun/star/lang/NullPointerException.hpp>
@@ -287,15 +290,13 @@ void KabImplModule::impl_throwKdeTooNewException()
 }
 
 
-KabConnection* KabImplModule::createConnection( KabDriver* _pDriver ) const
+css::uno::Reference<css::sdbc::XConnection> KabImplModule::createConnection(
+    KabDriver * driver) const
 {
-    OSL_PRECOND( m_hConnectorModule, "KabImplModule::createConnection: not 
initialized!" );
-
-    void* pUntypedConnection = (*m_pConnectionFactoryFunc)( _pDriver );
-    if ( !pUntypedConnection )
-        throw RuntimeException();
-
-    return static_cast< KabConnection* >( pUntypedConnection );
+    assert(m_pConnectionFactoryFunc != nullptr);
+    return css::uno::Reference<css::sdbc::XConnection>(
+        (*m_pConnectionFactoryFunc)(m_xContext, driver),
+        css::uno::UNO_QUERY_THROW);
 }
 
 
@@ -382,25 +383,20 @@ Sequence< OUString > SAL_CALL 
KabDriver::getSupportedServiceNames(  ) throw(Runt
     return getSupportedServiceNames_Static();
 }
 
-Reference< XConnection > SAL_CALL KabDriver::connect( const OUString& url, 
const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException, 
std::exception)
+Reference< XConnection > SAL_CALL KabDriver::connect( const OUString&, const 
Sequence< PropertyValue >& ) throw(SQLException, RuntimeException, 
std::exception)
 {
     ::osl::MutexGuard aGuard(m_aMutex);
 
     m_aImplModule.init();
 
     // create a new connection with the given properties and append it to our 
vector
-    KabConnection* pConnection = m_aImplModule.createConnection( this );
-    SAL_WARN_IF( !pConnection, "connectivity." KAB_SERVICE_NAME, 
"KabDriver::connect: no connection has been created by the factory!" );
-
-    // by definition, the factory function returned an object which was 
acquired once
-    Reference< XConnection > xConnection = pConnection;
-    pConnection->release();
-
-    // late constructor call which can throw exception and allows a correct 
dtor call when so
-    pConnection->construct( url, info );
+    // perhaps we should pass url and info into createConnection:
+    // perhaps we should analyze the URL to know whether the addressbook is 
local, over LDAP, etc...
+    // perhaps we should get some user and password information from "info" 
properties
+    Reference< XConnection > xConnection(m_aImplModule.createConnection(this));
 
     // remember it
-    m_xConnections.push_back( WeakReferenceHelper( *pConnection ) );
+    m_xConnections.push_back( WeakReferenceHelper( xConnection ) );
 
     return xConnection;
 }
diff --git a/connectivity/source/drivers/kab/KDriver.hxx 
b/connectivity/source/drivers/kab/KDriver.hxx
index 4987ef7..fb998bc 100644
--- a/connectivity/source/drivers/kab/KDriver.hxx
+++ b/connectivity/source/drivers/kab/KDriver.hxx
@@ -31,13 +31,16 @@ namespace connectivity
 {
     namespace kab
     {
-        class KabConnection;
         class KabDriver;
 
-        typedef void*   (SAL_CALL * ConnectionFactoryFunction)( void* _pDriver 
);
+        extern "C" {
+        typedef css::uno::XInterface * (SAL_CALL * ConnectionFactoryFunction)(
+            css::uno::Reference<css::uno::XComponentContext> const &,
+            css::uno::Reference<css::sdbc::XDriver> const &);
         typedef void    (SAL_CALL * ApplicationInitFunction)( void );
         typedef void    (SAL_CALL * ApplicationShutdownFunction)( void );
         typedef int     (SAL_CALL * KDEVersionCheckFunction)( void );
+        }
 
         typedef std::vector< ::com::sun::star::uno::WeakReferenceHelper > 
OWeakRefArray;
 
@@ -99,7 +102,8 @@ namespace connectivity
                 @raises ::com::sun::star::uno::RuntimeException
                     if no connection object could be created (which is a 
severe error, normally impossible)
             */
-            KabConnection*  createConnection( KabDriver* _pDriver ) const;
+            css::uno::Reference<css::sdbc::XConnection> createConnection(
+                KabDriver * driver) const;
 
         private:
             /** loads the implementation module and retrieves the needed 
symbols
@@ -162,9 +166,6 @@ namespace connectivity
             static OUString getImplementationName_Static(  ) 
throw(::com::sun::star::uno::RuntimeException);
             static ::com::sun::star::uno::Sequence< OUString > 
getSupportedServiceNames_Static(  ) throw 
(::com::sun::star::uno::RuntimeException);
 
-            ::com::sun::star::uno::Reference< 
::com::sun::star::uno::XComponentContext >
-            getComponentContext() const { return m_xContext; }
-
             /** returns the driver's implementation name (being pure ASCII) 
for reference in various places
             */
             static const sal_Char*  impl_getAsciiImplementationName();
diff --git a/connectivity/source/drivers/kab/KStatement.cxx 
b/connectivity/source/drivers/kab/KStatement.cxx
index 1c35390..f8b2ca2 100644
--- a/connectivity/source/drivers/kab/KStatement.cxx
+++ b/connectivity/source/drivers/kab/KStatement.cxx
@@ -62,7 +62,7 @@ IMPLEMENT_SERVICE_INFO(KabStatement, 
"com.sun.star.sdbc.drivers.KabStatement", "
 KabCommonStatement::KabCommonStatement(KabConnection* _pConnection )
     : KabCommonStatement_BASE(m_aMutex),
     OPropertySetHelper(KabCommonStatement_BASE::rBHelper),
-    m_aParser(_pConnection->getDriver()->getComponentContext()),
+    m_aParser(_pConnection->getComponentContext()),
     m_aSQLIterator(_pConnection, _pConnection->createCatalog()->getTables(), 
m_aParser, NULL ),
     m_pParseTree(NULL),
     m_pConnection(_pConnection),
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to