예제 #1
0
SQSharedState::~SQSharedState()
{
    if(_releasehook) { _releasehook(_foreignptr,0); _releasehook = NULL; }
    _constructoridx.Null();
    _table(_registry)->Finalize();
    _table(_consts)->Finalize();
    _table(_metamethodsmap)->Finalize();
    _registry.Null();
    _consts.Null();
    _metamethodsmap.Null();
    while(!_systemstrings->empty()) {
        _systemstrings->back().Null();
        _systemstrings->pop_back();
    }
    _thread(_root_vm)->Finalize();
    _root_vm.Null();
    _table_default_delegate.Null();
    _array_default_delegate.Null();
    _string_default_delegate.Null();
    _number_default_delegate.Null();
    _closure_default_delegate.Null();
    _generator_default_delegate.Null();
    _thread_default_delegate.Null();
    _class_default_delegate.Null();
    _instance_default_delegate.Null();
    _weakref_default_delegate.Null();
    _refs_table.Finalize();
#ifndef NO_GARBAGE_COLLECTOR
    SQCollectable *t = _gc_chain;
    SQCollectable *nx = NULL;
    if(t) {
        t->_uiRef++;
        while(t) {
            t->Finalize();
            nx = t->_next;
            if(nx) nx->_uiRef++;
            if(--t->_uiRef == 0)
                t->Release();
            t = nx;
        }
    }
    assert(_gc_chain==NULL); //just to proove a theory
    while(_gc_chain){
        _gc_chain->_uiRef++;
        _gc_chain->Release();
    }
#endif

    sq_delete(_types,SQObjectPtrVec);
    sq_delete(_systemstrings,SQObjectPtrVec);
    sq_delete(_metamethods,SQObjectPtrVec);
    sq_delete(_stringtable,SQStringTable);
    if(_scratchpad)SQ_FREE(_scratchpad,_scratchpadsize);
}
예제 #2
0
파일: sqapi.cpp 프로젝트: noriter/nit
void sq_close(HSQUIRRELVM v, SQGCFinalizeReport* optReport)
{
	SQSharedState *ss = _ss(v);
#ifndef NO_GARBAGE_COLLECTOR
		ss->_gc_finalize_report = optReport;
#endif
	sqi_table(ss->_root_table)->Finalize();
	sqi_thread(ss->_root_vm)->Finalize();
	sq_delete(ss, SQSharedState);
}
예제 #3
0
HSQUIRRELVM sq_newthread(HSQUIRRELVM friendvm, SQInteger initialstacksize)
{
	SQSharedState *ss;
	SQVM *v;
	ss=_ss(friendvm);
	
	v= (SQVM *)SQ_MALLOC(sizeof(SQVM));
	new (v) SQVM(ss);
	
	if(v->Init(friendvm, initialstacksize)) {
		friendvm->Push(v);
		return v;
	} else {
		sq_delete(v, SQVM);
		return NULL;
	}
}
예제 #4
0
HSQUIRRELVM sq_open(SQInteger initialstacksize)
{
	SQSharedState *ss;
	SQVM *v;
	sq_new(ss, SQSharedState);
	ss->Init();
	v = (SQVM *)SQ_MALLOC(sizeof(SQVM));
	new (v) SQVM(ss);
	ss->_root_vm = v;
	if(v->Init(NULL, initialstacksize)) {
		return v;
	} else {
		sq_delete(v, SQVM);
		return NULL;
	}
	return v;
}
예제 #5
0
void sq_close(HSQUIRRELVM v)
{
	SQSharedState *ss = _ss(v);
	_thread(ss->_root_vm)->Finalize();
	sq_delete(ss, SQSharedState);
}
예제 #6
0
void SQFuncState::PopChildState()
{
	SQFuncState *child = _childstates.back();
	sq_delete(child,SQFuncState);
	_childstates.pop_back();
}
예제 #7
0
파일: sqstate.cpp 프로젝트: noriter/nit
SQSharedState::~SQSharedState()
{
//	SSFinale(this);
	
	// HACK: to avoid circular reference between class and instances
	for (SQUnsignedInteger i = 0; i < _classes->size(); ++i)
	{
		SQWeakRef* w = sqi_weakref((*_classes)[i]);
		if (w->_obj._type == OT_NULL) continue;
		SQClass* c = sqi_class(w->_obj);
		// ignore classname (_methods[0]), namespace (_methods[1])
		for (SQUnsignedInteger j = 2; j < c->_methods.size(); ++j)
		{
			c->_methods[j].val.Null();
		}
	}

	_thisidx = _null_;
	_classnameidx = _null_;
	_namespaceidx = _null_;
	_initializeridx = _null_;
	_constructoridx = _null_;
	_destructoridx = _null_;
	_unnamed = _null_;
	sqi_table(_registry)->Finalize();
	sqi_table(_consts)->Finalize();
	sqi_table(_metamethodsmap)->Finalize();
	_registry = _null_;
	_consts = _null_;
	_metamethodsmap = _null_;
	while(!_systemstrings->empty()) {
		_systemstrings->back()=_null_;
		_systemstrings->pop_back();
	}
	sqi_thread(_root_vm)->Finalize();
	_root_table = _null_;
	_root_vm = _null_;
	_null_default_delegate = _null_;
	_table_default_delegate = _null_;
	_array_default_delegate = _null_;
	_string_default_delegate = _null_;
	_number_default_delegate = _null_;
	_closure_default_delegate = _null_;
	_generator_default_delegate = _null_;
	_thread_default_delegate = _null_;
	_class_default_delegate = _null_;
	_instance_default_delegate = _null_;
	_weakref_default_delegate = _null_;
	_nativeweakref_default_delegate = _null_;
	_refs_table.Finalize();

#ifndef NO_GARBAGE_COLLECTOR
	// sweepCount: count of isolated objects unlinked during above _null_ifying (especially roottable)
	SQInteger sweepCount = 0;
	sweepCount = _gc.fullSweep();

	// stickyCount: count of isolated objects which stay alive very above FullSweep() (perhaps native related)
	SQInteger stickyCount = 0;			
	stickyCount = _gc.finalize();

	if (_gc_finalize_report)
	{
		_gc_finalize_report->sweepCount = sweepCount;
		_gc_finalize_report->stickyCount = stickyCount;
		_gc_finalize_report->leakCount = _gc._objtotal;
	}
#endif

	sq_delete(_types,SQObjectPtrVec);
	sq_delete(_systemstrings,SQObjectPtrVec);
	sq_delete(_metamethods,SQObjectPtrVec);
	sq_delete(_classes,SQObjectPtrVec);
	sq_delete(_stringtable,SQStringTable);

	for (size_t i=0; i<_scratchpads.size(); ++i)
	{
		if (_scratchpads[i].buf)
			SQ_FREE(_scratchpads[i].buf, _scratchpads[i].size);
	}
}
예제 #8
0
void SQWeakRef::Release() { 
	if(ISREFCOUNTED(_obj._type)) { 
		_obj._unVal.pRefCounted->_weakref = NULL;
	} 
	sq_delete(this,SQWeakRef);
}
예제 #9
0
int TextbookAdapter_delete(SeqList *list,int pos){
	if(sq_delete(list->list,&(list->length),pos - 1))
		return DELETE_FAIL;
	return SUCCESS;
}