From: John L. <jr...@us...> - 2007-08-22 20:17:15
|
Update of /cvsroot/wxlua/wxLua/bindings/wxwidgets In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv25335/wxLua/bindings/wxwidgets Modified Files: wxxml_override.hpp wxxml_xml.i Log Message: Fix SF bug 1776184, XML binding crashes, by adding %gc and %ungc for functions that either take ownership or release a pointer. Index: wxxml_xml.i =================================================================== RCS file: /cvsroot/wxlua/wxLua/bindings/wxwidgets/wxxml_xml.i,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** wxxml_xml.i 16 Jul 2007 19:34:27 -0000 1.1 --- wxxml_xml.i 22 Aug 2007 20:17:09 -0000 1.2 *************** *** 33,42 **** %class %delete %noclassinfo %encapsulate wxXmlNode wxXmlNode() ! wxXmlNode(wxXmlNodeType type, const wxString& name, const wxString& content = wxEmptyString) wxXmlNode(wxXmlNode *parent, wxXmlNodeType type, const wxString& name, const wxString& content, wxXmlProperty *props, wxXmlNode *next) ! void AddChild(wxXmlNode *child) ! void InsertChild(wxXmlNode *child, wxXmlNode *before_node) ! bool RemoveChild(wxXmlNode *child) void AddProperty(const wxString& name, const wxString& value) bool DeleteProperty(const wxString& name) --- 33,49 ---- %class %delete %noclassinfo %encapsulate wxXmlNode wxXmlNode() ! wxXmlNode(wxXmlNodeType type, const wxString& name, const wxString& content = "") ! ! // %override wxXmlNode::wxXmlNode(wxXmlNode *parent, wxXmlNodeType type, const wxString& name, const wxString& content, wxXmlProperty *props, wxXmlNode *next) ! // C++ Func: No change: if parent is not NULL, created node is not garbage collected. wxXmlNode(wxXmlNode *parent, wxXmlNodeType type, const wxString& name, const wxString& content, wxXmlProperty *props, wxXmlNode *next) ! void AddChild(%ungc wxXmlNode *child) ! void InsertChild(%ungc wxXmlNode *child, wxXmlNode *before_node) ! ! // %override bool RemoveChild(%gc wxXmlNode *child) ! // C++ Func: No change: only if child is removed will we garbage collect it ! bool RemoveChild(%gc wxXmlNode *child) ! void AddProperty(const wxString& name, const wxString& value) bool DeleteProperty(const wxString& name) *************** *** 60,66 **** void SetParent(wxXmlNode *parent) void SetNext(wxXmlNode *next) ! void SetChildren(wxXmlNode *child) ! void SetProperties(wxXmlProperty *prop) ! void AddProperty(wxXmlProperty *prop) %endclass --- 67,73 ---- void SetParent(wxXmlNode *parent) void SetNext(wxXmlNode *next) ! void SetChildren(%ungc wxXmlNode *child) ! void SetProperties(%ungc wxXmlProperty *prop) ! void AddProperty(%ungc wxXmlProperty *prop) %endclass *************** *** 97,101 **** wxString GetVersion() const; wxString GetFileEncoding() const; ! void SetRoot(wxXmlNode *node); void SetVersion(const wxString& version); void SetFileEncoding(const wxString& encoding); --- 104,108 ---- wxString GetVersion() const; wxString GetFileEncoding() const; ! void SetRoot(%ungc wxXmlNode *node); void SetVersion(const wxString& version); void SetFileEncoding(const wxString& encoding); Index: wxxml_override.hpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/bindings/wxwidgets/wxxml_override.hpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** wxxml_override.hpp 16 Jul 2007 19:34:27 -0000 1.1 --- wxxml_override.hpp 22 Aug 2007 20:17:09 -0000 1.2 *************** *** 10,13 **** --- 10,67 ---- // ---------------------------------------------------------------------------- + %override wxLua_wxXmlNode_constructor2 + // wxXmlNode(wxXmlNode *parent, wxXmlNodeType type, const wxString& name, const wxString& content, wxXmlProperty *props, wxXmlNode *next) + static int LUACALL wxLua_wxXmlNode_constructor2(lua_State *L) + { + wxluabind_removetableforcall(L); + wxLuaState wxlState(L); + wxXmlNode *returns; + // wxXmlNode next + wxXmlNode * next = (wxXmlNode *)wxlState.GetUserDataType(6, s_wxluatag_wxXmlNode); + // wxXmlProperty props + wxXmlProperty * props = (wxXmlProperty *)wxlState.GetUserDataType(5, s_wxluatag_wxXmlProperty); + // const wxString content + const wxString content = wxlState.GetwxStringType(4); + // const wxString name + const wxString name = wxlState.GetwxStringType(3); + // wxXmlNodeType type + wxXmlNodeType type = (wxXmlNodeType)wxlua_getintegertype(L, 2); + // wxXmlNode parent + wxXmlNode * parent = (wxXmlNode *)wxlState.GetUserDataType(1, s_wxluatag_wxXmlNode); + // call constructor + returns = new wxXmlNode(parent, type, name, content, props, next); + // add to tracked memory list + if (parent == NULL) + wxlState.AddTrackedObject((long)returns, new wxLua_wxObject_wxXmlNode((wxXmlNode *)returns)); + // push the constructed class pointer + wxlState.PushUserDataType(s_wxluatag_wxXmlNode, returns); + + return 1; + } + %end + + %override wxLua_wxXmlNode_RemoveChild + // bool RemoveChild(%gc wxXmlNode *child) + static int LUACALL wxLua_wxXmlNode_RemoveChild(lua_State *L) + { + wxLuaState wxlState(L); + bool returns; + // wxXmlNode child + wxXmlNode * child = (wxXmlNode *)wxlState.GetUserDataType(2, s_wxluatag_wxXmlNode); + // get this + wxXmlNode * self = (wxXmlNode *)wxlState.GetUserDataType(1, s_wxluatag_wxXmlNode); + // call RemoveChild + returns = (self->RemoveChild(child)); + + if (returns && !wxlState.IsTrackedObject(child)) + wxlState.AddTrackedObject((long)child, new wxLua_wxObject_wxXmlNode(child)); + + // push the result flag + lua_pushboolean(L, returns); + + return 1; + } + %end + %override wxLua_wxXmlNode_GetPropValPtr // %rename GetPropValPtr bool GetPropVal(const wxString& propName, wxString *value) const; |