The Trunk: System-nice.236.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: System-nice.236.mcz

commits-2
Nicolas Cellier uploaded a new version of System to project The Trunk:
http://source.squeak.org/trunk/System-nice.236.mcz

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

Name: System-nice.236
Author: nice
Time: 18 January 2010, 3:37:10.564 pm
UUID: abcc9501-98b4-8740-aaed-9740044deb36
Ancestors: System-nice.235

Use readOnlyFileNamed:do: pattern
Use literal ByteArray

=============== Diff against System-nice.235 ===============

Item was changed:
  ----- Method: DigitalSignatureAlgorithm class>>testExamplesFromDisk (in category 'examples') -----
  testExamplesFromDisk
  "verify messages from file on disk"
  "Note: Secure random numbers are needed for key generation and message signing, but not for signature verification. There is no need to call initRandomFromUser if you are merely checking a signature."
  "DigitalSignatureAlgorithm testExamplesFromDisk"
 
+ FileStream readOnlyFileNamed: 'dsa.test.out' do: [:file |
- | file |
- file := FileStream readOnlyFileNamed: 'dsa.test.out'.
- [
  | msg  sig publicKey |
  [file atEnd] whileFalse: [
  sig := file nextChunk.
  msg := file nextChunk.
  publicKey := Compiler evaluate: file nextChunk.
  (self verify: sig isSignatureOf: msg publicKey: publicKey) ifTrue: [
  Transcript show: 'SUCCESS: ',msg; cr.
  ] ifFalse: [
  self error: 'ERROR!! Signature verification failed'
  ].
  ].
+ ]!
- ] ensure: [file close]
- !

Item was changed:
  ----- Method: MidiPrimTester>>playNoteOnPort: (in category 'tests') -----
  playNoteOnPort: portNum
  "MidiPrimTester new playNoteOnPort: 0"
 
  | noteOn noteOff bytesWritten |
+ noteOn := #[144 60 100].
+ noteOff := #[144 60 0].
- noteOn := #(144 60 100) as: ByteArray.
- noteOff := #(144 60 0) as: ByteArray.
  self openPort: portNum andDo: [
  bytesWritten := self primMIDIWritePort: portNum from: noteOn at: 0.
  (Delay forMilliseconds: 500) wait.
  bytesWritten := bytesWritten + (self primMIDIWritePort: portNum from: noteOff at: 0)].
 
  bytesWritten = 6 ifFalse: [self error: 'not all bytes were sent'].
  !

Item was changed:
  ----- Method: MidiPrimTester>>playDrumRoll:count:onPort: (in category 'tests') -----
  playDrumRoll: mSecsBetweenNotes count: tapCount onPort: portNum
  "MidiPrimTester new playDrumRoll: 75 count: 64 onPort: 0"
  "Play middle-C tapCount times with the given space between notes. This example works best with a short percussive voice, like a drum."
  "Details: This test can be used to investigate the real-time performance of your system. On a 110 MHz PowerPC Mac, this method can genererate very fast and smooth drum rolls up to about 100 beats/sec (10 mSecs between notes). However, many factors can prevent one from seeing this level of performance including a slow CPU, lack of a level-2 cache, networking or other background processes stealing chunks of processor time from Squeak, or a sluggish MIDI synthesizer."
  "Details: By default, this method does an incremental GC on every note. While not really needed for this example, it illustrates a useful technique for real-time processing in Squeak: do an incremental GC when you know you have a few milliseconds of idle time to avoid triggering one during a time-critical task. In this case, we're also using the GC time to provide a small delay between the note-on and note-off events. If the GC time is too short, as it could be on a fast machine, the note may not sound at all unless you add a few milliseconds of additional delay!!"
  "Note: This example works best if the VM's millisecond clock has 1 millisecond resolution."
 
  | gcDuringNote noteOn noteOff endTime waitTime |
  gcDuringNote := true.
  "these events use running status, so the command byte is omitted"
  noteOn := #(60 100) as: ByteArray.
  noteOff := #(60 0) as: ByteArray.
  self primMIDIOpenPort: portNum readSemaIndex: 0 interfaceClockRate: 1000000.
 
  "send an initial event with command byte to initiate running status"
+ self primMIDIWritePort: portNum from: #[144 60 0] at: 0.
- self primMIDIWritePort: portNum from: (#(144 60 0) as: ByteArray) at: 0.
 
  1 to: tapCount do: [:i |
  endTime := Time millisecondClockValue + mSecsBetweenNotes.
  self primMIDIWritePort: portNum from: noteOn at: 0.
  gcDuringNote
  ifTrue: [
  "do quick GC; takes a few milliseconds and provides the note-down time"
  "Note: if GC is too fast on your machine, you need to add a few mSecs delay!!"
  Smalltalk garbageCollectMost]
  ifFalse: [(Delay forMilliseconds: 3) wait].
 
  self primMIDIWritePort: portNum from: noteOff at: 0.
  waitTime := endTime - Time millisecondClockValue.
  waitTime > 0 ifTrue: [(Delay forMilliseconds: waitTime) wait]].
 
  self primMIDIClosePort: portNum.
  !

Item was changed:
  ----- Method: FilePackage>>fromFileNamed: (in category 'initialize') -----
  fromFileNamed: aName
- | stream |
  fullName := aName.
+ FileStream readOnlyFileNamed: aName do: [:stream |
+ stream setConverterForCode.
+ self fileInFrom: stream]!
- stream := FileStream readOnlyFileNamed: aName.
- stream setConverterForCode.
- [self fileInFrom: stream] ensure:[stream close].!

Item was changed:
  ----- Method: MidiPrimTester>>playScale:onPort: (in category 'tests') -----
  playScale: mSecsPerNote onPort: portNum
  "MidiPrimTester new playScale: 130 onPort: 0"
 
  | noteOn noteOff |
+ noteOn := #[144 0 100].
+ noteOff := #[144 0 0].
- noteOn := #(144 0 100) as: ByteArray.
- noteOff := #(144 0 0) as: ByteArray.
  self openPort: portNum andDo: [
  #(60 62 64 65 67 69 71 72 74 72 71 69 67 65 64 62 60) do: [:midiKey |
  noteOn at: 2 put: midiKey.
  noteOff at: 2 put: midiKey.
  self primMIDIWritePort: portNum from: noteOn at: 0.
  (Delay forMilliseconds: mSecsPerNote - 10) wait.
  self primMIDIWritePort: portNum from: noteOff at: 0.
  (Delay forMilliseconds: 10) wait]].
  !

Item was changed:
  ----- Method: NaturalLanguageTranslator class>>mergeTranslationFileNamed: (in category 'file-services') -----
  mergeTranslationFileNamed: fileFullNameString
  "merge the translation in the file named fileFullNameString"
 
+ FileStream readOnlyFileNamed: fileFullNameString do: [:stream |
+ | localeID translator |
+ localeID := LocaleID isoString: stream localName sansPeriodSuffix.
+ translator := self localeID: localeID.
+ translator loadFromStream: stream]
- | stream |
- stream := FileStream readOnlyFileNamed: fileFullNameString.
- [ | localeID translator |
- localeID := LocaleID isoString: stream localName sansPeriodSuffix.
- translator := self localeID: localeID.
- translator loadFromStream: stream]
- ensure: [stream close].
  LanguageEnvironment resetKnownEnvironments.
 
  !

Item was changed:
  ----- Method: DigitalSignatureAlgorithm class>>writeExamplesToDisk (in category 'examples') -----
  writeExamplesToDisk
  "Example of signing a message and verifying its signature. Used to create samples from one implementation that could later be tested with a different implementation"
  "Note: Secure random numbers are needed for key generation and message signing, but not for signature verification. There is no need to call initRandomFromUser if you are merely checking a signature."
  "DigitalSignatureAlgorithm writeExamplesToDisk"
 
+ | keyList dsa msgList |
- | file keyList dsa msgList |
-
  dsa := DigitalSignatureAlgorithm new.
  dsa initRandomFromUser.
  self inform: 'About to generate 5 key sets. Will take a while'.
  keyList := {self testKeySet},((1 to: 5) collect: [ :ignore | self generateKeySet]).
  msgList := {'This is a test...'. 'This is the second test period.'. 'And finally, a third message'}.
+ FileStream newFileNamed: 'dsa.test.out' do: [:file |
- file := FileStream newFileNamed: 'dsa.test.out'.
- [
  msgList do: [ :msg |
  keyList do: [ :keys |
  | sig |
  sig := self sign: msg privateKey: keys first dsa: dsa.
  (self verify: sig isSignatureOf: msg publicKey: keys last) ifTrue: [
  file
  nextChunkPut: sig;
  nextChunkPut: msg;
  nextChunkPut: keys last storeString.
  ] ifFalse: [
  self error: 'ERROR!! Signature verification failed'
  ].
  ].
  ].
+ ]
- ] ensure: [file close]
  !