Change 14584: Fix horrible list maintencance bugs (MacPerl Bug #443568)

[email protected] (Chris Nandor) Thu, 7 Feb 2002 16:39:05 -0500
Newsgroups perl.perl5.changes.mac
Message-ID <p0510030ab888a4690d48@[10.0.1.177]>
Change 14584 by pudge@pudge-mobile on 2002/02/07 18:38:03

	Fix horrible list maintencance bugs (MacPerl Bug #443568)

Affected files ...

.... //depot/maint-5.6/macperl/macos/macperl/MPAEVTStream.cp#3 edit

Differences ...

==== //depot/maint-5.6/macperl/macos/macperl/MPAEVTStream.cp#3 (text) ====
Index: perl/macos/macperl/MPAEVTStream.cp
--- perl/macos/macperl/MPAEVTStream.cp.~1~	Thu Feb  7 11:45:10 2002
+++ perl/macos/macperl/MPAEVTStream.cp	Thu Feb  7 11:45:10 2002
@@ -5,6 +5,9 @@
 Language	:	MPW C/C++
 
 $Log: MPAEVTStream.cp,v $
+Revision 1.5  2002/01/28 07:42:35  neeri
+Fix horrible list maintencance bugs (MacPerl Bug #443568)
+
 Revision 1.4  2002/01/04 03:34:45  pudge
 Modifications for universal headers 3.4
 
@@ -516,7 +519,7 @@
 		AEDesc	doneDesc;
 		
 		if (AEGetParamDesc(input, 'SASE', typeAERecord, &sase))
-			if (mode = 'DPLX')
+			if (mode == 'DPLX')
 				AEBuild(&sase, "{evcl: McPL, evid: SASE}");
 		if (sase.dataHandle) {
 			AEGetAttributeDesc(input, keyAddressAttr, typeWildCard, &target);
@@ -532,67 +535,48 @@
 
 void MPAEVTDevice::KillInput()
 {
-	int				runs = 0;
-	MPAEVTSocket * sock = first;
-
-	if (sock)
-		while ((runs += sock == first) < 2) {
-			if (sock->needy) 
-				sock->eof = true;
-			
-			sock = sock->next;
-		}
+	for (MPAEVTSocket * sock = first; sock; sock = sock->next)
+		if (sock->needy) 
+			sock->eof = true;
 }
 
 void MPAEVTDevice::FlushInput()
 {
-	int				runs = 0;
-	MPAEVTSocket * sock = first;
-
-	if (sock)
-		while ((runs += sock == first) < 2) {
-			if (sock->inData) 
-				SetHandleSize(sock->inData, 0);
-			
-			sock = sock->next;
-		}
+	for (MPAEVTSocket * sock = first; sock; sock = sock->next)
+		if (sock->inData) 
+			SetHandleSize(sock->inData, 0);
 	AEDisposeDesc(&sase);
 	AEDisposeDesc(&target);
 }
 
 void MPAEVTDevice::CollectOutput(AppleEvent * output)
 {
-	OSErr				err;
+	OSErr			err;
 	MPAEStream 		want;
 	AEDesc			desc;
 	int				wantCount = 0;
-	int				runs = 0;
-	MPAEVTSocket * sock = first;
 	
 	desc.descriptorType = 'TEXT';
 	
 	want.OpenList();
 	
-	if (sock)
-		while ((runs += sock == first) < 2) {
-			if (sock->outData && GetHandleSize(sock->outData)) {
-				desc.dataHandle = sock->outData;
-				if (sock->key == '----')
-					if (!AEPutParamDesc(output, '----', &desc))
-						SetHandleSize(sock->outData, 0);
-					else 
-						return;							// This is sort of disastrous
-				else if (outputData.WriteKey(sock->key) || outputData.WriteDesc(desc))				
-					return;								// 	... so is this.
+	for (MPAEVTSocket * sock = first; sock; sock = sock->next) {
+		if (sock->outData && GetHandleSize(sock->outData)) {
+			desc.dataHandle = sock->outData;
+			if (sock->key == '----')
+				if (!AEPutParamDesc(output, '----', &desc))
+					SetHandleSize(sock->outData, 0);
 				else 
-					++outputDataCount;
-			}
-			if (sock->inData && sock->needy)
-				if (!want.WriteDesc(typeEnumerated, &sock->key, 4))
-					++wantCount;
-			
-			sock = sock->next;
+					return;							// This is sort of disastrous
+			else if (outputData.WriteKey(sock->key) || outputData.WriteDesc(desc))				
+				return;								// 	... so is this.
+			else 
+				++outputDataCount;
 		}
+		if (sock->inData && sock->needy)
+			if (!want.WriteDesc(typeEnumerated, &sock->key, 4))
+				++wantCount;
+	}
 	
 	if (outputDirect.dataHandle) {
 		err = AEPutParamDesc(output, '----', &outputDirect);
@@ -630,17 +614,17 @@
 		want.Close();
 	
 	AEPutParamPtr(output, 'DONE', typeBoolean, (Ptr) &finish, 1);
-	
-	if (sock)	
-		for (runs = 0; (runs += sock == first) < 2; sock = sock->next) 
-			if (sock->outData) 
-				SetHandleSize(sock->outData, 0);
+
+	for (MPAEVTSocket * sock = first; sock; sock = sock->next)
+		if (sock->outData) 
+			SetHandleSize(sock->outData, 0);
 }
 
 void MPAEVTDevice::Enqueue(MPAEVTSocket * sock)
 {
 	sock->prev = nil;
-	sock->next = first;
+	if (sock->next = first)
+		first->prev = sock;
 	first = sock;
 }
 
@@ -656,10 +640,7 @@
 
 MPAEVTSocket * MPAEVTDevice::Lookup(OSType key, Boolean input, Boolean output)
 {
-	int				runs = 0;
-	MPAEVTSocket * sock = first;
-	
-	while (sock)
+	for (MPAEVTSocket * sock = first; sock; sock = sock->next)
 		if (sock->key == key) {
 			if (input && !sock->inData)
 				sock->inData = NewHandle(0);
@@ -667,8 +648,7 @@
 				sock->outData = NewHandle(0);
 			
 			return sock;
-		} else
-			sock = sock->next;
+		}
 	
 	return new MPAEVTSocket(key, input, output);
 }
End of Patch.