Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2941 - [Backport] Fixing FFIConstantHandleType externalType wrong in 64 bit #2945

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/FFI-Kernel/ByteArray.extension.st
Expand Up @@ -12,8 +12,8 @@ ByteArray >> booleanAt: byteOffset [
Examples:
(#[1 2 0 4] booleanAt: 2) >>> true.
(#[1 2 0 4] booleanAt: 3) >>> false."
^(self integerAt: byteOffset size: 1 signed: false) ~= 0

^ (self integerAt: byteOffset size: 1 signed: false) ~= 0
]

{ #category : #'*FFI-Kernel' }
Expand Down
14 changes: 8 additions & 6 deletions src/FFI-Kernel/ExternalAddress.class.st
Expand Up @@ -86,7 +86,9 @@ ExternalAddress >> + offset [
"Convert xaddr -> bytes"
bytes := self asByteArrayPointer.
"Update bytes using platform dependent accessors"
bytes unsignedLongAt: 1 put: (bytes unsignedLongAt: 1) + offset.
self size = 4
ifTrue: [bytes unsignedLongAt: 1 put: (bytes unsignedLongAt: 1) + offset]
ifFalse: [bytes unsignedLongLongAt: 1 put: (bytes unsignedLongLongAt: 1) + offset].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why writing this by hand like that and not reusing pointerAt:put:?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to us that size will return the actual size of a word for an address...
Alternatively, there is also platformLongAt:put: that uses the platform size...

"Convert bytes -> xaddr"
^bytes asExternalPointer
]
Expand All @@ -95,7 +97,7 @@ ExternalAddress >> + offset [
ExternalAddress >> asByteArrayPointer [
"Answer a ByteArray containing a copy of pointer to the contents of the receiver."
| sz |
^(ByteArray basicNew: (sz := self class wordSize))
^(ByteArray basicNew: (sz := self size))
replaceFrom: 1 to: sz with: self startingAt: 1 "answers self"
]

Expand All @@ -108,10 +110,10 @@ ExternalAddress >> asExternalPointer [
{ #category : #converting }
ExternalAddress >> asInteger [
"convert address to integer"
^ self asByteArrayPointer integerAt: 1 size: self class wordSize signed: false
^ self asByteArrayPointer integerAt: 1 size: self size signed: false
]

{ #category : #'initialize-release' }
{ #category : #initialization }
ExternalAddress >> beNull [
"Make the receiver a NULL pointer"
self atAllPut: 0.
Expand Down Expand Up @@ -144,7 +146,7 @@ ExternalAddress >> finalize [
self free
]

{ #category : #'initialize-release' }
{ #category : #initialization }
ExternalAddress >> free [
"Primitive. Free the object pointed to on the external heap.
Dangerous - may break your system if the receiver hasn't been
Expand All @@ -159,7 +161,7 @@ ExternalAddress >> fromInteger: address [
"Do we really need this? bf 2/21/2001 23:48"

| sz pointer |
sz := self class wordSize.
sz := self size.
pointer := ByteArray new: sz.
pointer integerAt: 1 put: address size: sz signed: false. .
self basicAt: 1 put: (pointer byteAt: 1);
Expand Down
4 changes: 2 additions & 2 deletions src/FFI-Kernel/ExternalFunction.class.st
Expand Up @@ -176,7 +176,7 @@ ExternalFunction >> flags [
^flags
]

{ #category : #'initialize-release' }
{ #category : #initialization }
ExternalFunction >> initialize [
"Initialize the receiver"
handle := ExternalAddress new.
Expand Down Expand Up @@ -220,7 +220,7 @@ ExternalFunction >> invokeWith: arg1 with: arg2 with: arg3 with: arg4 with: arg5
{ #category : #invoking }
ExternalFunction >> invokeWithArguments: argArray [
"Manually invoke the receiver, representing an external function."
<primitive: 'primitiveCalloutWithArgs' module:'SqueakFFIPrims'>
<primitive: 'primitiveCalloutWithArgs' module: 'SqueakFFIPrims' error: ec>
^self externalCallFailed
]

Expand Down
4 changes: 2 additions & 2 deletions src/FFI-Kernel/ExternalLibrary.class.st
Expand Up @@ -18,7 +18,7 @@ ExternalLibrary class >> moduleName [
^nil
]

{ #category : #'initialize-release' }
{ #category : #initialization }
ExternalLibrary >> forceLoading [
"Primitive. Force loading the given library.
The primitive will fail if the library is not available
Expand All @@ -32,7 +32,7 @@ ExternalLibrary >> handle [
^handle
]

{ #category : #'initialize-release' }
{ #category : #initialization }
ExternalLibrary >> initialize [
"Initialize the receiver"
name := self class moduleName.
Expand Down