Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Introduce strict and non-strict modes
- Loading branch information
Showing
5 changed files
with
88 additions
and
28 deletions.
There are no files selected for viewing
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
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
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,37 @@ | ||
" | ||
I resolve ffi call-out arguments in a non-strict way. | ||
This is the backwards compatibility mode and should not be used unless you know what you do. | ||
I try to guess what type to use for a literal. | ||
For example, for a self reference I can guess it by looking at the type of the class of self. | ||
However, some types are problematic. For example, ints and floats can have different size/precisions. | ||
" | ||
Class { | ||
#name : #FFIInferenceResolutionMode, | ||
#superclass : #Object, | ||
#category : #'UnifiedFFI-Callouts' | ||
} | ||
|
||
{ #category : #resolution } | ||
FFIInferenceResolutionMode >> resolveUndeclaredTypeForArgument: aFFIValueArgument withResolver: aResolver [ | ||
|
||
(aFFIValueArgument value isNil | ||
or: [aFFIValueArgument value = 'nil' | ||
or: [ aFFIValueArgument value = 'NULL' ]]) | ||
ifTrue: [ ^ (aResolver resolveType: #'void *') ]. | ||
(#(true false) includes: aFFIValueArgument value) | ||
ifTrue: [ ^ aResolver resolveType: #bool ]. | ||
aFFIValueArgument value isInteger | ||
ifTrue: [ ^ (aFFIValueArgument value >=0 | ||
ifTrue: [ aResolver resolveType: #uint32 ] | ||
ifFalse: [ aResolver resolveType: #int32 ]) ]. | ||
(aFFIValueArgument value == #self) ifTrue: [ | ||
^ (aResolver requestor asExternalTypeOn: aResolver) | ||
prepareAsSelfFromCalloutDeclaration ]. | ||
|
||
^ aFFIValueArgument value isSymbol | ||
ifTrue: [ | ||
"This is actually a class variable with a value..." | ||
aResolver resolveType: aFFIValueArgument value ] | ||
ifFalse: [ aResolver unsupportedUntypedLiteral: aFFIValueArgument value ] | ||
] |
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 @@ | ||
" | ||
I resolve arguments strictly: if they have no type declaration I throw an exception. | ||
" | ||
Class { | ||
#name : #FFIStrictResolutionMode, | ||
#superclass : #Object, | ||
#category : #'UnifiedFFI-Callouts' | ||
} | ||
|
||
{ #category : #resolution } | ||
FFIStrictResolutionMode >> resolveUndeclaredTypeForArgument: aFFIValueArgument withResolver: aResolver [ | ||
|
||
aResolver unsupportedUntypedLiteral: aFFIValueArgument value | ||
] |
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