[Spiderape-cvs] SF.net SVN: spiderape: [43] plugins/ncurses
Status: Beta
Brought to you by:
sgbeal
|
From: <sg...@us...> - 2007-09-28 04:23:10
|
Revision: 43
http://spiderape.svn.sourceforge.net/spiderape/?rev=43&view=rev
Author: sgbeal
Date: 2007-09-27 21:23:08 -0700 (Thu, 27 Sep 2007)
Log Message:
-----------
endwin-related window cleanup issues appear to be solved.
Modified Paths:
--------------
plugins/ncurses/binder.cpp
plugins/ncurses/ncwrapper.cpp
Modified: plugins/ncurses/binder.cpp
===================================================================
--- plugins/ncurses/binder.cpp 2007-09-28 03:44:42 UTC (rev 42)
+++ plugins/ncurses/binder.cpp 2007-09-28 04:23:08 UTC (rev 43)
@@ -16,6 +16,13 @@
}
} // namespace Private
+ JWBinder::BinderList & JWBinder::all_binders()
+ {
+ static BinderList bob;
+ return bob;
+ }
+
+
void JWBinder::link_child( JWBinder * ch )
{
if( ! ch ) return;
@@ -43,7 +50,7 @@
{
::ape::bind::bind_native<PANEL>( this->m_cx, this->m_v, this->m_pnl );
}
- //JWBinder::all_binders().push_back(this);
+ JWBinder::all_binders().push_back(this);
}
JWBinder::JWBinder(JSContext *cx, PANEL *p, jsval jv ) :
m_cx(cx), m_win(panel_window(p)), m_pnl(p), m_v(jv),
@@ -60,14 +67,6 @@
jsval JWBinder::js_value() const { return this->m_v; }
-// unsigned long JWBinder::flags() const { return this->m_f; }
-// unsigned long JWBinder::flags( unsigned long f )
-// {
-// unsigned long ret = f;
-// this->m_f = f;
-// return ret;
-// }
-
JSContext * JWBinder::js_context() { return this->m_cx; }
WINDOW * JWBinder::window() { return this->m_win; }
@@ -105,74 +104,80 @@
JWBinder::~JWBinder()
{
- //JWBinder::all_binders().remove(this);
- this->parent( 0 );
+ JWBinder::all_binders().remove(this);
::ape::bind::unbind_native<JWBinder>( this->m_cx, this->m_v, this );
- ::ape::bind::unbind_native<WINDOW>( this->m_cx, this->m_v, this->m_win );
- if( 0 )
+
+ // We re-grab the WINDOW from the central repo to avoid having a dangling WINDOW
+ // when two binders point to the same WINDOW (as in the case of PANELized WINDOWS).
+ WINDOW * theWin = ape::bind::get_native<WINDOW*>( this->m_cx, this->m_v );
+ if( ! theWin ) return;
+ ::ape::bind::unbind_native<WINDOW>( this->m_cx, this->m_v, theWin );
+
+#if 0
{
void * pt = this->m_pnl ? (void*)this->m_pnl : (void*)this->m_win;
- CERR << "Deleting "<<
- (this->m_pnl ? "PANEL " : "WINDOW ") << std::hex << pt
- << " with"<<(this->m_parent?"out":" ")<<" parent"
- << ", JSObject " << std::hex << jsval_to_cstring( this->js_context(), this->js_value() )
+ CERR << "Deleting WINDOW"<<
+ (this->m_pnl ? "+PANEL" : "") << std::hex << pt
+ << ", "<<(this->m_parent?"with":"without")<<" parent"
<< '\n';
}
+#endif //debuggering output
- {
- // Kludge: remove stream-to-window redirects:
+ this->parent( 0 );
+
+ { // KLUDGE #1: remove stream-to-window redirects:
using namespace Private;
WindowStreamMap & str = captured_streams();
typedef WindowStreamMap::iterator WIT;
- WIT stit = str.lower_bound(this->m_win);
+ WIT stit = str.lower_bound(theWin);
WIT head = stit;
- WIT stet = str.upper_bound(this->m_win);
+ WIT stet = str.upper_bound(theWin);
for( ; stet != stit; ++stit )
{
delete (*stit).second;
//str.erase(stit);
}
str.erase( head, stet );
- // /KLUDGE
- }
- {
- // KLUDGE #2: remove data bound via nc_set_userdata()
+ } // /KLUDGE #1
+
+ { // KLUDGE #2: remove data bound via nc_set_userdata()
typedef ::ape::jsval_t JT;
- JT * j = ::ape::bind::get_native<JT>( this->js_context(), this->js_value() );
+ JT * j = ::ape::bind::get_native<JT>( this->js_context(), this->m_v );
if( j )
{
- ::ape::bind::unbind_native<JT>( this->js_context(), this->js_value(), j );
+ ::ape::bind::unbind_native<JT>( this->js_context(), this->m_v, j );
delete j;
j = 0;
}
- // /KLUDGE #2
+ }// /KLUDGE #2
+
+ { // Free up children ...
+ BinderList lcp(this->m_ch); // need a copy to avoid modifying original while we're deleting.
+ BinderList::iterator it = lcp.begin();
+ for( ; lcp.end() != it; ++it )
+ {
+#if 0
+ CERR << "Deleting child WINDOW " << std::hex << (*it)->window() << '\n';
+#endif // debuggering output
+ delete *it;
+ }
}
- BinderList lcp(this->m_ch); // need a copy to avoid modifying original while we're deleting.
- BinderList::iterator it = lcp.begin();
- for( ; lcp.end() != it; ++it )
- {
- if(1) CERR << "Deleting child WINDOW " << std::hex << (*it)->window()
- << ", JSObject " << std::hex << jsval_to_cstring( this->js_context(), (*it)->js_value() )
- << '\n';
- delete *it;
- }
- if( stdscr && this->m_win )
+ if( stdscr && theWin )
{
- if( this->m_win != stdscr )
+ //werase(theWin);
+ //CERR << "FIXME: panel is not being freed!\n";
+ this->free_panel();
+ if( theWin != stdscr )
{
- werase(this->m_win);
- delwin( this->m_win );
+ delwin(theWin);
}
}
- this->free_panel();
}
void JWBinder::endwin_cleanup()
{
- CERR << "JWBinder::endwin_cleanup()...\n";
-
{
// Kludge: remove stream-to-window redirects:
using namespace Private;
@@ -188,7 +193,7 @@
}
// /KLUDGE
}
-#if 0
+#if 1
/**
We walk the list of all binders and make a deletion
queue for items WITHOUT parents (those with parents
@@ -198,7 +203,8 @@
avoid a segfault later on.
*/
BinderList them;
- BinderList & bl = JWBinder::all_binders();
+ BinderList bl( JWBinder::all_binders() );
+ //JWBinder::all_binders().clear();
BinderList::reverse_iterator rit = bl.rbegin();
JWBinder * cur = 0;
for( ; bl.rend() != rit; ++rit )
@@ -220,17 +226,12 @@
#endif
}
- JWBinder::BinderList & JWBinder::all_binders()
- {
- static BinderList bob;
- return bob;
- }
-
int JWBinder::free_panel()
{
- if( !stdscr || !this->m_pnl ) return ERR;
- ::ape::bind::unbind_native<PANEL>( this->m_cx, this->m_v, this->m_pnl );
- int ret = del_panel( this->m_pnl );
+ PANEL * thePanel = ape::bind::get_native<PANEL*>( this->m_cx, this->m_v );
+ if( !stdscr || !thePanel ) return ERR;
+ ::ape::bind::unbind_native<PANEL*>( this->m_cx, this->m_v, thePanel );
+ int ret = del_panel( thePanel );
this->m_pnl = 0;
return ret;
}
Modified: plugins/ncurses/ncwrapper.cpp
===================================================================
--- plugins/ncurses/ncwrapper.cpp 2007-09-28 03:44:42 UTC (rev 42)
+++ plugins/ncurses/ncwrapper.cpp 2007-09-28 04:23:08 UTC (rev 43)
@@ -794,12 +794,8 @@
return JS_TRUE;
}
ripoff::reset(); // must come before JWBinder::endwin_cleanup()!!!
- //CERR << "Freeing stdscr property...\n";
JS_DeleteProperty(cx, obj, "stdscr");
- //CERR << "Freed stdscr property.\n";
- CERR << "FIXME: nc_endwin cleanup: need to nuke all window resources!\n";
JWBinder::endwin_cleanup();
- //CERR << "DONE: endwin_cleanup()!\n";
int rc = endwin();
if( 0 != rc )
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|