Skip to content

Commit 09a9ad6

Browse files
committed
PythonInterpreter,PythonCodeCompletion,XmlRpcEmbedder: remove XmlRpcMgr (and correctly free memory in PythonInterpreter, which fixes crash on exit)
1 parent fadfbdc commit 09a9ad6

7 files changed

Lines changed: 83 additions & 71 deletions

File tree

‎PythonCodeCompletion/PythonCodeCompletion-unix.cbp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<Option output="PythonCodeCompletion" prefix_auto="0" extension_auto="1" />
1111
<Option type="3" />
1212
<Option compiler="gcc" />
13+
<Option parameters="--debug-log --multiple-instance -ns -ni -p debug" />
1314
<Option host_application="codeblocks" />
1415
<Option run_host_application_in_terminal="0" />
1516
<Compiler>

‎PythonCodeCompletion/PythonCodeCompletion.cpp‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ void PythonCodeCompletion::OnAttach()
118118
#endif
119119
Manager::Get()->GetLogManager()->DebugLog(_T("PYCC: Launching python on ")+script);
120120
Manager::Get()->GetLogManager()->DebugLog(_T("PYCC: with command ")+command);
121-
py_server = XmlRpcMgr::Get().LaunchProcess(command,port);
121+
py_server = new XmlRpcInstance(command,port);
122122
if(py_server->IsDead())
123123
{
124124
Manager::Get()->GetLogManager()->LogError(_("Error Starting Python Code Completion Server"));
@@ -244,7 +244,10 @@ void PythonCodeCompletion::OnRelease(bool appShutDown)
244244
// m_IsAttached will be FALSE...
245245
EditorHooks::UnregisterHook(m_EditorHookId, true);
246246
if(py_server && !py_server->IsDead()) //TODO: Really should wait until serverr is no longer busy and request it to terminate via XMLRPC
247+
{
247248
py_server->KillProcess(true);
249+
delete py_server;
250+
}
248251
if(m_pImageList)
249252
delete m_pImageList;
250253
}

‎PythonDebugger/PyDebugger-unix.cbp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<Option host_application="$(#cb)/devel/codeblocks" />
1515
<Option run_host_application_in_terminal="0" />
1616
<Compiler>
17+
<Add option="-ansi" />
1718
<Add option="-g" />
1819
</Compiler>
1920
<Linker>
@@ -66,6 +67,9 @@
6667
<Add option="`pkg-config --libs codeblocks`" />
6768
<Add directory="$(#cb)/devel" />
6869
</Linker>
70+
<Unit filename="DebuggerController.h">
71+
<Option target="default" />
72+
</Unit>
6973
<Unit filename="PyDebugger.cpp">
7074
<Option target="default" />
7175
</Unit>

‎PythonDebugger/PyDebugger.h‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,6 @@ typedef std::set<int> BPLtype;
4242

4343
typedef std::vector<cb::shared_ptr<cbStackFrame> > StackList;
4444

45-
//class PyDebuggerConfiguration:public cbDebuggerConfiguration
46-
//{
47-
// public:
48-
// PyDebuggerConfiguration(const ConfigManagerWrapper &config):cbDebuggerConfiguration(config) {}
49-
// virtual ~PyDebuggerConfiguration() {}
50-
//
51-
// virtual cbDebuggerConfiguration* Clone() const {return new PyDebuggerConfiguration(*this);}
52-
//
53-
// virtual wxPanel* MakePanel(wxWindow *parent) {return new wxPanel();}
54-
// virtual bool SaveChanges(wxPanel *panel) {return true;}
55-
//
56-
//};
57-
5845
class PyBreakpoint:public cbBreakpoint
5946
{
6047
public:

‎PythonInterpreter/PythonInterpCtrl.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ long PythonInterpCtrl::LaunchProcess(const wxString &processcmd, const wxArraySt
200200
if(!global&&!local) //No interpreter script found, return failure.
201201
return -2; //TODO: Return meaningful messages (or at least use the codeblocks logger)
202202

203-
m_pyinterp = XmlRpcMgr::Get().LaunchProcess(cmd,m_port);
203+
m_pyinterp = new XmlRpcInstance(cmd,m_port);
204204
if(m_pyinterp->IsDead())
205205
{
206206
Manager::Get()->GetLogManager()->Log(_("Error Starting Interpreter"));

‎XmlRpcEmbedder/xmlrpc_embedder.cpp‎

Lines changed: 50 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <wx/listimpl.cpp>
55
#include <wx/arrimpl.cpp>
66
#include "ExecHiddenMSW.h"
7-
WX_DEFINE_OBJARRAY(XmlRpcInstanceCollection);
7+
//WX_DEFINE_OBJARRAY(XmlRpcInstanceCollection);
88
WX_DEFINE_LIST(XmlRpcJobQueue);
99

1010
using namespace std;
@@ -341,7 +341,7 @@ XmlRpcInstance::~XmlRpcInstance()
341341
m_pipeclient=NULL;
342342
}
343343

344-
XmlRpcInstance::XmlRpcInstance(const wxString &processcmd, const wxString &hostaddress, int port, wxWindow *parent)
344+
XmlRpcInstance::XmlRpcInstance(const wxString &processcmd, int port, const wxString &hostaddress, wxWindow *parent)
345345
{
346346
m_parent=parent;
347347
m_port=port;
@@ -354,12 +354,8 @@ XmlRpcInstance::XmlRpcInstance(const wxString &processcmd, const wxString &hosta
354354
m_proc_killlevel=0;
355355
m_jobrunning=false;
356356
// Launch process
357-
LaunchProcess(processcmd); //TODO: The command for the interpreter process should come from the manager (and be stored in a config file)
358-
// Setup XMLRPC client and use introspection API to look up the supported methods
359-
if(port==-1)
360-
m_pipeclient = new XmlRpcPipeClient(m_proc);
361-
else
362-
m_client = new XmlRpc::XmlRpcClient(hostaddress.char_str(), port);
357+
if (processcmd!=wxEmptyString)
358+
LaunchProcess(processcmd); //TODO: The command for the interpreter process should come from the manager (and be stored in a config file)
363359
}
364360

365361
long XmlRpcInstance::LaunchProcess(const wxString &processcmd)
@@ -388,6 +384,12 @@ long XmlRpcInstance::LaunchProcess(const wxString &processcmd)
388384
// std::cout<<"PyCC: LAUNCHING PROCESS SUCCEEDED"<<std::endl;
389385
m_proc_dead=false;
390386
m_proc_killlevel=0;
387+
388+
// Setup XMLRPC client and use introspection API to look up the supported methods
389+
if(m_port==-1)
390+
m_pipeclient = new XmlRpcPipeClient(m_proc);
391+
else
392+
m_client = new XmlRpc::XmlRpcClient(m_hostaddress.char_str(), m_port);
391393
}
392394
return m_proc_id;
393395
}
@@ -434,6 +436,7 @@ void XmlRpcInstance::OnEndProcess(wxProcessEvent &event)
434436
wxCommandEvent ce(wxEVT_XMLRPC_PROC_END,0);
435437
if(m_parent)
436438
m_parent->AddPendingEvent(ce);
439+
// XmlRpcMgr::Get().Remove(this);
437440
}
438441

439442
void XmlRpcInstance::Break()
@@ -544,29 +547,42 @@ void XmlRpcInstance::OnJobNotify(wxCommandEvent &event)
544547
NextJob();
545548
}
546549

547-
XmlRpcMgr::XmlRpcMgr()
548-
{
549-
}
550-
551-
XmlRpcMgr::~XmlRpcMgr()
552-
{
553-
m_Interpreters.Empty();
554-
}
555-
556-
XmlRpcInstance *XmlRpcMgr::LaunchProcess(const wxString &cmd,int port,const wxString &address)
557-
{
558-
XmlRpcInstance *p=new XmlRpcInstance(cmd,address,port);
559-
if(p)
560-
m_Interpreters.Add(p);
561-
return p;
562-
}
563-
564-
XmlRpcMgr &XmlRpcMgr::Get()
565-
{
566-
if (theSingleInstance.get() == 0)
567-
theSingleInstance.reset(new XmlRpcMgr);
568-
return *theSingleInstance;
569-
}
570-
571-
std::auto_ptr<XmlRpcMgr> XmlRpcMgr::theSingleInstance;
572-
550+
//XmlRpcMgr::XmlRpcMgr()
551+
//{
552+
//}
553+
//
554+
//XmlRpcMgr::~XmlRpcMgr()
555+
//{
556+
// m_Interpreters.Clear();
557+
//}
558+
//
559+
//XmlRpcInstance *XmlRpcMgr::LaunchProcess(const wxString &cmd,int port,const wxString &address)
560+
//{
561+
// XmlRpcInstance *p=new XmlRpcInstance(cmd,address,port);
562+
// if(p)
563+
// m_Interpreters.Add(p);
564+
// return p;
565+
//}
566+
//
567+
//void XmlRpcMgr::Remove(XmlRpcInstance *p)
568+
//{
569+
//// m_Interpreters.Remove(*p);
570+
//// for (size_t i=0; i<m_Interpreters.GetCount(); ++i)
571+
//// {
572+
//// if (m_Interpreters.Item(i) == *p)
573+
//// {
574+
//// m_Interpreters.RemoveAt(i);
575+
//// return;
576+
//// }
577+
//// }
578+
//}
579+
//
580+
//XmlRpcMgr &XmlRpcMgr::Get()
581+
//{
582+
// if (theSingleInstance.get() == 0)
583+
// theSingleInstance.reset(new XmlRpcMgr);
584+
// return *theSingleInstance;
585+
//}
586+
//
587+
//std::auto_ptr<XmlRpcMgr> XmlRpcMgr::theSingleInstance;
588+
//

‎XmlRpcEmbedder/xmlrpc_embedder.h‎

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include <wx/wx.h>
55
#include <wx/app.h>
6-
#include <wx/dynarray.h>
6+
//#include <wx/dynarray.h>
77
#include <wx/process.h>
88

99
#include <memory>
@@ -58,7 +58,7 @@ class XmlRpcInstance: public wxEvtHandler
5858
friend class XmlRpcJob;
5959
public:
6060
// Standard constructor -- generally should use the Manager instance to create these
61-
XmlRpcInstance(const wxString &processcmd, const wxString &hostaddress, int port=-1, wxWindow *parent=NULL);
61+
XmlRpcInstance(const wxString &processcmd, int port=-1, const wxString &hostaddress=_T("localhost"), wxWindow *parent=NULL);
6262

6363
// Copy constructor
6464
XmlRpcInstance(const XmlRpcInstance &copy);
@@ -124,25 +124,26 @@ class XmlRpcInstance: public wxEvtHandler
124124
DECLARE_EVENT_TABLE()
125125
};
126126

127-
WX_DECLARE_OBJARRAY(XmlRpcInstance, XmlRpcInstanceCollection);
128-
129-
/////////////////////////////////////////////////////////////////////////////////////
130-
// XmlRpcMgr: manages the collection of interpreters
131-
/////////////////////////////////////////////////////////////////////////////////////
132-
class XmlRpcMgr
133-
{
134-
public:
135-
XmlRpcInstance *LaunchProcess(const wxString &cmd,int port=-1,const wxString &address=_("localhost"));
136-
static XmlRpcMgr &Get();
137-
~XmlRpcMgr();
138-
protected:
139-
XmlRpcMgr();
140-
private:
141-
XmlRpcInstanceCollection m_Interpreters;
142-
static std::auto_ptr<XmlRpcMgr> theSingleInstance;
143-
// todo: create an xmlrpc server?
144-
145-
};
146-
127+
//WX_DECLARE_OBJARRAY(XmlRpcInstance, XmlRpcInstanceCollection);
128+
//
129+
///////////////////////////////////////////////////////////////////////////////////////
130+
//// XmlRpcMgr: manages the collection of interpreters
131+
///////////////////////////////////////////////////////////////////////////////////////
132+
//class XmlRpcMgr
133+
//{
134+
//public:
135+
// XmlRpcInstance *LaunchProcess(const wxString &cmd,int port=-1,const wxString &address=_("localhost"));
136+
// void Remove(XmlRpcInstance *p);
137+
// static XmlRpcMgr &Get();
138+
// ~XmlRpcMgr();
139+
//protected:
140+
// XmlRpcMgr();
141+
//private:
142+
// XmlRpcInstanceCollection m_Interpreters;
143+
// static std::auto_ptr<XmlRpcMgr> theSingleInstance;
144+
//// todo: create an xmlrpc server?
145+
//
146+
//};
147+
//
147148

148149
#endif //PYEMBEDDER_H_INCLUDED

0 commit comments

Comments
 (0)