From 15c6cf46bf05b5faf70ec5272f1e99c68c5351b5 Mon Sep 17 00:00:00 2001 From: Guille Polito Date: Mon, 4 Dec 2023 08:53:31 +0100 Subject: [PATCH] Revert "Revert "[WIP] Redo "Activate strict FFI"""" --- src/Athens-Cairo/AthensCairoCanvas.class.st | 4 ++-- .../CairoFontMetricsProvider.class.st | 22 ++++++++++++------- .../UnixEnvironment.class.st | 6 ++--- .../FFICalloutAPITest.class.st | 4 ++-- src/UnifiedFFI/FFILibrary.class.st | 2 +- .../FFIStrictResolutionMode.class.st | 10 +++++++++ 6 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/Athens-Cairo/AthensCairoCanvas.class.st b/src/Athens-Cairo/AthensCairoCanvas.class.st index 36f9a984818..498793a7a5e 100644 --- a/src/Athens-Cairo/AthensCairoCanvas.class.st +++ b/src/Athens-Cairo/AthensCairoCanvas.class.st @@ -227,8 +227,8 @@ AthensCairoCanvas >> primResetDashes: anOffset [ double offset);" ^ self ffiCall: #(void cairo_set_dash ( self, - 0, - 0, + void* 0, + int 0, double anOffset) ) ] diff --git a/src/Athens-Cairo/CairoFontMetricsProvider.class.st b/src/Athens-Cairo/CairoFontMetricsProvider.class.st index 4bbbdfab2b6..6805ac36357 100644 --- a/src/Athens-Cairo/CairoFontMetricsProvider.class.st +++ b/src/Athens-Cairo/CairoFontMetricsProvider.class.st @@ -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, @@ -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' } diff --git a/src/System-OSEnvironments/UnixEnvironment.class.st b/src/System-OSEnvironments/UnixEnvironment.class.st index d2f177026ef..413e6416b6f 100644 --- a/src/System-OSEnvironments/UnixEnvironment.class.st +++ b/src/System-OSEnvironments/UnixEnvironment.class.st @@ -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 ] diff --git a/src/UnifiedFFI-Tests/FFICalloutAPITest.class.st b/src/UnifiedFFI-Tests/FFICalloutAPITest.class.st index 66064fecdb2..9dae33adb13 100644 --- a/src/UnifiedFFI-Tests/FFICalloutAPITest.class.st +++ b/src/UnifiedFFI-Tests/FFICalloutAPITest.class.st @@ -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' } diff --git a/src/UnifiedFFI/FFILibrary.class.st b/src/UnifiedFFI/FFILibrary.class.st index 868791936f0..44cb0f656bc 100644 --- a/src/UnifiedFFI/FFILibrary.class.st +++ b/src/UnifiedFFI/FFILibrary.class.st @@ -32,7 +32,7 @@ FFILibrary class >> new [ { #category : 'options' } FFILibrary class >> options [ - ^ #() + ^ #( #+ optStrict ) ] { #category : 'instance creation' } diff --git a/src/UnifiedFFI/FFIStrictResolutionMode.class.st b/src/UnifiedFFI/FFIStrictResolutionMode.class.st index dc1797db514..182b1361474 100644 --- a/src/UnifiedFFI/FFIStrictResolutionMode.class.st +++ b/src/UnifiedFFI/FFIStrictResolutionMode.class.st @@ -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 ]