From: John L. <jr...@us...> - 2007-07-22 04:38:35
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv12109/wxLua/modules/wxlua/src Modified Files: wxlbind.cpp wxlstate.cpp wxlua.cpp Log Message: Add parameter to wxLuaState::RemoveTrackedObject to select how we untrack it Fixes removing derived methods for the %ungc binding tag Index: wxlua.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlua.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** wxlua.cpp 14 Jun 2007 23:59:48 -0000 1.2 --- wxlua.cpp 22 Jul 2007 04:38:30 -0000 1.3 *************** *** 41,45 **** wxLuaState * self = (wxLuaState *)wxlState.GetUserDataType(1, s_wxluatag_wxLuaState); // if removed from tracked mem list, reset the tag so that gc() is not called on this object. ! if ((self != NULL) && wxlState.RemoveTrackedObject(self)) { lua_pushnil(L); --- 41,45 ---- wxLuaState * self = (wxLuaState *)wxlState.GetUserDataType(1, s_wxluatag_wxLuaState); // if removed from tracked mem list, reset the tag so that gc() is not called on this object. ! if ((self != NULL) && wxlState.RemoveTrackedObject(self, wxLuaState::DELETE_OBJECT|wxLuaState::CLEAR_LUA_TRACKED|wxLuaState::CLEAR_DERIVED_METHODS)) { lua_pushnil(L); *************** *** 128,132 **** wxLuaObject * self = (wxLuaObject *)wxlState.GetUserDataType(1, s_wxluatag_wxLuaObject); // if removed from tracked mem list, reset the tag so that gc() is not called on this object. ! if ((self != NULL) && wxlState.RemoveTrackedObject(self)) { lua_pushnil(L); --- 128,132 ---- wxLuaObject * self = (wxLuaObject *)wxlState.GetUserDataType(1, s_wxluatag_wxLuaObject); // if removed from tracked mem list, reset the tag so that gc() is not called on this object. ! if ((self != NULL) && wxlState.RemoveTrackedObject(self, wxLuaState::DELETE_OBJECT|wxLuaState::CLEAR_LUA_TRACKED|wxLuaState::CLEAR_DERIVED_METHODS)) { lua_pushnil(L); Index: wxlstate.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlstate.cpp,v retrieving revision 1.122 retrieving revision 1.123 diff -C2 -d -r1.122 -r1.123 *** wxlstate.cpp 19 Jul 2007 03:09:46 -0000 1.122 --- wxlstate.cpp 22 Jul 2007 04:38:29 -0000 1.123 *************** *** 398,401 **** --- 398,411 ---- } + void LUACALL wxlua_tuntrackuserdata(lua_State *L, const void *u) + { + wxlua_pushkey_wxLuaObjects(L); + lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push result (the object table) + lua_pushlightuserdata(L, (void*)u); + lua_pushnil(L); // t["lightuserdata ptr"] = nil to remove it + lua_rawset(L, -3); + lua_pop(L, 1); // pop objects table + } + int LUACALL wxlua_ttag(lua_State *L, int stack_idx) { *************** *** 2249,2253 **** } ! bool wxLuaState::RemoveTrackedObject(void *pObject, bool fDelete) { wxCHECK_MSG(Ok() && pObject, false, wxT("Invalid wxLuaState or object")); --- 2259,2263 ---- } ! bool wxLuaState::RemoveTrackedObject(void *pObject, int flags) { wxCHECK_MSG(Ok() && pObject, false, wxT("Invalid wxLuaState or object")); *************** *** 2256,2268 **** // No derived methods anymore ! wxlua_removederivedmethod(L, pObject); ! // Nor are we tracking it within Lua ! wxlua_pushkey_wxLuaObjects(L); ! lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push result (the object table) ! lua_pushlightuserdata(L, (void*)pObject); ! lua_pushnil(L); // t["lightuserdata ptr"] = nil to remove it ! lua_rawset(L, -3); ! lua_pop(L, 1); wxLongToLongHashMap::iterator it = M_WXLSTATEDATA->m_wxlStateData->m_trackedObjects.find((long) pObject); --- 2266,2275 ---- // No derived methods anymore ! if (WXLUA_HASBIT(flags, CLEAR_DERIVED_METHODS)) ! wxlua_removederivedmethod(L, pObject); ! // Nor are we tracking it within the Lua reg table ! if (WXLUA_HASBIT(flags, CLEAR_LUA_TRACKED)) ! wxlua_tuntrackuserdata(L, pObject); wxLongToLongHashMap::iterator it = M_WXLSTATEDATA->m_wxlStateData->m_trackedObjects.find((long) pObject); *************** *** 2274,2278 **** // always delete the object for the case where it's encapsulated wxObject *pDeleteObject = (wxObject*)it->second; ! if (fDelete && (pDeleteObject != NULL)) delete pDeleteObject; --- 2281,2285 ---- // always delete the object for the case where it's encapsulated wxObject *pDeleteObject = (wxObject*)it->second; ! if (WXLUA_HASBIT(flags, DELETE_OBJECT) && (pDeleteObject != NULL)) delete pDeleteObject; Index: wxlbind.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlbind.cpp,v retrieving revision 1.85 retrieving revision 1.86 diff -C2 -d -r1.85 -r1.86 *** wxlbind.cpp 19 Jul 2007 03:09:46 -0000 1.85 --- wxlbind.cpp 22 Jul 2007 04:38:29 -0000 1.86 *************** *** 255,259 **** // clean up the rest of this, this won't error if the key doesn't exist ! wxlState.RemoveTrackedObject(key, true); } --- 255,259 ---- // clean up the rest of this, this won't error if the key doesn't exist ! wxlState.RemoveTrackedObject(key, wxLuaState::DELETE_OBJECT|wxLuaState::CLEAR_LUA_TRACKED|wxLuaState::CLEAR_DERIVED_METHODS); } |