Article # 52, added by Geoworks, historical record
| first | previous | index | next | last |

Using @self instead of fixing up pself.



* Version 3.0 of the GEOS kernel will now automatically fix 'pself'
  in C message handlers. The app writer no longer need worry about
  'pself' becoming invalid.

GOC:
* Added a new keyword '@self' to be used in place of 'pself'. You can 
  still continue to use 'pself' as '@self' is just an alias for 'pself'.  
  But using '@self' will allow you to pass the instance data pointer to
  functions and not worry about it becoming invalid. You never need to
  fixup '@self', it will always point to your objects instance data.

  Example:

	@method MyTriggerClass, MSG_GEN_SET_USABLE {
              /*
               * pself and @self are both pointers to MyTriggerInstance. 
               */
	    if ( @self->GI_states != pself->GI_states ) {
		CFatalError( ERROR_IN_MY_CODE );
            }
	    @callsuper();
              /*
               * No need to deref since oself and @self are always valid
               * after a system call (@callsuper or @call method).
               */
	    if ( !( @self->GI_states & GS_USABLE ) ) {
		CFatalError( ERROR_IN_MY_CODE );
            }
	    AllocateChunk( @self, oself );
	}

	void AllocateChunk( MyTriggerInstance *@self, optr oself ) {
              /*
               * you can continue to use @self as you did in the 
               * message handler.
               */
	    if ( !( @self->GI_states & GS_USABLE ) ) {
		CFatalError( ERROR_IN_JOONS_CODE );
            }
              /*
               * and @self will remain valid even if the object 
               * block moves.
               */
	    @self->MTI_chunk = LMemAlloc( OptrToHandle( oself ), 4096 );
	}