On Sun, 18 Oct 2009, Pritpal Bedi wrote:
Hi Pritpal,
[...]
> > void * hbqt_gcpointer( int iParam, HB_GARBAGE_FUNC_PTR pFunc )
> > {
> > void ** ph = ( void ** ) hb_parptrGC( pFunc, iParam );
> > return ( ph && * ph ? * ph : hb_parptr( iParam ) );
> > }
> > PRG Call:
> > oWnd := QMainWindow():new()
> > oWnd:anyAction() => GPFs
> Nothing wrong. Code is correct. GPF is due to way
> .prg class structure passes pointer to parent class and then
> the methods of parent class cast the pointers to its native garbage pointer.
I do not think so. Any code like:
return ( ph && * ph ? * ph : hb_parptr( iParam ) );
is potential source of GPF. If ph is NULL then user passed wrong parameter.
If *ph is NULL then parameter was freed by QT. In such context using
hb_parptr( iParam )
breaks functionality given by using QPointer class because the fact that
references were cleared is ignored and code code access wrong memory
area. It can be source of any other unexpected behavior so it's hard to
analyze your problems because it's possible that they are caused by above
peace of code.
> Let's analyze:
[...]
> HB_FUNC( QT_QWIDGET_SHOW )
> {
> hbqt_par_QWidget( 1 )->show();
> }
This is also very bad code. It does not check if pointer returned by
hbqt_par_QWidget( 1 ) is not NULL so it will simply GPF when other code
(detection of freed pointer or wrong user parameters) will work as expected.
I strongly suggest to introduce RT errors and at least basic parameter
verification, i.e.:
void * hbqt_gcpointerRTE( int iParam, HB_GARBAGE_FUNC_PTR pFunc )
{
void ** ph = ( void ** ) hb_parptrGC( pFunc, iParam );
if( ph && * ph )
return * ph;
hb_errRT_BASE( EG_ARG, 1123, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
return NULL;
}
#define hbqt_par_QWidget( n ) \
( ( QWidget * ) hbqt_gcpointerRTE( n, release_QWidget ) )
[...]
HB_FUNC( QT_QWIDGET_SHOW )
{
QWidget * qw = hbqt_par_QWidget( 1 );
if( qw )
{
qw->show();
}
}
otherwise you will have to fight with unexpected GPFs and it will be very
hard to introduce extensions without touching most of existing code so
it's very important to encode basic parameters validation at beginning
and then only extend it.
best regards,
Przemek
_______________________________________________
Harbour mailing list
[email protected]
http://lists.harbour-project.org/mailman/listinfo/harbour