[Scummvm-cvs-logs] SF.net SVN: scummvm:[53934] scummvm/trunk/engines/tinsel

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Sat Oct 30 02:33:54 CEST 2010


Revision: 53934
          http://scummvm.svn.sourceforge.net/scummvm/?rev=53934&view=rev
Author:   fingolfin
Date:     2010-10-30 00:33:54 +0000 (Sat, 30 Oct 2010)

Log Message:
-----------
TINSEL: Fix subtle leak in coroutine code, some minor tweaks

* Fix a bug which caused coroutines invoked with nullContext to
  leak their state.
  Sadly, nullContext is underdocumented, yet very delicate and
  full of subtleties... ./
* Move nullContext decl from sched.cpp to coroutine.cpp
* Enhance a few doxygen comments

Modified Paths:
--------------
    scummvm/trunk/engines/tinsel/coroutine.cpp
    scummvm/trunk/engines/tinsel/coroutine.h
    scummvm/trunk/engines/tinsel/sched.cpp

Modified: scummvm/trunk/engines/tinsel/coroutine.cpp
===================================================================
--- scummvm/trunk/engines/tinsel/coroutine.cpp	2010-10-30 00:33:31 UTC (rev 53933)
+++ scummvm/trunk/engines/tinsel/coroutine.cpp	2010-10-30 00:33:54 UTC (rev 53934)
@@ -28,6 +28,10 @@
 
 namespace Tinsel {
 
+
+CoroContext nullContext = NULL;
+
+
 #if COROUTINE_DEBUG
 namespace {
 static int s_coroCount = 0;

Modified: scummvm/trunk/engines/tinsel/coroutine.h
===================================================================
--- scummvm/trunk/engines/tinsel/coroutine.h	2010-10-30 00:33:31 UTC (rev 53933)
+++ scummvm/trunk/engines/tinsel/coroutine.h	2010-10-30 00:33:54 UTC (rev 53934)
@@ -109,11 +109,9 @@
 };
 
 
-#define CORO_PARAM     CoroContext &coroParam
+#define CORO_PARAM    CoroContext &coroParam
 
-#define CORO_SUBCTX   coroParam->_subctx
 
-
 /**
  * Begin the declaration of a coroutine context.
  * This allows declaring variables which are 'persistent' during the
@@ -159,7 +157,10 @@
  * @see CORO_END_CODE
  */
 #define CORO_END_CODE \
-			if (&coroParam == &nullContext) nullContext = NULL; \
+			if (&coroParam == &nullContext) { \
+				delete nullContext; \
+				nullContext = NULL; \
+			} \
 		}
 
 /**
@@ -181,11 +182,28 @@
 #define CORO_KILL_SELF() \
 		do { if (&coroParam != &nullContext) { coroParam->_sleep = -1; } return; } while (0)
 
+
 /**
+ * This macro is to be used in conjunction with CORO_INVOKE_ARGS and
+ * similar macros for calling coroutines-enabled subroutines.
+ */
+#define CORO_SUBCTX   coroParam->_subctx
+
+/**
  * Invoke another coroutine.
  *
  * What makes this tricky is that the coroutine we called my yield/sleep,
  * and we need to deal with this adequately.
+ *
+ * @param subCoro	name of the coroutine-enabled function to invoke
+ * @param ARGS		list of arguments to pass to subCoro
+ *
+ * @note ARGS must be surrounded by parentheses, and the first argument
+ *       in this list must always be CORO_SUBCTX. For example, the
+ *       regular function call
+ *          myFunc(a, b);
+ *       becomes the following:
+ *          CORO_INVOKE_ARGS(myFunc, (CORO_SUBCTX, a, b));
  */
 #define CORO_INVOKE_ARGS(subCoro, ARGS)  \
 		do {\

Modified: scummvm/trunk/engines/tinsel/sched.cpp
===================================================================
--- scummvm/trunk/engines/tinsel/sched.cpp	2010-10-30 00:33:31 UTC (rev 53933)
+++ scummvm/trunk/engines/tinsel/sched.cpp	2010-10-30 00:33:54 UTC (rev 53934)
@@ -45,8 +45,6 @@
 
 #include "common/pack-end.h"	// END STRUCT PACKING
 
-CoroContext nullContext = NULL;
-
 //----------------- LOCAL GLOBAL DATA --------------------
 
 static uint32 numSceneProcess;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list