[Vm-dev] VM Maker: VMMaker.oscog-AlistairGrant.2465.mcz

commits at source.squeak.org commits at source.squeak.org
Fri Oct 19 06:00:23 UTC 2018


Alistair Grant uploaded a new version of VMMaker to project VM Maker:
http://source.squeak.org/VMMaker/VMMaker.oscog-AlistairGrant.2465.mcz

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

Name: VMMaker.oscog-AlistairGrant.2465
Author: AlistairGrant
Time: 19 October 2018, 7:55:54.986682 am
UUID: eecc906e-bc44-461f-bcfe-0df53a6ecbff
Ancestors: VMMaker.oscog-eem.2464

strncpy & primitiveFailForOSError

VMClass>>strncpy:_:_:  If the destination buffer is longer than the source buffer, 0 fill the remaining bytes (SVr4, 4.3BSD, C89, C99).
Update associated test case.

Add SpurMemoryManager>>primitiveFailForOSError: (based off #primitiveFailFor:).

=============== Diff against VMMaker.oscog-eem.2464 ===============

Item was added:
+ ----- Method: SpurMemoryManager>>primitiveFailForOSError: (in category 'simulation only') -----
+ primitiveFailForOSError: reasonCode
+ 	"hack around the CoInterpreter/ObjectMemory split refactoring"
+ 	<doNotGenerate>
+ 	^coInterpreter primitiveFailForOSError: reasonCode!

Item was changed:
  ----- Method: VMClass>>strncpy:_:_: (in category 'C library simulation') -----
  strncpy: aString _: bString _: n
  	<doNotGenerate>
  	"implementation of strncpy(3)"
  
  	| getBlock setBlock count |
  
  	count := n.
  	aString isString ifTrue: 
  		[setBlock := [ :idx :ch | aString at: idx put: ch asCharacter]]
  	ifFalse: [aString class == ByteArray ifTrue: 
  			[setBlock := [ :idx :ch | aString at: idx put: ch]]
  	ifFalse: [aString isInteger ifTrue: 
  		[setBlock := [ :idx :ch | self byteAt: aString + idx - 1 put: ch]]]].
  	bString isString ifTrue: [
  		getBlock := [ :idx | (bString at: idx) asInteger ].
  		count := count min: bString size]
  	ifFalse: [bString class == ByteArray ifTrue: [
  		getBlock := [ :idx | bString at: idx].
  		count := count min: bString size]
  	ifFalse: [bString isInteger ifTrue: 
  		[getBlock := [ :idx | self byteAt: bString + idx - 1]]
  	ifFalse: [bString class == CArray ifTrue:
  			[getBlock := [ :idx | bString at: idx - 1]]]]].
  	1 to: count do: [ :i | | v |
  		v := getBlock value: i.
+ 		setBlock value: i value: v].
+ 	"SVr4, 4.3BSD, C89, C99 require the remainder of the buffer be filled with nulls"
+ 	count+1 to: n do: [ :i |
+ 		setBlock value: i value: 0].
- 		setBlock value: i value: v.
- 		v = 0 ifTrue: [^aString] ].
  	^aString!

Item was changed:
  ----- Method: VMClassTests>>testStrncpy (in category 'tests') -----
  testStrncpy
  
  	| stringA byteArrayA |
  
  	stringA := String new: 5.
  	vmclass strncpy: stringA _: testString _: stringA size.
  	self assert: stringA equals: 'hello'.
  
  	stringA := String new: testString size + 3.
  	vmclass strncpy: stringA _: testString _: stringA size.
  	self assert: stringA equals: (testString, (String new: 3)).
  
  	byteArrayA := ByteArray new: 5.
  	vmclass strncpy: byteArrayA _: testString _: byteArrayA size.
  	self assert: byteArrayA equals: 'hello' asByteArray.
  
  	byteArrayA := ByteArray new: testString size + 3.
  	vmclass strncpy: byteArrayA _: testString _: byteArrayA size.
  	self assert: byteArrayA equals: (testString, (String new: 3)) asByteArray.
  
+ 	"SVr4, 4.3BSD, C89, C99 require the destination space after the string be null filled"
+ 	byteArrayA := ByteArray new: testString size + 3.
+ 	byteArrayA atAllPut: 255.
+ 	vmclass strncpy: byteArrayA _: testString _: byteArrayA size.
+ 	self assert: byteArrayA equals: (testString, (String new: 3)) asByteArray.
+ 
  !



More information about the Vm-dev mailing list