stratagus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Stratagus-CVS] stratagus/src ai/ai_rules.c ai/ccl_ai.c clone/c...


From: ludovic pollet
Subject: [Stratagus-CVS] stratagus/src ai/ai_rules.c ai/ccl_ai.c clone/c...
Date: Mon, 10 Nov 2003 14:25:36 -0500

CVSROOT:        /cvsroot/stratagus
Module name:    stratagus
Branch:         
Changes by:     ludovic pollet <address@hidden> 03/11/10 14:25:35

Modified files:
        src/ai         : ai_rules.c ccl_ai.c 
        src/clone      : ccl.c 
        src/include    : network.h 
        src/network    : commands.c 
        src/unit       : ccl_unittype.c unittype.c 

Log message:
        Fixed GC crash with GUILE (bug #6392)

Patches:
Index: stratagus/src/ai/ai_rules.c
diff -u stratagus/src/ai/ai_rules.c:1.6 stratagus/src/ai/ai_rules.c:1.7
--- stratagus/src/ai/ai_rules.c:1.6     Sat Nov  1 11:52:19 2003
+++ stratagus/src/ai/ai_rules.c Mon Nov 10 14:25:31 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: ai_rules.c,v 1.6 2003/11/01 16:52:19 pludov Exp $
+//      $Id: ai_rules.c,v 1.7 2003/11/10 19:25:31 pludov Exp $
 
 //@{
 
@@ -833,7 +833,7 @@
 
     // Launch the code.
     code = gh_eval(gh_cadr(gh_cdr(gh_car(script->Action))), NIL);
-    AiScript->Script = code;
+    CclGcProtectedAssign(&AiScript->Script, code);
     AiScript->SleepCycles = 0;
 
     // Don't add anymore units to this force.
Index: stratagus/src/ai/ccl_ai.c
diff -u stratagus/src/ai/ccl_ai.c:1.77 stratagus/src/ai/ccl_ai.c:1.78
--- stratagus/src/ai/ccl_ai.c:1.77      Mon Nov  3 06:21:35 2003
+++ stratagus/src/ai/ccl_ai.c   Mon Nov 10 14:25:31 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: ccl_ai.c,v 1.77 2003/11/03 11:21:35 pludov Exp $
+//      $Id: ccl_ai.c,v 1.78 2003/11/10 19:25:31 pludov Exp $
 
 //@{
 
@@ -1105,32 +1105,12 @@
 local SCM CclAiClearForce(SCM s_force)
 {
     int force;
-/*    AiUnitType * aiut,*next;
-    AiUnit *aiu,*next_u;
-*/
+
     force = gh_scm2int(s_force);
     if (force < 0 || force >= AI_MAX_FORCES) {
        errl("Force out of range", s_force);
     }
-/*
-    aiut=AiPlayer->Force[force].UnitTypes;
-    while(aiut){
-       next=aiut->Next;
-       free(aiut);
-       aiut=next;
-    }
-    AiPlayer->Force[force].UnitTypes=0;
-
-    aiu=AiPlayer->Force[force].Units;
-    while(aiu){
-       next_u=aiu->Next;
-       free(aiu);
-       aiu=next_u;
-    }
-    AiPlayer->Force[force].Units=0;
-    
-    AiAssignFreeUnitsToForce();
-    */
+
     AiEraseForce(force);
     return SCM_BOOL_F;
 
@@ -1761,11 +1741,11 @@
 local SCM CclAiRestart(void)
 {
     int i;
-    AiPlayer->Scripts[0].Script = AiPlayer->AiType->Script;
+    CclGcProtectedAssign(&AiPlayer->Scripts[0].Script, 
AiPlayer->AiType->Script);
     AiPlayer->Scripts[0].SleepCycles = 0;
     snprintf(AiPlayer->Scripts[0].ident, 10, "Main AI");
     for (i = 1; i < AI_MAX_RUNNING_SCRIPTS; i++) {
-       AiPlayer->Scripts[i].Script = NIL;
+       CclGcProtectedAssign(&AiPlayer->Scripts[i].Script, NIL);
        AiPlayer->Scripts[i].SleepCycles = 0;
        snprintf(AiPlayer->Scripts[i].ident, 10, "Empty");
     }
@@ -1783,13 +1763,13 @@
 */
 global void AiRunScript(int script, SCM list, int hotSpotX, int hotSpotY, int 
hotSpotRay)
 {
-    AiPlayer->Scripts[script].Script = list;
+    CclGcProtectedAssign(&AiPlayer->Scripts[script].Script, list);
     AiPlayer->Scripts[script].SleepCycles = 0;
     snprintf(AiPlayer->Scripts[script].ident, 10, "AiRunScript");
     AiPlayer->Scripts[script].HotSpot_X = hotSpotX;
     AiPlayer->Scripts[script].HotSpot_Y = hotSpotY;
     AiPlayer->Scripts[script].HotSpot_Ray = hotSpotRay;
-    // TODO : Compute gauges here ?    
+    // FIXME : Compute gauges here ?
 }
 
 /**
@@ -1797,7 +1777,7 @@
 */
 local SCM CclAiSwitchTo(SCM value)
 {
-    AiScript->Script = value;
+    CclGcProtectedAssign(&AiScript->Script, value);
     AiScript->SleepCycles = 0;
     return SCM_BOOL_T;
 }
@@ -1808,11 +1788,11 @@
 local SCM CclAiScript(SCM value)
 {
     int i;
-    AiPlayer->Scripts[0].Script = value;
+    CclGcProtectedAssign(&AiPlayer->Scripts[0].Script, value);
     AiPlayer->Scripts[0].SleepCycles = 0;
     snprintf(AiPlayer->Scripts[0].ident, 10, "MainScript");
     for (i = 1; i < AI_MAX_RUNNING_SCRIPTS; i++) {
-       AiPlayer->Scripts[i].Script = NIL;
+       CclGcProtectedAssign(&AiPlayer->Scripts[i].Script, NIL);
        AiPlayer->Scripts[i].SleepCycles = 0;
        AiEraseForce(AiPlayer->Scripts[i].ownForce);
        snprintf(AiPlayer->Scripts[i].ident, 10, "Empty");      
@@ -2037,303 +2017,6 @@
     DebugCheck(i < 0 || i > PlayerMax);
     Players[i].Ai = ai;
 
-#if 0
-    i = gh_scm2int(gh_car(list));
-    list = gh_cdr(list);
-
-    DebugCheck(i < 0 || i > PlayerMax);
-    DebugLevel0Fn("%p %d\n" _C_ Players[i].Ai _C_ Players[i].AiEnabled);
-    // FIXME: loose this:
-    // DebugCheck( Players[i].Ai || !Players[i].AiEnabled );
-
-    ai = Players[i].Ai = calloc(1, sizeof (PlayerAi));
-    ai->Player = &Players[i];
-
-    snprintf(AiPlayer->Scripts[0].ident, 10, "Empty");
-    for (i = 1; i < AI_MAX_RUNNING_SCRIPTS; i++) {
-       ai->Scripts[i].Script = NIL;
-       ai->Scripts[i].SleepCycles = 0;
-       snprintf(AiPlayer->Scripts[i].ident, 10, "Empty");
-    }
-
-    //
-    //  Parse the list: (still everything could be changed!)
-    //
-    while (!gh_null_p(list)) {
-
-       value = gh_car(list);
-       list = gh_cdr(list);
-
-       if (gh_eq_p(value, gh_symbol2scm("ai-type"))) {
-           AiType *ait;
-
-           str = gh_scm2newstr(gh_car(list), NULL);
-           for (ait = AiTypes; ait; ait = ait->Next) {
-               if (!strcmp(ait->Name, str)) {
-                   break;
-               }
-           }
-           free(str);
-           if (!ait) {
-               errl("ai-type not found", gh_car(list));
-           }
-           ai->AiType = ait;
-           ai->Scripts[0].Script = ait->Script;
-           list = gh_cdr(list);
-       } else if (gh_eq_p(value, gh_symbol2scm("script"))) {
-           sublist = gh_car(list);
-           value = gh_car(sublist);
-           sublist = gh_cdr(sublist);
-           if (gh_eq_p(value, gh_symbol2scm("aitypes"))) {
-               i = gh_scm2int(gh_car(sublist));
-               while (i--) {
-                   ai->Scripts[0].Script = gh_cdr(ai->Scripts[0].Script);
-               }
-           } else {
-               DebugLevel0Fn("FIXME: not written\n");
-           }
-           list = gh_cdr(list);
-       } else if (gh_eq_p(value, gh_symbol2scm("script-debug"))) {
-           ai->ScriptDebug = gh_scm2bool(gh_car(list));
-           list = gh_cdr(list);
-       } else if (gh_eq_p(value, gh_symbol2scm("sleep-cycles"))) {
-           ai->Scripts[0].SleepCycles = gh_scm2int(gh_car(list));
-           list = gh_cdr(list);
-       } else if (gh_eq_p(value, gh_symbol2scm("force"))) {
-           sublist = gh_car(list);
-           value = gh_car(sublist);
-           sublist = gh_cdr(sublist);
-           i = gh_scm2int(value);
-           while (!gh_null_p(sublist)) {
-               value = gh_car(sublist);
-               sublist = gh_cdr(sublist);
-               if (gh_eq_p(value, gh_symbol2scm("complete"))) {
-                   ai->Force[i].Completed = 1;
-               } else if (gh_eq_p(value, gh_symbol2scm("recruit"))) {
-                   ai->Force[i].Completed = 0;
-               } else if (gh_eq_p(value, gh_symbol2scm("attack"))) {
-                   ai->Force[i].Attacking = 1;
-               } else if (gh_eq_p(value, gh_symbol2scm("role"))) {
-                   if (gh_eq_p(gh_car(sublist), gh_symbol2scm("attack"))) {
-                       ai->Force[i].Role = AiForceRoleAttack;
-                   } else if (gh_eq_p(gh_car(sublist), 
gh_symbol2scm("defend"))) {
-                       ai->Force[i].Role = AiForceRoleDefend;
-                   }
-                   sublist = gh_cdr(sublist);
-               } else if (gh_eq_p(value, gh_symbol2scm("types"))) {
-                   AiUnitType **queue;
-                   SCM subsublist;
-                   subsublist = gh_car(sublist);
-                   queue = &ai->Force[i].UnitTypes;
-                   while (!gh_null_p(subsublist)) {
-                       int num;
-                       char *ident;
-                       value = gh_car(subsublist);
-                       subsublist = gh_cdr(subsublist);
-                       num = gh_scm2int(value);
-                       value = gh_car(subsublist);
-                       subsublist = gh_cdr(subsublist);
-                       ident = get_c_string(value);
-                       *queue = malloc(sizeof (AiUnitType));
-                       (*queue)->Next = NULL;
-                       (*queue)->Want = num;
-                       (*queue)->Type = UnitTypeByIdent(ident);
-                       queue = &(*queue)->Next;
-                   }
-                   sublist = gh_cdr(sublist);
-               } else if (gh_eq_p(value, gh_symbol2scm("units"))) {
-                   AiUnit **queue;
-                   SCM subsublist;
-                   subsublist = gh_car(sublist);
-                   queue = &ai->Force[i].Units;
-                   while (!gh_null_p(subsublist)) {
-                       int num;
-                       char *ident;
-                       value = gh_car(subsublist);
-                       subsublist = gh_cdr(subsublist);
-                       num = gh_scm2int(value);
-                       value = gh_car(subsublist);
-                       subsublist = gh_cdr(subsublist);
-                       ident = get_c_string(value);
-                       *queue = malloc(sizeof (AiUnit));
-                       (*queue)->Next = NULL;
-                       (*queue)->Unit = UnitSlots[num];
-                       queue = &(*queue)->Next;
-                   }
-               }
-           }
-           list = gh_cdr(list);
-       } else if (gh_eq_p(value, gh_symbol2scm("reserve"))) {
-           sublist = gh_car(list);
-           while (!gh_null_p(sublist)) {
-               char *type;
-               int num;
-               value = gh_car(sublist);
-               sublist = gh_cdr(sublist);
-               type = get_c_string(value);
-               value = gh_car(sublist);
-               sublist = gh_cdr(sublist);
-               num = gh_scm2int(value);
-               ai->Reserve[DefaultResourceNumber(type)] = num;
-           }
-           list = gh_cdr(list);
-       } else if (gh_eq_p(value, gh_symbol2scm("used"))) {
-           sublist = gh_car(list);
-           while (!gh_null_p(sublist)) {
-               char *type;
-               int num;
-               value = gh_car(sublist);
-               sublist = gh_cdr(sublist);
-               type = get_c_string(value);
-               value = gh_car(sublist);
-               sublist = gh_cdr(sublist);
-               num = gh_scm2int(value);
-               ai->Used[DefaultResourceNumber(type)] = num;
-           }
-           list = gh_cdr(list);
-       } else if (gh_eq_p(value, gh_symbol2scm("needed"))) {
-           sublist = gh_car(list);
-           while (!gh_null_p(sublist)) {
-               char *type;
-               int num;
-               value = gh_car(sublist);
-               sublist = gh_cdr(sublist);
-               type = get_c_string(value);
-               value = gh_car(sublist);
-               sublist = gh_cdr(sublist);
-               num = gh_scm2int(value);
-               ai->Needed[DefaultResourceNumber(type)] = num;
-           }
-           list = gh_cdr(list);
-       } else if (gh_eq_p(value, gh_symbol2scm("collect"))) {
-           sublist = gh_car(list);
-           while (!gh_null_p(sublist)) {
-               char *type;
-               int num;
-               value = gh_car(sublist);
-               sublist = gh_cdr(sublist);
-               type = get_c_string(value);
-               value = gh_car(sublist);
-               sublist = gh_cdr(sublist);
-               num = gh_scm2int(value);
-               ai->Collect[DefaultResourceNumber(type)] = num;
-           }
-           list = gh_cdr(list);
-       } else if (gh_eq_p(value, gh_symbol2scm("need-mask"))) {
-           sublist = gh_car(list);
-           while (!gh_null_p(sublist)) {
-               char *type;
-               value = gh_car(sublist);
-               sublist = gh_cdr(sublist);
-               type = get_c_string(value);
-               ai->NeededMask |= (1 << DefaultResourceNumber(type));
-           }
-           list = gh_cdr(list);
-       } else if (gh_eq_p(value, gh_symbol2scm("need-food"))) {
-           ai->NeedFood = 1;
-       } else if (gh_eq_p(value, gh_symbol2scm("unit-type"))) {
-           sublist = gh_car(list);
-           i = 0;
-           if (gh_length(sublist)) {
-               ai->UnitTypeRequests =
-                   malloc(gh_length(sublist) / 2 * sizeof (AiUnitTypeTable));
-           }
-           while (!gh_null_p(sublist)) {
-               char *ident;
-               int count;
-               value = gh_car(sublist);
-               sublist = gh_cdr(sublist);
-               ident = get_c_string(value);
-               value = gh_car(sublist);
-               sublist = gh_cdr(sublist);
-               count = gh_scm2int(value);
-               ai->UnitTypeRequests[i].Table[0] = UnitTypeByIdent(ident);
-               ai->UnitTypeRequests[i].Count = count;
-               ++i;
-           }
-           ai->UnitTypeRequestsCount = i;
-           list = gh_cdr(list);
-       } else if (gh_eq_p(value, gh_symbol2scm("upgrade"))) {
-           sublist = gh_car(list);
-           i = 0;
-           if (gh_length(sublist)) {
-               ai->UpgradeToRequests = malloc(gh_length(sublist) * sizeof 
(UnitType *));
-           }
-           while (!gh_null_p(sublist)) {
-               char *ident;
-               value = gh_car(sublist);
-               sublist = gh_cdr(sublist);
-               ident = get_c_string(value);
-               ai->UpgradeToRequests[i] = UnitTypeByIdent(ident);
-               ++i;
-           }
-           ai->UpgradeToRequestsCount = i;
-           list = gh_cdr(list);
-       } else if (gh_eq_p(value, gh_symbol2scm("research"))) {
-           sublist = gh_car(list);
-           i = 0;
-           if (gh_length(sublist)) {
-               ai->ResearchRequests = malloc(gh_length(sublist) * sizeof 
(Upgrade *));
-           }
-           while (!gh_null_p(sublist)) {
-               char *ident;
-               value = gh_car(sublist);
-               sublist = gh_cdr(sublist);
-               ident = get_c_string(value);
-               ai->ResearchRequests[i] = UpgradeByIdent(ident);
-               ++i;
-           }
-           ai->ResearchRequestsCount = i;
-           list = gh_cdr(list);
-       } else if (gh_eq_p(value, gh_symbol2scm("building"))) {
-           AiBuildQueue **queue;
-           sublist = gh_car(list);
-           queue = &ai->UnitTypeBuilded;
-           while (!gh_null_p(sublist)) {
-               char *ident;
-               int made;
-               int want;
-               value = gh_car(sublist);
-               sublist = gh_cdr(sublist);
-               ident = get_c_string(value);
-               value = gh_car(sublist);
-               sublist = gh_cdr(sublist);
-               made = gh_scm2int(value);
-               value = gh_car(sublist);
-               sublist = gh_cdr(sublist);
-               want = gh_scm2int(value);
-               *queue = malloc(sizeof (AiBuildQueue));
-               (*queue)->Next = NULL;
-               (*queue)->Type = UnitTypeByIdent(ident);
-               (*queue)->Want = want;
-               (*queue)->Made = made;
-               queue = &(*queue)->Next;
-           }
-           list = gh_cdr(list);
-       } else if (gh_eq_p(value, gh_symbol2scm("repair-building"))) {
-           ai->LastRepairBuilding = gh_scm2int(gh_car(list));
-           list = gh_cdr(list);
-       } else if (gh_eq_p(value, gh_symbol2scm("repair-workers"))) {
-           sublist = gh_car(list);
-           while (!gh_null_p(sublist)) {
-               int num;
-               int workers;
-               value = gh_car(sublist);
-               sublist = gh_cdr(sublist);
-               num = gh_scm2int(value);
-               value = gh_car(sublist);
-               sublist = gh_cdr(sublist);
-               workers = gh_scm2int(value);
-               ai->TriedRepairWorkers[num] = workers;
-               ++i;
-           }
-           list = gh_cdr(list);
-       } else {
-           // FIXME: this leaves a half initialized ai player
-           errl("Unsupported tag", value);
-       }
-    }
-#endif
     return SCM_UNSPECIFIED;
 }
 
Index: stratagus/src/clone/ccl.c
diff -u stratagus/src/clone/ccl.c:1.126 stratagus/src/clone/ccl.c:1.127
--- stratagus/src/clone/ccl.c:1.126     Sat Nov  8 18:02:13 2003
+++ stratagus/src/clone/ccl.c   Mon Nov 10 14:25:33 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: ccl.c,v 1.126 2003/11/08 23:02:13 nehalmistry Exp $
+//     $Id: ccl.c,v 1.127 2003/11/10 19:25:33 pludov Exp $
 
 //@{
 
@@ -65,6 +65,7 @@
 #include "sound.h"
 #include "sound_server.h"
 #include "netconnect.h"
+#include "network.h"
 #include "cdaudio.h"
 #include "spells.h"
 
@@ -73,6 +74,9 @@
 --     Variables
 ----------------------------------------------------------------------------*/
 
+/// Uncomment this to enable additionnal check on GC operations
+// #define DEBUG_GC
+
 #ifdef USE_GUILE
 #define GC_PROTECT_VALUE 1
 #endif
@@ -93,6 +97,24 @@
 global int     ShowTips;               /// Show tips at start of level
 global int     CurrentTip;             /// Current tip to display
 
+#ifdef DEBUG_GC
+
+#ifdef USE_GUILE
+#define CHECK_GC_VALUES 1
+#else
+#ifdef SIOD_HEAP_GC
+#define CHECK_GC_VALUES 1
+#endif
+#endif
+
+local SCM*   ProtectedCells[16384];
+local int    ProtectedCellCount=0;
+#ifdef CHECK_GC_VALUES
+local SCM    ProtectedCellValues[16384];
+#endif
+
+#endif
+
 /*----------------------------------------------------------------------------
 --     Functions
 ----------------------------------------------------------------------------*/
@@ -206,7 +228,69 @@
 }
 
 
+#ifdef DEBUG_GC
+
+/**
+**     Check if a cell is already protected
+**
+**     @param val      the cell to find
+**     @return         the index of the cell or -1
+*/
+local int FindProtectedCell(SCM * val)
+{
+    int i;
+    for (i = 0; i < ProtectedCellCount; i++) {
+       if (ProtectedCells[i] == val) {
+           return i;
+       }
+    }
+    return -1;
+}
+
+local void AddProtectedCell(SCM * var)
+{
+    DebugCheck(ProtectedCellCount >= 16384);
+    ProtectedCells[ProtectedCellCount] = var;
+#ifdef CHECK_GC_VALUES
+    ProtectedCellValues[ProtectedCellCount] = *var;
+#endif
+
+    ProtectedCellCount++;
+}
+
+local void DelProtectedCell(int id)
+{
+    ProtectedCellCount--;
+    
+    ProtectedCells[id]=ProtectedCells[ProtectedCellCount];
+#ifdef CHECK_GC_VALUES
+    ProtectedCellValues[id]=ProtectedCellValues[ProtectedCellCount];
+#endif
+}
+
+local void CheckProtectedCell(SCM* obj,int id)
+{
+#ifdef CHECK_GC_VALUES
+    DebugCheck(ProtectedCellValues[id] != *obj);
+#endif
+}
+
+local void SetProtectedCell(int id,SCM obj)
+{
+#ifdef CHECK_GC_VALUES
+    ProtectedCellValues[id] = obj;
+#endif
+}
+
+#endif
+
 #ifdef GC_PROTECT_VALUE
+/**
+**     Check if it is usefull to GC-protect a given value
+**
+**     @param val the value to GC-protect
+**     @return 1 if the value is neither SCM_UNSPECIFIED nor NULL
+*/
 local int CclNeedProtect(SCM val)
 {
     return (val != SCM_UNSPECIFIED) && (!gh_null_p(val));
@@ -220,6 +304,12 @@
 */
 global void CclGcProtect(SCM * obj)
 {
+#ifdef DEBUG_GC
+    // Protecting an already protected cell ?
+    DebugCheck(FindProtectedCell(obj) >= 0);
+    AddProtectedCell(obj);
+#endif
+
 #ifdef GC_PROTECT_VALUE
     if (!CclNeedProtect(*obj)) {
        return;
@@ -247,6 +337,16 @@
 */
 global void CclGcUnprotect(SCM * obj)
 {
+#ifdef DEBUG_GC
+    int id;
+
+    // Check if already protected
+    id = FindProtectedCell(obj);
+    DebugCheck( id == -1);
+    CheckProtectedCell(obj,id);
+    DelProtectedCell(id);
+#endif
+
 #ifdef GC_PROTECT_VALUE
     if (!CclNeedProtect(*obj)) {
        return;
@@ -286,10 +386,21 @@
 global void CclGcProtectedAssign(SCM* obj, SCM value)
 {
 #ifdef GC_PROTECT_VALUE
-    CclGcProtect(&value);
     CclGcUnprotect(obj);
-#endif
     (*obj) = value;
+    CclGcProtect(obj);
+#else
+#ifdef DEBUG_GC
+    int id;
+    
+    // Check if already protected
+    id = FindProtectedCell(obj);
+    DebugCheck(id == -1);
+    CheckProtectedCell(obj,id);
+    SetProtectedCell(id,value);
+#endif         // DEBUG_GC
+    (*obj) = value;
+#endif // GC_PROTECT_VALUE
 }
 
 global void CclFlushOutput(void)
@@ -923,7 +1034,7 @@
 #else
     // Stop & copy GC : scan only allocated cells
     sargv[2] = "-g1";
-    sargv[3] = "-h800000";
+    sargv[3] = "-h4000000";
 #endif
     buf = malloc(strlen(StratagusLibPath) + 4);
     sprintf(buf, "-l%s", StratagusLibPath);
@@ -961,6 +1072,7 @@
     gh_new_procedureN("define-default-resource-names", 
CclDefineDefaultResourceNames);
     gh_new_procedureN("define-default-resource-amounts", 
CclDefineDefaultResourceAmounts);
 
+    NetworkCclRegister();
     IconCclRegister();
     MissileCclRegister();
     PlayerCclRegister();
@@ -1056,7 +1168,9 @@
     gh_define("stratagus-feature-libcda", SCM_BOOL_T);
 #endif
 
+#ifndef SIOD_HEAP_GC
     gh_define("*ccl-protect*", NIL);
+#endif
 
     print_welcome();
 }
@@ -1131,7 +1245,7 @@
     }
 
     fprintf(fd, ";;; -----------------------------------------\n");
-    fprintf(fd, ";;; $Id: ccl.c,v 1.126 2003/11/08 23:02:13 nehalmistry Exp 
$\n");
+    fprintf(fd, ";;; $Id: ccl.c,v 1.127 2003/11/10 19:25:33 pludov Exp $\n");
 
     fprintf(fd, "(set-video-resolution! %d %d)\n", VideoWidth, VideoHeight);
     
@@ -1156,7 +1270,7 @@
     }
 
     fprintf(fd, ";;; -----------------------------------------\n");
-    fprintf(fd, ";;; $Id: ccl.c,v 1.126 2003/11/08 23:02:13 nehalmistry Exp 
$\n");
+    fprintf(fd, ";;; $Id: ccl.c,v 1.127 2003/11/10 19:25:33 pludov Exp $\n");
 
     // Global options
     if (OriginalFogOfWar) {
@@ -1267,7 +1381,7 @@
     extern SCM oblistvar;
 
     CLprintf(file, "\n;;; -----------------------------------------\n");
-    CLprintf(file, ";;; MODULE: CCL $Id: ccl.c,v 1.126 2003/11/08 23:02:13 
nehalmistry Exp $\n\n");
+    CLprintf(file, ";;; MODULE: CCL $Id: ccl.c,v 1.127 2003/11/10 19:25:33 
pludov Exp $\n\n");
 
     for (list = oblistvar; gh_list_p(list); list = gh_cdr(list)) {
        SCM sym;
Index: stratagus/src/include/network.h
diff -u stratagus/src/include/network.h:1.44 
stratagus/src/include/network.h:1.45
--- stratagus/src/include/network.h:1.44        Sun Nov  2 16:12:53 2003
+++ stratagus/src/include/network.h     Mon Nov 10 14:25:34 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: network.h,v 1.44 2003/11/02 21:12:53 mr-russ Exp $
+//     $Id: network.h,v 1.45 2003/11/10 19:25:34 pludov Exp $
 
 #ifndef __NETWORK_H__
 #define __NETWORK_H__
@@ -197,7 +197,8 @@
     /// Send extended network command.
 extern void NetworkSendExtendedCommand(int command,int arg1,int arg2,int arg3,
        int arg4,int status);
-
+    /// Register ccl functions related to network
+extern void NetworkCclRegister(void);
 //@}
 
 #endif // !__NETWORK_H__
Index: stratagus/src/network/commands.c
diff -u stratagus/src/network/commands.c:1.73 
stratagus/src/network/commands.c:1.74
--- stratagus/src/network/commands.c:1.73       Fri Nov  7 23:58:43 2003
+++ stratagus/src/network/commands.c    Mon Nov 10 14:25:34 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: commands.c,v 1.73 2003/11/08 04:58:43 jsalmon3 Exp $
+//     $Id: commands.c,v 1.74 2003/11/10 19:25:34 pludov Exp $
 
 //@{
 
@@ -143,7 +143,7 @@
        fprintf(LogFile, "(replay-log\n");
        fprintf(LogFile, "  'comment\t\"Generated by Stratagus Version " 
VERSION "\"\n");
        fprintf(LogFile, "  'comment\t\"Visit http://Stratagus.Org for more 
information\"\n");
-       fprintf(LogFile, "  'comment\t\"$Id: commands.c,v 1.73 2003/11/08 
04:58:43 jsalmon3 Exp $\"\n");
+       fprintf(LogFile, "  'comment\t\"$Id: commands.c,v 1.74 2003/11/10 
19:25:34 pludov Exp $\"\n");
        if (NetworkFildes == (Socket)-1) {
            fprintf(LogFile, "  'type\t\"%s\"\n", "single-player");
            fprintf(LogFile, "  'race\t%d\n", GameSettings.Presets[0].Race);
@@ -412,8 +412,7 @@
     gh_define("*replay_log*", NIL);
     vload(name, 0, 1);
 
-    ReplayLog = symbol_value(gh_symbol2scm("*replay_log*"), NIL);
-    CclGcProtect(&ReplayLog);
+    CclGcProtectedAssign(&ReplayLog, 
symbol_value(gh_symbol2scm("*replay_log*"), NIL));
     NextLogCycle = ~0UL;
     if (!CommandLogDisabled) {
        CommandLogDisabled = 1;
@@ -440,7 +439,7 @@
        fclose(LogFile);
        LogFile = NULL;
     }
-    CclGcUnprotect(&ReplayLog);
+    CclGcProtectedAssign(&ReplayLog,SCM_UNSPECIFIED);
 }
 
 /**
@@ -448,7 +447,7 @@
 */
 global void CleanReplayLog(void)
 {
-    ReplayLog = NIL;
+    CclGcProtectedAssign(&ReplayLog, NIL);
     // FIXME: LoadGame disables the log since replays aren't saved in the
     // FIXME: saved games yet.  Always enable the log again for now even
     // FIXME: though it ignores the -l command line option.
@@ -620,7 +619,7 @@
        DebugLevel0Fn("Invalid name: %s" _C_ name);
     }
 
-    ReplayLog = gh_cdr(ReplayLog);
+    CclGcProtectedAssign(&ReplayLog, gh_cdr(ReplayLog));
 }
 
 /**
@@ -1155,6 +1154,12 @@
        NetworkSendExtendedCommand(ExtendedMessageSharedVision,
            -1, player, state, opponent, 0);
     }
+}
+
+global void NetworkCclRegister(void)
+{
+    ReplayLog = SCM_UNSPECIFIED;
+    CclGcProtect(&ReplayLog);
 }
 
 //@}
Index: stratagus/src/unit/ccl_unittype.c
diff -u stratagus/src/unit/ccl_unittype.c:1.110 
stratagus/src/unit/ccl_unittype.c:1.111
--- stratagus/src/unit/ccl_unittype.c:1.110     Sat Nov  8 21:42:05 2003
+++ stratagus/src/unit/ccl_unittype.c   Mon Nov 10 14:25:34 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: ccl_unittype.c,v 1.110 2003/11/09 02:42:05 n0body Exp $
+//     $Id: ccl_unittype.c,v 1.111 2003/11/10 19:25:34 pludov Exp $
 
 //@{
 
@@ -139,7 +139,6 @@
     type->NumDirections = 8;
 
     type->Property = SCM_UNSPECIFIED;
-    CclGcProtect((SCM*)&type->Property);
 
     //
     // Parse the list: (still everything could be changed!)
@@ -953,7 +952,15 @@
     if (!property) {
        DebugLevel0Fn("oops, my fault\n");
     }
-    CclGcProtectedAssign((SCM*)&type->Property, property);
+
+    if (property != SCM_UNSPECIFIED && (SCM)type->Property == SCM_UNSPECIFIED) 
{
+       CclGcProtect((SCM*)&type->Property);
+    } else if (property == SCM_UNSPECIFIED && (SCM)type->Property != 
SCM_UNSPECIFIED) {
+       CclGcProtectedAssign((SCM*)&type->Property, property);
+       CclGcUnprotect((SCM*)&type->Property);
+    } else {
+       CclGcProtectedAssign((SCM*)&type->Property, property);
+    }
 
     return property;
 }
Index: stratagus/src/unit/unittype.c
diff -u stratagus/src/unit/unittype.c:1.124 stratagus/src/unit/unittype.c:1.125
--- stratagus/src/unit/unittype.c:1.124 Sat Nov  8 21:42:05 2003
+++ stratagus/src/unit/unittype.c       Mon Nov 10 14:25:35 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: unittype.c,v 1.124 2003/11/09 02:42:05 n0body Exp $
+//     $Id: unittype.c,v 1.125 2003/11/10 19:25:35 pludov Exp $
 
 //@{
 
@@ -1191,7 +1191,7 @@
     char** sp;
 
     CLprintf(file, "\n;;; -----------------------------------------\n");
-    CLprintf(file, ";;; MODULE: unittypes $Id: unittype.c,v 1.124 2003/11/09 
02:42:05 n0body Exp $\n\n");
+    CLprintf(file, ";;; MODULE: unittypes $Id: unittype.c,v 1.125 2003/11/10 
19:25:35 pludov Exp $\n\n");
 
     // Original number to internal unit-type name.
 
@@ -1524,7 +1524,11 @@
 
        free(type->BoolFlag);
        free(type->CanTargetFlag);
-       CclGcUnprotect((SCM*)&type->Property);
+
+       if ((SCM)type->Property != SCM_UNSPECIFIED) {
+           CclGcUnprotect((SCM*)&type->Property);
+       }
+
        if (type->SameSprite) {
            free(type->SameSprite);
        }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]