Browse Source

prevent multiple signals on blocked thread
block on null causes exception

Greg 16 years ago
parent
commit
f92eb77ff9

+ 6 - 0
gmsrc/doc/ChangeLog.txt

@@ -346,3 +346,9 @@ o Fixed (hopefully) endon() kills threads correctly and gets along with other bl
 05/06/09
 o Fix and improve format() Thanks DrEvil.
 o Add some more gmVariable accessors (similar to gm_ex)
+
+25/01/10
+o Remove orphaned code in gmBlock dated 25/10/04 "Changed behaviour of Block() to yeild if blocked on 'null'."
+o Changed block on null behavior to cause script thread exception.
+o Fix signal behavior so multiple signals cannot accumulate on a blocked thread. Thanks DrEvil.
+o Changing gm version format from vMajor.Minor.BetaLetter to vMajor.Minor.Build. Probably won't change coded version to store past Minor unless process is automated.

+ 7 - 0
gmsrc/src/gm/gmMachine.cpp

@@ -923,6 +923,12 @@ int gmMachine::Sys_Block(gmThread * a_thread, int m_numBlocks, const gmVariable
   int i;
   for(i = 0; i < m_numBlocks; ++i)
   {
+    // Catch attempts to block on null
+    if( a_blocks[i].IsNull() )
+    {
+      return -2;
+    }
+
 #if GM_USE_ENDON
     // hunt for an existing block on the thread
     gmBlock * block = a_thread->Sys_GetBlocks();
@@ -1030,6 +1036,7 @@ void gmMachine::Sys_SwitchState(gmThread * a_thread, int a_to)
     case gmThread::SYS_PENDING :
     {
       // remove and clean up the blocks.
+      Sys_RemoveSignals(a_thread); // Prevent signals from accumulating
       Sys_RemoveBlocks(a_thread);
       m_blockedThreads.Remove(a_thread);
       break;

+ 1 - 1
gmsrc/src/gm/gmMachine.h

@@ -60,7 +60,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #undef GetObject //Argh Windows defines this in WINGDI.H
 
-#define GM_VERSION "1.25"
+#define GM_VERSION "1.26"
 
 // fwd decls
 class gmStringObject;

+ 3 - 1
gmsrc/src/gm/gmMachineLib.cpp

@@ -650,7 +650,9 @@ static int GM_CDECL gmBlock(gmThread * a_thread) // var, ...
   }
   else if(res == -2)
   {
-    return GM_SYS_YIELD;
+    // Failed to block, so exception to prevent undefined or unexpected behavior
+    GM_EXCEPTION_MSG("cannot block on null");
+    return GM_EXCEPTION;
   }
   a_thread->Push(a_thread->Param(res));
   return GM_OK;

+ 1 - 1
gmsrc/src/gm/gmVariable.h

@@ -91,7 +91,7 @@ struct gmVariable
   
 
   inline void Nullify() { m_type = GM_NULL; m_value.m_int = 0; }
-  inline bool IsNull() { return m_type == GM_NULL; }
+  inline bool IsNull() const { return m_type == GM_NULL; }
   inline bool IsReference() const { return m_type > GM_FLOAT; }
 	inline bool IsInt() const { return m_type == GM_INT; }
   inline bool IsFloat() const { return m_type == GM_FLOAT; }