# HG changeset patch # User Claus Gittinger # Date 892121342 -7200 # Node ID be1b59238c4cea46c8819fde25c6d34b742aa65b # Parent 55b7b83bf8591c70e09eac162f76a8a80c1d6d73 care for position-error when extracting source diff -r 55b7b83bf859 -r be1b59238c4c Method.st --- a/Method.st Wed Apr 08 12:33:55 1998 +0200 +++ b/Method.st Thu Apr 09 13:29:02 1998 +0200 @@ -418,70 +418,70 @@ "/ aStream close "/ ] - LastMethodSources notNil ifTrue:[ - junk := LastMethodSources at:self ifAbsent:nil. - junk notNil ifTrue:[ - ^ junk - ] - ]. - - "/ keep the last source file open, because open/close - "/ operations maybe slow on NFS-mounted file systems. - "/ Since the reference to the file is weak, it will be closed - "/ automatically if the file is not referenced for a while. - "/ Neat trick. - - LastFileLock critical:[ - aStream := LastFileReference at:1. - LastFileReference at:1 put:0. - - aStream == 0 ifTrue:[ - aStream := nil. - ] ifFalse:[ - LastSourceFileName = source ifFalse:[ - aStream close. - aStream := nil. - ]. - ]. - ]. - - "/ a negative sourcePosition indicates - "/ that this is a local file (not to be requested - "/ via the sourceCodeManager) - "/ This kludge was added, to allow sourceCode to be - "/ saved to a local source file (i.e. 'st.src') - "/ and having a clue for which file is meant later. - - sourcePosition < 0 ifTrue:[ - aStream := source asFilename readStream. - aStream isNil ifTrue:[ - fileName := Smalltalk getSourceFileName:source. - fileName notNil ifTrue:[ - aStream := fileName asFilename readStream. - ]. - ]. - ]. - - aStream isNil ifTrue:[ - "/ - "/ if there is no SourceManager, look in standard places - "/ first - "/ - (mgr := Smalltalk at:#SourceCodeManager) isNil ifTrue:[ - fileName := Smalltalk getSourceFileName:source. - fileName notNil ifTrue:[ - aStream := fileName asFilename readStream. - ]. - ]. - - aStream isNil ifTrue:[ - "/ - "/ nope - ask my class for the source (this also invokes the SCMgr) - "/ - who := self who. - who notNil ifTrue:[ - myClass := who methodClass. - aStream := myClass sourceStreamFor:source. + LastMethodSources notNil ifTrue:[ + junk := LastMethodSources at:self ifAbsent:nil. + junk notNil ifTrue:[ + ^ junk + ] + ]. + + "/ keep the last source file open, because open/close + "/ operations maybe slow on NFS-mounted file systems. + "/ Since the reference to the file is weak, it will be closed + "/ automatically if the file is not referenced for a while. + "/ Neat trick. + + LastFileLock critical:[ + aStream := LastFileReference at:1. + LastFileReference at:1 put:0. + + aStream == 0 ifTrue:[ + aStream := nil. + ] ifFalse:[ + LastSourceFileName = source ifFalse:[ + aStream close. + aStream := nil. + ]. + ]. + ]. + + "/ a negative sourcePosition indicates + "/ that this is a local file (not to be requested + "/ via the sourceCodeManager) + "/ This kludge was added, to allow sourceCode to be + "/ saved to a local source file (i.e. 'st.src') + "/ and having a clue for which file is meant later. + + sourcePosition < 0 ifTrue:[ + aStream := source asFilename readStream. + aStream isNil ifTrue:[ + fileName := Smalltalk getSourceFileName:source. + fileName notNil ifTrue:[ + aStream := fileName asFilename readStream. + ]. + ]. + ]. + + aStream isNil ifTrue:[ + "/ + "/ if there is no SourceManager, look in standard places + "/ first + "/ + (mgr := Smalltalk at:#SourceCodeManager) isNil ifTrue:[ + fileName := Smalltalk getSourceFileName:source. + fileName notNil ifTrue:[ + aStream := fileName asFilename readStream. + ]. + ]. + + aStream isNil ifTrue:[ + "/ + "/ nope - ask my class for the source (this also invokes the SCMgr) + "/ + who := self who. + who notNil ifTrue:[ + myClass := who methodClass. + aStream := myClass sourceStreamFor:source. "/ the check below is no good - "/ the classes stream may be an HTTP-stream, cached fileStream @@ -494,76 +494,80 @@ "/ aStream close. "/ aStream := nil. "/ ] - ]. - - aStream isNil ifTrue:[ - "/ - "/ nope - look in standard places - "/ (if there is a source-code manager - otherwise, we already did that) - "/ - mgr notNil ifTrue:[ - fileName := Smalltalk getSourceFileName:source. - fileName notNil ifTrue:[ - aStream := fileName asFilename readStream. - ] - ]. - - "/ - "/ final chance: try current directory - "/ - aStream isNil ifTrue:[ - aStream := source asFilename readStream. - ] - ]. - - (aStream isNil and:[who isNil and:[source notNil]]) ifTrue:[ - "/ - "/ mhmh - seems to be a method which used to be in some - "/ class, but has been overwritten by another or removed. - "/ (i.e. it has no containing class anyMore) - "/ try to guess the class from the sourceFileName. - "/ and retry. - "/ - className := Smalltalk classNameForFile:source. - className knownAsSymbol ifTrue:[ - myClass := Smalltalk at:className asSymbol ifAbsent:nil. - myClass notNil ifTrue:[ - aStream := myClass sourceStreamFor:source. - ] - ] - ] - ] - ]. - - aStream notNil ifTrue:[ - aStream position:sourcePosition abs. - junk := aStream nextChunk. - - " - keep a weak reference - it may be needed again soon ... - " - LastFileLock critical:[ - (LastFileReference at:1) == 0 ifTrue:[ - LastFileReference at:1 put:aStream. - LastSourceFileName := source. - ] ifFalse:[ - aStream close. - ]. - ]. - ] + ]. + + aStream isNil ifTrue:[ + "/ + "/ nope - look in standard places + "/ (if there is a source-code manager - otherwise, we already did that) + "/ + mgr notNil ifTrue:[ + fileName := Smalltalk getSourceFileName:source. + fileName notNil ifTrue:[ + aStream := fileName asFilename readStream. + ] + ]. + + "/ + "/ final chance: try current directory + "/ + aStream isNil ifTrue:[ + aStream := source asFilename readStream. + ] + ]. + + (aStream isNil and:[who isNil and:[source notNil]]) ifTrue:[ + "/ + "/ mhmh - seems to be a method which used to be in some + "/ class, but has been overwritten by another or removed. + "/ (i.e. it has no containing class anyMore) + "/ try to guess the class from the sourceFileName. + "/ and retry. + "/ + className := Smalltalk classNameForFile:source. + className knownAsSymbol ifTrue:[ + myClass := Smalltalk at:className asSymbol ifAbsent:nil. + myClass notNil ifTrue:[ + aStream := myClass sourceStreamFor:source. + ] + ] + ] + ] + ]. + + aStream notNil ifTrue:[ + Stream positionErrorSignal handle:[:ex | + ^ nil + ] do:[ + aStream position:sourcePosition abs. + ]. + junk := aStream nextChunk. + + " + keep a weak reference - it may be needed again soon ... + " + LastFileLock critical:[ + (LastFileReference at:1) == 0 ifTrue:[ + LastFileReference at:1 put:aStream. + LastSourceFileName := source. + ] ifFalse:[ + aStream close. + ]. + ]. + ] ]. junk notNil ifTrue:[ - LastMethodSources isNil ifTrue:[ - LastMethodSources := CacheDictionary new:20. - ]. - LastMethodSources at:self put:junk. + LastMethodSources isNil ifTrue:[ + LastMethodSources := CacheDictionary new:20. + ]. + LastMethodSources at:self put:junk. ]. ^ junk "Modified: / 7.1.1997 / 16:20:09 / stefan" - "Modified: / 9.1.1998 / 14:54:14 / cg" + "Modified: / 9.4.1998 / 12:37:41 / cg" ! source:aString @@ -1881,6 +1885,23 @@ ! +hasResource + "return true if the method had a definition in its + source. This was found in ST-80 methods, and currently not supported + by ST/X (except for remembering this flag). + It can be used to find resource-flagged methods quicker." + +%{ /* NOCONTEXT */ + +#ifdef F_RESOURCE + RETURN (((INT)__INST(flags) & __MASKSMALLINT(F_RESOURCE)) ? true : false); +#endif +%}. + ^ false + + +! + homeMethod "for common protocol with blocks: if the receiver is a method, return the receiver; otherwise, if its a block, return its home @@ -2519,6 +2540,6 @@ !Method class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libbasic/Method.st,v 1.157 1998-03-20 15:27:27 tz Exp $' + ^ '$Header: /cvs/stx/stx/libbasic/Method.st,v 1.158 1998-04-09 11:29:02 cg Exp $' ! ! Method initialize!