author | Jan Vrany <jan.vrany@labware.com> |
Wed, 03 Feb 2021 11:52:30 +0000 | |
branch | jv |
changeset 25410 | c91ea94445d1 |
parent 25400 | 74da99aeab66 |
child 25439 | 0ef9bb1cd7bc |
permissions | -rw-r--r-- |
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1 |
" |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
2 |
COPYRIGHT (c) 1995 by Claus Gittinger |
25391
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
3 |
COPYRIGHT (c) 2017 Jan Vrany |
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
4 |
COPYRIGHT (c) 2020 LabWare |
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
5 |
All Rights Reserved |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
6 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
7 |
This software is furnished under a license and may be used |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
8 |
only in accordance with the terms of that license and with the |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
9 |
inclusion of the above copyright notice. This software may not |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
10 |
be provided or otherwise made available to, or used by, any |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
11 |
other person. No title to or ownership of the software is |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
12 |
hereby transferred. |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
13 |
" |
6491
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
14 |
"{ Package: 'stx:libbasic' }" |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
15 |
|
18828 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
18 |
Object subclass:#ExternalAddress |
1267 | 19 |
instanceVariableNames:'address*' |
20 |
classVariableNames:'' |
|
21 |
poolDictionaries:'' |
|
22 |
category:'System-Support' |
|
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
23 |
! |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
24 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
25 |
!ExternalAddress class methodsFor:'documentation'! |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
26 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
27 |
copyright |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
28 |
" |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
29 |
COPYRIGHT (c) 1995 by Claus Gittinger |
23217
5811aa416119
Fixed `ExternalAddress >> setAddress:` to allow for parameter to be `0` or `nil`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21024
diff
changeset
|
30 |
COPYRIGHT (c) 2017 Jan Vrany |
25391
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
31 |
COPYRIGHT (c) 2020 LabWare |
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
32 |
All Rights Reserved |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
33 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
34 |
This software is furnished under a license and may be used |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
35 |
only in accordance with the terms of that license and with the |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
36 |
inclusion of the above copyright notice. This software may not |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
37 |
be provided or otherwise made available to, or used by, any |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
38 |
other person. No title to or ownership of the software is |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
39 |
hereby transferred. |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
40 |
" |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
41 |
! |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
42 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
43 |
documentation |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
44 |
" |
19513 | 45 |
Instances of this class represent external (non-Smalltalk) memory addresses. |
46 |
They are only useful to represent handles as returned by C functions, |
|
47 |
or to pass them to C functions. |
|
48 |
For example, Window- or WidgetIDs (which are actually 32 bit pointers) can be represented this way, |
|
49 |
but better create a handle-subclass for it, to care for proper finalization. |
|
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
50 |
(you should not use SmallIntegers for this, since they can only represent 31 |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
51 |
bits; LargeIntegers could be used in theory, but it is not a very good style |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
52 |
to do so, since it makes things a bit cryptic - having ExternalAddresses |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
53 |
around makes things pretty clear in inspectors etc.). |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
54 |
|
19513 | 55 |
There is not much you can do with ExternalAddresses on the Smalltalk level; |
8463 | 56 |
creation/use should be done in primitive C-code via |
1317 | 57 |
__MKEXTERNALADDRESS(voidPtr) and __ExternalAddressVal(obj). |
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
58 |
|
19513 | 59 |
ExternalAddresses are much like ExternalBytes - however, ExternalAddresses do not know |
60 |
the size of the memory block and therefore do not allow you to access bytes via indexed at:/at:put: messages |
|
61 |
(which ExternalBytes do). |
|
62 |
ExternalAddresses are meant to remain anonymous, opaque handles. |
|
8463 | 63 |
Also, memory blocks which are freeable should be represented as ExternalBytes. |
1286 | 64 |
|
65 |
[author:] |
|
8463 | 66 |
Claus Gittinger |
1317 | 67 |
|
68 |
[see also:] |
|
8463 | 69 |
ByteArray |
70 |
ExternalBytes ExternalFunction |
|
71 |
( how to write primitive code :html: programming/primitive.html ) |
|
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
72 |
" |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
73 |
! |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
74 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
75 |
examples |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
76 |
" |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
77 |
To pass some C-pointer from primitive code to smalltalk: |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
78 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
79 |
... |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
80 |
RETURN (__MKEXTERNALADDRESS(foo)); |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
81 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
82 |
pass it back to C and use it there: |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
83 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
84 |
... |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
85 |
if (__isExternalAddress(anExternalAddress)) { |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
86 |
ptr = __externalAddressVal(anExternalAddress)); |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
87 |
} |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
88 |
... |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
89 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
90 |
concrete example: |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
91 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
92 |
test1 |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
93 |
%{ |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
94 |
static char foo[] = {'h', 'e' ,'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '\n'}; |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
95 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
96 |
RETURN (__MKEXTERNALADDRESS(foo)); |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
97 |
%} |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
98 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
99 |
test2:anExternalAddress |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
100 |
%{ |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
101 |
if (__isExternalAddress(anExternalAddress)) { |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
102 |
printf(__externalAddressVal(anExternalAddress)); |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
103 |
RETURN (self); |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
104 |
} |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
105 |
%} |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
106 |
" |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
107 |
! ! |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
108 |
|
3957 | 109 |
!ExternalAddress class methodsFor:'instance creation'! |
110 |
||
25391
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
111 |
fromExternalAddress: anExternalAddress |
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
112 |
"Creates a new instance referring to the same |
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
113 |
memory as parameter `anExternalAddress`. |
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
114 |
|
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
115 |
This method is called by FFI (ExternalLibraryFunction) |
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
116 |
to create a return value of this type. |
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
117 |
" |
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
118 |
self == anExternalAddress class ifTrue:[ |
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
119 |
^ anExternalAddress |
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
120 |
]. |
25400
74da99aeab66
Do not call `new` in `ExternalAddress >> fromExternalAddress:`
Jan Vrany <jan.vrany@labware.com>
parents:
25391
diff
changeset
|
121 |
^ self basicNew |
74da99aeab66
Do not call `new` in `ExternalAddress >> fromExternalAddress:`
Jan Vrany <jan.vrany@labware.com>
parents:
25391
diff
changeset
|
122 |
initialize; |
74da99aeab66
Do not call `new` in `ExternalAddress >> fromExternalAddress:`
Jan Vrany <jan.vrany@labware.com>
parents:
25391
diff
changeset
|
123 |
setAddress: anExternalAddress; |
74da99aeab66
Do not call `new` in `ExternalAddress >> fromExternalAddress:`
Jan Vrany <jan.vrany@labware.com>
parents:
25391
diff
changeset
|
124 |
yourself |
25391
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
125 |
|
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
126 |
"Created: / 24-12-2014 / 22:18:45 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
127 |
"Modified: / 25-12-2014 / 10:33:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
25400
74da99aeab66
Do not call `new` in `ExternalAddress >> fromExternalAddress:`
Jan Vrany <jan.vrany@labware.com>
parents:
25391
diff
changeset
|
128 |
"Modified: / 12-08-2020 / 12:04:48 / Jan Vrany <jan.vrany@labware.com>" |
25391
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
129 |
! |
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
130 |
|
3957 | 131 |
newAddress:addr |
20967 | 132 |
"return a new externalAddress (pointer), pointing to addr." |
133 |
||
3957 | 134 |
^ self new setAddress:addr |
20967 | 135 |
|
136 |
"Modified (comment): / 15-11-2016 / 11:57:34 / cg" |
|
137 |
! |
|
138 |
||
139 |
newAddressFromBytes:bytesContainingAddress |
|
140 |
"return a new externalAddress (pointer), pointing to the addr contained in the argument. |
|
141 |
The argument must be a byteArray-like object, whose first pointerSize bytes are extracted" |
|
142 |
||
143 |
^ (bytesContainingAddress pointerAt:1) |
|
144 |
||
145 |
" |
|
146 |
|bytes ptr| |
|
147 |
||
148 |
bytes := ByteArray new:(ExternalAddress pointerSize). |
|
149 |
bytes pointerAt:1 put:16r12345678. |
|
150 |
ptr := ExternalAddress newAddressFromBytes:bytes. |
|
151 |
self assert:(ptr address = 16r12345678). |
|
152 |
" |
|
153 |
||
154 |
"Created: / 15-11-2016 / 12:53:21 / cg" |
|
3957 | 155 |
! ! |
156 |
||
25391
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
157 |
|
13183 | 158 |
!ExternalAddress class methodsFor:'Compatibility-V''Age'! |
159 |
||
160 |
fromAddress:anInteger |
|
161 |
^ self newAddress:anInteger |
|
162 |
||
163 |
"Created: / 22-12-2010 / 13:48:42 / cg" |
|
164 |
! |
|
13180 | 165 |
|
166 |
sizeInBytes |
|
167 |
^ self pointerSize |
|
168 |
||
169 |
"Created: / 21-12-2010 / 15:18:06 / cg" |
|
170 |
! ! |
|
171 |
||
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
172 |
!ExternalAddress class methodsFor:'queries'! |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
173 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
174 |
isBuiltInClass |
1267 | 175 |
"return true if this class is known by the run-time-system. |
20967 | 176 |
Here, true is returned (but not for subclasses)." |
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
177 |
|
3552 | 178 |
^ self == ExternalAddress |
1267 | 179 |
|
20967 | 180 |
"Modified: / 11-06-1998 / 17:12:40 / cg" |
181 |
"Modified (comment): / 15-11-2016 / 11:56:55 / cg" |
|
6491
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
182 |
! |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
183 |
|
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
184 |
pointerSize |
19485 | 185 |
"answer the size in bytes of a pointer. |
186 |
Notice: this is inlined by the compiler(s) as a constant, |
|
20967 | 187 |
therefore, queries like |
188 |
'ExternalAddress pointerSize == 8' |
|
189 |
cost nothing; they are compiled in as a constant |
|
190 |
(and even conditionals are eliminated)." |
|
6491
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
191 |
|
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
192 |
%{ /* NOCONTEXT */ |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
193 |
RETURN(__mkSmallInteger(sizeof(void *))); |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
194 |
%}. |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
195 |
|
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
196 |
" |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
197 |
self pointerSize |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
198 |
" |
20967 | 199 |
|
200 |
"Modified (comment): / 15-11-2016 / 11:56:38 / cg" |
|
201 |
! |
|
202 |
||
203 |
sizeOfPointer |
|
204 |
"answer the size in bytes of a pointer. |
|
205 |
Notice: this is inlined by the compiler(s) as a constant, |
|
206 |
therefore, queries like |
|
207 |
'ExternalAddress pointerSize == 8' |
|
208 |
cost nothing; they are compiled in as a constant |
|
209 |
(and even conditionals are eliminated)." |
|
210 |
||
211 |
%{ /* NOCONTEXT */ |
|
212 |
RETURN(__mkSmallInteger(sizeof(void *))); |
|
213 |
%}. |
|
214 |
||
215 |
" |
|
216 |
self sizeOfPointer |
|
217 |
" |
|
218 |
||
219 |
"Created: / 15-11-2016 / 11:40:52 / cg" |
|
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
220 |
! ! |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
221 |
|
8463 | 222 |
!ExternalAddress methodsFor:'Compatibility-Squeak'! |
223 |
||
224 |
beNull |
|
225 |
self setAddress:0 |
|
13105 | 226 |
! |
227 |
||
228 |
isNull |
|
229 |
^ self address = 0 |
|
230 |
||
231 |
"Created: / 26-10-2010 / 23:17:57 / cg" |
|
8463 | 232 |
! ! |
233 |
||
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
234 |
!ExternalAddress methodsFor:'accessing'! |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
235 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
236 |
address |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
237 |
"return the start address as an integer" |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
238 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
239 |
%{ /* NOCONTEXT */ |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
240 |
|
2869 | 241 |
unsigned INT addr; |
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
242 |
|
2877 | 243 |
addr = (unsigned INT)__INST(address_); |
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
244 |
RETURN ( __MKUINT(addr)); |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
245 |
%} |
4673 | 246 |
! |
247 |
||
248 |
instVarAt:index |
|
249 |
"redefined to suppress direct access to my address, which is a non-object" |
|
250 |
||
12865 | 251 |
index == 1 ifTrue:[^ self address]. |
4673 | 252 |
^ super instVarAt:index |
253 |
||
254 |
"Created: / 3.9.1999 / 13:47:03 / ps" |
|
255 |
! |
|
256 |
||
257 |
instVarAt:index put:newAddress |
|
258 |
"redefined to suppress direct access to my address, which is a non-object" |
|
259 |
||
260 |
index == 1 ifTrue:[ |
|
261 |
self setAddress:newAddress. |
|
262 |
^ newAddress |
|
263 |
]. |
|
264 |
^ super instVarAt:index put:newAddress |
|
265 |
||
266 |
"Created: / 3.9.1999 / 14:31:57 / ps" |
|
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
267 |
! ! |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
268 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
269 |
!ExternalAddress methodsFor:'comparing'! |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
270 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
271 |
= anExternalAddress |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
272 |
"return true, if two externalAddress instance represent the same |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
273 |
C pointer" |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
274 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
275 |
%{ /* NOCONTEXT */ |
14648
7a9bec61d6fe
fix equal compare for subclasses
Claus Gittinger <cg@exept.de>
parents:
13192
diff
changeset
|
276 |
if ((__Class(anExternalAddress) == __Class(self)) |
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
277 |
&& (__externalAddressVal(self) == __externalAddressVal(anExternalAddress))) { |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
278 |
RETURN (true); |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
279 |
} |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
280 |
%}. |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
281 |
^ false |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
282 |
! |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
283 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
284 |
hash |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
285 |
"return a number useful for hashing" |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
286 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
287 |
%{ /* NOCONTEXT */ |
2869 | 288 |
unsigned INT addr = (unsigned INT) __externalAddressVal(self); |
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
289 |
|
2472
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
290 |
if (addr > _MAX_INT) { |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
291 |
if ((addr & 1) == 0) { |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
292 |
addr >>= 1; |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
293 |
} |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
294 |
if (addr > _MAX_INT) { |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
295 |
if ((addr & 1) == 0) { |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
296 |
addr >>= 1; |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
297 |
} |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
298 |
} |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
299 |
if (addr > _MAX_INT) { |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
300 |
addr &= _MAX_INT; |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
301 |
} |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
302 |
} else { |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
303 |
addr <<= 1; |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
304 |
if (addr <= _MAX_INT) { |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
305 |
addr <<= 1; |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
306 |
if (addr <= _MAX_INT) { |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
307 |
addr <<= 1; |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
308 |
} |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
309 |
} |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
310 |
addr >>= 1; |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
311 |
} |
8913 | 312 |
RETURN (__mkSmallInteger(addr)); |
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
313 |
%} |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
314 |
! ! |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
315 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
316 |
!ExternalAddress methodsFor:'converting'! |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
317 |
|
6491
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
318 |
asExternalAddress |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
319 |
"convert to an ExternalAddress. |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
320 |
Useful to convert subclasses" |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
321 |
|
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
322 |
%{ /* NOCONTEXT */ |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
323 |
|
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
324 |
if (__qClass(self) == @global(ExternalAddress)) { |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
325 |
RETURN(self) |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
326 |
} |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
327 |
RETURN(__MKEXTERNALADDRESS(__INST(address_))); |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
328 |
%}. |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
329 |
|
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
330 |
" |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
331 |
(ExternalAddress newAddress:16r12345678) asExternalAddress |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
332 |
" |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
333 |
! |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
334 |
|
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
335 |
asExternalBytes |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
336 |
"return an ExternalBytes object pointing to where the receiver points to. |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
337 |
Use of this is not recommended; primitives which return externalAddresses |
20796 | 338 |
don't think that access to the memory is required/useful, while primitives |
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
339 |
which do think so should return an externalBytes instance right away." |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
340 |
|
6491
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
341 |
%{ /* NOCONTEXT */ |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
342 |
|
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
343 |
RETURN(__MKEXTERNALBYTES(__INST(address_))); |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
344 |
%} |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
345 |
|
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
346 |
" |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
347 |
(ExternalAddress newAddress:16r12345678) asExternalBytes |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
348 |
" |
12595
ab229fdd630c
added: #copyCStringFromHeap
Claus Gittinger <cg@exept.de>
parents:
12462
diff
changeset
|
349 |
! |
ab229fdd630c
added: #copyCStringFromHeap
Claus Gittinger <cg@exept.de>
parents:
12462
diff
changeset
|
350 |
|
ab229fdd630c
added: #copyCStringFromHeap
Claus Gittinger <cg@exept.de>
parents:
12462
diff
changeset
|
351 |
copyCStringFromHeap |
ab229fdd630c
added: #copyCStringFromHeap
Claus Gittinger <cg@exept.de>
parents:
12462
diff
changeset
|
352 |
^ self asExternalBytes copyCStringFromHeap |
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
353 |
! ! |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
354 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
355 |
!ExternalAddress methodsFor:'printing & storing'! |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
356 |
|
7018
5ceb0daa7b1b
Print address when doing #printOn:
Stefan Vogel <sv@exept.de>
parents:
6491
diff
changeset
|
357 |
printOn:aStream |
5ceb0daa7b1b
Print address when doing #printOn:
Stefan Vogel <sv@exept.de>
parents:
6491
diff
changeset
|
358 |
"return a printed representation of the receiver" |
2957 | 359 |
|
7018
5ceb0daa7b1b
Print address when doing #printOn:
Stefan Vogel <sv@exept.de>
parents:
6491
diff
changeset
|
360 |
self class name printOn:aStream. |
18828 | 361 |
aStream nextPutAll:'@'. |
7018
5ceb0daa7b1b
Print address when doing #printOn:
Stefan Vogel <sv@exept.de>
parents:
6491
diff
changeset
|
362 |
self address printOn:aStream base:16. |
18828 | 363 |
|
364 |
" |
|
365 |
self new printString |
|
366 |
" |
|
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
367 |
! ! |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
368 |
|
7258 | 369 |
!ExternalAddress methodsFor:'private-accessing'! |
3957 | 370 |
|
25391
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
371 |
setAddress:anIntegerOrExternalAddressLike |
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
372 |
"set the address" |
3957 | 373 |
|
25391
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
374 |
%{ /* NOCONTEXT */ |
3957 | 375 |
|
25391
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
376 |
unsigned INT addr; |
3957 | 377 |
|
25391
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
378 |
if (anIntegerOrExternalAddressLike == nil) { |
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
379 |
addr = (unsigned INT)NULL; |
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
380 |
} else if (__isExternalAddressLike(anIntegerOrExternalAddressLike)) { |
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
381 |
addr = (unsigned INT)__externalAddressVal(anIntegerOrExternalAddressLike); |
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
382 |
} else if (__isSmallInteger(anIntegerOrExternalAddressLike)) { |
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
383 |
addr = __intVal(anIntegerOrExternalAddressLike); |
3957 | 384 |
} else { |
25391
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
385 |
addr = __unsignedLongIntVal(anIntegerOrExternalAddressLike); |
3957 | 386 |
} |
387 |
__INST(address_) = (OBJ)addr; |
|
25391
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
388 |
%} |
20967 | 389 |
|
390 |
"Modified: / 15-11-2016 / 11:59:24 / cg" |
|
9477 | 391 |
! |
392 |
||
393 |
setAddressFromBytes:aByteArray |
|
394 |
"set the address from a pointer to which we have a pointer to" |
|
395 |
||
396 |
%{ /* NOCONTEXT */ |
|
397 |
||
12462
1a3054e5c032
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
9477
diff
changeset
|
398 |
if (__isByteArrayLike(aByteArray)) { |
9477 | 399 |
if (__byteArraySize(aByteArray) == sizeof(void *)) { |
400 |
__INST(address_) = (OBJ)(((void **)__byteArrayVal(aByteArray))[0]); |
|
401 |
RETURN (self); |
|
402 |
} |
|
403 |
} |
|
404 |
%}. |
|
405 |
self primitiveFailed. |
|
406 |
||
407 |
"Created: / 27-07-2006 / 14:37:57 / fm" |
|
408 |
"Modified: / 07-08-2006 / 15:16:32 / fm" |
|
3957 | 409 |
! ! |
410 |
||
13186 | 411 |
!ExternalAddress methodsFor:'testing'! |
412 |
||
413 |
isExternalAddress |
|
414 |
^ true |
|
415 |
||
416 |
"Created: / 22-12-2010 / 17:14:57 / cg" |
|
417 |
! ! |
|
418 |
||
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
419 |
!ExternalAddress class methodsFor:'documentation'! |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
420 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
421 |
version |
18828 | 422 |
^ '$Header$' |
12462
1a3054e5c032
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
9477
diff
changeset
|
423 |
! |
1a3054e5c032
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
9477
diff
changeset
|
424 |
|
1a3054e5c032
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
9477
diff
changeset
|
425 |
version_CVS |
18828 | 426 |
^ '$Header$' |
25391
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
427 |
! |
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
428 |
|
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
429 |
version_HG |
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
430 |
|
cad52f81f60c
FFI: refactor creation of return value from FFI call-outs.
Jan Vrany <jan.vrany@labware.com>
parents:
23217
diff
changeset
|
431 |
^ '$Changeset: <not expanded> $' |
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
432 |
! ! |
18828 | 433 |