X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fsquirrel%2Fsquirrel%2Fsquserdata.h;h=d19255932f6c387b99f6a756e584f51e56a13cd5;hb=fea3446f05e1e7673607b835c269d3e8d1929ab3;hp=7b85913e740ec23d529f25f79d3051fe8f838940;hpb=60908c905544776c376421b8d3e12eeb936c068f;p=supertux.git diff --git a/src/squirrel/squirrel/squserdata.h b/src/squirrel/squirrel/squserdata.h index 7b85913e7..d19255932 100644 --- a/src/squirrel/squirrel/squserdata.h +++ b/src/squirrel/squirrel/squserdata.h @@ -1,45 +1,38 @@ -/* see copyright notice in squirrel.h */ -#ifndef _SQUSERDATA_H_ -#define _SQUSERDATA_H_ - -struct SQUserData : SQDelegable -{ - SQUserData(SQSharedState *ss){ _uiRef = 0; _delegate = 0; _hook = NULL; INIT_CHAIN(); ADD_TO_CHAIN(&_ss(this)->_gc_chain, this); } - ~SQUserData() - { - REMOVE_FROM_CHAIN(&_ss(this)->_gc_chain, this); - SetDelegate(NULL); - } - static SQUserData* Create(SQSharedState *ss, int size) - { - SQUserData* ud = (SQUserData*)SQ_MALLOC(sizeof(SQUserData)+(size-1)); - new (ud) SQUserData(ss); - ud->_size = size; - ud->_typetag = 0; - return ud; - } -#ifndef NO_GARBAGE_COLLECTOR - void Mark(SQCollectable **chain); - void Finalize(){SetDelegate(NULL);} -#endif - void Release() { - if (_hook) _hook(_val,_size); - int tsize = _size - 1; - this->~SQUserData(); - SQ_FREE(this, sizeof(SQUserData) + tsize); - } - void SetDelegate(SQTable *mt) - { - if (mt) __ObjAddRef(mt); - __ObjRelease(_delegate); - _delegate = mt; - } - - - int _size; - SQRELEASEHOOK _hook; - unsigned int _typetag; - SQChar _val[1]; -}; - -#endif //_SQUSERDATA_H_ +/* see copyright notice in squirrel.h */ +#ifndef _SQUSERDATA_H_ +#define _SQUSERDATA_H_ + +struct SQUserData : SQDelegable +{ + SQUserData(SQSharedState *ss){ _delegate = 0; _hook = NULL; INIT_CHAIN(); ADD_TO_CHAIN(&_ss(this)->_gc_chain, this); } + ~SQUserData() + { + REMOVE_FROM_CHAIN(&_ss(this)->_gc_chain, this); + SetDelegate(NULL); + } + static SQUserData* Create(SQSharedState *ss, SQInteger size) + { + SQUserData* ud = (SQUserData*)SQ_MALLOC(sizeof(SQUserData)+(size-1)); + new (ud) SQUserData(ss); + ud->_size = size; + ud->_typetag = 0; + return ud; + } +#ifndef NO_GARBAGE_COLLECTOR + void Mark(SQCollectable **chain); + void Finalize(){SetDelegate(NULL);} +#endif + void Release() { + if (_hook) _hook(_val,_size); + SQInteger tsize = _size - 1; + this->~SQUserData(); + SQ_FREE(this, sizeof(SQUserData) + tsize); + } + + SQInteger _size; + SQRELEASEHOOK _hook; + SQUserPointer _typetag; + SQChar _val[1]; +}; + +#endif //_SQUSERDATA_H_