Am Dienstag, 19. September 2006 00:39 schrieb Christian Ohm:
> OK, this might work. Please check before applying, as I might have been
> too tired to get the pointer stuff correct.
I had a quick look at the patch and wondered why you pass a pointer to a 
pointer to RETSTACK_TYPE to PopRetStack()

The you set the given pointer to point to a value in the stack.
Is that sane? What if the value gets overwritten for some reason?
And why didn't you just copy the entry like it was done before?

I attached another patch which does it like I would have done it.
It doesn't crash at least. Didn't test it thoroughly, because there were those 
problems with the scripting engine and functions.

--Dennis
Index: lib/script/script.h
===================================================================
--- lib/script/script.h	(revision 369)
+++ lib/script/script.h	(working copy)
@@ -20,6 +20,12 @@
 	SCR_NODEBUG,		// Do not generate debug info
 } SCR_DEBUGTYPE;
 
+typedef struct _retstack_type
+{
+	UDWORD event;
+	UDWORD *address;
+} RETSTACK_TYPE;
+
 // If this is defined we save out the compiled scripts
 #define SCRIPTTYPE SCR_DEBUGINFO
 
@@ -61,10 +67,10 @@
  * Return stack stuff
  */
 extern void retStackReset(void);
-extern UDWORD RetStackRemember(UDWORD EvTrigIndex, UDWORD address);
+extern BOOL RetStackRemember(UDWORD EvTrigIndex, UDWORD *address);
 
 extern BOOL IsRetStackEmpty(void);
-extern BOOL PopRetStack(UDWORD  *psVal);
+extern BOOL PopRetStack(RETSTACK_TYPE *psVal);
 extern SDWORD GetCallDepth(void);
 
 /***********************************************************************************
Index: lib/script/interp.c
===================================================================
--- lib/script/interp.c	(revision 369)
+++ lib/script/interp.c	(working copy)
@@ -19,8 +19,6 @@
 // an infinite loop
 #define INTERP_MAXINSTRUCTIONS		100000
 
-
-
 /* The size of each opcode */
 SDWORD aOpSize[] =
 {
@@ -329,7 +327,7 @@
 				case OP_FUNC:
 					//debug( LOG_SCRIPT, "-OP_FUNC" );
 					//debug( LOG_SCRIPT, "OP_FUNC: remember event %d, ip=%d", CurEvent, (ip + 2) );
-					if(!RetStackRemember(CurEvent, *(ip + 2)))	//Remember where to jump back later
+					if(!RetStackRemember(CurEvent, (ip + 2)))	//Remember where to jump back later
 					{
 						debug( LOG_ERROR, "interpRunScript() - RetStackRemember() failed.");
 						return FALSE;
@@ -727,6 +725,7 @@
 
 			if(!IsRetStackEmpty())		//There was a caller function before this one
 			{
+				RETSTACK_TYPE retstack;
 				//debug(LOG_SCRIPT, "GetCallDepth = %d", GetCallDepth());
 
 				//reset local vars (since trigger can't be called, only local vars of an event can be reset here)
@@ -736,20 +735,14 @@
 					goto exit_with_error;
 				}
 
-				if(!PopRetStack((UDWORD *)&ip))		//Pop return address
+				if (!PopRetStack(&retstack))
 				{
-					debug( LOG_ERROR, "interpRunScript() - PopRetStack(): failed to pop return adress.");
+					debug( LOG_ERROR, "interpRunScript() - PopRetStack() failed.");
 					return FALSE;
 				}
+				ip = retstack.address;
+				CurEvent = retstack.event;
 
-				//debug(LOG_SCRIPT, "Return adress = %d", ip);
-
- 				if(!PopRetStack(&CurEvent))	//Pop event index
-				{
-					debug( LOG_ERROR, "interpRunScript() - PopRetStack(): failed to pop return event index.");
-					return FALSE;
-				}
-
 				//debug( LOG_SCRIPT, "RETURNED TO CALLER EVENT %d", CurEvent );
 
 				//Set new boundries
@@ -930,7 +923,7 @@
 
 /* Call stack stuff */
 
-static UDWORD	retStack[200];	//Primitive stack
+static RETSTACK_TYPE	retStack[100];	//Primitive stack
 static SDWORD	retStackPos;	//Current Position, always points to the last valid element
 
 void retStackReset(void)
@@ -939,19 +932,18 @@
 }
 
 //Remember current script execution adress
-UDWORD RetStackRemember(UDWORD EvTrigIndex, UDWORD address)
+BOOL RetStackRemember(UDWORD EvTrigIndex, UDWORD *address)
 {
 	//DbgMsg("To remember: %d, %d, %d", EvTrigIndex, address, retStackPos);
 
-	if (retStackPos >= 200)
+	if (retStackPos >= 100)
 	{
 		debug( LOG_ERROR, "RetStackRemember() - return address stack is full");
 		return FALSE;	//Stack full
 	}
 
-	retStackPos = retStackPos + 2;
-	retStack[retStackPos - 1] = EvTrigIndex;	//First store event index
-	retStack[retStackPos] = address;			//current ip
+	retStack[++retStackPos].event = EvTrigIndex;	//First store event index
+	retStack[retStackPos].address = address;			//current ip
 
 	//debug( LOG_SCRIPT, "RetStackRemember: ip=%d, event=%d", address, EvTrigIndex);
 
@@ -964,18 +956,16 @@
 	return FALSE;
 }
 
-BOOL PopRetStack(UDWORD  *psVal)
+BOOL PopRetStack(RETSTACK_TYPE *psVal)
 {
-	if(retStackPos < 0)
+	if (retStackPos < 0)
 	{
 		debug( LOG_ERROR, "PopRetStack: retStackPos < 0");
 		return FALSE;
 	}
 
-	*psVal = retStack[retStackPos];
+	*psVal = retStack[retStackPos--];
 
-	retStackPos = retStackPos - 1;
-
 	//debug( LOG_SCRIPT, "PopRetStack: val=%d", *psVal);
 
 	return TRUE;
@@ -983,5 +973,5 @@
 
 SDWORD GetCallDepth(void)
 {
-	return (retStackPos + 1) / 2;
+	return (retStackPos + 1);
 }

Attachment: pgpzoYr8B01kc.pgp
Description: PGP signature

_______________________________________________
Warzone-dev mailing list
Warzone-dev@gna.org
https://mail.gna.org/listinfo/warzone-dev

Reply via email to