void SQTable::Rehash(bool force) { SQInteger oldsize=_numofnodes; //prevent problems with the integer division if(oldsize<4)oldsize=4; _HashNode *nold=_nodes; SQInteger nelems=CountUsed(); if (nelems >= oldsize-oldsize/4) /* using more than 3/4? */ AllocNodes(oldsize*2); else if (nelems <= oldsize/4 && /* less than 1/4? */ oldsize > MINPOWER2) AllocNodes(oldsize/2); else if(force) AllocNodes(oldsize); else return; _usednodes = 0; for (SQInteger i=0; i<oldsize; i++) { _HashNode *old = nold+i; if (sqi_type(old->key) != OT_NULL) NewSlot(old->key,old->val); } for(SQInteger k=0;k<oldsize;k++) nold[k].~_HashNode(); SQ_FREE(nold,oldsize*sizeof(_HashNode)); }
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); }
static void FreeCond_m (SRCThread_cl *self, SRCThread_Condition *c) { SQ_FREE (c->sq); EC_FREE (c->ec); }
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); } }
static void FreeMutex_m (SRCThread_cl *self, SRCThread_Mutex *mu) { SQ_FREE (mu->sq); EC_FREE (mu->ec); }