Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
17241 ffi-nb is not cleaning compiled methods. then they fail when platform changes https://pharo.fogbugz.com/f/cases/17241 http://files.pharo.org/image/50/50497.zip
- Loading branch information
Jenkins Build Server
authored and
ci
committed
Dec 14, 2015
1 parent
8812a3e
commit dfd4f3a
Showing
2,076 changed files
with
11,149 additions
and
1,388 deletions.
There are no files selected for viewing
7 changes: 0 additions & 7 deletions
7
AST-Core.package/RBParser.class/instance/private-parsing/basicParsePragma.st
This file was deleted.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
AST-FFI-Pharo50Compatibility.package/RBFFICallPragma.class/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
additionnal smalltalk semantic for FFI calls |
8 changes: 8 additions & 0 deletions
8
...a.class/class/instance creation/externalName_module_callType_returnType_argumentTypes_.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
externalName: anExternalName module: aModuleName callType: aCallType returnType: aReturnType argumentTypes: arguments | ||
|
||
^ self new | ||
initializeWithExternalName: anExternalName | ||
module: aModuleName | ||
callType: aCallType | ||
returnType: aReturnType | ||
argumentTypes: arguments |
5 changes: 5 additions & 0 deletions
5
AST-FFI-Pharo50Compatibility.package/RBFFICallPragma.class/definition.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
RBPragmaNode subclass: #RBFFICallPragma | ||
instanceVariableNames: 'externalName moduleName callType returnType argumentTypes' | ||
classVariableNames: '' | ||
poolDictionaries: '' | ||
category: 'AST-FFI-Pharo50Compatibility' |
6 changes: 6 additions & 0 deletions
6
...50Compatibility.package/RBFFICallPragma.class/instance/as yet unclassified/asPrimitive.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
asPrimitive | ||
|
||
^ IRPrimitive new | ||
num: 120; | ||
spec: self cFunction; | ||
yourself |
8 changes: 8 additions & 0 deletions
8
...ro50Compatibility.package/RBFFICallPragma.class/instance/as yet unclassified/cFunction.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
cFunction | ||
|
||
^ ExternalLibraryFunction | ||
name: externalName | ||
module: moduleName | ||
callType: callType | ||
returnType: returnType | ||
argumentTypes: argumentTypes |
7 changes: 7 additions & 0 deletions
7
...alization-release/initializeWithExternalName_module_callType_returnType_argumentTypes_.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
initializeWithExternalName: anExternalName module: aModuleName callType: aCallType returnType: aReturnType argumentTypes: someArgumentTypes | ||
|
||
externalName := anExternalName. | ||
moduleName:= aModuleName. | ||
callType := aCallType. | ||
returnType := aReturnType. | ||
argumentTypes := someArgumentTypes. |
2 changes: 2 additions & 0 deletions
2
...I-Pharo50Compatibility.package/RBFFICallPragma.class/instance/testing/isCompilerOption.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
isCompilerOption | ||
^ false |
3 changes: 3 additions & 0 deletions
3
...FI-Pharo50Compatibility.package/RBFFICallPragma.class/instance/testing/isFFICallPragma.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
isFFICallPragma | ||
|
||
^ true |
2 changes: 2 additions & 0 deletions
2
AST-FFI-Pharo50Compatibility.package/RBFFICallPragma.class/instance/testing/isPrimitive.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
isPrimitive | ||
^ true |
2 changes: 2 additions & 0 deletions
2
...I-Pharo50Compatibility.package/RBFFICallPragma.class/instance/testing/isPrimitiveError.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
isPrimitiveError | ||
^ false |
1 change: 1 addition & 0 deletions
1
AST-FFI-Pharo50Compatibility.package/ShortRunArray.class/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
I'm a class needed to load FFI and nothing else. FFI declares ExternalObject to be in the startup list after myself. That's why in my initialize class side method I declare myself to be in the startup list. |
3 changes: 3 additions & 0 deletions
3
...Pharo50Compatibility.package/ShortRunArray.class/class/class initialization/initialize.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
initialize | ||
|
||
Smalltalk addToStartUpList: self. |
5 changes: 5 additions & 0 deletions
5
AST-FFI-Pharo50Compatibility.package/ShortRunArray.class/definition.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Object subclass: #ShortRunArray | ||
instanceVariableNames: 'parent comments properties' | ||
classVariableNames: 'FormatterClass' | ||
poolDictionaries: '' | ||
category: 'AST-FFI-Pharo50Compatibility' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
AST-FFI-Pharo50Compatibility.package/extension/OCASTTranslator/instance/visitPragmaNode_.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
visitPragmaNode: aPragmaNode | ||
aPragmaNode isFFICallPragma | ||
ifFalse: [ methodBuilder addPragma: aPragmaNode asPragma ]. | ||
aPragmaNode isPrimitiveError ifTrue: [ | ||
methodBuilder storeTemp: aPragmaNode arguments last value]. |
10 changes: 10 additions & 0 deletions
10
AST-FFI-Pharo50Compatibility.package/extension/RBParser/instance/basicParsePragma.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
basicParsePragma | ||
^ currentToken isIdentifier | ||
ifTrue: [ self parseUnaryPragma ] | ||
ifFalse: [ | ||
currentToken isKeyword | ||
ifTrue: [ | ||
(currentToken value = #apicall: or: [ currentToken value = #cdecl: ]) | ||
ifTrue: [ ^ self externalFunctionDeclaration ]. | ||
self parseKeywordPragma ] | ||
ifFalse: [ self parseBinaryPragma ] ] |
47 changes: 47 additions & 0 deletions
47
...I-Pharo50Compatibility.package/extension/RBParser/instance/externalFunctionDeclaration.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
externalFunctionDeclaration | ||
"Parse the function declaration for a call to an external library." | ||
|
||
| descriptorClass callType retType externalName args argType module | | ||
descriptorClass := Smalltalk globals at: #ExternalFunction ifAbsent: [ nil ]. | ||
descriptorClass == nil | ||
ifTrue: [ ^ false ]. | ||
callType := descriptorClass callingConventionFor: currentToken value. | ||
callType == nil | ||
ifTrue: [ ^ false ]. "Parse return type" | ||
self step. | ||
retType := self externalType: descriptorClass. | ||
retType == nil | ||
ifTrue: [ ^ self parserError: 'lack return type' ]. "Parse function name or index" | ||
externalName := currentToken value. | ||
(self match: String) | ||
ifTrue: [ externalName := externalName asSymbol ] | ||
ifFalse: [ (self match: Number) | ||
ifFalse: [ self parserError: 'function name or index' ] ]. | ||
(self matchToken: $() | ||
ifFalse: [ ^ self parserError: 'argument list' ]. | ||
args := Array new writeStream. | ||
[ currentToken value == $) ] | ||
whileFalse: [ | ||
argType := self externalType: descriptorClass. | ||
argType == nil | ||
ifTrue: [ ^ self parserError: 'argument' ]. | ||
argType isVoid & argType isPointerType not | ||
ifFalse: [ args nextPut: argType ] ]. | ||
(args position = currentScope selector numArgs) ifFalse: [ | ||
^self parserError: 'Matching number of arguments']. | ||
(self matchToken: $)) | ||
ifFalse: [ ^ self parserError: ')' ]. | ||
(self matchToken: 'module:') | ||
ifTrue: [ | ||
module := currentToken value. | ||
(self match: String) | ||
ifFalse: [ ^ self parserError: 'String' ]. | ||
module := module asSymbol ]. | ||
|
||
^ RBFFICallPragma | ||
externalName: externalName | ||
module: module | ||
callType: callType | ||
returnType: retType | ||
argumentTypes: args contents | ||
|
13 changes: 13 additions & 0 deletions
13
AST-FFI-Pharo50Compatibility.package/extension/RBParser/instance/externalType_.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
externalType: descriptorClass | ||
"Parse an return an external type" | ||
| xType | | ||
xType := descriptorClass atomicTypeNamed: currentToken value. | ||
xType == nil ifTrue:["Look up from class scope" | ||
Symbol hasInterned: currentToken value ifTrue:[:sym| | ||
xType := descriptorClass structTypeNamed: sym]]. | ||
xType == nil ifTrue:[ | ||
xType := descriptorClass forceTypeNamed: currentToken value]. | ||
self step. | ||
(self matchToken:#*) | ||
ifTrue:[^xType asPointerType] | ||
ifFalse:[^xType] |
2 changes: 2 additions & 0 deletions
2
AST-FFI-Pharo50Compatibility.package/extension/RBParser/instance/ffiCallClass.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ffiCallClass | ||
^ RBFFICallPragma |
4 changes: 4 additions & 0 deletions
4
AST-FFI-Pharo50Compatibility.package/extension/RBParser/instance/matchToken_.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
matchToken: thing | ||
"Matches the token, not its type." | ||
currentToken value = thing ifTrue: [self step. ^true]. | ||
^false |
8 changes: 8 additions & 0 deletions
8
AST-FFI-Pharo50Compatibility.package/extension/RBParser/instance/match_.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
match: type | ||
"Answer with true if next tokens type matches." | ||
|
||
(currentToken value isKindOf: type) | ||
ifTrue: | ||
[self step. | ||
^true]. | ||
^false |
3 changes: 3 additions & 0 deletions
3
AST-FFI-Pharo50Compatibility.package/extension/RBProgramNode/instance/isFFICallPragma.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
isFFICallPragma | ||
|
||
^ false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
Alien.package/Alien.class/class/callbacks/invokeCallbackContext_.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
invokeCallbackContext: vmCallbackContextAddress "<Integer>" "^<FFICallbackReturnValue>" | ||
"The low-level entry-point for callbacks sent from the VM/IA32ABI plugin. | ||
Return via primReturnFromContext:through:. thisContext's sender is the | ||
call-out context." | ||
| callbackAlien type | | ||
callbackAlien := (Smalltalk wordSize = 4 | ||
ifTrue: [VMCallbackContext32] | ||
ifFalse: [VMCallbackContext64]) | ||
atAddress: vmCallbackContextAddress. | ||
[type := Callback evaluateCallbackForContext: callbackAlien] | ||
ifCurtailed: [self error: 'attempt to non-local return across a callback']. | ||
type ifNil: | ||
[type := 1. callbackAlien wordResult: -1]. | ||
callbackAlien primReturnAs: type fromContext: thisContext |
10 changes: 10 additions & 0 deletions
10
Alien.package/Alien.class/class/callbacks/invokeCallback_stack_registers_jmpbuf_.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
invokeCallback: thunkPtr "<Integer>" stack: stackPtr "<Integer>" registers: regsPtr "<Integer>" jmpbuf: jmpBufPtr "<Integer>" "^<FFICallbackReturnValue>" | ||
"The low-level entry-point for callbacks sent from the VM/IA32ABI plugin. | ||
Return via primReturnFromContext:through:. thisContext's sender is the | ||
call-out context." | ||
| resultProxy | | ||
[resultProxy := Callback evaluateCallbackForThunk: thunkPtr stack: stackPtr] | ||
ifCurtailed: [self error: 'attempt to non-local return across a callback']. | ||
resultProxy ifNil: | ||
[(resultProxy := FFICallbackReturnValue new) returnInteger: 0]. | ||
resultProxy primReturnFromContext: thisContext through: jmpBufPtr |
26 changes: 26 additions & 0 deletions
26
Alien.package/Alien.class/class/class initialization/ensureInSpecialObjectsArray.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
ensureInSpecialObjectsArray | ||
"Alien must be in the specialObjectsArray to enable the Newsqueak FFI. Because of | ||
the bootstrap the specialObjectsArray may already have been partially initialized with | ||
the callback selector and to be large enough (as part of loading immutability), but | ||
it will be missing Alien until Alien is loaded. So check if the specialObjectsArray is | ||
of the expected size before recreating and slam Alien in if the specialObjectsArray | ||
is already large enough." | ||
|
||
| index | | ||
self ~~ Alien ifTrue: [^self]. | ||
|
||
index := 53. | ||
((Smalltalk includesKey: #ObjectMemory) | ||
and: [((Smalltalk at: #ObjectMemory) classPool at: #ClassAlien ifAbsent: []) ~~ (index - 1)]) ifTrue: | ||
[self error: 'index probably wrong']. | ||
|
||
Smalltalk specialObjectsArray size < index ifTrue: | ||
[Smalltalk recreateSpecialObjectsArray]. | ||
|
||
(Smalltalk specialObjectsArray size < index | ||
or: [(Smalltalk specialObjectsArray at: index) ~~ nil | ||
and: [(Smalltalk specialObjectsArray at: index) ~~ self]]) ifTrue: | ||
[self error: 'SystemDictionary>>recreateSpecialObjectsArray appears incompatible']. | ||
|
||
(Smalltalk specialObjectsArray at: index) == nil ifTrue: | ||
[Smalltalk specialObjectsArray at: index put: self] |
5 changes: 5 additions & 0 deletions
5
Alien.package/Alien.class/class/class initialization/ensureNotifiedAtStartup.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ensureNotifiedAtStartup | ||
"Alien needs to be notified at system startup to clear the LoadedLibraries table | ||
and otherwise sanitise Aliens with dangling pointers." | ||
self ~~ Alien ifTrue: [^self]. | ||
Smalltalk addToStartUpList: self after: Delay |
4 changes: 4 additions & 0 deletions
4
Alien.package/Alien.class/class/class initialization/ensureNotifiedAtStartupAfter_.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ensureNotifiedAtStartupAfter: anotherClass | ||
"Support routine for putting Alien classes in the start-up list." | ||
anotherClass ensureNotifiedAtStartup. | ||
Smalltalk addToStartUpList: self after: anotherClass |
8 changes: 8 additions & 0 deletions
8
Alien.package/Alien.class/class/class initialization/initialize.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
initialize | ||
"Alien initialize" | ||
LoadedLibraries isNil ifTrue: | ||
[LoadedLibraries := Dictionary new]. | ||
GCMallocedAliens isNil ifTrue: | ||
[GCMallocedAliens := AlienWeakTable newForOwner: self]. | ||
self ensureInSpecialObjectsArray. | ||
self ensureNotifiedAtStartup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
exampleCqsort | ||
"Call the libc qsort function (which requires a callback)." | ||
"Alien exampleCqsort" | ||
"(Time millisecondsToRun: [100 timesRepeat: [Alien exampleCqsort]]) / 100.0" | ||
| cb rand nElements sizeofDouble values orig sort | | ||
rand := Random new. | ||
values := Alien newC: (nElements := 100) * (sizeofDouble := 8). | ||
1 to: values dataSize by: sizeofDouble do: | ||
[:i| values doubleAt: i put: rand next]. | ||
orig := (1 to: values dataSize by: sizeofDouble) collect: [:i| values doubleAt: i]. | ||
cb := Callback | ||
signature: #(int (*)(const void *, const void *)) | ||
block: [ :arg1 :arg2 | ((arg1 doubleAt: 1) - (arg2 doubleAt: 1)) sign]. | ||
(Alien lookup: 'qsort' inLibrary: Alien libcName) | ||
primFFICallResult: nil | ||
with: values pointer | ||
with: nElements | ||
with: sizeofDouble | ||
with: cb thunk. | ||
sort := (1 to: values dataSize by: sizeofDouble) collect: [:i| values doubleAt: i]. | ||
values free. | ||
^orig -> sort |
30 changes: 30 additions & 0 deletions
30
Alien.package/Alien.class/class/examples/exampleEnumFontFamiliesEx.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
exampleEnumFontFamiliesEx | ||
"Call the Win32 EnumFontFamiliesEx function." | ||
"Alien exampleEnumFontFamiliesEx" | ||
"(Time millisecondsToRun: [1000 timesRepeat: [Alien exampleEnumFontFamiliesEx]]) / 1000.0" | ||
| fontNames r gle err hDC cb | | ||
fontNames := OrderedCollection new. | ||
gle := self lookup: 'GetLastError' inLibrary: 'kernel32.dll'. | ||
hDC := (self lookup: 'GetDC' inLibrary: 'user32.dll') | ||
primFFICallResult: (Alien new: 4) | ||
with: 0. "entire screen" | ||
err := Alien new: 4. | ||
cb := Callback | ||
block: [:args :result| | ||
fontNames addLast: args logicalFontData elfFullName. | ||
result returnInteger: 1] | ||
stdcallArgsClass: EnumFontFamExProc. | ||
(self lookup: 'EnumFontFamiliesExA' inLibrary: 'gdi32.dll') | ||
primFFICallResult: (r := Alien new: 4) | ||
with: hDC | ||
with: (LOGFONTA newC lfCharset: LOGFONTA DEFAULTCHARSET; yourself) pointer | ||
with: cb thunk | ||
with: 0 | ||
with: 0. | ||
(r signedLongAt: 1) ~= 1 ifTrue: | ||
[gle primFFICallResult: err]. | ||
(self lookup: 'ReleaseDC' inLibrary: 'user32.dll') | ||
primFFICallResult: (Alien new: 4) | ||
with: 0 "entire screen" | ||
with: hDC. | ||
^(err signedLongAt: 1) -> fontNames -> fontNames size |
17 changes: 17 additions & 0 deletions
17
Alien.package/Alien.class/class/examples/exampleEnumWindows.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
exampleEnumWindows | ||
"Call the Win32 EnumWindows function, which takes a callback. | ||
Count how many windows. Use an Alien to hold the counter on the C heap. | ||
Answer the count of windows (number of callbacks)." | ||
"Alien exampleEnumWindows" | ||
| counter cb | | ||
counter := Alien newC: 4. | ||
cb := Callback | ||
block: [:args :result| | ptr | | ||
ptr := Alien forPointer: args lParam. | ||
ptr signedLongAt: 1 put: (ptr signedLongAt: 1) + 1. | ||
result returnInteger: (ptr signedLongAt: 1)] | ||
stdcallArgsClass: EnumWindowsProc. | ||
^((self lookup: 'EnumWindows' inLibrary: 'user32.dll') | ||
primFFICallResult: (Alien new: 4) | ||
with: cb thunk | ||
with: counter pointer) signedLongAt: 1 |
20 changes: 20 additions & 0 deletions
20
Alien.package/Alien.class/class/examples/exampleEnumWindowsCallbackPerformance.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
exampleEnumWindowsCallbackPerformance | ||
"Measure the speed of callbacks using the Win32 EnumWindows function. | ||
Count how many windows using a Smalltalk counter. | ||
Answer seconds -> callbacks -> microseconds per callback." | ||
"Alien exampleEnumWindowsCallbackPerformance" | ||
| enumWin count ms cb | | ||
Smalltalk garbageCollect. | ||
enumWin := self lookup: 'EnumWindows' inLibrary: 'user32.dll'. | ||
count := 0. | ||
cb := Callback | ||
block: [:args :result| | ||
result returnInteger: (count := count + 1)] | ||
stdcallArgsClass: EnumWindowsProc. | ||
ms := Time millisecondsToRun: | ||
[1000 timesRepeat: | ||
[enumWin | ||
primFFICallResult: (Alien new: 4) | ||
with: cb thunk | ||
with: 0]]. | ||
^ms / 1000.0 -> count -> (ms * 1000.0 / count) |
15 changes: 15 additions & 0 deletions
15
Alien.package/Alien.class/class/examples/exampleEnumWindowsSimple.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
exampleEnumWindowsSimple | ||
"Call the Win32 EnumWindows function, which takes a callback. | ||
Count how many windows. Use an Alien to hold the counter on the C heap. | ||
Answer the count of windows (number of callbacks)." | ||
"Alien exampleEnumWindowsSimple" | ||
| count cb | | ||
count := 0. | ||
cb := Callback | ||
block: [:args :result| | ||
result returnInteger: (count := count + 1)] | ||
stdcallArgsClass: EnumWindowsProc. | ||
^((self lookup: 'EnumWindows' inLibrary: 'user32.dll') | ||
primFFICallResult: (Alien new: 4) | ||
with: cb thunk | ||
with: 0) signedLongAt: 1 |
Oops, something went wrong.