gcc3.3.1 insn-scheduling bug workaround
authorClaus Gittinger <cg@exept.de>
Tue, 09 Nov 2004 18:26:59 +0100
changeset 8627 5a86b95bebbb
parent 8626 ae1fcb227a45
child 8628 38dc3601e16b
gcc3.3.1 insn-scheduling bug workaround
FileStream.st
--- a/FileStream.st	Tue Nov 09 13:21:41 2004 +0100
+++ b/FileStream.st	Tue Nov 09 18:26:59 2004 +0100
@@ -33,7 +33,7 @@
 # ifndef fileno
    /* kludge: inmos forgot fileno */
 #  define fileno(f)     ((f)->__file)
-# endif 
+# endif
 
 #else /* not transputer */
 
@@ -188,7 +188,7 @@
     system (i.e. its an interface to the stdio library).
 
     Notice, that on some systems, the standard I/O library has performance
-    problems when a file is opened for readwrite. 
+    problems when a file is opened for readwrite.
     For best results, open files either readonly or writeonly.
 
     Also notice, that some OperatingSystems do not fully support
@@ -233,7 +233,7 @@
     since all of the above is private protocol, and it is considered bad style to
     access these from user programs, we recommend subclassing FileStream as
     something like VMSFixedRecordFileStream, and redefine the instance creation
-    method(s) there as appropriate. 
+    method(s) there as appropriate.
     This will retain VMS specifics in one place and enhance maintanability.
 "
 ! !
@@ -403,7 +403,7 @@
     ^ newStream openForReading.
 
     "
-     FileStream readonlyFileNamed:'dAsGiBtEsNiChT' 
+     FileStream readonlyFileNamed:'dAsGiBtEsNiChT'
     "
 !
 
@@ -580,13 +580,13 @@
      The old behavior is simulated by providing an exception
      handler, which proceeds with nil:
 
-        OpenError ignoreIn:[ 
-            'old code expecting nil return values on errors when doing an open'.
+	OpenError ignoreIn:[
+	    'old code expecting nil return values on errors when doing an open'.
 
-            ('/dasGIBtEsbeStimmtNiChT' asFilename readStream) isNil ifTrue:[
-                self warn:'open failed'.
-            ].
-        ]
+	    ('/dasGIBtEsbeStimmtNiChT' asFilename readStream) isNil ifTrue:[
+		self warn:'open failed'.
+	    ].
+	]
     "
 
     LastErrorNumber := lastErrorNumber.
@@ -609,19 +609,19 @@
      Therefore, this method is reimplemented here (from ExternalStream)"
 
     outStream isExternalStream ifTrue:[
-        pos := self position0Based.
-        n := self size - pos.
-        nWritten := OperatingSystem 
-            copyFromFd:(self fileDescriptor)
-            toFd:(outStream fileDescriptor)
-            startIndex:pos 
-            count:n.
-        nWritten = n ifTrue:[
-            ^ self
-        ].
-        nWritten > 0 ifTrue:[
-            self position0Based:pos+nWritten.
-        ].
+	pos := self position0Based.
+	n := self size - pos.
+	nWritten := OperatingSystem
+	    copyFromFd:(self fileDescriptor)
+	    toFd:(outStream fileDescriptor)
+	    startIndex:pos
+	    count:n.
+	nWritten = n ifTrue:[
+	    ^ self
+	].
+	nWritten > 0 ifTrue:[
+	    self position0Based:pos+nWritten.
+	].
     ].
     ^ super copyToEndInto:outStream.
 
@@ -650,24 +650,24 @@
 	    f = __FILEVal(__INST(filePointer));
 #ifdef WIN32
 	    __threadErrno = 0;
-	    if (__INST(buffered) == true) {                             
+	    if (__INST(buffered) == true) {
 # if 0
-		currentPosition = STX_C_CALL1( "ftell", ftell, f);     
+		currentPosition = STX_C_CALL1( "ftell", ftell, f);
 # else
-		currentPosition = ftell(f);     
+		currentPosition = ftell(f);
 # endif
-	    } else {                                                   
-		OBJ rA = __INST(readAhead);                            
+	    } else {
+		OBJ rA = __INST(readAhead);
 		off_t offs = 0;
 
-		if (rA != nil) {                                       
-		    __INST(readAhead) = nil;                           
+		if (rA != nil) {
+		    __INST(readAhead) = nil;
 		    offs = -1;
-		}                                                      
+		}
 # if 0
-		currentPosition = STX_C_CALL3( "lseek", lseek, fileno(f), offs, SEEK_CUR); 
+		currentPosition = STX_C_CALL3( "lseek", lseek, fileno(f), offs, SEEK_CUR);
 # else
-		currentPosition = lseek(fileno(f), offs, SEEK_CUR); 
+		currentPosition = lseek(fileno(f), offs, SEEK_CUR);
 # endif
 	    }
 #else /* !WIN32 */
@@ -712,94 +712,94 @@
     OBJ fp;
 
     if ((__INST(canPosition) != false) || (newPos == __MKSMALLINT(0))) {
-        if ((fp = __INST(filePointer)) != nil) {
+	if ((fp = __INST(filePointer)) != nil) {
 
 #if defined(_LFS_LARGE_FILE) && !defined(WIN32)
 # define FSEEK fseeko
-            off_t nP;
+	    off_t nP;
 #else
 #define FSEEK fseek
-            long nP;
+	    long nP;
 #endif
 
-            if (__isSmallInteger(newPos)) {
-                nP = __intVal(newPos);
-                if (nP < 0) {
-                    __INST(lastErrorNumber) = __MKSMALLINT(EINVAL);
-                    goto getOutOfHere;
-                }
-            } else {
-                nP = __signedLongIntVal(newPos);
-                if (nP < 0) {
-                    __INST(lastErrorNumber) = __MKSMALLINT(EINVAL);
-                    goto getOutOfHere;
-                }
-                if (nP == 0) {
-                    if (sizeof(nP) == 8) {
-                        if (__signedLong64IntVal(newPos, &nP) == 0 || nP < 0) {
-                            __INST(lastErrorNumber) = __MKSMALLINT(EINVAL);
-                            goto getOutOfHere;
-                        }
-                    } else {
-                        __INST(lastErrorNumber) = __MKSMALLINT(EINVAL);
-                        goto getOutOfHere;
-                    }
-                }
-            }
+	    if (__isSmallInteger(newPos)) {
+		nP = __intVal(newPos);
+		if (nP < 0) {
+		    __INST(lastErrorNumber) = __MKSMALLINT(EINVAL);
+		    goto getOutOfHere;
+		}
+	    } else {
+		nP = __signedLongIntVal(newPos);
+		if (nP < 0) {
+		    __INST(lastErrorNumber) = __MKSMALLINT(EINVAL);
+		    goto getOutOfHere;
+		}
+		if (nP == 0) {
+		    if (sizeof(nP) == 8) {
+			if (__signedLong64IntVal(newPos, &nP) == 0 || nP < 0) {
+			    __INST(lastErrorNumber) = __MKSMALLINT(EINVAL);
+			    goto getOutOfHere;
+			}
+		    } else {
+			__INST(lastErrorNumber) = __MKSMALLINT(EINVAL);
+			goto getOutOfHere;
+		    }
+		}
+	    }
 
-            f = __FILEVal(fp);
+	    f = __FILEVal(fp);
 
-            do {
+	    do {
 #ifdef WIN32
-                __threadErrno = 0;
-                if (__INST(buffered) == true) {                                          
-                    ret = STX_C_CALL3( "fseek", fseek, f, nP, SEEK_SET);    
-                } else {                                                    
-                    __INST(readAhead) = nil;                            
-                    ret = STX_C_CALL3( "lseek", lseek, fileno(f), nP, SEEK_SET); 
-                }
+		__threadErrno = 0;
+		if (__INST(buffered) == true) {
+		    ret = STX_C_CALL3( "fseek", fseek, f, nP, SEEK_SET);
+		} else {
+		    __INST(readAhead) = nil;
+		    ret = STX_C_CALL3( "lseek", lseek, fileno(f), nP, SEEK_SET);
+		}
 #else
-                if (__INST(buffered) == true) {
-                    ret = FSEEK(f, nP, SEEK_SET);
-                } else {
-                    ret = lseek(fileno(f), nP, SEEK_SET);
-                }
+		if (__INST(buffered) == true) {
+		    ret = FSEEK(f, nP, SEEK_SET);
+		} else {
+		    ret = lseek(fileno(f), nP, SEEK_SET);
+		}
 #endif
-            } while ((ret < 0) && (__threadErrno == EINTR));
-            if (ret >= 0) {
-                __INST(position) = newPos; __STORE(self, newPos);
-                /*
-                 * just to make certain ...
-                 */
-                __INST(hitEOF) = false;
-                RETURN ( self );
-            }
-            __INST(lastErrorNumber) = __MKSMALLINT(__threadErrno);
-        }
+	    } while ((ret < 0) && (__threadErrno == EINTR));
+	    if (ret >= 0) {
+		__INST(position) = newPos; __STORE(self, newPos);
+		/*
+		 * just to make certain ...
+		 */
+		__INST(hitEOF) = false;
+		RETURN ( self );
+	    }
+	    __INST(lastErrorNumber) = __MKSMALLINT(__threadErrno);
+	}
     }
     getOutOfHere: ;
 #undef FSEEK
 %}.
     canPosition == false ifTrue:[
-        "/ position by rewinding & re-reading everything up-to
-        "/ that point.
-        ^ self slowPosition0Based:newPos
+	"/ position by rewinding & re-reading everything up-to
+	"/ that point.
+	^ self slowPosition0Based:newPos
     ].
     lastErrorNumber notNil ifTrue:[
-        (OperatingSystem errorSymbolForNumber:lastErrorNumber) == #EINVAL ifTrue:[
-            "/ invalid position
-            ^ self positionError
-        ].
-        "/ assume I/O error
-        ^ self ioError
+	(OperatingSystem errorSymbolForNumber:lastErrorNumber) == #EINVAL ifTrue:[
+	    "/ invalid position
+	    ^ self positionError
+	].
+	"/ assume I/O error
+	^ self ioError
     ].
     filePointer isNil ifTrue:[^ self errorNotOpen].
 
     rslt := self positionFile:filePointer position:newPos.
     rslt >= 0 ifTrue:[
-        position := newPos.
+	position := newPos.
     ] ifFalse:[
-        hitEOF := true.
+	hitEOF := true.
     ]
 !
 
@@ -816,17 +816,17 @@
 	do {
 #ifdef WIN32
 	    __threadErrno = 0;
-	    if (__INST(buffered) == true) {                                            
-		ret = STX_C_CALL3( "fseek", fseek, f, 0L, SEEK_END);    
-	    } else {                                                   
-		__INST(readAhead) = nil;                           
+	    if (__INST(buffered) == true) {
+		ret = STX_C_CALL3( "fseek", fseek, f, 0L, SEEK_END);
+	    } else {
+		__INST(readAhead) = nil;
 		ret = STX_C_CALL3( "lseek", lseek, fileno(f), 0L, SEEK_END);
 	    }
 #else
 	    if (__INST(buffered) == true) {
 #ifdef _LFS_LARGE_FILE
 		ret = fseeko(f, (off_t)0, SEEK_END);
-#else                
+#else
 		ret = fseek(f, 0L, SEEK_END);
 #endif
 	    } else {
@@ -924,7 +924,7 @@
 
     super closeFile.
     removeOnClose == true ifTrue:[
-        pathName asFilename remove.
+	pathName asFilename remove.
     ]
 
     "Created: / 13.8.1998 / 12:11:22 / cg"
@@ -950,7 +950,7 @@
 !
 
 openFile:pathName withMode:openmode attributes:attributeSpec
-    "open the file; 
+    "open the file;
      openmode is the string defining the way to open as defined by the stdio library
      (i.e. the 2nd fopen argument).
 
@@ -969,238 +969,250 @@
 %{
     HFILE f;
     HFILE fopen();
-    OBJ fp;
     int pass = 0;
 
 retry:
     if (__isNonNilObject(pathName) && (__qClass(pathName)==String)) {
 #ifdef __VMS__
-        do {
-            /*
-             * allow passing additional RMS arguments.
-             * stupid: DEC does not seem to offer an interface for passing a char **.
-             */
-            __threadErrno = 0;
+	do {
+	    /*
+	     * allow passing additional RMS arguments.
+	     * stupid: DEC does not seem to offer an interface for passing a char **.
+	     */
+	    __threadErrno = 0;
 
-            {
-                if (__isArray(attributeSpec)) {
-                    OBJ *ap = __ArrayInstPtr(attributeSpec)->a_element;
-                    int numAttrib = 0;
-                    int i;
+	    {
+		if (__isArray(attributeSpec)) {
+		    OBJ *ap = __ArrayInstPtr(attributeSpec)->a_element;
+		    int numAttrib = 0;
+		    int i;
 
-                    numAttrib = __arraySize(attributeSpec);
-                    for (i=0; i<numAttrib;i++) {
-                        if (! __isString(ap[i])) {
-                            f = NULL;
-                            __threadErrno = EINVAL; /* invalid argument */
-                            goto getOutOfHere;
-                        }
-                    }
-                    switch (numAttrib) {
-                        case 0:
-                            __BEGIN_INTERRUPTABLE__
-                            f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode));
-                            __END_INTERRUPTABLE__
-                            break;
-                        case 1:
-                            __BEGIN_INTERRUPTABLE__
-                            f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
-                                      __stringVal(ap[0]));
-                            __END_INTERRUPTABLE__
-                            break;
-                        case 2:
-                            __BEGIN_INTERRUPTABLE__
-                            f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
-                                      __stringVal(ap[0]), __stringVal(ap[1]));
-                            __END_INTERRUPTABLE__
-                            break;
-                        case 3:
-                            __BEGIN_INTERRUPTABLE__
-                            f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
-                                      __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]));
-                            __END_INTERRUPTABLE__
-                            break;
-                        case 4:
-                            __BEGIN_INTERRUPTABLE__
-                            f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
-                                      __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
-                                      __stringVal(ap[3]));
-                            __END_INTERRUPTABLE__
-                            break;
-                        case 5:
-                            __BEGIN_INTERRUPTABLE__
-                            f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
-                                      __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
-                                      __stringVal(ap[3]), __stringVal(ap[4]));
-                            __END_INTERRUPTABLE__
-                            break;
-                        case 6:
-                            __BEGIN_INTERRUPTABLE__
-                            f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
-                                      __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
-                                      __stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]));
-                            __END_INTERRUPTABLE__
-                            break;
-                        case 7:
-                            __BEGIN_INTERRUPTABLE__
-                            f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
-                                      __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
-                                      __stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]),
-                                      __stringVal(ap[6]));
-                            __END_INTERRUPTABLE__
-                            break;
-                        case 8:
-                            __BEGIN_INTERRUPTABLE__
-                            f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
-                                      __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
-                                      __stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]),
-                                      __stringVal(ap[6]), __stringVal(ap[7]));
-                            __END_INTERRUPTABLE__
-                            break;
-                        case 9:
-                            __BEGIN_INTERRUPTABLE__
-                            f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
-                                      __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
-                                      __stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]),
-                                      __stringVal(ap[6]), __stringVal(ap[7]), __stringVal(ap[8]));
-                            __END_INTERRUPTABLE__
-                            break;
-                        case 10:
-                            __BEGIN_INTERRUPTABLE__
-                            f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
-                                      __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
-                                      __stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]),
-                                      __stringVal(ap[6]), __stringVal(ap[7]), __stringVal(ap[8]),
-                                      __stringVal(ap[9]));
-                            __END_INTERRUPTABLE__
-                            break;
-                        default:
-                            f = NULL;
-                            __threadErrno = E2BIG; /* too many args */
-                            goto getOutOfHere;
-                    }
-                } else if (attributeSpec != nil) {
-                    f = NULL;
-                    __threadErrno = EINVAL; /* invalid argument */
-                    goto getOutOfHere;
-                } else {
-                    /*
-                     * create file as sequential streamLF by default.
-                     */
-                    __BEGIN_INTERRUPTABLE__
-                    f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), "rfm=stmlf");
-                    __END_INTERRUPTABLE__
-                }
-            }
-        } while ((f == NULL) && (__threadErrno == EINTR));
+		    numAttrib = __arraySize(attributeSpec);
+		    for (i=0; i<numAttrib;i++) {
+			if (! __isString(ap[i])) {
+			    f = NULL;
+			    __threadErrno = EINVAL; /* invalid argument */
+			    goto getOutOfHere;
+			}
+		    }
+		    switch (numAttrib) {
+			case 0:
+			    __BEGIN_INTERRUPTABLE__
+			    f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode));
+			    __END_INTERRUPTABLE__
+			    break;
+			case 1:
+			    __BEGIN_INTERRUPTABLE__
+			    f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
+				      __stringVal(ap[0]));
+			    __END_INTERRUPTABLE__
+			    break;
+			case 2:
+			    __BEGIN_INTERRUPTABLE__
+			    f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
+				      __stringVal(ap[0]), __stringVal(ap[1]));
+			    __END_INTERRUPTABLE__
+			    break;
+			case 3:
+			    __BEGIN_INTERRUPTABLE__
+			    f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
+				      __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]));
+			    __END_INTERRUPTABLE__
+			    break;
+			case 4:
+			    __BEGIN_INTERRUPTABLE__
+			    f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
+				      __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
+				      __stringVal(ap[3]));
+			    __END_INTERRUPTABLE__
+			    break;
+			case 5:
+			    __BEGIN_INTERRUPTABLE__
+			    f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
+				      __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
+				      __stringVal(ap[3]), __stringVal(ap[4]));
+			    __END_INTERRUPTABLE__
+			    break;
+			case 6:
+			    __BEGIN_INTERRUPTABLE__
+			    f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
+				      __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
+				      __stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]));
+			    __END_INTERRUPTABLE__
+			    break;
+			case 7:
+			    __BEGIN_INTERRUPTABLE__
+			    f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
+				      __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
+				      __stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]),
+				      __stringVal(ap[6]));
+			    __END_INTERRUPTABLE__
+			    break;
+			case 8:
+			    __BEGIN_INTERRUPTABLE__
+			    f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
+				      __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
+				      __stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]),
+				      __stringVal(ap[6]), __stringVal(ap[7]));
+			    __END_INTERRUPTABLE__
+			    break;
+			case 9:
+			    __BEGIN_INTERRUPTABLE__
+			    f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
+				      __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
+				      __stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]),
+				      __stringVal(ap[6]), __stringVal(ap[7]), __stringVal(ap[8]));
+			    __END_INTERRUPTABLE__
+			    break;
+			case 10:
+			    __BEGIN_INTERRUPTABLE__
+			    f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
+				      __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
+				      __stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]),
+				      __stringVal(ap[6]), __stringVal(ap[7]), __stringVal(ap[8]),
+				      __stringVal(ap[9]));
+			    __END_INTERRUPTABLE__
+			    break;
+			default:
+			    f = NULL;
+			    __threadErrno = E2BIG; /* too many args */
+			    goto getOutOfHere;
+		    }
+		} else if (attributeSpec != nil) {
+		    f = NULL;
+		    __threadErrno = EINVAL; /* invalid argument */
+		    goto getOutOfHere;
+		} else {
+		    /*
+		     * create file as sequential streamLF by default.
+		     */
+		    __BEGIN_INTERRUPTABLE__
+		    f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), "rfm=stmlf");
+		    __END_INTERRUPTABLE__
+		}
+	    }
+	} while ((f == NULL) && (__threadErrno == EINTR));
 
 #else /* not VMS */
 
 # ifdef WIN32
-        {
-            char _aPathName[MAXPATHLEN];
-            char _openMode[64];
+	{
+	    char _aPathName[MAXPATHLEN];
+	    char _openMode[64];
 
-            strncpy(_aPathName, __stringVal(pathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0';
-            strncpy(_openMode, __stringVal(openmode), sizeof(_openMode)-1); _openMode[sizeof(_openMode)-1] = '\0';
-            do {
-                __threadErrno = 0;
-                f = STX_C_CALL2( "fopen", fopen, _aPathName, _openMode);
-                if (__threadErrno == EINTR) {
-                    f = NULL;
-                }
-            } while ((f == NULL) && (__threadErrno == EINTR));
-        }
+	    strncpy(_aPathName, __stringVal(pathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0';
+	    strncpy(_openMode, __stringVal(openmode), sizeof(_openMode)-1); _openMode[sizeof(_openMode)-1] = '\0';
+	    do {
+		__threadErrno = 0;
+		f = STX_C_CALL2( "fopen", fopen, _aPathName, _openMode);
+		if (__threadErrno == EINTR) {
+		    f = NULL;
+		}
+	    } while ((f == NULL) && (__threadErrno == EINTR));
+	}
 # else /* not WIN32 */
 
-        do {
-            __BEGIN_INTERRUPTABLE__
+	do {
+	    __BEGIN_INTERRUPTABLE__
 #  ifdef LINUX
-            /* 
-             * LINUX may ret a non-NULL f even when interrupted.
-             * Therefore, check errno and fake a null-ret.
-             */
-            __threadErrno = 0;
-            f = fopen((char *) __stringVal(pathName), (char *) __stringVal(openmode));
-            if (__threadErrno == EINTR)
-                f = NULL;
+	    /*
+	     * LINUX may ret a non-NULL f even when interrupted.
+	     * Therefore, check errno and fake a null-ret.
+	     */
+	    __threadErrno = 0;
+	    f = fopen((char *) __stringVal(pathName), (char *) __stringVal(openmode));
+	    if (__threadErrno == EINTR)
+		f = NULL;
 #  else /* not LINUX */
-            f = fopen((char *) __stringVal(pathName), (char *) __stringVal(openmode));
+	    f = fopen((char *) __stringVal(pathName), (char *) __stringVal(openmode));
 #  endif /* not LINUX */
-            __END_INTERRUPTABLE__
-        } while ((f == NULL) && (__threadErrno == EINTR));
+	    __END_INTERRUPTABLE__
+	} while ((f == NULL) && (__threadErrno == EINTR));
 
 # endif /* not WIN32 */
 #endif /* not VMS */
 
-        if (f == NULL) {
-            /*
-             * If no filedescriptors available, try to finalize
-             * possibly collected fd's and try again.
-             */
-            if (pass == 0 && (__threadErrno == ENFILE || __threadErrno == EMFILE)) {
-                pass = 1;
-                __SSEND0(@global(ObjectMemory), @symbol(scavenge), 0);
-                __SSEND0(@global(ObjectMemory), @symbol(finalize), 0);
-                goto retry;
-            }
-        getOutOfHere: ;
-            __INST(lastErrorNumber) = __MKSMALLINT(__threadErrno);
-            __INST(position) = nil;
-        } else {
+	if (f == NULL) {
+	    /*
+	     * If no filedescriptors available, try to finalize
+	     * possibly collected fd's and try again.
+	     */
+	    if (pass == 0 && (__threadErrno == ENFILE || __threadErrno == EMFILE)) {
+		pass = 1;
+		__SSEND0(@global(ObjectMemory), @symbol(scavenge), 0);
+		__SSEND0(@global(ObjectMemory), @symbol(finalize), 0);
+		goto retry;
+	    }
+	getOutOfHere: ;
+	    __INST(lastErrorNumber) = __MKSMALLINT(__threadErrno);
+	    __INST(position) = nil;
+	} else {
 #ifdef __VMS__
-            /*
-             * check to see if this is positionable ...
-             */
-            __INST(canPosition) = false;
+	    /*
+	     * check to see if this is positionable ...
+	     */
+	    __INST(canPosition) = false;
 # ifndef _POSIX_C_SOURCE
-            {
-                struct stat statBuffer;
+	    {
+		struct stat statBuffer;
 
-                if (fstat(fileno(f), &statBuffer) >= 0) {
-                    switch (statBuffer.st_fab_rfm) {
-                        case FAB$C_UDF: /* undefined (also stream binary)   */
-                        case FAB$C_VAR: /* variable length records          */
-                        case FAB$C_VFC: /* variable fixed control           */
-                        case FAB$C_STM: /* RMS-11 stream (valid only for sequen> */
-                        default:
-                            __INST(canPosition) = false;
-                            break;
+		if (fstat(fileno(f), &statBuffer) >= 0) {
+		    switch (statBuffer.st_fab_rfm) {
+			case FAB$C_UDF: /* undefined (also stream binary)   */
+			case FAB$C_VAR: /* variable length records          */
+			case FAB$C_VFC: /* variable fixed control           */
+			case FAB$C_STM: /* RMS-11 stream (valid only for sequen> */
+			default:
+			    __INST(canPosition) = false;
+			    break;
 
-                        case FAB$C_FIX: /* fixed length records             */
-                        case FAB$C_STMLF: /* LF stream (valid only for sequential> */
-                        case FAB$C_STMCR: /* CR stream (valid only for sequential> */
-                            __INST(canPosition) = true;
-                            break;
-                    }
-                }
-            }
-# endif 
+			case FAB$C_FIX: /* fixed length records             */
+			case FAB$C_STMLF: /* LF stream (valid only for sequential> */
+			case FAB$C_STMCR: /* CR stream (valid only for sequential> */
+			    __INST(canPosition) = true;
+			    break;
+		    }
+		}
+	    }
+# endif
 #else /* not VMS */
-            __INST(canPosition) = true;
+	    __INST(canPosition) = true;
 #endif /* poor VMS */
 
-            if (@global(FileOpenTrace) == true) {
-                fprintf(stderr, "fopen %s [FileStream] -> %x\n", __stringVal(pathName), f);
-            }
-            if (f != NULL) {
-                wasBlocked = __BLOCKINTERRUPTS();
-                __INST(filePointer) = fp = __MKOBJ((INT)f); __STORE(self, fp);
-            }
-        }
+	    if (@global(FileOpenTrace) == true) {
+		fprintf(stderr, "fopen %s [FileStream] -> %x\n", __stringVal(pathName), f);
+	    }
+	    if (f != NULL) {
+		OBJ fp;
+
+		wasBlocked = __BLOCKINTERRUPTS();
+#if 0
+		// The original code was:
+		__INST(filePointer) = fp = __MKOBJ((INT)f); __STORE(self, fp);
+		// but for that, gcc generates wrong code, which loads self (volatile) into
+		// a register (bp), then calls __MKOBJ, then stores indirect bp.
+		// That is wrong if a scavenge occurs in MKOBJ, as bp is now still pointing to the old
+		// object.
+#else
+		fp = __MKOBJ((INT)f);
+		__INST(filePointer) = fp;
+		__STORE(self, fp);
+#endif
+	    }
+	}
     }
 %}.
     position := ZeroPosition.
     filePointer notNil ifTrue:[
-        Lobby register:self.
-        wasBlocked == false ifTrue:[OperatingSystem unblockInterrupts].
+	Lobby register:self.
+	wasBlocked == false ifTrue:[OperatingSystem unblockInterrupts].
     ].
     ^ filePointer
 !
 
 openForAppending
     "open the file for writeonly appending to the end.
-     If the file does not exist its an error, raise OpenError; 
+     If the file does not exist its an error, raise OpenError;
      otherwise return the receiver."
 
     mode := #writeonly.
@@ -1210,7 +1222,7 @@
 
 openForReadWrite
     "open the file for read/write.
-     If the file does not exist its an error, raise OpenError; 
+     If the file does not exist its an error, raise OpenError;
      otherwise return the receiver."
 
     mode := #readwrite.
@@ -1219,7 +1231,7 @@
 
 openForReading
     "open the file for readonly.
-     If the file does not exist its an error, raise OpenError; 
+     If the file does not exist its an error, raise OpenError;
      otherwise return the receiver."
 
     mode := #readonly.
@@ -1229,7 +1241,7 @@
 
 openForWriting
     "open the file writeonly. The contents of the file is preserved.
-     If the file does not exist its an error, raise OpenError; 
+     If the file does not exist its an error, raise OpenError;
      otherwise return the receiver."
 
     mode := #writeonly.
@@ -1245,12 +1257,12 @@
 
      This is a private entry, but maybe useful to open a file in a special mode,
      which is proprietrary to the operatingSystem."
-     
+
     ^ self openWithMode:openmode attributes:nil
 !
 
 openWithMode:openmode attributes:attributeSpec
-    "open the file; 
+    "open the file;
      openmode is the string defining the way to open as defined by the stdio library
      (i.e. the 2nd fopen argument).
 
@@ -1268,14 +1280,14 @@
 
     filePointer := self openFile:pathName withMode:openmode attributes:attributeSpec.
     filePointer isNil ifTrue:[
-        "
-         the open failed for some reason ...
-        "
-        ^ self openError
+	"
+	 the open failed for some reason ...
+	"
+	^ self openError
     ].
     position := ZeroPosition.
     buffered isNil ifTrue:[
-        buffered := true.       "default is buffered"
+	buffered := true.       "default is buffered"
     ].
 !
 
@@ -1300,37 +1312,37 @@
      sent after snapin to reopen streams."
 
     filePointer notNil ifTrue:[
-        "it was open, when snapped-out"
-        filePointer := nil.
-        Lobby unregister:self.
-        pathName isNil ifTrue:[
-            ^ self.
-        ].
-        [
-            |oldPos|
+	"it was open, when snapped-out"
+	filePointer := nil.
+	Lobby unregister:self.
+	pathName isNil ifTrue:[
+	    ^ self.
+	].
+	[
+	    |oldPos|
 
-            "should take care of appending files and open them for
-             append / position them to the end"
+	    "should take care of appending files and open them for
+	     append / position them to the end"
 
-            oldPos := position.
+	    oldPos := position.
 
-            mode == #readonly ifTrue: [
-                self openForReading
-            ] ifFalse:[mode == #writeonly ifTrue: [
-                self openForWriting.
-            ] ifFalse:[
-                self openForReadWrite.
-            ]].
+	    mode == #readonly ifTrue: [
+		self openForReading
+	    ] ifFalse:[mode == #writeonly ifTrue: [
+		self openForWriting.
+	    ] ifFalse:[
+		self openForReadWrite.
+	    ]].
 
-            oldPos notNil ifTrue:[
-                self position:oldPos.
-            ]
-        ] on:OpenError do:[:ex|
-            "this happens, if after a restart, 
-             the file is no longer present or accessable ..."
+	    oldPos notNil ifTrue:[
+		self position:oldPos.
+	    ]
+	] on:OpenError do:[:ex|
+	    "this happens, if after a restart,
+	     the file is no longer present or accessable ..."
 
-            (self class name , ' [warning]: could not reopen file: ', pathName) errorPrintCR.
-        ]. 
+	    (self class name , ' [warning]: could not reopen file: ', pathName) errorPrintCR.
+	].
     ]
 
     "Modified: 10.1.1997 / 17:50:51 / cg"
@@ -1429,7 +1441,7 @@
 !FileStream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/FileStream.st,v 1.115 2004-09-29 13:42:29 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/FileStream.st,v 1.116 2004-11-09 17:26:59 cg Exp $'
 ! !
 
 FileStream initialize!