author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Mon, 26 Apr 2010 19:26:38 +0100 | |
branch | jv |
changeset 17761 | b0e5971141bc |
parent 17759 | ed6ccf3b537d |
child 17763 | 019bb9c842c5 |
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 |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
3 |
All Rights Reserved |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
4 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
5 |
This software is furnished under a license and may be used |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
6 |
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
|
7 |
inclusion of the above copyright notice. This software may not |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
8 |
be provided or otherwise made available to, or used by, any |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
9 |
other person. No title to or ownership of the software is |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
10 |
hereby transferred. |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
11 |
" |
6491
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
12 |
"{ Package: 'stx:libbasic' }" |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
13 |
|
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
14 |
Object subclass:#ExternalAddress |
1267 | 15 |
instanceVariableNames:'address*' |
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'System-Support' |
|
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
19 |
! |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
20 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
21 |
!ExternalAddress class methodsFor:'documentation'! |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
22 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
23 |
copyright |
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 |
COPYRIGHT (c) 1995 by Claus Gittinger |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
26 |
All Rights Reserved |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
27 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
28 |
This software is furnished under a license and may be used |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
29 |
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
|
30 |
inclusion of the above copyright notice. This software may not |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
31 |
be provided or otherwise made available to, or used by, any |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
32 |
other person. No title to or ownership of the software is |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
33 |
hereby transferred. |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
34 |
" |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
35 |
! |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
36 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
37 |
documentation |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
38 |
" |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
39 |
Instances of this class represent external (non-Smalltalk) addresses. |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
40 |
They are only useful to represent handles as returned by C functions |
8463 | 41 |
as smalltalk objects. |
42 |
For example, Window- or WidgetIDs (which are actually 32 bit pointers) could be represented this way |
|
43 |
(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
|
44 |
(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
|
45 |
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
|
46 |
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
|
47 |
around makes things pretty clear in inspectors etc.). |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
48 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
49 |
There is not much you can do with ExternalAddresses on the smalltalk level; |
8463 | 50 |
creation/use should be done in primitive C-code via |
1317 | 51 |
__MKEXTERNALADDRESS(voidPtr) and __ExternalAddressVal(obj). |
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
52 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
53 |
ExternallAddresses are much like ExternalBytes - however, the latter |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
54 |
allow you to access bytes via indexed at:/at:put: messages. |
8463 | 55 |
ExternalAddresses do not allow such accesses (they are meant to remain anonymous, opaque handles). |
56 |
Also, memory blocks which are freeable should be represented as ExternalBytes. |
|
1286 | 57 |
|
58 |
[author:] |
|
8463 | 59 |
Claus Gittinger |
1317 | 60 |
|
61 |
[see also:] |
|
8463 | 62 |
ByteArray |
63 |
ExternalBytes ExternalFunction |
|
64 |
( how to write primitive code :html: programming/primitive.html ) |
|
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
65 |
" |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
66 |
! |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
67 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
68 |
examples |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
69 |
" |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
70 |
To pass some C-pointer from primitive code to smalltalk: |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
71 |
|
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 |
RETURN (__MKEXTERNALADDRESS(foo)); |
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 |
pass it back to C and use it there: |
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 |
... |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
78 |
if (__isExternalAddress(anExternalAddress)) { |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
79 |
ptr = __externalAddressVal(anExternalAddress)); |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
80 |
} |
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 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
83 |
concrete example: |
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 |
test1 |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
86 |
%{ |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
87 |
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
|
88 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
89 |
RETURN (__MKEXTERNALADDRESS(foo)); |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
90 |
%} |
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 |
test2:anExternalAddress |
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 |
if (__isExternalAddress(anExternalAddress)) { |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
95 |
printf(__externalAddressVal(anExternalAddress)); |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
96 |
RETURN (self); |
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 |
" |
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 |
|
3957 | 102 |
!ExternalAddress class methodsFor:'instance creation'! |
103 |
||
104 |
newAddress:addr |
|
105 |
^ self new setAddress:addr |
|
106 |
! ! |
|
107 |
||
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
108 |
!ExternalAddress class methodsFor:'queries'! |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
109 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
110 |
isBuiltInClass |
1267 | 111 |
"return true if this class is known by the run-time-system. |
112 |
Here, true is returned." |
|
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
113 |
|
3552 | 114 |
^ self == ExternalAddress |
1267 | 115 |
|
3552 | 116 |
"Modified: / 11.6.1998 / 17:12:40 / cg" |
6491
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
117 |
! |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
118 |
|
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
119 |
pointerSize |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
120 |
"answer the size in bytes of a pointer" |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
121 |
|
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
122 |
%{ /* NOCONTEXT */ |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
123 |
RETURN(__mkSmallInteger(sizeof(void *))); |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
124 |
%}. |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
125 |
|
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
126 |
" |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
127 |
self pointerSize |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
128 |
" |
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
129 |
! ! |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
130 |
|
8463 | 131 |
!ExternalAddress methodsFor:'Compatibility-Squeak'! |
132 |
||
133 |
beNull |
|
134 |
self setAddress:0 |
|
135 |
! ! |
|
136 |
||
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
137 |
!ExternalAddress methodsFor:'accessing'! |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
138 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
139 |
address |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
140 |
"return the start address as an integer" |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
141 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
142 |
%{ /* NOCONTEXT */ |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
143 |
|
2869 | 144 |
unsigned INT addr; |
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
145 |
|
2877 | 146 |
addr = (unsigned INT)__INST(address_); |
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
147 |
RETURN ( __MKUINT(addr)); |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
148 |
%} |
4673 | 149 |
! |
150 |
||
151 |
instVarAt:index |
|
152 |
"redefined to suppress direct access to my address, which is a non-object" |
|
153 |
||
17759
ed6ccf3b537d
Reverted bad rev. 10512 (some mess during merge)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17758
diff
changeset
|
154 |
index == 1 ifTrue:[ |
ed6ccf3b537d
Reverted bad rev. 10512 (some mess during merge)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17758
diff
changeset
|
155 |
^ self address |
ed6ccf3b537d
Reverted bad rev. 10512 (some mess during merge)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17758
diff
changeset
|
156 |
]. |
4673 | 157 |
^ super instVarAt:index |
158 |
||
159 |
"Created: / 3.9.1999 / 13:47:03 / ps" |
|
160 |
! |
|
161 |
||
162 |
instVarAt:index put:newAddress |
|
163 |
"redefined to suppress direct access to my address, which is a non-object" |
|
164 |
||
165 |
index == 1 ifTrue:[ |
|
166 |
self setAddress:newAddress. |
|
167 |
^ newAddress |
|
168 |
]. |
|
169 |
^ super instVarAt:index put:newAddress |
|
170 |
||
171 |
"Created: / 3.9.1999 / 14:31:57 / ps" |
|
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
172 |
! ! |
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 |
!ExternalAddress methodsFor:'comparing'! |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
175 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
176 |
= anExternalAddress |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
177 |
"return true, if two externalAddress instance represent the same |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
178 |
C pointer" |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
179 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
180 |
%{ /* NOCONTEXT */ |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
181 |
if (__isExternalAddress(anExternalAddress) |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
182 |
&& (__externalAddressVal(self) == __externalAddressVal(anExternalAddress))) { |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
183 |
RETURN (true); |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
184 |
} |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
185 |
%}. |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
186 |
^ false |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
187 |
! |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
188 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
189 |
hash |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
190 |
"return a number useful for hashing" |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
191 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
192 |
%{ /* NOCONTEXT */ |
2869 | 193 |
unsigned INT addr = (unsigned INT) __externalAddressVal(self); |
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
194 |
|
2472
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
195 |
if (addr > _MAX_INT) { |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
196 |
if ((addr & 1) == 0) { |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
197 |
addr >>= 1; |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
198 |
} |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
199 |
if (addr > _MAX_INT) { |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
200 |
if ((addr & 1) == 0) { |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
201 |
addr >>= 1; |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
202 |
} |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
203 |
} |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
204 |
if (addr > _MAX_INT) { |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
205 |
addr &= _MAX_INT; |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
206 |
} |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
207 |
} else { |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
208 |
addr <<= 1; |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
209 |
if (addr <= _MAX_INT) { |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
210 |
addr <<= 1; |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
211 |
if (addr <= _MAX_INT) { |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
212 |
addr <<= 1; |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
213 |
} |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
214 |
} |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
215 |
addr >>= 1; |
00e7a1b3b07f
better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents:
1960
diff
changeset
|
216 |
} |
8913 | 217 |
RETURN (__mkSmallInteger(addr)); |
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
218 |
%} |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
219 |
! ! |
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 |
!ExternalAddress methodsFor:'converting'! |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
222 |
|
6491
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
223 |
asExternalAddress |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
224 |
"convert to an ExternalAddress. |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
225 |
Useful to convert subclasses" |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
226 |
|
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
227 |
%{ /* NOCONTEXT */ |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
228 |
|
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
229 |
if (__qClass(self) == @global(ExternalAddress)) { |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
230 |
RETURN(self) |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
231 |
} |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
232 |
RETURN(__MKEXTERNALADDRESS(__INST(address_))); |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
233 |
%}. |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
234 |
|
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
235 |
" |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
236 |
(ExternalAddress newAddress:16r12345678) asExternalAddress |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
237 |
" |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
238 |
! |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
239 |
|
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
240 |
asExternalBytes |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
241 |
"return an ExternalBytes object pointing to where the receiver points to. |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
242 |
Use of this is not recommended; primitives which return externalAddresses |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
243 |
dont think that access to the memory is required/useful, while primitives |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
244 |
which do think so should return an externalBytes instance right away." |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
245 |
|
6491
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
246 |
%{ /* NOCONTEXT */ |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
247 |
|
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
248 |
RETURN(__MKEXTERNALBYTES(__INST(address_))); |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
249 |
%} |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
250 |
|
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
251 |
" |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
252 |
(ExternalAddress newAddress:16r12345678) asExternalBytes |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
4673
diff
changeset
|
253 |
" |
17742 | 254 |
! |
255 |
||
256 |
copyCStringFromHeap |
|
257 |
^ self asExternalBytes copyCStringFromHeap |
|
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
258 |
! ! |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
259 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
260 |
!ExternalAddress methodsFor:'printing & storing'! |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
261 |
|
7018
5ceb0daa7b1b
Print address when doing #printOn:
Stefan Vogel <sv@exept.de>
parents:
6491
diff
changeset
|
262 |
printOn:aStream |
5ceb0daa7b1b
Print address when doing #printOn:
Stefan Vogel <sv@exept.de>
parents:
6491
diff
changeset
|
263 |
"return a printed representation of the receiver" |
2957 | 264 |
|
7018
5ceb0daa7b1b
Print address when doing #printOn:
Stefan Vogel <sv@exept.de>
parents:
6491
diff
changeset
|
265 |
self class name printOn:aStream. |
5ceb0daa7b1b
Print address when doing #printOn:
Stefan Vogel <sv@exept.de>
parents:
6491
diff
changeset
|
266 |
aStream nextPutAll:' at:'. |
5ceb0daa7b1b
Print address when doing #printOn:
Stefan Vogel <sv@exept.de>
parents:
6491
diff
changeset
|
267 |
self address printOn:aStream base:16. |
847
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 |
|
7258 | 270 |
!ExternalAddress methodsFor:'private-accessing'! |
3957 | 271 |
|
272 |
setAddress:anInteger |
|
273 |
"set the address" |
|
274 |
||
275 |
%{ /* NOCONTEXT */ |
|
276 |
||
277 |
unsigned INT addr; |
|
278 |
||
279 |
if (__isSmallInteger(anInteger)) { |
|
8595
a756fee49327
#setAddress: use unsignedLongIntVal()
Stefan Vogel <sv@exept.de>
parents:
8463
diff
changeset
|
280 |
addr = __intVal(anInteger); |
3957 | 281 |
} else { |
8595
a756fee49327
#setAddress: use unsignedLongIntVal()
Stefan Vogel <sv@exept.de>
parents:
8463
diff
changeset
|
282 |
addr = __unsignedLongIntVal(anInteger); |
3957 | 283 |
} |
284 |
__INST(address_) = (OBJ)addr; |
|
285 |
%} |
|
9477 | 286 |
! |
287 |
||
288 |
setAddressFromBytes:aByteArray |
|
289 |
"set the address from a pointer to which we have a pointer to" |
|
290 |
||
291 |
%{ /* NOCONTEXT */ |
|
292 |
||
17735 | 293 |
if (__isByteArrayLike(aByteArray)) { |
9477 | 294 |
if (__byteArraySize(aByteArray) == sizeof(void *)) { |
295 |
__INST(address_) = (OBJ)(((void **)__byteArrayVal(aByteArray))[0]); |
|
296 |
RETURN (self); |
|
297 |
} |
|
298 |
} |
|
299 |
%}. |
|
300 |
self primitiveFailed. |
|
301 |
||
302 |
"Created: / 27-07-2006 / 14:37:57 / fm" |
|
303 |
"Modified: / 07-08-2006 / 15:16:32 / fm" |
|
3957 | 304 |
! ! |
305 |
||
847
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
306 |
!ExternalAddress class methodsFor:'documentation'! |
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
307 |
|
a79ec4e6670d
ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
308 |
version |
17761
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17759
diff
changeset
|
309 |
^ '$Id: ExternalAddress.st 10517 2010-04-26 18:26:38Z vranyj1 $' |
17735 | 310 |
! |
311 |
||
312 |
version_CVS |
|
17759
ed6ccf3b537d
Reverted bad rev. 10512 (some mess during merge)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17758
diff
changeset
|
313 |
^ '§Header: /cvs/stx/stx/libbasic/ExternalAddress.st,v 1.24 2009/12/07 15:58:16 cg Exp §' |
17761
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17759
diff
changeset
|
314 |
! |
17735 | 315 |
|
17761
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17759
diff
changeset
|
316 |
version_SVN |
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17759
diff
changeset
|
317 |
^ '$Id: ExternalAddress.st 10517 2010-04-26 18:26:38Z vranyj1 $' |
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17759
diff
changeset
|
318 |
! ! |