On Fri, 23 Oct 2009, Pritpal Bedi wrote:

Hi,

> This is the code how object is created and GC applied.
> This code compiles perfect but receive GPF at its first invocation.

It's expected behavior. You are storing pointer to temporaryGC table
located on C stacks which is overload immediately by other functions
calls.

> //---------------------------------------//
> HB_GARBAGE_FUNC( Q_release )
> {
>    QGC_POINTER * p = ( QGC_POINTER * ) Cargo;
>    if( p && p->ph )
>    {
>       p->func( p->ph );
>    }
> }
> 
> const HB_GC_FUNCS QT_gcFuncs =
> {
>    Q_release,
>    hb_gcDummyMark
> };
> 
> HB_GC_FUNCS gcFuncs( void )
> {
>    return QT_gcFuncs;
> }

Should be:

   const HB_GC_FUNCS * gcFuncs( void ) { return &QT_gcFuncs; }

> void * hbqt_gcpointer( int iParam )
> {
>    HB_GC_FUNCS qt_gcFuncs = gcFuncs();
>    QGC_POINTER * p = ( QGC_POINTER * ) hb_parptrGC( &qt_gcFuncs, iParam );

Should be:

   void * hbqt_gcpointer( int iParam )
   {
      QGC_POINTER * p = ( QGC_POINTER * ) hb_parptrGC( gcFuncs(), iParam );


>    ///////////////////      I cannot reach past this point   ///////////////
>    if( p && p->ph )
>    {
>       return p->ph;
>    }
>    else
>    {
>       return hb_parptr( iParam );

This line is a bug which makes all other code unusable, i.e. it fully
breaks QPointer<> class functionality.

>    }
> }
> 
> //--------------------------------------------------//
> 
> QT_G_FUNC( release_QMainWindow )
> {
>    void * ph = ( void * ) Cargo;
>    if( ph )
>    {
>       const QMetaObject * m = ( ( QObject * ) ph )->metaObject();
>       if( ( QString ) m->className() != ( QString ) "QObject" )

This condition is something what I do not understand at all.
If some other code is buggy and can activate this destructor for
wrong objects then such code should be fixed instead of adding
workarounds for bugs.

>       {
>          delete ( ( QMainWindow * ) ph );
>          ph = NULL;
>       }
>    }
> }
> Where is the error ?

See above. Few things can cause GPF in such code though probably
gcFuncs() usage was the 1-st reason.
I strongly suggest to encapsulate all classes in separate files
with separate destructors without and tricks with explicit casting
and with public functions to retrieve object pointers from HVM items
and/or parameters.

best regards,
Przemek
_______________________________________________
Harbour mailing list
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to