memory leaks fixed

This commit is contained in:
Uwe Rathmann 2018-02-28 08:37:40 +01:00
parent 28660cca7d
commit 6b87084678
4 changed files with 37 additions and 33 deletions

View File

@ -12,12 +12,21 @@
#include <private/qobject_p.h> #include <private/qobject_p.h>
namespace
{
// to get access to the private section of QSlotObjectBase
struct SlotObject
{
QAtomicInt ref;
QskMetaCall::Invokable::InvokeFunction invoke;
};
}
namespace QskMetaCall namespace QskMetaCall
{ {
inline Invokable::InvokeFunction invokeCall( const Invokable* invokable ) inline Invokable::InvokeFunction invokeCall( const Invokable* invokable )
{ {
struct Data { QAtomicInt dummy; Invokable::InvokeFunction invoke; }; return ( ( SlotObject* )( invokable ) )->invoke;
return ( ( Data* )( invokable ) )->invoke;
} }
int Invokable::typeInfo() const int Invokable::typeInfo() const
@ -31,6 +40,11 @@ namespace QskMetaCall
return value; return value;
} }
int Invokable::refCount() const
{
return ( ( SlotObject* )( this ) )->ref.load();
}
} }
namespace namespace
@ -45,7 +59,6 @@ namespace
QMetaCallEvent( invokable, nullptr, 0, nargs, types, args, semaphore ), QMetaCallEvent( invokable, nullptr, 0, nargs, types, args, semaphore ),
m_invokable ( invokable ) m_invokable ( invokable )
{ {
invokable->ref();
} }
virtual ~FunctionCallEvent() virtual ~FunctionCallEvent()

View File

@ -35,6 +35,7 @@ namespace QskMetaCall
enum { TypeInfo = NumOperations + 1 }; enum { TypeInfo = NumOperations + 1 };
int typeInfo() const; int typeInfo() const;
int refCount() const;
protected: protected:
explicit Invokable( InvokeFunction f ): explicit Invokable( InvokeFunction f ):

View File

@ -10,7 +10,7 @@
QskMetaCallback::QskMetaCallback( const QObject* object, QskMetaCallback::QskMetaCallback( const QObject* object,
const QMetaMethod& method, Qt::ConnectionType connectionType ): const QMetaMethod& method, Qt::ConnectionType connectionType ):
m_object( const_cast< QObject* >( object ) ), m_object( const_cast< QObject* >( object ) ),
m_method( method ), m_method( new QMetaMethod( method ) ),
m_type( MetaMethod ), m_type( MetaMethod ),
m_connectionType( static_cast< ushort >( connectionType & ~Qt::UniqueConnection ) ) m_connectionType( static_cast< ushort >( connectionType & ~Qt::UniqueConnection ) )
{ {
@ -19,7 +19,7 @@ QskMetaCallback::QskMetaCallback( const QObject* object,
QskMetaCallback::QskMetaCallback( const QObject* object, QskMetaCallback::QskMetaCallback( const QObject* object,
const QskMetaFunction& function, Qt::ConnectionType connectionType ): const QskMetaFunction& function, Qt::ConnectionType connectionType ):
m_object( const_cast< QObject* >( object ) ), m_object( const_cast< QObject* >( object ) ),
m_function( function ), m_function( new QskMetaFunction( function ) ),
m_type( MetaFunction ), m_type( MetaFunction ),
m_connectionType( static_cast< ushort >( connectionType & ~Qt::UniqueConnection ) ) m_connectionType( static_cast< ushort >( connectionType & ~Qt::UniqueConnection ) )
{ {
@ -40,11 +40,11 @@ QskMetaCallback::QskMetaCallback( const QskMetaCallback& other ):
switch( m_type ) switch( m_type )
{ {
case MetaMethod: case MetaMethod:
m_method = other.m_method; m_method = new QMetaMethod( *other.m_method );
break; break;
case MetaFunction: case MetaFunction:
m_function = other.m_function; m_function = new QskMetaFunction( *other.m_function );
break; break;
default: default:
@ -68,18 +68,12 @@ QskMetaCallback& QskMetaCallback::operator=( const QskMetaCallback& other )
m_type = other.m_type; m_type = other.m_type;
} }
switch( m_type ) if ( other.m_type != Invalid )
{ {
case MetaMethod: if ( other.m_type == MetaMethod )
m_method = other.m_method; m_method = new QMetaMethod( *other.m_method );
break; else
m_function = new QskMetaFunction( *other.m_function );
case MetaFunction:
m_function = other.m_function;
break;
default:
break;
} }
return *this; return *this;
@ -95,11 +89,13 @@ void QskMetaCallback::reset()
switch( m_type ) switch( m_type )
{ {
case MetaMethod: case MetaMethod:
m_method.~QMetaMethod(); delete m_method;
m_method = nullptr;
break; break;
case MetaFunction: case MetaFunction:
m_function.~QskMetaFunction(); delete m_function;
m_function = nullptr;
break; break;
default: default:
@ -117,17 +113,17 @@ QVector< int > QskMetaCallback::parameterTypes() const
{ {
case MetaMethod: case MetaMethod:
{ {
const int paramCount = m_method.parameterCount(); const int paramCount = m_method->parameterCount();
paramTypes.reserve( paramCount ); paramTypes.reserve( paramCount );
for ( int i = 0; i < paramCount; i++ ) for ( int i = 0; i < paramCount; i++ )
paramTypes += m_method.parameterType( i ); paramTypes += m_method->parameterType( i );
break; break;
} }
case MetaFunction: case MetaFunction:
{ {
auto types = m_function.parameterTypes(); auto types = m_function->parameterTypes();
if ( types ) if ( types )
{ {
while ( *types ) while ( *types )
@ -152,12 +148,12 @@ void QskMetaCallback::invoke( void* args[] )
case MetaMethod: case MetaMethod:
{ {
if ( object ) if ( object )
QskMetaCall::invoke( object, m_method, args, connectionType() ); QskMetaCall::invoke( object, *m_method, args, connectionType() );
break; break;
} }
case MetaFunction: case MetaFunction:
{ {
m_function.invoke( object, args, connectionType() ); m_function->invoke( object, args, connectionType() );
break; break;
} }

View File

@ -59,17 +59,11 @@ private:
QPointer< const QObject > m_object; QPointer< const QObject > m_object;
#if 1
/*
This union does not work - call of constructors
are missing
*/
union union
{ {
QskMetaFunction m_function; QskMetaFunction* m_function;
QMetaMethod m_method; QMetaMethod* m_method;
}; };
#endif
int m_type : 3; int m_type : 3;
ushort m_connectionType : 3; ushort m_connectionType : 3;