[Vm-dev] VM Maker: FileAttributesPlugin.oscog-eem.37.mcz

commits at source.squeak.org commits at source.squeak.org
Fri Nov 29 20:26:35 UTC 2019

Eliot Miranda uploaded a new version of FileAttributesPlugin to project VM Maker:

==================== Summary ====================

Name: FileAttributesPlugin.oscog-eem.37
Author: eem
Time: 20 September 2018, 4:48:56.754659 pm
UUID: 8a9411e4-e8c4-4562-b282-57c8056ad629
Ancestors: FileAttributesPlugin.oscog-AlistairGrant.36

Refactor mem:cp:y: => memcpy:_:_:, st:rn:cpy: => strncpy:_:_:

=============== Diff against FileAttributesPlugin.oscog-AlistairGrant.36 ===============

Item was changed:
  ----- Method: FileAttributesPlugin>>byteArrayFromCString:to: (in category 'private') -----
  byteArrayFromCString: aCString to: byteArrayOop
  	"Answer a new ByteArray copied from a null-terminated C string.
  	Caution: This may invoke the garbage collector."
  	| len newByteArray byteArrayPtr |
  	<var: 'aCString' type: #'const char *'>
  	<var: 'byteArrayPtr' type: #'unsigned char *'>
  	<var: 'byteArrayOop' type: #'sqInt *'>
  	len := self strlen: aCString.
  	"We never return strings longer than PATH_MAX"
  	len > #PATH_MAX ifTrue: [^self stringTooLong].
  	newByteArray := interpreterProxy
  		instantiateClass: interpreterProxy classByteArray
  		indexableSize: len.
  	newByteArray ifNil:
  		[^interpreterProxy primitiveFailFor: PrimErrNoMemory].
  	byteArrayPtr := interpreterProxy arrayValueOf: newByteArray.
+ 	self memcpy: byteArrayPtr _: aCString _: len.
- 	self mem: byteArrayPtr cp: aCString y: len.
  	byteArrayOop at: 0 put: newByteArray.

Item was changed:
  ----- Method: FileAttributesPlugin>>openDirectoryStream:ptr: (in category 'private - directory') -----
  openDirectoryStream: cPathName ptr: osdirPtr
  	"Open a new directory stream. Answer a pointer to the directory stream or NULL."
  	| len dir |
  	<var: 'osdirPtr' type: #'osdir **'>
  	<var: 'dir' type: #'osdir *'>
  	<var: 'cPathName' type: 'char *'>
  	<returnTypeC: #'int'>
  	len := self strlen: cPathName.
  	"The path buffer needs room for a trailing slash and the file name, so subtracting 2 is conservative"
  	len > (#PATH_MAX - 2) ifTrue: [^self stringTooLong].
  	(self canOpenDirectoryStreamFor: cPathName length: len)
  			dir := self cCode: '(osdir *) malloc(sizeof(osdir))'.
  			dir = nil ifTrue: [^self cantAllocateMemory].
+ 			self memcpy: dir path _: cPathName _: len.
- 			self mem: dir path cp: cPathName y: len.
  			"Ensure path has a trailing slash"
  			self cCode: 'if (dir->path[len-1] !!= ''/'') {
  				dir->path[len++] = ''/'';
  			self cCode: 'dir->path_file = dir->path + len'.
  			self cCode: 'dir->path_file[0] = ''\0'''.
  			self cCode: 'dir->path_len = len'.
  			self cCode: 'dir->dp =  opendir(dir->path)'.
  			dir dp ifNil:
  				[self free: dir.
  				^self cantOpenDir].
  			osdirPtr at: 0 put: dir.
  	"If we get here, we can't open the directory"
  	^self cantOpenDir

Item was changed:
  ----- Method: FileAttributesPlugin>>pathOop:toBuffer:maxLen: (in category 'private - file') -----
  pathOop: pathNameOop toBuffer: cPathName maxLen: maxLen
  	"Copy the supplied path name string object to the supplied c string buffer"
  	| len sPtr |
  	<var: 'cPathName' type: #'char *'>
  	<var: 'sPtr' type: #'char *'>
  	<returnTypeC: #'int'>
  	len := interpreterProxy stSizeOf: pathNameOop.
  	(len >= maxLen) ifTrue: [^self stringTooLong].
  	"Copy pathName to the new string"
  	sPtr := interpreterProxy arrayValueOf: pathNameOop.
  	((self canStatFilePath: sPtr length: len) = 0) ifTrue: [^self cantStatPath].
+ 	self memcpy: cPathName _: sPtr _: len.
- 	self mem: cPathName cp: sPtr y: len.
  	cPathName at: len put: 0.

Item was changed:
  ----- Method: FileAttributesPlugin>>primitiveReaddir (in category 'file primitives') -----
  	"Get the next entry in the directory stream. Answer the name of the entry, or
  	nil for the end of the directory stream.
  	- directoryPointer (ByteArray)"
  	| dirPointerOop dirStream ent entryName attributeArray resultArray haveEntry entry_len status |
  	<export: true>
  	<var: 'ent' type: #'struct dirent *'>
  	<var: 'dirStream' type: #'osdir *'>
  	<var: 'haveEntry' type: #int>
  	dirPointerOop := interpreterProxy stackValue: 0.
  	dirStream := self pointerFrom: dirPointerOop.
  	dirStream ifNil:
  		[^interpreterProxy primitiveFailFor: PrimErrBadArgument].
  	haveEntry := 0.
  	[ent := self readdir: dirStream dp.
  	 self cCode: 'if (ent == NULL ||
                   		((!! (ent->d_name[0] == ''.'' && strlen(ent->d_name) == 1)) && strcmp(ent->d_name, "..")))
                       		haveEntry = 1'.
  	 haveEntry = 0] whileTrue.
  	ent ifNil: "This is the normal case for the end of a directory stream,
  			although it may indicate other error conditions for which errno would be updated.
  			Assume the normal case here."
  		[^interpreterProxy pop: 2 thenPush: interpreterProxy nilObject].
  	entryName := self unixPathToOop: ent d_name.
  	"Build the path name (append the entry name to the path name)"
  	entry_len := self strlen: ent d_name.
  	[dirStream path_len + entry_len > (#PATH_MAX - 1)] ifTrue:
  		[^interpreterProxy primitiveFailForOSError: self stringTooLong].
+ 	self memcpy: dirStream path_file _: ent d_name _: entry_len.
- 	self mem: dirStream path_file cp: ent d_name y: entry_len.
  	dirStream path_file at: entry_len put: 0.
  	status := self fileToAttributeArray: dirStream path mask: 1 array: (self addressOf: attributeArray put: [:val| attributeArray := val]).
  	"If the stat() fails, still return the filename, just no attributes"
  	status ~= 0 ifTrue: [attributeArray := interpreterProxy nilObject].
  	self remapOop: #(entryName attributeArray)
  		in: [resultArray := interpreterProxy instantiateClass: interpreterProxy classArray indexableSize: 2].
  	resultArray ifNil:
  		[^interpreterProxy primitiveFailFor: PrimErrNoMemory].
  		storePointer: 0 ofObject: resultArray withValue: entryName;
  		storePointer: 1 ofObject: resultArray withValue: attributeArray;
  		pop: 2 thenPush: resultArray!

Item was changed:
  ----- Method: FileAttributesPlugin>>stringFromCString: (in category 'private') -----
  stringFromCString: aCString
  	"Answer a new String copied from a null-terminated C string.
  	Caution: This may invoke the garbage collector."
  	| len newString |
  	<var: 'aCString' type: #'const char *'>
  	len := self strlen: aCString.
  	newString := interpreterProxy
  		instantiateClass: interpreterProxy classString
  		indexableSize: len.
  	newString ifNil: [^interpreterProxy primitiveFailFor: PrimErrNoMemory].
+ 	self strncpy: (interpreterProxy arrayValueOf: newString)
+ 		_: aCString
+ 		_: len. "(char *)strncpy()"
- 	self st: (interpreterProxy arrayValueOf: newString)
- 		rn: aCString
- 		cpy: len. "(char *)strncpy()"
  	^ newString

More information about the Vm-dev mailing list