Skip to content

Commit

Permalink
Revert "Revert "[WIP] Redo "Activate strict FFI""""
Browse files Browse the repository at this point in the history
  • Loading branch information
guillep authored Dec 4, 2023
1 parent bfcc0b6 commit 15c6cf4
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/Athens-Cairo/AthensCairoCanvas.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ AthensCairoCanvas >> primResetDashes: anOffset [
double offset);"
^ self ffiCall: #(void cairo_set_dash (
self,
0,
0,
void* 0,
int 0,
double anOffset) )
]

Expand Down
22 changes: 14 additions & 8 deletions src/Athens-Cairo/CairoFontMetricsProvider.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,17 @@ CairoFontMetricsProvider >> cairoFont [

{ #category : 'private' }
CairoFontMetricsProvider >> convertString: utf8String len: strlen ofFont: aScaledFont toGlyphs: glyphs numGlyphs: numGlyphs x: x y: y [
"
all of this for using
http://www.cairographics.org/manual/cairo-User-Fonts.html#cairo-user-scaled-font-text-to-glyphs-func-t
"
"cairo_status_t
cairo_scaled_font_text_to_glyphs (cairo_scaled_font_t *scaled_font,
double x,
double y,
const char *utf8,
int utf8_len,
cairo_glyph_t **glyphs,
int *num_glyphs,
cairo_text_cluster_t **clusters,
int *num_clusters,
cairo_text_cluster_flags_t *cluster_flags);"
^ self ffiCall: #(
cairo_status_t cairo_scaled_font_text_to_glyphs (CairoScaledFont aScaledFont,
double x,
Expand All @@ -55,9 +61,9 @@ http://www.cairographics.org/manual/cairo-User-Fonts.html#cairo-user-scaled-font
int strlen,
void ** glyphs,
int * numGlyphs,
NULL,
NULL,
NULL))
void* 0,
void* 0,
void* 0))
]

{ #category : 'accessing' }
Expand Down
6 changes: 3 additions & 3 deletions src/System-OSEnvironments/UnixEnvironment.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ UnixEnvironment >> removeKey: key encoded: anEncoding [
^ self rawRemoveKey: (key encodeWith: anEncoding)
]

{ #category : 'private' }
{ #category : 'accessing' }
UnixEnvironment >> setEnv: nameString value: valueString [
"This method calls the Standard C Library setenv() function"
"int setenv(const char *name, const char *value, int overwrite);"

^ self ffiCall: #(int setenv #(String nameString , String valueString , 1)) module: LibC
^ self ffiCall: #(int setenv #(String nameString , String valueString , int 1)) module: LibC
]
4 changes: 2 additions & 2 deletions src/UnifiedFFI-Tests/FFICalloutAPITest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ FFICalloutAPITest >> ffiLongLongAbs: number [

{ #category : 'primitives constant' }
FFICalloutAPITest >> ffiTestConstantFormat: format to: buffer [
^ self ffiCall: #( int sprintf ( ByteArray buffer, String format, 65, 65, 1 ) ) fixedArgumentCount: 2
^ self ffiCall: #( int sprintf ( ByteArray buffer, String format, int 65, int 65, int 1 ) ) fixedArgumentCount: 2
]

{ #category : 'primitives constant' }
FFICalloutAPITest >> ffiTestContantFormat: format value: aNumber to: buffer [
^ self ffiCall: #( int sprintf ( ByteArray buffer, String format, 65, 65, long aNumber ) ) fixedArgumentCount: 2
^ self ffiCall: #( int sprintf ( ByteArray buffer, String format, int 65, int 65, long aNumber ) ) fixedArgumentCount: 2
]

{ #category : 'primitives atomic' }
Expand Down
2 changes: 1 addition & 1 deletion src/UnifiedFFI/FFILibrary.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ FFILibrary class >> new [
{ #category : 'options' }
FFILibrary class >> options [

^ #()
^ #( #+ optStrict )
]

{ #category : 'instance creation' }
Expand Down
10 changes: 10 additions & 0 deletions src/UnifiedFFI/FFIStrictResolutionMode.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,15 @@ FFIStrictResolutionMode >> isStrict [
{ #category : 'resolution' }
FFIStrictResolutionMode >> resolveUndeclaredTypeForArgument: aFFIValueArgument withResolver: aResolver [

"Make strict all declarations except those using self.
This is safe because:
- We can infer self from the current class
- the only implementor of prepareAsSelfFromCalloutDeclaration are those classes representing pointers"
aFFIValueArgument value == #self ifTrue: [
| externalType |
externalType := aResolver requestor asExternalTypeOn: aResolver.
^ externalType prepareAsSelfFromCalloutDeclaration ].

"Otherwise, this is an untyped literal which is unsupported"
aResolver unsupportedUntypedLiteral: aFFIValueArgument value
]

0 comments on commit 15c6cf4

Please sign in to comment.