On Mon, 12 Oct 2009, Pritpal Bedi wrote: Hi,
> I did a few experiments which lead to some > satisfying results but also with some weired ones, > which at the moment I am unable to fix, your help is > requested in highest needs. > 1. Download attached are files which outlines my concept. > http://www.nabble.com/file/p25865022/hbqt_misc.zip hbqt_misc.zip > 2. Redistribute them in respective folders. > 3. Make the following change in QWidget.cpp > /* > * QSize size () const > */ > HB_FUNC( QT_QWIDGET_SIZE ) > { > #if 0 > hb_retptr( new QSize( hbqt_par_QWidget( 1 )->size() ) ); > #else > void ** ph = ( void ** ) hb_gcAlloc( sizeof( void * ), QObject_release ); > * ph = new QSize( hbqt_par_QWidget( 1 )->size() ) ; > hb_retptrGC( ph ); > #endif > } > 4. Issue - \harbour\contrib\hbqt\generator:\>hbmk2 hbqtgen -run > 5. Recompile HBQT.lib. > 6. Move to tests folder and compile demoqt.prg as > hbmk2 demoqt -lxhb -Lc:\qt\2009.01\qt\lib -run > 7. Open up some debugger utility to view the debug messages. > You may uncomment block at line # 143 to generate GPF right > after demoqt.exe shows up. > THE REAL ISSUE: hbqt_slots.cpp > =========== > HB_GARBAGE_FUNC( QObject_release ) > { > char str[50]; > void ** ph = ( void ** ) Cargo; > hb_snprintf( str, sizeof( str ), "QObject_release 0" ); OutputDebugString( > str ); > if( ph && * ph ) > { > try > { > const QMetaObject * m = ( ( QObject * ) * ph )->metaObject(); > hb_snprintf( str, sizeof( str ), "QObject_release 000" ); > OutputDebugString( str ); > if( m != NULL ) > { > const char * name = m->className(); > hb_snprintf( str, sizeof( str ), "QObject_release 1 %s", m->className() ); > OutputDebugString( str ); > delete ( ( QObject * ) * ph ); > } > * ph = NULL; > } > catch ( int &e ) > { > > } > } > hb_snprintf( str, sizeof( str ), "QObject_release 2" ); OutputDebugString( > str ); > } > The GPF is generated right at > const QMetaObject * m = ( ( QObject * ) * ph )->metaObject(); > This can happen in two situations: > 1. If the <ph> is not of type <QObject> : in case we > uncomment block shown above. What seem to be expected. > 2. If the object is released by Qt itself and detection line if( ph && * > ph ) > does not reconizes that the pointer has been releases. This detection works only for object released by GC block destructors or released/detached by your own helper functions which explicitly clear the reference inside ph. It does not help in any way to detect that object was released by QT code. To resolve this problem you should "detach" all objects which are managed by QT and will be released by QT code. If it's hard for you to implement such detaching then you should use guarded pointers as Teo suggested and store them in GC block instead of direct QObject pointers. > Please note that try{}catch{} mechanism is not helping any way. It usually do not help to resolve programmers errors so it's not a solution. Never create code which uses try/catch as some type of workaround for bugs in code, i.e. to hide problems with doubly free pointers. > I need following favours: > 1. If it can be detected the <ph> is a valid pointer. See above. > 2. If it could be determined which type of object <ph> is referring to. > [ All objects deriving from QObject are detected fine but any other > class does not respect this construct, i.e. QSize and allied > classes ] You have to use different GC blocks with different destructors for each class which do not have common destructor. You can also add 'type' filed and try to implement it using single GC destructor function but IMO it's not good idea. > 3. If GPF could be trapped anyway if any of the above implementions are > not possible. It can be trapped but it will not resolve any problems so fighting with it it's a waste of time and in the worst case you will only hide very serious application bugs which will still exists but problems will be exploited in different places, i.e. GPFs in valid code which fails due to memory corruption caused by hidden real errors. best regards, Przemek _______________________________________________ Harbour mailing list [email protected] http://lists.harbour-project.org/mailman/listinfo/harbour
