Skip to content

Commit 1c02aaf

Browse files
committed
Merge pull request #4 from tfabbri/destructor-fix
Destructor fix
2 parents 88b0f94 + 673b52e commit 1c02aaf

2 files changed

Lines changed: 20 additions & 23 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ if(NOT DEFINED CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
2626
endif()
2727

2828

29-
30-
3129
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${Boost_INCLUDE_DIRS} ${MOOS_INCLUDE_DIRS})
3230

3331
set(src
@@ -46,7 +44,6 @@ set_target_properties(pymoos
4644
PREFIX "")
4745

4846

49-
5047
file(GLOB ExampleFiles ${CMAKE_SOURCE_DIR}/Documentation/examples/*.py)
5148
add_custom_target(copy)
5249
get_target_property(pymoosLocation pymoos LOCATION)
@@ -56,13 +53,7 @@ foreach(ExampleFile ${ExampleFiles})
5653
COMMAND ${CMAKE_COMMAND} -E
5754
copy ${ExampleFile} ${pymoosDir})
5855
endforeach()
59-
add_dependencies(pymoos copy)
60-
61-
56+
add_dependencies(pymoos copy)
6257

6358

6459
TARGET_LINK_LIBRARIES(pymoos ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} ${MOOS_LIBRARIES})
65-
66-
67-
68-

pyMOOS.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ struct pyMOOSException : std::exception {
2626
}
2727
char const* what() const throw () {
2828
return s_.c_str();
29-
return "lala";/*return s_.c_str();*/
3029
}
3130
std::string s_;
3231
};
@@ -45,6 +44,10 @@ class AsyncCommsWrapper : public MOOS::MOOSAsyncCommClient {
4544
private:
4645
typedef MOOSAsyncCommClient BASE;
4746
public:
47+
48+
~AsyncCommsWrapper(){
49+
Close(true);
50+
}
4851

4952
bool Run(const std::string & sServer, int Port, const std::string & sMyName) {
5053
return BASE::Run(sServer, Port, sMyName, 0);//Comms Tick not used in Async version
@@ -81,13 +84,14 @@ class AsyncCommsWrapper : public MOOS::MOOSAsyncCommClient {
8184
return true;
8285
}
8386

84-
bool Close(bool nice)
85-
{
86-
Py_BEGIN_ALLOW_THREADS
87-
//PyGILState_STATE gstate = PyGILState_Ensure();
88-
BASE::Close(nice);
89-
//PyGILState_Release(gstate);
90-
Py_END_ALLOW_THREADS
87+
bool Close(bool nice){
88+
Py_BEGIN_ALLOW_THREADS
89+
//PyGILState_STATE gstate = PyGILState_Ensure();
90+
closing_ = true;
91+
BASE::Close(true);
92+
93+
//PyGILState_Release(gstate);
94+
Py_END_ALLOW_THREADS
9195
}
9296

9397

@@ -124,13 +128,14 @@ class AsyncCommsWrapper : public MOOS::MOOSAsyncCommClient {
124128
}
125129

126130
bool on_mail() {
127-
128131
bool bResult = false;
129132

130133
PyGILState_STATE gstate = PyGILState_Ensure();
131134
try {
132-
bp::object result = on_mail_object_();
133-
bResult = bp::extract<bool>(result);
135+
if(!closing_){
136+
bp::object result = on_mail_object_();
137+
bResult = bp::extract<bool>(result);
138+
}
134139
} catch (const bp::error_already_set& e) {
135140
PyGILState_Release(gstate);
136141
throw pyMOOSException(
@@ -140,7 +145,6 @@ class AsyncCommsWrapper : public MOOS::MOOSAsyncCommClient {
140145
PyGILState_Release(gstate);
141146

142147
return bResult;
143-
144148
}
145149

146150
static bool active_queue_delegate(CMOOSMsg & M, void* pParam) {
@@ -209,7 +213,9 @@ class AsyncCommsWrapper : public MOOS::MOOSAsyncCommClient {
209213
/** callback functions (stored) */
210214
bp::object on_connect_object_;
211215
bp::object on_mail_object_;
212-
216+
217+
/** close connection flag */
218+
bool closing_;
213219
};
214220
}
215221
;//namesapce

0 commit comments

Comments
 (0)