Skip to content

Commit

Permalink
Make natDisconnect() be called upon ext module deallocation (#211)
Browse files Browse the repository at this point in the history
These changes make it so the natDisconnect() function is called for
you automatically if you forget it.  No effect in-process.
  • Loading branch information
drmfinlay authored Sep 26, 2024
1 parent 3af908d commit 62611ac
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
7 changes: 7 additions & 0 deletions NatlinkSource/DragonCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,13 @@ BOOL CDragonCode::isNatSpeakRunning()

//---------------------------------------------------------------------------

void CDragonCode::freeModule()
{
natDisconnect();
}

//---------------------------------------------------------------------------

void CDragonCode::releaseObjects()
{
// iterate over all the grammar objects and free them; note that when we
Expand Down
4 changes: 4 additions & 0 deletions NatlinkSource/DragonCode.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ class CDragonCode
void setAppClass( CDgnAppSupport * pAppClass ) { m_pAppClass = pAppClass; }
void setDuringInit( BOOL bState ) { m_bDuringInit = bState; }

// this is called when the natlink module (this class!) is deallocated from
// Python
void freeModule();

// these functions are called from CGrammarObject
ISRCentral * pISRCentral() { return m_pISRCentral; }
void addGramObj(CGrammarObject * pGramObj );
Expand Down
22 changes: 17 additions & 5 deletions NatlinkSource/pythwrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2317,16 +2317,28 @@ static struct PyMethodDef natlink_methods[] = {
{ NULL }
};

//---------------------------------------------------------------------------
// natlink module free function.

void natlink_free( void * p )
{
cDragon.freeModule();
}

//---------------------------------------------------------------------------
// import natlink from Python
//
// We tell Python about our functions and also create an error type.
static struct PyModuleDef NatlinkModule = {
PyModuleDef_HEAD_INIT,
"_natlink_core", /* name of module */
"natlink with python3 compatability",
-1,
natlink_methods
PyModuleDef_HEAD_INIT, /* m_base */
"_natlink_core", /* m_name */
"natlink with python3 compatability", /* m_doc */
-1, /* m_size */
natlink_methods, /* m_methods */
NULL, /* m_slots */
NULL, /* m_traverse */
NULL, /* m_clear */
natlink_free /* m_free */
};


Expand Down

0 comments on commit 62611ac

Please sign in to comment.