'From Pharo0.1 of 16 May 2008 [Latest update: #10293] on 1 May 2009 at 6:33:19 pm'!
"Change Set:		RemoteString_FixFileClose-nice
Date:			1 May 2009
Author:			nice

RemoteString don't close the file they open.
This is no well behaved and put too much pressure on finalization mechanism.

This changeSet correct a few miss-behaved methods."!


!CompiledMethod methodsFor: 'source code management' stamp: 'nice 5/1/2009 18:31'!
sourceClass
	"Get my receiver class (method class) from the preamble of my source.  Return nil if not found."

	^ [| theFile |
		theFile := self sourceFileStream.
		[(Compiler evaluate: (theFile backChunk "blank"; backChunk "preamble")) theClass] ensure: [theFile close]] on: Error do: [nil]! !


!RemoteString methodsFor: 'accessing' stamp: 'nice 5/1/2009 18:25'!
string 
	"Answer the receiver's string if remote files are enabled.
	Use a read only copy to avoid syntax errors when accessed via
	multiple processes."
	
	| theFile |
	(sourceFileNumber == nil or: [(SourceFiles at: sourceFileNumber) == nil]) ifTrue: [^''].
	theFile := (SourceFiles at: sourceFileNumber) readOnlyCopy.
	^[theFile position: filePositionHi.
	theFile nextChunk] ensure: [theFile close]! !

!RemoteString methodsFor: 'accessing' stamp: 'nice 5/1/2009 18:26'!
text 
	"Answer the receiver's string asText if remote files are enabled.
	Use a read only copy to avoid syntax errors when accessed via
	multiple processes."
	
	| theFile |
	(sourceFileNumber == nil or: [(SourceFiles at: sourceFileNumber) == nil]) ifTrue: [^ nil].
	theFile := (SourceFiles at: sourceFileNumber) readOnlyCopy.
	^[theFile position: filePositionHi.
	theFile position > theFile size ifTrue: [
		self error: 'RemoteString past end of file' ].
	theFile nextChunkText] ensure: [theFile close]! !

