void objectString_Release( asstring_t *obj ) { obj->asRefCount--; clamp_low( obj->asRefCount, 0 ); if( !obj->asRefCount ) { QAS_Free( obj->buffer ); QAS_Free( obj ); } }
int qasReleaseContext( int contextHandle ) { contexthandle_t *prevhandle; contexthandle_t *ch = qasGetContextHandle( contextHandle ); if( !ch ) return QASINVALIDHANDLE; if( ch == contextHandlesHead ) { contextHandlesHead = ch->next; } else { // find the handle that links our handle as next for( prevhandle = contextHandlesHead; prevhandle != NULL; prevhandle = prevhandle->next ) { if( prevhandle->next == ch ) { prevhandle->next = ch->next; break; } } } ch->ctx->Release(); QAS_Free( ch ); return 1; }
asstring_t *objectString_AssignString( asstring_t *self, const char *string, size_t strlen ) { if( strlen >= self->size ) { QAS_Free( self->buffer ); self->size = strlen + 1; self->buffer = (char *)QAS_Malloc( self->size ); } self->len = strlen; Q_strncpyz( self->buffer, string, self->size ); return self; }
int qasReleaseScriptEngine( int engineHandle ) { enginehandle_t *prevhandle; enginehandle_t *eh = qasGetEngineHandle( engineHandle ); contexthandle_t *ch, *next_ch, *prev_ch; if( !eh ) return QASINVALIDHANDLE; // release all contexts linked to this engine for( ch = contextHandlesHead, prev_ch = NULL; ch != NULL; ch = next_ch ) { next_ch = ch->next; if( ch->owner == engineHandle ) { if( prev_ch ) prev_ch->next = next_ch; qasReleaseContext( ch->handle ); } else { prev_ch = ch; } } // release the engine handle if( eh == engineHandlesHead ) { engineHandlesHead = eh->next; } else { // find the handle that links our handle as next for( prevhandle = engineHandlesHead; prevhandle != NULL; prevhandle = prevhandle->next ) { if( prevhandle->next == eh ) { prevhandle->next = eh->next; break; } } } eh->engine->Release(); QAS_Free( eh ); return 1; }
static asstring_t *objectString_AddAssignString( asstring_t *self, const char *string, size_t strlen ) { if( strlen ) { char *tem = self->buffer; self->len = strlen + self->len; self->size = self->len + 1; self->buffer = (char *)QAS_Malloc( self->size ); Q_snprintfz( self->buffer, self->size, "%s%s", tem, string ); QAS_Free( tem ); } return self; }
int qasCreateContext( int engineHandle ) { asIScriptContext *ctx; contexthandle_t *ch; enginehandle_t *eh; int error; eh = qasGetEngineHandle( engineHandle ); if( !eh ) return QASINVALIDHANDLE; // always new ctx = eh->engine->CreateContext(); if( !ctx ) return -1; ch = ( contexthandle_t * )QAS_Malloc( sizeof( contexthandle_t ) ); // We don't want to allow the script to hang the application, e.g. with an // infinite loop, so we'll use the line callback function to set a timeout // that will abort the script after a certain time. Before executing the // script the timeOut variable will be set to the time when the script must // stop executing. error = ctx->SetLineCallback( asFUNCTION(qasGenericLineCallback), &ch->timeOut, asCALL_CDECL ); if( error < 0 ) { QAS_Free( ch ); return -1; } ch->ctx = ctx; ch->handle = numRegisteredContexts++; ch->owner = eh->handle; ch->next = contextHandlesHead; contextHandlesHead = ch; return ch->handle; }
static void qasFree( void *mem ) { QAS_Free( mem ); }