author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Mon, 21 Mar 2016 07:50:50 +0000 | |
branch | jv |
changeset 19410 | f9d7cb8bd74c |
parent 19332 | 9686fae7951b |
parent 19376 | 5dc7266efb72 |
child 19412 | 1e842c25e51e |
permissions | -rw-r--r-- |
6459 | 1 |
" |
2 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
3 |
All Rights Reserved |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
4 |
|
6459 | 5 |
This software is furnished under a license and may be used |
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
19376 | 12 |
'From Smalltalk/X, Version:6.2.5.0 on 18-03-2016 at 10:24:59' ! |
13 |
||
5378 | 14 |
"{ Package: 'stx:libbasic' }" |
15 |
||
17627 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
3208
2d71538b9fd5
now subclass of UIBytes - which contains common protocol
Claus Gittinger <cg@exept.de>
parents:
3206
diff
changeset
|
18 |
UninterpretedBytes subclass:#ExternalBytes |
3211
ef7a5411afa1
remove methods which are provided by my (new) superClass
Claus Gittinger <cg@exept.de>
parents:
3208
diff
changeset
|
19 |
instanceVariableNames:'address* size' |
10137
7bfdc51fcb65
Avoid deadlock when free is called by finalization code (Stefan Vogel)
Michael Beyl <mb@exept.de>
parents:
9895
diff
changeset
|
20 |
classVariableNames:'AllocatedInstances Lobby DebugMalloc TraceMalloc' |
3211
ef7a5411afa1
remove methods which are provided by my (new) superClass
Claus Gittinger <cg@exept.de>
parents:
3208
diff
changeset
|
21 |
poolDictionaries:'' |
ef7a5411afa1
remove methods which are provided by my (new) superClass
Claus Gittinger <cg@exept.de>
parents:
3208
diff
changeset
|
22 |
category:'System-Support' |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
23 |
! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
24 |
|
14749 | 25 |
!ExternalBytes primitiveDefinitions! |
26 |
%{ |
|
19376 | 27 |
#include <stdlib.h> |
28 |
#include <stdio.h> |
|
29 |
#include <malloc.h> |
|
30 |
||
31 |
extern char *__stx_malloc(size_t); |
|
32 |
extern char *__stx_calloc(size_t, size_t); |
|
33 |
extern char *__stx_realloc(char *, size_t); |
|
34 |
extern void __stx_free(char *); |
|
35 |
extern void __stx_mallocStatistics(void); |
|
14749 | 36 |
%} |
37 |
! ! |
|
38 |
||
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
39 |
!ExternalBytes primitiveFunctions! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
40 |
%{ |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
41 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
42 |
struct mallocList { |
19376 | 43 |
char *chunk; |
44 |
size_t size; |
|
45 |
struct mallocList *next; |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
46 |
}; |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
47 |
static struct mallocList *mallocList = (struct mallocList *)0; |
8913 | 48 |
static INT mallocCount = 0; |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
49 |
|
6242 | 50 |
static void |
19376 | 51 |
removeFromMallocList(char *ptr) |
6242 | 52 |
{ |
53 |
struct mallocList *this, *prev, *next; |
|
54 |
int found = 0; |
|
55 |
||
56 |
if (@global(DebugMalloc) != true) return; |
|
57 |
||
58 |
if (ptr) { |
|
19376 | 59 |
found = 0; |
60 |
for (this=mallocList, prev=0; this; this=next) { |
|
61 |
next = this->next; |
|
62 |
if (this->chunk == ptr) { |
|
63 |
if (prev) { |
|
64 |
prev->next = next; |
|
65 |
} else { |
|
66 |
mallocList = next; |
|
67 |
} |
|
68 |
free(this); |
|
69 |
found++; |
|
70 |
mallocCount--; |
|
71 |
} else { |
|
72 |
prev = this; |
|
73 |
} |
|
74 |
} |
|
75 |
if (! found) { |
|
76 |
console_printf("ExternalBytes [warning]: **** free: alien %"_lx_" (allocated somewhere else ?))\n", (INT)ptr); |
|
77 |
} |
|
6242 | 78 |
} |
79 |
} |
|
80 |
||
81 |
static void |
|
19376 | 82 |
addToMallocList(char *ptr, size_t nBytes) |
6242 | 83 |
{ |
84 |
struct mallocList *e, *this; |
|
9895 | 85 |
void *malloc(); |
6242 | 86 |
int found; |
87 |
||
88 |
if (@global(DebugMalloc) != true) return; |
|
89 |
||
90 |
if (ptr) { |
|
19376 | 91 |
found = 0; |
92 |
for (this=mallocList; this; this=this->next) { |
|
93 |
if (this->chunk == ptr) { |
|
94 |
console_printf("ExternalBytes [warning]: **** %016"_lx_" already allocated (freed somewhere else ?)\n", (INT)ptr); |
|
95 |
found++; |
|
96 |
} |
|
97 |
} |
|
98 |
if (! found) { |
|
99 |
e = (struct mallocList *) malloc(sizeof(struct mallocList)); |
|
100 |
e->next = mallocList; |
|
101 |
e->chunk = ptr; |
|
102 |
e->size = nBytes; |
|
103 |
mallocList = e; |
|
104 |
mallocCount++; |
|
105 |
} |
|
6242 | 106 |
} |
107 |
} |
|
108 |
||
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
109 |
char * |
19376 | 110 |
__stx_malloc(size_t nBytes) { |
111 |
char *ptr = malloc(nBytes); |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
112 |
|
19376 | 113 |
if (@global(TraceMalloc) == true) { |
114 |
console_printf("ExternalBytes [info]: allocated %d bytes at: %016"_lx_"\n", nBytes, (INT)ptr); |
|
115 |
} |
|
116 |
addToMallocList(ptr, nBytes); |
|
6242 | 117 |
|
19376 | 118 |
return ptr; |
119 |
} |
|
6242 | 120 |
|
19376 | 121 |
char * |
122 |
__stx_calloc(size_t n, size_t size) { |
|
123 |
char *ptr = __stx_malloc(n * size); |
|
124 |
if (ptr != 0) { |
|
125 |
bzero(ptr, (n * size)); |
|
126 |
} |
|
127 |
return ptr; |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
128 |
} |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
129 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
130 |
char * |
19376 | 131 |
__stx_realloc(char *ptr, size_t nBytes) |
132 |
{ |
|
133 |
char *newPtr; |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
134 |
|
19376 | 135 |
removeFromMallocList(ptr); |
136 |
newPtr = realloc(ptr, nBytes); |
|
137 |
addToMallocList(newPtr, nBytes); |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
138 |
|
19376 | 139 |
if (@global(TraceMalloc) == true) { |
140 |
console_printf("ExternalBytes [info]: realloc %d bytes for %"_lx_" at: %"_lx_"\n", nBytes, (INT)ptr, (INT)newPtr); |
|
141 |
} |
|
142 |
return newPtr; |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
143 |
} |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
144 |
|
18653 | 145 |
void |
19376 | 146 |
__stx_free(char *ptr) |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
147 |
{ |
19376 | 148 |
if (@global(TraceMalloc) == true) { |
149 |
console_printf("ExternalBytes: free bytes at: %"_lx_"\n", (INT)ptr); |
|
150 |
} |
|
151 |
removeFromMallocList(ptr); |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
152 |
|
19376 | 153 |
free(ptr); |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
154 |
} |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
155 |
|
18653 | 156 |
void |
3320 | 157 |
__stx_mallocStatistics() { |
19376 | 158 |
struct mallocList *this; |
159 |
int amount = 0; |
|
160 |
int n = 0; |
|
3320 | 161 |
|
19376 | 162 |
for (this=mallocList; this; this=this->next) { |
163 |
n++; |
|
164 |
amount += this->size; |
|
165 |
} |
|
166 |
console_printf("ExternalBytes [info]: allocated %d blocks with %d bytes overall\n", n, amount); |
|
3320 | 167 |
} |
168 |
||
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
169 |
%} |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
170 |
! ! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
171 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
172 |
!ExternalBytes class methodsFor:'documentation'! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
173 |
|
6459 | 174 |
copyright |
175 |
" |
|
176 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
177 |
All Rights Reserved |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
178 |
|
6459 | 179 |
This software is furnished under a license and may be used |
180 |
only in accordance with the terms of that license and with the |
|
181 |
inclusion of the above copyright notice. This software may not |
|
182 |
be provided or otherwise made available to, or used by, any |
|
183 |
other person. No title to or ownership of the software is |
|
184 |
hereby transferred. |
|
185 |
" |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
186 |
! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
187 |
|
6459 | 188 |
documentation |
189 |
" |
|
190 |
This class provides access to any memory in the system. Its main purpose |
|
8908 | 191 |
is to provide a baseclass for objects referencing structured external data. |
6459 | 192 |
Normally, instances are created by primitive code which wants to pass C-data |
193 |
to Smalltalk AND grants smalltalk access to individual bytes afterwards. |
|
194 |
Primitives which do not want to grant this access should return instances of |
|
195 |
ExternalAddress. See more info there. Also, have a look at ExternalFunction |
|
196 |
which is another similar class, but specialized to represent callable C-functions. |
|
8908 | 197 |
|
6459 | 198 |
Since the memory address of an instance stays fixed (once allocated), |
8908 | 199 |
it can also be used to share data with external C-parts |
6459 | 200 |
(which are not prepared for objects to change their address). |
201 |
||
8908 | 202 |
Use with great care - access is not always checked for out-of-bounds |
6459 | 203 |
or valid addresses. |
204 |
||
205 |
Since the data is allocated outside the garbage collected smalltalk space, |
|
206 |
its address stays fix. Thus, it can be passed to external C-functions without |
|
207 |
any danger. However, you have to take care for freeing the memory yourself. |
|
208 |
||
8908 | 209 |
To help in avoiding memory bugs, instances created with #new: are |
6459 | 210 |
registered in a local classvar and deregistered when the underlying memory |
211 |
is explicitely freed. Since a life reference (from that classvar) exists, |
|
212 |
the garbage collector will never find these to be reclaimable, and the |
|
213 |
underlying memory stays allocated (at a fix address) forever. |
|
214 |
To release the memory, either #free it or #unprotect it. |
|
215 |
The first will immediately release the memory, while the second will delay |
|
216 |
freeing until the next garbage collect occurs. |
|
217 |
||
218 |
If you need memory which is automatically freed, create |
|
219 |
the instance via #unprotectedNew: right away; the underlying malloced-memory |
|
220 |
will be released as soon as no smalltalk reference to the ExtBytes object |
|
221 |
exists any more (however, you have to know for sure, that no C-references |
|
222 |
exist to this memory). |
|
223 |
||
8908 | 224 |
To release all memory call #releaseAllMemory which simply sets the |
6459 | 225 |
AllocatedInstances class variable to nil (thus releasing those refs). |
226 |
||
227 |
Example (automatic freeing as soon as ref to buffer is gone): |
|
228 |
|buffer| |
|
229 |
||
230 |
buffer := ExternalBytes unprotectedNew:100. |
|
231 |
... |
|
232 |
||
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
233 |
|
6459 | 234 |
Example (manual freeing - never freed, if ref to buffer is gone): |
235 |
|buffer| |
|
236 |
||
237 |
buffer := ExternalBytes new:100. |
|
238 |
... |
|
239 |
buffer free |
|
240 |
||
241 |
||
242 |
Example (delayed automatic freeing as soon as ref to buffer is gone): |
|
243 |
|buffer| |
|
244 |
||
245 |
buffer := ExternalBytes new:100. |
|
246 |
... |
|
247 |
buffer unregister |
|
248 |
||
8908 | 249 |
This class only supports unstructured external data |
6459 | 250 |
- see the companion class ExternalStructure for more. |
251 |
||
252 |
Notice: support for external data is still being developed - |
|
253 |
a parser for C structure syntax and typedefs is on the way, |
|
254 |
making shared data with C programs much easier in the future. |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
255 |
|
6459 | 256 |
Also notice, that this class may not be available or behave different |
257 |
in other smalltalk systems, making code using it very unportable. |
|
258 |
It is provided for C interfacing only. |
|
259 |
||
260 |
Finally note, that ST/X's memory system is much faster than malloc/free |
|
261 |
in the normal case - especially for short term temporary objects, |
|
262 |
automatically reclaimed object memory is about 5-10 times faster than |
|
263 |
malloc/free. |
|
264 |
Things may be different for huge byte-valued objects, which are to be |
|
8908 | 265 |
reclaimed by the oldspace colletor. |
266 |
Anyway, for portability, we strongly warn from using this as a substitute |
|
6459 | 267 |
for byteArrays; it is meant for shared data with external C-functions ONLY. |
268 |
||
8908 | 269 |
Debugging: |
6459 | 270 |
since all manual memory systems are subject of obscure errors, |
271 |
you may want to turn malloc-tracing on; this traces all allocations/frees |
|
272 |
done here. To do this, evaluate: 'ExternalBytes mallocTrace:true'. |
|
273 |
||
274 |
In addition, you may turn on full debugging (with 'ExternalBytes mallocDebug:true'); |
|
275 |
if turned on, all malloc/realloc requests are remembered and later free / realloc |
|
276 |
requests validated against this list (i.e. to detect freeing unallocated chunks). |
|
277 |
||
278 |
To benefit from this in C-code, we recommend you use __stx_malloc() / __stx_free() |
|
279 |
instead of malloc() / free(). To do so, redefine them in a header file (or cc comand line) |
|
6242 | 280 |
and recompile your external c-libraries with this. |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
281 |
|
6242 | 282 |
I used this here to find memory leaks in the Xt libraries (there are still some in |
283 |
the HTML widget ...). If mallocDebug is on, #dumpMallocChunks will print out what is |
|
284 |
leftOver. This may help to find trouble spots in your C-code. |
|
1286 | 285 |
|
286 |
[author:] |
|
6242 | 287 |
Claus Gittinger |
1317 | 288 |
|
289 |
[see also:] |
|
6242 | 290 |
ExternalAddress ExternalFunction |
291 |
ByteArray |
|
292 |
( how to write primitive code :html: programming/primitive.html ) |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
293 |
" |
6459 | 294 |
! |
295 |
||
8908 | 296 |
examples |
6459 | 297 |
" |
298 |
These examples below are not directly executable; |
|
7191
82bddba980b6
tuned the replaceBytes from another externalBytes object case.
Claus Gittinger <cg@exept.de>
parents:
7184
diff
changeset
|
299 |
some require primitive code to be compiled, or are simply given as sceletton. |
6459 | 300 |
Notice, that in C, indexing is 0-based, while in Smalltalk, indices start |
301 |
at 1. |
|
302 |
||
303 |
allocating memory in ST, passing it to C: |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
304 |
|
6459 | 305 |
in smalltalk: |
8908 | 306 |
... |
307 |
bytes := ExternalBytes new:100. |
|
308 |
... |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
309 |
|
6459 | 310 |
in C (assuming that the bytes-object has been passed): |
311 |
||
8908 | 312 |
... |
313 |
char *bytePtr; |
|
6459 | 314 |
|
8908 | 315 |
bytePtr = (char *)(__externalBytesAddress(bytes)); |
316 |
if (bytePtr) { |
|
317 |
... do something with bytes at bytePtr ... |
|
318 |
} |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
319 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
320 |
freeing (in ST): |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
321 |
|
8908 | 322 |
... |
323 |
bytes free. |
|
324 |
... |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
325 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
326 |
allocating memory in C, passing it to ST: |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
327 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
328 |
in C: |
8908 | 329 |
... |
330 |
char *bytePtr; |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
331 |
|
8908 | 332 |
bytePtr = (char *)(malloc(100)); |
333 |
... |
|
334 |
RETURN (__MKEXTERNALBYTES(bytePtr)); |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
335 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
336 |
in Smalltalk (extracting bytes, integers or strings): |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
337 |
|
8908 | 338 |
byteVal := bytes byteAt:1. |
339 |
... |
|
340 |
intVal := bytes doubleWordAt:1 MSB:true. |
|
341 |
... |
|
342 |
string := bytes stringAt:20. |
|
343 |
... |
|
7191
82bddba980b6
tuned the replaceBytes from another externalBytes object case.
Claus Gittinger <cg@exept.de>
parents:
7184
diff
changeset
|
344 |
|
82bddba980b6
tuned the replaceBytes from another externalBytes object case.
Claus Gittinger <cg@exept.de>
parents:
7184
diff
changeset
|
345 |
|
82bddba980b6
tuned the replaceBytes from another externalBytes object case.
Claus Gittinger <cg@exept.de>
parents:
7184
diff
changeset
|
346 |
|data bytes2| |
82bddba980b6
tuned the replaceBytes from another externalBytes object case.
Claus Gittinger <cg@exept.de>
parents:
7184
diff
changeset
|
347 |
|
82bddba980b6
tuned the replaceBytes from another externalBytes object case.
Claus Gittinger <cg@exept.de>
parents:
7184
diff
changeset
|
348 |
data := #[0 1 2 3 4 5 6 7 8 9 9 8 7 6 5 4 3 2 1 0] copy. |
82bddba980b6
tuned the replaceBytes from another externalBytes object case.
Claus Gittinger <cg@exept.de>
parents:
7184
diff
changeset
|
349 |
bytes2 := ExternalBytes new:30. |
82bddba980b6
tuned the replaceBytes from another externalBytes object case.
Claus Gittinger <cg@exept.de>
parents:
7184
diff
changeset
|
350 |
bytes2 replaceBytesFrom:1 to:20 with:data startingAt:1. |
82bddba980b6
tuned the replaceBytes from another externalBytes object case.
Claus Gittinger <cg@exept.de>
parents:
7184
diff
changeset
|
351 |
data replaceBytesFrom:2 to:20 with:bytes2 startingAt:1. |
82bddba980b6
tuned the replaceBytes from another externalBytes object case.
Claus Gittinger <cg@exept.de>
parents:
7184
diff
changeset
|
352 |
bytes2 |
82bddba980b6
tuned the replaceBytes from another externalBytes object case.
Claus Gittinger <cg@exept.de>
parents:
7184
diff
changeset
|
353 |
|
82bddba980b6
tuned the replaceBytes from another externalBytes object case.
Claus Gittinger <cg@exept.de>
parents:
7184
diff
changeset
|
354 |
|data bytes1 bytes2| |
82bddba980b6
tuned the replaceBytes from another externalBytes object case.
Claus Gittinger <cg@exept.de>
parents:
7184
diff
changeset
|
355 |
|
82bddba980b6
tuned the replaceBytes from another externalBytes object case.
Claus Gittinger <cg@exept.de>
parents:
7184
diff
changeset
|
356 |
data := #[0 1 2 3 4 5 6 7 8 9 9 8 7 6 5 4 3 2 1 0]. |
82bddba980b6
tuned the replaceBytes from another externalBytes object case.
Claus Gittinger <cg@exept.de>
parents:
7184
diff
changeset
|
357 |
bytes1 := ExternalBytes new:30. |
82bddba980b6
tuned the replaceBytes from another externalBytes object case.
Claus Gittinger <cg@exept.de>
parents:
7184
diff
changeset
|
358 |
bytes2 := ExternalBytes new:30. |
82bddba980b6
tuned the replaceBytes from another externalBytes object case.
Claus Gittinger <cg@exept.de>
parents:
7184
diff
changeset
|
359 |
bytes1 replaceBytesFrom:1 to:20 with:data startingAt:1. |
82bddba980b6
tuned the replaceBytes from another externalBytes object case.
Claus Gittinger <cg@exept.de>
parents:
7184
diff
changeset
|
360 |
bytes2 atAllPut:99. |
82bddba980b6
tuned the replaceBytes from another externalBytes object case.
Claus Gittinger <cg@exept.de>
parents:
7184
diff
changeset
|
361 |
bytes2 replaceBytesFrom:2 to:21 with:bytes1 startingAt:1. |
8908 | 362 |
bytes2 asByteArray |
7191
82bddba980b6
tuned the replaceBytes from another externalBytes object case.
Claus Gittinger <cg@exept.de>
parents:
7184
diff
changeset
|
363 |
|
7192
3a388e746946
tuned the replaceBytes to/from another externalBytes object case.
Claus Gittinger <cg@exept.de>
parents:
7191
diff
changeset
|
364 |
|data1 bytes1 data2| |
3a388e746946
tuned the replaceBytes to/from another externalBytes object case.
Claus Gittinger <cg@exept.de>
parents:
7191
diff
changeset
|
365 |
|
3a388e746946
tuned the replaceBytes to/from another externalBytes object case.
Claus Gittinger <cg@exept.de>
parents:
7191
diff
changeset
|
366 |
data1 := #[0 1 2 3 4 5 6 7 8 9 9 8 7 6 5 4 3 2 1 0]. |
3a388e746946
tuned the replaceBytes to/from another externalBytes object case.
Claus Gittinger <cg@exept.de>
parents:
7191
diff
changeset
|
367 |
bytes1 := ExternalBytes new:30. |
3a388e746946
tuned the replaceBytes to/from another externalBytes object case.
Claus Gittinger <cg@exept.de>
parents:
7191
diff
changeset
|
368 |
bytes1 replaceBytesFrom:1 to:20 with:data1 startingAt:1. |
3a388e746946
tuned the replaceBytes to/from another externalBytes object case.
Claus Gittinger <cg@exept.de>
parents:
7191
diff
changeset
|
369 |
|
3a388e746946
tuned the replaceBytes to/from another externalBytes object case.
Claus Gittinger <cg@exept.de>
parents:
7191
diff
changeset
|
370 |
data2 := ByteArray new:30 withAll:99. |
3a388e746946
tuned the replaceBytes to/from another externalBytes object case.
Claus Gittinger <cg@exept.de>
parents:
7191
diff
changeset
|
371 |
data2 replaceBytesFrom:2 to:21 with:bytes1 startingAt:1. |
8908 | 372 |
data2 |
7192
3a388e746946
tuned the replaceBytes to/from another externalBytes object case.
Claus Gittinger <cg@exept.de>
parents:
7191
diff
changeset
|
373 |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
374 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
375 |
! ! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
376 |
|
6459 | 377 |
!ExternalBytes class methodsFor:'initialization'! |
378 |
||
379 |
initialize |
|
380 |
Lobby isNil ifTrue:[ |
|
11854 | 381 |
Lobby := Registry new. |
6459 | 382 |
] |
383 |
! ! |
|
384 |
||
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
385 |
!ExternalBytes class methodsFor:'instance creation'! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
386 |
|
6459 | 387 |
address:aNumber |
388 |
"return a new ExternalBytes object to access bytes starting at aNumber. |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
389 |
The memory at aNumber has been allocated elsewhere. The size is not known, |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
390 |
therefore byte accesses will NOT be checked for valid index. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
391 |
Use this, if you get a pointer from some external source (such as a |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
392 |
C-callBack function) and you have to extract bytes from that. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
393 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
394 |
DANGER ALERT: this method allows very bad things to be done to the |
6242 | 395 |
system - use with GREAT care (better: do not use it)" |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
396 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
397 |
^ self basicNew setAddress:aNumber size:nil |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
398 |
! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
399 |
|
6459 | 400 |
address:aNumber size:size |
401 |
"return a new ExternalBytes object to access bytes starting at aNumber. |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
402 |
The memory at aNumber has been allocated elsewhere. The size is known, |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
403 |
which allows byte accesses to be checked for valid index. |
8908 | 404 |
Use this, if you get a pointer to a structure from some external source |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
405 |
(such as a C-callBack function) and you have to extract things from that. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
406 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
407 |
DANGER ALERT: this method allows very bad things to be done to the |
6242 | 408 |
system - use with GREAT care (better: do not use it)" |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
409 |
|
8908 | 410 |
^ self basicNew setAddress:aNumber size:size |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
411 |
! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
412 |
|
6459 | 413 |
new:numberOfBytes |
414 |
"allocate some memory usable for data; |
|
15398 | 415 |
the memory safe from being finalized by the garbage collector. |
6459 | 416 |
Return a corresponding ExternalBytes object or raise MallocFailure (if malloc fails). |
417 |
||
8908 | 418 |
Use this, if you have to pass a block of bytes to some |
6459 | 419 |
external destination (such as a C function) which does not copy the |
420 |
data, but instead keeps a reference to it. For example, many functions |
|
421 |
which expect strings simply keep a ref to the passed string - for those, |
|
422 |
an ST/X string-pointer is not the right thing to pass, since ST/X objects |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
423 |
may change their address. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
424 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
425 |
DANGER ALERT: the memory is NOT automatically freed until it is either |
18653 | 426 |
MANUALLY freed (see #free) or the returned externalBytes object |
427 |
is unprotected or the classes releaseAllMemory method is called." |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
428 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
429 |
|newInst| |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
430 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
431 |
newInst := self unprotectedNew:numberOfBytes. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
432 |
newInst protectFromGC. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
433 |
^ newInst |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
434 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
435 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
436 |
|bytes| |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
437 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
438 |
bytes := ExternalBytes new:100. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
439 |
bytes wordAt:1 put:1. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
440 |
bytes doubleWordAt:3 put:16r12345678. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
441 |
bytes inspect |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
442 |
" |
6459 | 443 |
! |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
444 |
|
10925 | 445 |
newNullTerminatedFromString:aString |
11854 | 446 |
^ ((self new:aString size+1) |
447 |
replaceBytesFrom:1 to:aString size with:aString startingAt:1) |
|
448 |
at:aString size+1 put:0; |
|
449 |
yourself |
|
10925 | 450 |
! |
451 |
||
6459 | 452 |
unprotectedNew:numberOfBytes |
8908 | 453 |
"allocate some memory usable for data; |
15398 | 454 |
the memory is under the control of the garbage collector (i.e. the instance will |
455 |
be finalized and the malloc'd memory will be freed, if the instance goes away). |
|
6459 | 456 |
Return a corresponding ExternalBytes object or raise MallocFailure (if malloc fails). |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
457 |
|
6459 | 458 |
DANGER ALERT: the memory block as allocated will be automatically freed |
18653 | 459 |
as soon as the reference to the returned externalBytes object |
460 |
is gone (by the next garbage collect). |
|
461 |
If the memory has been passed to a C-function which |
|
462 |
remembers this pointer, bad things may happen ...." |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
463 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
464 |
|newInst| |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
465 |
|
6444 | 466 |
newInst := self basicNew allocateBytes:numberOfBytes. |
9388 | 467 |
newInst registerForFinalization. |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
468 |
^ newInst |
6444 | 469 |
|
470 |
" |
|
471 |
|bytes| |
|
472 |
||
473 |
bytes := ExternalBytes unprotectedNew:100. |
|
474 |
bytes wordAt:1 put:1. |
|
475 |
bytes doubleWordAt:3 put:16r12345678. |
|
476 |
bytes inspect |
|
477 |
" |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
478 |
! ! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
479 |
|
6459 | 480 |
!ExternalBytes class methodsFor:'instance release'! |
481 |
||
482 |
releaseAllMemory |
|
483 |
AllocatedInstances := nil |
|
484 |
" |
|
485 |
... the next GC will get 'em |
|
486 |
" |
|
487 |
! ! |
|
488 |
||
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
489 |
!ExternalBytes class methodsFor:'malloc debug'! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
490 |
|
6459 | 491 |
dumpMallocChunks |
492 |
%{ /* NOCONTEXT */ |
|
493 |
struct mallocList *entry; |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
494 |
|
6459 | 495 |
for (entry = mallocList; entry; entry=entry->next) { |
14632 | 496 |
console_printf(" %"_lx_" (%d)\n", (INT)(entry->chunk), entry->size); |
6459 | 497 |
} |
498 |
%} |
|
3321 | 499 |
" |
6459 | 500 |
self dumpMallocChunks |
3321 | 501 |
" |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
502 |
! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
503 |
|
6459 | 504 |
freeAllMallocChunks |
505 |
"free all stx_malloc'd memory. Be careful, this does no validation at all; |
|
506 |
It simply walks through all chunks and frees them unconditionally. |
|
507 |
This may be helpful during debugging memory-leaks, to release memory which |
|
508 |
was not correctly freed by C-code. Howeve, only memory which was allocated |
|
509 |
by __stx_malloc() is freed here - so you better compile your primitive code with |
|
510 |
malloc redefined to stx_malloc. |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
511 |
Also, mallocDebug has to be on to do this." |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
512 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
513 |
"first free my own memory ..." |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
514 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
515 |
self releaseAllMemory. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
516 |
ObjectMemory garbageCollect. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
517 |
%{ |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
518 |
struct mallocList *entry; |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
519 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
520 |
while ((entry = mallocList) != (struct mallocList *)0) { |
13704 | 521 |
if (@global(TraceMalloc) == true ) { |
14632 | 522 |
console_printf("ExternalBytes [info]: **** forced free of %"_lx_" (%d)\n", (INT)entry->chunk, entry->size); |
13704 | 523 |
} |
524 |
__stx_free(entry->chunk); |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
525 |
} |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
526 |
%} |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
527 |
! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
528 |
|
6459 | 529 |
mallocDebug:aBoolean |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
530 |
DebugMalloc := aBoolean |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
531 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
532 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
533 |
ExternalBytes mallocDebug:true |
8908 | 534 |
ExternalBytes mallocDebug:false |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
535 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
536 |
! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
537 |
|
6459 | 538 |
mallocStatistics |
539 |
%{ |
|
540 |
__stx_mallocStatistics(); |
|
541 |
%} |
|
542 |
" |
|
543 |
self mallocStatistics |
|
3486 | 544 |
" |
545 |
! |
|
546 |
||
6459 | 547 |
mallocTrace:aBoolean |
548 |
TraceMalloc := aBoolean |
|
549 |
||
550 |
" |
|
551 |
ExternalBytes mallocTrace:true |
|
552 |
ExternalBytes mallocTrace:false |
|
553 |
" |
|
554 |
! |
|
555 |
||
556 |
numberOfAllocatedChunks |
|
557 |
%{ /* NOCONTEXT */ |
|
8913 | 558 |
RETURN ( __mkSmallInteger(mallocCount) ); |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
559 |
%} |
3321 | 560 |
" |
561 |
self numberOfAllocatedChunks |
|
562 |
" |
|
6459 | 563 |
! ! |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
564 |
|
6459 | 565 |
!ExternalBytes class methodsFor:'queries'! |
566 |
||
18580 | 567 |
doubleAlignment |
568 |
"return the alignement of longs in structs and unions" |
|
569 |
||
570 |
%{ /* NOCONTEXT */ |
|
571 |
struct { |
|
18653 | 572 |
char c; |
573 |
double d; |
|
18580 | 574 |
} dummy; |
18582 | 575 |
RETURN (__mkSmallInteger( (char *)&dummy.d - (char *)&dummy.c )); |
576 |
%} |
|
577 |
" |
|
578 |
ExternalBytes doubleAlignment |
|
579 |
" |
|
580 |
! |
|
581 |
||
18607 | 582 |
isBuiltInClass |
583 |
"return true if this class is known by the run-time-system. |
|
584 |
Here, true is returned." |
|
585 |
||
586 |
^ self == ExternalBytes |
|
587 |
||
588 |
"Modified: / 11.6.1998 / 17:12:51 / cg" |
|
589 |
! |
|
590 |
||
18580 | 591 |
longAlignment |
592 |
"return the alignement of longs in structs and unions" |
|
593 |
||
594 |
%{ /* NOCONTEXT */ |
|
595 |
struct { |
|
18653 | 596 |
char c; |
597 |
long l; |
|
18580 | 598 |
} dummy; |
18582 | 599 |
RETURN (__mkSmallInteger( (char *)&dummy.l - (char *)&dummy.c )); |
18580 | 600 |
%} |
601 |
" |
|
602 |
ExternalBytes longAlignment |
|
603 |
" |
|
604 |
! |
|
605 |
||
6459 | 606 |
sizeofDouble |
607 |
"return the number of bytes used by the machines native doubles" |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
608 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
609 |
%{ /* NOCONTEXT */ |
8913 | 610 |
RETURN (__mkSmallInteger( sizeof(double))); |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
611 |
%} |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
612 |
" |
8908 | 613 |
ExternalBytes sizeofDouble |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
614 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
615 |
! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
616 |
|
6459 | 617 |
sizeofFloat |
17627 | 618 |
"return the number of bytes used by the machine's native floats" |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
619 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
620 |
%{ /* NOCONTEXT */ |
8913 | 621 |
RETURN (__mkSmallInteger( sizeof(float))); |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
622 |
%} |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
623 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
624 |
ExternalBytes sizeofFloat |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
625 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
626 |
! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
627 |
|
6459 | 628 |
sizeofInt |
17627 | 629 |
"return the number of bytes used by the machine's native integer" |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
630 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
631 |
%{ /* NOCONTEXT */ |
8913 | 632 |
RETURN (__mkSmallInteger( sizeof(int))); |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
633 |
%} |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
634 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
635 |
ExternalBytes sizeofInt |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
636 |
" |
6459 | 637 |
! |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
638 |
|
6459 | 639 |
sizeofLong |
17627 | 640 |
"return the number of bytes used by the machine's native longs" |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
641 |
|
6459 | 642 |
%{ /* NOCONTEXT */ |
8913 | 643 |
RETURN (__mkSmallInteger( sizeof(long))); |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
644 |
%} |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
645 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
646 |
ExternalBytes sizeofLong |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
647 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
648 |
! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
649 |
|
17627 | 650 |
sizeofLongDouble |
651 |
"return the number of bytes used by the machine's native longdouble. |
|
652 |
If the machine does not support them, return nil." |
|
653 |
||
654 |
%{ /* NOCONTEXT */ |
|
655 |
#if defined(__GNUC__) || defined(WIN32) |
|
656 |
RETURN (__mkSmallInteger( sizeof(long double))); |
|
657 |
#endif |
|
658 |
%}. |
|
659 |
^ nil |
|
660 |
||
661 |
" |
|
18653 | 662 |
ExternalBytes sizeofLongDouble |
17627 | 663 |
" |
664 |
! |
|
665 |
||
666 |
sizeofLongLong |
|
667 |
"return the number of bytes used by the machine's native longlongs. |
|
668 |
If the machine does not support them, return nil." |
|
669 |
||
670 |
%{ /* NOCONTEXT */ |
|
671 |
#ifdef HAS_LONGLONG |
|
672 |
RETURN (__mkSmallInteger( sizeof(long long))); |
|
673 |
#endif |
|
674 |
%}. |
|
675 |
^ nil |
|
676 |
||
677 |
" |
|
678 |
ExternalBytes sizeofLongLong |
|
679 |
" |
|
680 |
! |
|
681 |
||
18878 | 682 |
sizeofNativeInt |
683 |
"return the number of bytes used by the machine's SmallInteger native values" |
|
684 |
||
685 |
%{ /* NOCONTEXT */ |
|
686 |
RETURN (__mkSmallInteger( sizeof(INT))); |
|
687 |
%} |
|
688 |
" |
|
689 |
ExternalBytes sizeofNativeInt |
|
690 |
" |
|
691 |
! |
|
692 |
||
6459 | 693 |
sizeofPointer |
17627 | 694 |
"return the number of bytes used by the machine's native pointer" |
6459 | 695 |
|
696 |
%{ /* NOCONTEXT */ |
|
8913 | 697 |
RETURN (__mkSmallInteger( sizeof(char *))); |
6459 | 698 |
%} |
699 |
" |
|
700 |
ExternalBytes sizeofPointer |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
701 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
702 |
! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
703 |
|
6459 | 704 |
sizeofShort |
17627 | 705 |
"return the number of bytes used by the machine's native short" |
6459 | 706 |
|
707 |
%{ /* NOCONTEXT */ |
|
8913 | 708 |
RETURN (__mkSmallInteger( sizeof(short))); |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
709 |
%} |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
710 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
711 |
ExternalBytes sizeofShort |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
712 |
" |
6459 | 713 |
! ! |
714 |
||
715 |
!ExternalBytes methodsFor:'accessing'! |
|
716 |
||
717 |
address |
|
718 |
"return the start address as an integer" |
|
719 |
||
720 |
%{ /* NOCONTEXT */ |
|
721 |
||
11629 | 722 |
if (__INST(address_) != nil) { |
11854 | 723 |
unsigned INT addr; |
6459 | 724 |
|
11854 | 725 |
addr = (unsigned INT)__INST(address_); |
726 |
RETURN ( __MKUINT(addr)); |
|
6459 | 727 |
} |
728 |
%}. |
|
729 |
^ nil |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
730 |
! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
731 |
|
6459 | 732 |
basicAt:index |
733 |
"return the byte at index, anInteger; |
|
734 |
Indices are 1-based, therefore |
|
735 |
this is the byte at (address + index - 1)" |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
736 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
737 |
%{ /* NOCONTEXT */ |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
738 |
|
1822 | 739 |
unsigned char *cp = (unsigned char *)(__INST(address_)); |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
740 |
int idx; |
1997 | 741 |
OBJ sz; |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
742 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
743 |
if (cp && __isSmallInteger(index)) { |
6242 | 744 |
idx = __intVal(index); |
745 |
if (idx > 0) { |
|
746 |
if (((sz = __INST(size)) == nil) |
|
747 |
|| (__intVal(sz) >= idx)) { |
|
748 |
cp = cp + idx - 1; |
|
8913 | 749 |
RETURN ( __mkSmallInteger((*cp)) ); |
6242 | 750 |
} |
751 |
} |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
752 |
} |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
753 |
%}. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
754 |
(size notNil and:[self address notNil]) ifTrue:[ |
6242 | 755 |
^ self subscriptBoundsError:index |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
756 |
]. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
757 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
758 |
invalid index or unallocated |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
759 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
760 |
self primitiveFailed |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
761 |
! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
762 |
|
6459 | 763 |
basicAt:index put:value |
764 |
"set the byte at index, anInteger to value which must be 0..255. |
|
765 |
Returns value (sigh). |
|
766 |
Indices are 1-based, therefore |
|
767 |
this is the byte at (address + index - 1)" |
|
768 |
||
769 |
%{ /* NOCONTEXT */ |
|
770 |
||
771 |
unsigned char *cp = (unsigned char *)(__INST(address_)); |
|
772 |
int val; |
|
773 |
int idx; |
|
774 |
OBJ sz; |
|
775 |
||
776 |
if (__isSmallInteger(value)) { |
|
777 |
val = __smallIntegerVal(value); |
|
8908 | 778 |
} else if (__isCharacter(value)) { |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15003
diff
changeset
|
779 |
val = __smallIntegerVal(__characterVal(value)); |
6459 | 780 |
} else |
781 |
goto badArg; |
|
782 |
||
783 |
if (cp && __isSmallInteger(index)) { |
|
784 |
idx = __intVal(index); |
|
785 |
if (idx > 0) { |
|
6445 | 786 |
if (((sz = __INST(size)) == nil) |
787 |
|| (__intVal(sz) >= idx)) { |
|
788 |
if ((val & ~0xFF) == 0) /* i.e. (val >= 0) && (val <= 255) */ { |
|
789 |
cp[idx-1] = val; |
|
790 |
RETURN ( value ); |
|
791 |
} |
|
792 |
} |
|
793 |
} |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
794 |
} |
6302
32ede83e77e5
allow for character arg in #at:put:
Claus Gittinger <cg@exept.de>
parents:
6242
diff
changeset
|
795 |
|
32ede83e77e5
allow for character arg in #at:put:
Claus Gittinger <cg@exept.de>
parents:
6242
diff
changeset
|
796 |
badArg: ; |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
797 |
%}. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
798 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
799 |
(size notNil and:[self address notNil]) ifTrue:[ |
6445 | 800 |
(index between:1 and:size) ifTrue:[ |
801 |
^ ElementOutOfBoundsSignal raise |
|
802 |
]. |
|
803 |
^ self subscriptBoundsError:index |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
804 |
]. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
805 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
806 |
invalid index, invalid value or unallocated |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
807 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
808 |
self primitiveFailed |
1220 | 809 |
|
810 |
"Modified: 19.4.1996 / 11:15:05 / cg" |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
811 |
! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
812 |
|
6459 | 813 |
byteAt:index |
814 |
"return the unsigned byte at index, anInteger. |
|
815 |
Indices are 1-based, therefore |
|
816 |
this is the byte at (address + index - 1)" |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
817 |
|
6459 | 818 |
^ self basicAt:index |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
819 |
! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
820 |
|
6459 | 821 |
byteAt:index put:aByteValuedInteger |
822 |
"set the byte at index. |
|
823 |
Indices are 1-based, therefore |
|
824 |
this is the byte at (address + index - 1)" |
|
825 |
||
826 |
^ self basicAt:index put:aByteValuedInteger |
|
827 |
! |
|
828 |
||
13196
a8e595628fb5
added: #copyUnicodeStringFromHeap
Claus Gittinger <cg@exept.de>
parents:
13076
diff
changeset
|
829 |
copyCStringFromHeap |
a8e595628fb5
added: #copyUnicodeStringFromHeap
Claus Gittinger <cg@exept.de>
parents:
13076
diff
changeset
|
830 |
"fetch a 0-terminated string from my pointed-to address" |
6459 | 831 |
|
12594
d7267a747c2f
changed: #copyCStringFromHeap
Claus Gittinger <cg@exept.de>
parents:
11854
diff
changeset
|
832 |
|idx byte s| |
11739 | 833 |
|
12594
d7267a747c2f
changed: #copyCStringFromHeap
Claus Gittinger <cg@exept.de>
parents:
11854
diff
changeset
|
834 |
idx := 1. |
d7267a747c2f
changed: #copyCStringFromHeap
Claus Gittinger <cg@exept.de>
parents:
11854
diff
changeset
|
835 |
s := WriteStream on:String new. |
d7267a747c2f
changed: #copyCStringFromHeap
Claus Gittinger <cg@exept.de>
parents:
11854
diff
changeset
|
836 |
[(byte := self at:idx) ~~ 0] whileTrue:[ |
13704 | 837 |
s nextPut:(Character value:byte). |
838 |
idx := idx + 1. |
|
11739 | 839 |
]. |
13196
a8e595628fb5
added: #copyUnicodeStringFromHeap
Claus Gittinger <cg@exept.de>
parents:
13076
diff
changeset
|
840 |
^ s contents |
a8e595628fb5
added: #copyUnicodeStringFromHeap
Claus Gittinger <cg@exept.de>
parents:
13076
diff
changeset
|
841 |
! |
a8e595628fb5
added: #copyUnicodeStringFromHeap
Claus Gittinger <cg@exept.de>
parents:
13076
diff
changeset
|
842 |
|
a8e595628fb5
added: #copyUnicodeStringFromHeap
Claus Gittinger <cg@exept.de>
parents:
13076
diff
changeset
|
843 |
copyUnicodeStringFromHeap |
a8e595628fb5
added: #copyUnicodeStringFromHeap
Claus Gittinger <cg@exept.de>
parents:
13076
diff
changeset
|
844 |
"fetch a 0-terminated wide-string from my pointed-to address" |
a8e595628fb5
added: #copyUnicodeStringFromHeap
Claus Gittinger <cg@exept.de>
parents:
13076
diff
changeset
|
845 |
|
a8e595628fb5
added: #copyUnicodeStringFromHeap
Claus Gittinger <cg@exept.de>
parents:
13076
diff
changeset
|
846 |
|idx word s| |
a8e595628fb5
added: #copyUnicodeStringFromHeap
Claus Gittinger <cg@exept.de>
parents:
13076
diff
changeset
|
847 |
|
a8e595628fb5
added: #copyUnicodeStringFromHeap
Claus Gittinger <cg@exept.de>
parents:
13076
diff
changeset
|
848 |
idx := 1. |
a8e595628fb5
added: #copyUnicodeStringFromHeap
Claus Gittinger <cg@exept.de>
parents:
13076
diff
changeset
|
849 |
s := WriteStream on:Unicode16String new. |
a8e595628fb5
added: #copyUnicodeStringFromHeap
Claus Gittinger <cg@exept.de>
parents:
13076
diff
changeset
|
850 |
[(word := self unsignedShortAt:idx) ~~ 0] whileTrue:[ |
13704 | 851 |
s nextPut:(Character value:word). |
852 |
idx := idx + 2. |
|
13196
a8e595628fb5
added: #copyUnicodeStringFromHeap
Claus Gittinger <cg@exept.de>
parents:
13076
diff
changeset
|
853 |
]. |
a8e595628fb5
added: #copyUnicodeStringFromHeap
Claus Gittinger <cg@exept.de>
parents:
13076
diff
changeset
|
854 |
^ s contents |
a8e595628fb5
added: #copyUnicodeStringFromHeap
Claus Gittinger <cg@exept.de>
parents:
13076
diff
changeset
|
855 |
! |
a8e595628fb5
added: #copyUnicodeStringFromHeap
Claus Gittinger <cg@exept.de>
parents:
13076
diff
changeset
|
856 |
|
a8e595628fb5
added: #copyUnicodeStringFromHeap
Claus Gittinger <cg@exept.de>
parents:
13076
diff
changeset
|
857 |
instVarAt:index |
a8e595628fb5
added: #copyUnicodeStringFromHeap
Claus Gittinger <cg@exept.de>
parents:
13076
diff
changeset
|
858 |
"redefined to suppress direct access to my address, which is a non-object" |
a8e595628fb5
added: #copyUnicodeStringFromHeap
Claus Gittinger <cg@exept.de>
parents:
13076
diff
changeset
|
859 |
|
a8e595628fb5
added: #copyUnicodeStringFromHeap
Claus Gittinger <cg@exept.de>
parents:
13076
diff
changeset
|
860 |
index == 1 ifTrue:[^ self address]. |
a8e595628fb5
added: #copyUnicodeStringFromHeap
Claus Gittinger <cg@exept.de>
parents:
13076
diff
changeset
|
861 |
^ super instVarAt:index |
11739 | 862 |
! ! |
863 |
||
6491
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
864 |
!ExternalBytes methodsFor:'converting'! |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
865 |
|
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
866 |
asExternalAddress |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
867 |
"return the start address as an external address" |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
868 |
|
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
869 |
%{ /* NOCONTEXT */ |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
870 |
|
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
871 |
RETURN(__MKEXTERNALADDRESS(__INST(address_))); |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
872 |
%}. |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
873 |
! |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
874 |
|
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
875 |
asExternalBytes |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
876 |
|
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
877 |
^ self |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
878 |
! ! |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
879 |
|
6483
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
880 |
!ExternalBytes methodsFor:'filling & replacing'! |
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
881 |
|
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
882 |
replaceBytesFrom:start to:stop with:aCollection startingAt:repStart |
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
883 |
"replace elements from another collection, which must be a ByteArray- |
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
884 |
like collection. |
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
885 |
|
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
886 |
Notice: This operation modifies the receiver, NOT a copy; |
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
887 |
therefore the change may affect all others referencing the receiver." |
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
888 |
|
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
889 |
%{ /* NOCONTEXT */ |
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
890 |
|
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
891 |
int nIndex, repNIndex; |
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
892 |
int startIndex, stopIndex; |
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
893 |
REGISTER unsigned char *src; |
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
894 |
REGISTER int repStartIndex; |
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
895 |
int repStopIndex, count; |
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
896 |
REGISTER unsigned char *dst; |
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
897 |
OBJ cls; |
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
898 |
|
14076
5f68cf5ece9c
changed: #replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
13704
diff
changeset
|
899 |
if ((__isBytes(aCollection) || __isWords(aCollection) || __isExternalBytesLike(aCollection)) |
6483
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
900 |
&& __bothSmallInteger(start, stop) |
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
901 |
&& __isSmallInteger(repStart)) { |
14632 | 902 |
startIndex = __intVal(start) - 1; |
903 |
if (startIndex >= 0) { |
|
904 |
dst = (unsigned char *)__INST(address_) + startIndex; |
|
905 |
nIndex = __smallIntegerVal(__INST(size)); |
|
6483
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
906 |
|
14632 | 907 |
stopIndex = __intVal(stop) - 1; |
908 |
count = stopIndex - startIndex + 1; |
|
909 |
if (count == 0) { |
|
910 |
RETURN ( self ); |
|
911 |
} |
|
6483
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
912 |
|
14632 | 913 |
if ((count > 0) && (stopIndex < nIndex)) { |
914 |
repStartIndex = __intVal(repStart) - 1; |
|
915 |
if (repStartIndex >= 0) { |
|
916 |
if (__isExternalBytesLike(aCollection)) { |
|
917 |
OBJ sz; |
|
7191
82bddba980b6
tuned the replaceBytes from another externalBytes object case.
Claus Gittinger <cg@exept.de>
parents:
7184
diff
changeset
|
918 |
|
14632 | 919 |
src = __externalBytesVal(aCollection); |
920 |
if (src == 0) goto fallBack; |
|
6483
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
921 |
|
14632 | 922 |
sz = __externalBytesSize(aCollection); |
923 |
if (__isSmallInteger(sz)) { |
|
924 |
repNIndex = __smallIntegerVal(sz); |
|
925 |
} else { |
|
926 |
repNIndex = -1; /* unknown */ |
|
927 |
} |
|
928 |
src = src + repStartIndex; |
|
929 |
} else { |
|
930 |
repNIndex = __qSize(aCollection) - OHDR_SIZE; |
|
931 |
src = __byteArrayVal(aCollection) + repStartIndex; |
|
932 |
if ((cls = __qClass(aCollection)) != @global(ByteArray)) { |
|
933 |
int nInst; |
|
6483
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
934 |
|
14632 | 935 |
nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
936 |
src += nInst; |
|
937 |
repNIndex -= nInst; |
|
938 |
} |
|
939 |
} |
|
7191
82bddba980b6
tuned the replaceBytes from another externalBytes object case.
Claus Gittinger <cg@exept.de>
parents:
7184
diff
changeset
|
940 |
|
14632 | 941 |
repStopIndex = repStartIndex + (stopIndex - startIndex); |
942 |
if (repStopIndex < repNIndex) { |
|
943 |
if (aCollection == self) { |
|
944 |
/* take care of overlapping copy */ |
|
945 |
if (src < dst) { |
|
946 |
/* must do a reverse copy */ |
|
947 |
src += count; |
|
948 |
dst += count; |
|
949 |
while (count-- > 0) { |
|
950 |
*--dst = *--src; |
|
951 |
} |
|
952 |
RETURN ( self ); |
|
953 |
} |
|
954 |
} |
|
6483
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
955 |
|
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
956 |
#ifdef memcpy4 |
14632 | 957 |
if (((unsigned INT)src & 3) == ((unsigned INT)dst & 3)) { |
958 |
int nW; |
|
6483
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
959 |
|
14632 | 960 |
/* copy unaligned part */ |
961 |
while (count && ((unsigned INT)src & 3)) { |
|
962 |
*dst++ = *src++; |
|
963 |
count--; |
|
964 |
} |
|
6483
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
965 |
|
14632 | 966 |
if (count > 0) { |
967 |
/* copy aligned part */ |
|
968 |
nW = count >> 2; |
|
969 |
memcpy4(dst, src, nW); |
|
970 |
if ((count = count & 3) != 0) { |
|
971 |
/* copy any remaining part */ |
|
972 |
src += (nW<<2); |
|
973 |
dst += (nW<<2); |
|
974 |
while (count--) { |
|
975 |
*dst++ = *src++; |
|
976 |
} |
|
977 |
} |
|
978 |
} |
|
979 |
RETURN ( self ); |
|
980 |
} |
|
6483
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
981 |
#else |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8288
diff
changeset
|
982 |
# if __POINTER_SIZE__ == 8 |
14632 | 983 |
if (((unsigned INT)src & 7) == ((unsigned INT)dst & 7)) { |
984 |
/* copy unaligned part */ |
|
985 |
while (count && ((unsigned INT)src & 7)) { |
|
986 |
*dst++ = *src++; |
|
987 |
count--; |
|
988 |
} |
|
6483
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
989 |
|
14632 | 990 |
/* copy aligned part */ |
991 |
while (count >= 8) { |
|
992 |
((unsigned INT *)dst)[0] = ((unsigned INT *)src)[0]; |
|
993 |
dst += 8; |
|
994 |
src += 8; |
|
995 |
count -= 8; |
|
996 |
} |
|
997 |
while (count--) { |
|
998 |
*dst++ = *src++; |
|
999 |
} |
|
1000 |
RETURN ( self ); |
|
1001 |
} |
|
8908 | 1002 |
# endif /* 64bit */ |
6483
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
1003 |
#endif /* memcpy4 */ |
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
1004 |
|
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
1005 |
#ifdef FAST_MEMCPY |
14632 | 1006 |
memcpy(dst, src, count); |
6483
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
1007 |
#else |
8919 | 1008 |
# ifdef __UNROLL_LOOPS__ |
14632 | 1009 |
while (count >= 8) { |
1010 |
dst[0] = src[0]; dst[1] = src[1]; |
|
1011 |
dst[2] = src[2]; dst[3] = src[3]; |
|
1012 |
dst[4] = src[4]; dst[5] = src[5]; |
|
1013 |
dst[6] = src[6]; dst[7] = src[7]; |
|
1014 |
dst += 8; src += 8; |
|
1015 |
count -= 8; |
|
1016 |
} |
|
8919 | 1017 |
# endif /* __UNROLL_LOOPS__ */ |
14632 | 1018 |
while (count-- > 0) { |
1019 |
*dst++ = *src++; |
|
1020 |
} |
|
6483
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
1021 |
#endif |
14632 | 1022 |
RETURN ( self ); |
1023 |
} |
|
1024 |
} |
|
1025 |
} |
|
1026 |
} |
|
6483
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
1027 |
} |
7191
82bddba980b6
tuned the replaceBytes from another externalBytes object case.
Claus Gittinger <cg@exept.de>
parents:
7184
diff
changeset
|
1028 |
fallBack: ; |
6483
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
1029 |
%}. |
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
1030 |
" |
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
1031 |
fall back for the error report if any index is invalid |
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
1032 |
" |
7191
82bddba980b6
tuned the replaceBytes from another externalBytes object case.
Claus Gittinger <cg@exept.de>
parents:
7184
diff
changeset
|
1033 |
^ super replaceBytesFrom:start to:stop with:aCollection startingAt:repStart |
6483
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
1034 |
|
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
1035 |
" |
14125
6aec556d2bbf
comment changed: #replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
14080
diff
changeset
|
1036 |
((ExternalBytes unprotectedNew:16) |
14632 | 1037 |
replaceBytesFrom:1 to:8 |
1038 |
with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160] |
|
1039 |
startingAt:1) copy |
|
6483
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
1040 |
|
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
1041 |
(ExternalBytes unprotectedNew:16) |
14632 | 1042 |
replaceBytesFrom:3 to:10 |
1043 |
with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160] |
|
1044 |
startingAt:4 |
|
6483
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
1045 |
|
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
1046 |
(ExternalBytes unprotectedNew:16) |
14632 | 1047 |
replaceBytesFrom:3 to:4 |
1048 |
with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160] |
|
1049 |
startingAt:1 |
|
6483
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
1050 |
|
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
1051 |
(ExternalBytes unprotectedNew:16) |
14632 | 1052 |
replaceBytesFrom:0 to:9 |
1053 |
with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160] |
|
1054 |
startingAt:1 |
|
6483
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
1055 |
|
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
1056 |
(ExternalBytes unprotectedNew:16) |
14632 | 1057 |
replaceBytesFrom:1 to:10 |
1058 |
with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160] |
|
1059 |
startingAt:0 |
|
6483
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
1060 |
" |
19168 | 1061 |
! |
1062 |
||
1063 |
replaceNullTerminatedFromString:aString |
|
1064 |
"replace elements from aString, and add a 0-byte at the end" |
|
1065 |
||
19169 | 1066 |
|nChars| |
1067 |
||
1068 |
nChars := aString size. |
|
1069 |
self replaceBytesFrom:1 to:nChars with:aString startingAt:1. |
|
1070 |
self at:nChars+1 put:0. |
|
6483
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
1071 |
! ! |
ec599166f169
replaceBytesFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
6471
diff
changeset
|
1072 |
|
6444 | 1073 |
!ExternalBytes methodsFor:'finalization'! |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1074 |
|
6440
eb9cdc352a7c
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6425
diff
changeset
|
1075 |
executor |
8908 | 1076 |
"redefined to return a lightweight copy |
7184 | 1077 |
- all we need is the memory handle and the size." |
6491
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
1078 |
|
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
1079 |
%{ /* NOCONTEXT */ |
6440
eb9cdc352a7c
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6425
diff
changeset
|
1080 |
|
7386
0996b933cbf1
Need __STORE() when assigning class
Stefan Vogel <sv@exept.de>
parents:
7257
diff
changeset
|
1081 |
OBJ theCopy, cls; |
7184 | 1082 |
|
7855
27f64d1beaa1
Have to protect self, otherwise bad things happen in the VM.
Stefan Vogel <sv@exept.de>
parents:
7386
diff
changeset
|
1083 |
__PROTECT__(self); |
7184 | 1084 |
theCopy = __MKEXTERNALBYTES_N(__INST(address_), __smallIntegerVal(__INST(size))); |
7855
27f64d1beaa1
Have to protect self, otherwise bad things happen in the VM.
Stefan Vogel <sv@exept.de>
parents:
7386
diff
changeset
|
1085 |
__UNPROTECT__(self); |
7386
0996b933cbf1
Need __STORE() when assigning class
Stefan Vogel <sv@exept.de>
parents:
7257
diff
changeset
|
1086 |
__InstPtr(theCopy)->o_class = cls = __InstPtr(self)->o_class; |
0996b933cbf1
Need __STORE() when assigning class
Stefan Vogel <sv@exept.de>
parents:
7257
diff
changeset
|
1087 |
__STORE(theCopy, cls); |
7184 | 1088 |
RETURN (theCopy); |
6491
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
1089 |
%} |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
1090 |
|
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
1091 |
" |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
1092 |
(ExternalBytes unprotectedNew:10) executor |
6976d9b69e01
Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
1093 |
" |
6440
eb9cdc352a7c
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6425
diff
changeset
|
1094 |
! |
eb9cdc352a7c
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6425
diff
changeset
|
1095 |
|
6462
245e99c09df0
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6459
diff
changeset
|
1096 |
finalizationLobby |
245e99c09df0
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6459
diff
changeset
|
1097 |
"answer the registry used for finalization. |
245e99c09df0
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6459
diff
changeset
|
1098 |
ExternalBytes have their own Registry" |
245e99c09df0
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6459
diff
changeset
|
1099 |
|
245e99c09df0
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6459
diff
changeset
|
1100 |
^ Lobby |
245e99c09df0
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6459
diff
changeset
|
1101 |
! |
245e99c09df0
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6459
diff
changeset
|
1102 |
|
6440
eb9cdc352a7c
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6425
diff
changeset
|
1103 |
finalize |
2779 | 1104 |
"some ExternalBytes object was finalized; |
1105 |
free the associated heap memory with it" |
|
1106 |
||
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1107 |
%{ /* NOCONTEXT */ |
19376 | 1108 |
char *mem = (char *)__INST(address_); |
6457 | 1109 |
if (mem && (OBJ)mem != nil) { |
19376 | 1110 |
__stx_free(mem); |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1111 |
} |
1133 | 1112 |
__INST(address_) = __INST(size) = nil; |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1113 |
%} |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1114 |
! ! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1115 |
|
6444 | 1116 |
!ExternalBytes methodsFor:'freeing'! |
1117 |
||
6459 | 1118 |
free |
1119 |
"free a previously allocated piece of memory - be very careful, there |
|
1120 |
are no checks done here. All dangers you usually have with malloc/free |
|
1121 |
are present here ..." |
|
1122 |
||
1123 |
"at least, we check for double freeing the same chunk" |
|
1124 |
self address isNil ifTrue:[ |
|
1125 |
self error:'freeing memory twice'. |
|
1126 |
^ self |
|
1127 |
]. |
|
1128 |
Lobby unregister:self. |
|
1129 |
self finalize. "/ does what we need here .. |
|
1130 |
self unprotectFromGC |
|
7184 | 1131 |
! |
1132 |
||
1133 |
register |
|
1134 |
"register the receiver to be automatically finalized by the GC" |
|
1135 |
||
1136 |
Lobby register:self. |
|
6444 | 1137 |
! ! |
1138 |
||
6443 | 1139 |
!ExternalBytes methodsFor:'pointer arithmethic'! |
1140 |
||
6502
87f587d1542e
rename #from:to to #referenceToBytesFrom:to
Stefan Vogel <sv@exept.de>
parents:
6491
diff
changeset
|
1141 |
referenceToBytesFrom:start to:stop |
6459 | 1142 |
"answer a new ExternalBytes referencing a range within the receiver. |
6502
87f587d1542e
rename #from:to to #referenceToBytesFrom:to
Stefan Vogel <sv@exept.de>
parents:
6491
diff
changeset
|
1143 |
BE CAREFUL: after the receiver has been freed, the new ExternalBytes |
6459 | 1144 |
contents is undefined" |
1145 |
||
8908 | 1146 |
%{ /* NOCONTEXT */ |
6459 | 1147 |
|
6471 | 1148 |
char *addr; |
6459 | 1149 |
int size; |
1150 |
int __start, __stop; |
|
1151 |
||
1152 |
if (__bothSmallInteger(start, stop) && __INST(address_) != nil) { |
|
6503 | 1153 |
__start = __smallIntegerVal(start); |
1154 |
__stop = __smallIntegerVal(stop); |
|
1155 |
if (__start > 0 && __start <= __stop && __stop <= __smallIntegerVal(__INST(size))) { |
|
1156 |
addr = (char *)(__INST(address_)) + (__start - 1); |
|
1157 |
size = __stop - __start + 1; |
|
1158 |
RETURN( __MKEXTERNALBYTES_N(addr, size) ); |
|
1159 |
} |
|
6459 | 1160 |
} |
1161 |
%}. |
|
1162 |
^ self primitiveFailed |
|
6458 | 1163 |
! ! |
6443 | 1164 |
|
6458 | 1165 |
!ExternalBytes methodsFor:'printing & storing'! |
6443 | 1166 |
|
13076
29b8a558bcf2
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
12864
diff
changeset
|
1167 |
displayOn:aGCOrStream |
6459 | 1168 |
"return a printed representation of the receiver for displaying" |
1169 |
||
13076
29b8a558bcf2
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
12864
diff
changeset
|
1170 |
|addr| |
6443 | 1171 |
|
13076
29b8a558bcf2
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
12864
diff
changeset
|
1172 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
29b8a558bcf2
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
12864
diff
changeset
|
1173 |
"/ ST/X (and some old ST80's) mean: draw-yourself on a GC. |
16739 | 1174 |
(aGCOrStream isStream) ifFalse:[ |
18829 | 1175 |
^ super displayOn:aGCOrStream |
13076
29b8a558bcf2
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
12864
diff
changeset
|
1176 |
]. |
29b8a558bcf2
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
12864
diff
changeset
|
1177 |
|
29b8a558bcf2
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
12864
diff
changeset
|
1178 |
aGCOrStream nextPutAll:self className. |
29b8a558bcf2
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
12864
diff
changeset
|
1179 |
addr := self address. |
29b8a558bcf2
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
12864
diff
changeset
|
1180 |
addr isNil ifTrue:[ |
18829 | 1181 |
aGCOrStream nextPutAll:'[free]'. |
6459 | 1182 |
] ifFalse:[ |
18829 | 1183 |
size notNil ifTrue:[ |
1184 |
aGCOrStream nextPutAll:'[sz:'. |
|
1185 |
size printOn:aGCOrStream. |
|
1186 |
aGCOrStream space. |
|
1187 |
] ifFalse:[ |
|
1188 |
aGCOrStream nextPut:$[. |
|
1189 |
]. |
|
1190 |
aGCOrStream nextPutAll:'@'. |
|
1191 |
addr printOn:aGCOrStream base:16. |
|
1192 |
aGCOrStream nextPut:$]. |
|
6459 | 1193 |
]. |
1194 |
||
18829 | 1195 |
" |
1196 |
self new printString |
|
1197 |
(self new:5) displayString |
|
1198 |
" |
|
1199 |
||
1200 |
||
6459 | 1201 |
"Modified: / 24.2.2000 / 19:02:19 / cg" |
6458 | 1202 |
! ! |
1203 |
||
7257 | 1204 |
!ExternalBytes methodsFor:'private-accessing'! |
6458 | 1205 |
|
9388 | 1206 |
invalidateReference |
1207 |
"clear the start address and size" |
|
1208 |
||
1209 |
%{ /* NOCONTEXT */ |
|
1210 |
__INST(address_) = nil; |
|
1211 |
__INST(size) = nil; |
|
1212 |
%} |
|
1213 |
! |
|
1214 |
||
8908 | 1215 |
setAddress:aNumber size:sz |
6459 | 1216 |
"set the start address and size" |
1217 |
||
1218 |
%{ /* NOCONTEXT */ |
|
1219 |
if (__INST(address_) == nil) { |
|
1220 |
if (aNumber == nil) { |
|
1221 |
__INST(address_) = nil; |
|
1222 |
} else { |
|
1223 |
if (__isSmallInteger(aNumber)) { |
|
1224 |
__INST(address_) = (OBJ) __intVal(aNumber); |
|
1225 |
} else if(__isInteger(aNumber)) { |
|
1226 |
__INST(address_) = (OBJ) __unsignedLongIntVal(aNumber); |
|
1227 |
} else if(__isExternalAddress(aNumber)) { |
|
1228 |
__INST(address_) = __externalAddressVal(aNumber); |
|
1229 |
} |
|
6445 | 1230 |
} |
6459 | 1231 |
__INST(size) = sz; |
1232 |
RETURN (self); |
|
6443 | 1233 |
} |
1234 |
%}. |
|
6459 | 1235 |
^ self error:'cannot change address' |
8288 | 1236 |
! |
1237 |
||
8908 | 1238 |
setSize:sz |
8288 | 1239 |
"set the size - warning: dangerous if wrong" |
1240 |
||
1241 |
size := sz |
|
6443 | 1242 |
! ! |
1243 |
||
7257 | 1244 |
!ExternalBytes methodsFor:'private-allocation'! |
6444 | 1245 |
|
1246 |
allocateBytes:numberOfBytes |
|
11854 | 1247 |
"allocate (malloc) numberOfBytes; if doClear is true, the allocated memory is cleared. |
1248 |
Fail if already allocated. |
|
1249 |
Raise MallocFailure if malloc fails to allocate enough memory" |
|
1250 |
||
1251 |
^ self allocateBytes:numberOfBytes clear:true |
|
1252 |
! |
|
1253 |
||
1254 |
allocateBytes:numberOfBytes clear:doClear |
|
1255 |
"allocate (malloc) numberOfBytes; if doClear is true, the allocated memory is cleared. |
|
6444 | 1256 |
Fail if already allocated. |
1257 |
Raise MallocFailure if malloc fails to allocate enough memory" |
|
1258 |
||
1259 |
|mallocFailure| |
|
1260 |
||
6457 | 1261 |
%{ |
6444 | 1262 |
/* |
8908 | 1263 |
* Fail if already allocated |
6444 | 1264 |
*/ |
1265 |
if (__INST(address_) == nil && __isSmallInteger(numberOfBytes)) { |
|
19376 | 1266 |
INT nBytes = __smallIntegerVal(numberOfBytes); |
1267 |
if (nBytes > 0) { |
|
1268 |
char *space = __stx_malloc(nBytes); |
|
1269 |
if (space) { |
|
1270 |
if (doClear == true) { |
|
1271 |
bzero(space, nBytes); |
|
1272 |
} |
|
1273 |
__INST(address_) = (OBJ)space; |
|
1274 |
__INST(size) = numberOfBytes; |
|
1275 |
RETURN(self); |
|
1276 |
} else { |
|
1277 |
mallocFailure = true; |
|
1278 |
} |
|
1279 |
} |
|
6444 | 1280 |
} |
1281 |
%}. |
|
1282 |
mallocFailure == true ifTrue:[ |
|
19376 | 1283 |
^ MallocFailure raiseRequestWith:numberOfBytes. |
6444 | 1284 |
] ifFalse:[ |
19376 | 1285 |
self primitiveFailed. |
6444 | 1286 |
]. |
1287 |
! ! |
|
1288 |
||
5557 | 1289 |
!ExternalBytes methodsFor:'queries'! |
1290 |
||
6459 | 1291 |
basicSize |
1292 |
"we do not know how many bytes are valid" |
|
5557 | 1293 |
|
6459 | 1294 |
size isNil ifTrue:[^ 0]. |
1295 |
^ size |
|
6443 | 1296 |
! |
1297 |
||
18607 | 1298 |
containsNon7BitAscii |
1299 |
"return true, if any byte in the receiver has the 7th bit on. |
|
1300 |
This my look as a too specific operation to be put here, |
|
1301 |
put it is very helpful for UTF8 string reading (Java class reader), |
|
1302 |
to quickly determine, if UTF8 decoding is needed or not. |
|
1303 |
As most strings in a class file are in fact only containing 7bit ascii, |
|
1304 |
this should speedup class file reading considerably" |
|
1305 |
||
1306 |
%{ /* NOCONTEXT */ |
|
18653 | 1307 |
unsigned char *cp = (unsigned char *)(__INST(address_)); |
18607 | 1308 |
unsigned int size = __intVal(__INST(size)); |
1309 |
unsigned char *endP; |
|
1310 |
||
19328 | 1311 |
if (cp == NULL || size == 0) { |
18653 | 1312 |
RETURN(false); |
18607 | 1313 |
} |
1314 |
||
1315 |
endP = cp + size; |
|
1316 |
#if __POINTER_SIZE__ == 8 |
|
1317 |
while (cp+8 < endP) { |
|
18653 | 1318 |
if ( ((unsigned INT *)cp)[0] & 0x8080808080808080) RETURN( true ); |
1319 |
cp += 8; |
|
18607 | 1320 |
} |
1321 |
#endif |
|
1322 |
while (cp+4 < endP) { |
|
18653 | 1323 |
if ( ((unsigned int *)cp)[0] & 0x80808080) RETURN( true ); |
1324 |
cp += 4; |
|
18607 | 1325 |
} |
1326 |
while (cp < endP) { |
|
18653 | 1327 |
if (*cp++ & 0x80) RETURN( true ); |
18607 | 1328 |
} |
1329 |
RETURN ( false ); |
|
1330 |
%} |
|
1331 |
. |
|
1332 |
^ self contains:[:b | b bitTest:16r80]. |
|
1333 |
||
1334 |
" |
|
1335 |
#[1 2 3 1 2 3 1 2 127 ] asExternalBytes containsNon7BitAscii |
|
1336 |
#[1 2 3 1 2 3 1 2 250 251 250 251 255] asExternalBytes containsNon7BitAscii |
|
1337 |
" |
|
1338 |
! |
|
1339 |
||
9389 | 1340 |
isValid |
1341 |
"true if I gave an address" |
|
1342 |
||
1343 |
%{ /* NOCONTEXT */ |
|
1344 |
RETURN ((__INST(address_) == nil) ? false : true ); |
|
1345 |
%} |
|
1346 |
! |
|
1347 |
||
6459 | 1348 |
species |
1349 |
"when copying, or concatenating, return instances of this class" |
|
1350 |
||
1351 |
^ ByteArray |
|
5557 | 1352 |
! ! |
1353 |
||
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1354 |
!ExternalBytes methodsFor:'registration'! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1355 |
|
8908 | 1356 |
protectFromGC |
6459 | 1357 |
"enter a reference to the receiver into the AllocatedInstances |
1358 |
class variable - this prevents it from ever being finalized by |
|
1359 |
the garbage collector, thus protecting the underlying memory." |
|
1360 |
||
10137
7bfdc51fcb65
Avoid deadlock when free is called by finalization code (Stefan Vogel)
Michael Beyl <mb@exept.de>
parents:
9895
diff
changeset
|
1361 |
|wasBlocked| |
7bfdc51fcb65
Avoid deadlock when free is called by finalization code (Stefan Vogel)
Michael Beyl <mb@exept.de>
parents:
9895
diff
changeset
|
1362 |
|
7bfdc51fcb65
Avoid deadlock when free is called by finalization code (Stefan Vogel)
Michael Beyl <mb@exept.de>
parents:
9895
diff
changeset
|
1363 |
|
11854 | 1364 |
"using a Semaphore can cause a deadlock, since unprotectFromGC may be called by |
10137
7bfdc51fcb65
Avoid deadlock when free is called by finalization code (Stefan Vogel)
Michael Beyl <mb@exept.de>
parents:
9895
diff
changeset
|
1365 |
a finalization method" |
7bfdc51fcb65
Avoid deadlock when free is called by finalization code (Stefan Vogel)
Michael Beyl <mb@exept.de>
parents:
9895
diff
changeset
|
1366 |
|
7bfdc51fcb65
Avoid deadlock when free is called by finalization code (Stefan Vogel)
Michael Beyl <mb@exept.de>
parents:
9895
diff
changeset
|
1367 |
wasBlocked := OperatingSystem blockInterrupts. |
7bfdc51fcb65
Avoid deadlock when free is called by finalization code (Stefan Vogel)
Michael Beyl <mb@exept.de>
parents:
9895
diff
changeset
|
1368 |
"/ AccessLock critical:[ |
11854 | 1369 |
AllocatedInstances isNil ifTrue:[ |
1370 |
AllocatedInstances := IdentitySet new |
|
1371 |
]. |
|
1372 |
AllocatedInstances add:self. |
|
10137
7bfdc51fcb65
Avoid deadlock when free is called by finalization code (Stefan Vogel)
Michael Beyl <mb@exept.de>
parents:
9895
diff
changeset
|
1373 |
"/ ] |
7bfdc51fcb65
Avoid deadlock when free is called by finalization code (Stefan Vogel)
Michael Beyl <mb@exept.de>
parents:
9895
diff
changeset
|
1374 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1375 |
! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1376 |
|
8908 | 1377 |
unprotectFromGC |
6459 | 1378 |
"remove the receiver from the AllocatedInstances |
1379 |
class variable - if there is no other reference to the receiver, |
|
15398 | 1380 |
and this was ever allocated by me (i.e. not by the outside world), |
6459 | 1381 |
the next garbage collect will finalize the receiver and the underlying |
1382 |
memory be freed." |
|
1383 |
||
10137
7bfdc51fcb65
Avoid deadlock when free is called by finalization code (Stefan Vogel)
Michael Beyl <mb@exept.de>
parents:
9895
diff
changeset
|
1384 |
|wasBlocked| |
7bfdc51fcb65
Avoid deadlock when free is called by finalization code (Stefan Vogel)
Michael Beyl <mb@exept.de>
parents:
9895
diff
changeset
|
1385 |
|
7bfdc51fcb65
Avoid deadlock when free is called by finalization code (Stefan Vogel)
Michael Beyl <mb@exept.de>
parents:
9895
diff
changeset
|
1386 |
"using a Semaphore can cause a deadlock, since protectFromGC may be interrupted by me |
7bfdc51fcb65
Avoid deadlock when free is called by finalization code (Stefan Vogel)
Michael Beyl <mb@exept.de>
parents:
9895
diff
changeset
|
1387 |
being called by a finalization method" |
7bfdc51fcb65
Avoid deadlock when free is called by finalization code (Stefan Vogel)
Michael Beyl <mb@exept.de>
parents:
9895
diff
changeset
|
1388 |
|
7bfdc51fcb65
Avoid deadlock when free is called by finalization code (Stefan Vogel)
Michael Beyl <mb@exept.de>
parents:
9895
diff
changeset
|
1389 |
wasBlocked := OperatingSystem blockInterrupts. |
7bfdc51fcb65
Avoid deadlock when free is called by finalization code (Stefan Vogel)
Michael Beyl <mb@exept.de>
parents:
9895
diff
changeset
|
1390 |
"/ AccessLock critical:[ |
11854 | 1391 |
AllocatedInstances notNil ifTrue:[ |
18653 | 1392 |
AllocatedInstances remove:self ifAbsent:nil. |
10138 | 1393 |
]. |
10137
7bfdc51fcb65
Avoid deadlock when free is called by finalization code (Stefan Vogel)
Michael Beyl <mb@exept.de>
parents:
9895
diff
changeset
|
1394 |
"/ ] |
7bfdc51fcb65
Avoid deadlock when free is called by finalization code (Stefan Vogel)
Michael Beyl <mb@exept.de>
parents:
9895
diff
changeset
|
1395 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1396 |
! ! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1397 |
|
6457 | 1398 |
!ExternalBytes methodsFor:'resizing'! |
1399 |
||
1400 |
grow:numberOfBytes |
|
1401 |
"reallocate (realloc) numberOfBytes. |
|
1402 |
Raise MallocFailure if realloc fails to allocate enough memory" |
|
1403 |
||
1404 |
|mallocStatus| |
|
1405 |
||
16705 | 1406 |
size == numberOfBytes ifTrue:[^ self]. |
1407 |
||
6457 | 1408 |
%{ |
19376 | 1409 |
if (__isSmallInteger(numberOfBytes)) { |
1410 |
INT nBytes = __smallIntegerVal(numberOfBytes); |
|
1411 |
if (nBytes > 0) { |
|
1412 |
char *space; |
|
1413 |
char *prevSpace = (char *)__INST(address_); |
|
6457 | 1414 |
|
19376 | 1415 |
if (prevSpace == (char *)nil) |
1416 |
prevSpace = 0; /* allocate from scratch */ |
|
1417 |
space = __stx_realloc(prevSpace, nBytes); |
|
1418 |
if (space) { |
|
1419 |
__INST(address_) = (OBJ)space; |
|
1420 |
__INST(size) = numberOfBytes; |
|
1421 |
if (space == prevSpace) { |
|
1422 |
/* same address, no re-registration */ |
|
1423 |
RETURN(self); |
|
1424 |
} |
|
1425 |
mallocStatus = true; |
|
1426 |
} else { |
|
1427 |
mallocStatus = false; |
|
1428 |
} |
|
1429 |
} |
|
6457 | 1430 |
} |
1431 |
%}. |
|
1432 |
mallocStatus == true ifTrue:[ |
|
19376 | 1433 |
Lobby registerChange:self. |
6457 | 1434 |
] ifFalse:[mallocStatus == false ifTrue:[ |
19376 | 1435 |
^ MallocFailure raiseRequestWith:numberOfBytes. |
6457 | 1436 |
] ifFalse:[ |
19376 | 1437 |
self primitiveFailed. |
6457 | 1438 |
]]. |
1439 |
! ! |
|
1440 |
||
14080 | 1441 |
!ExternalBytes methodsFor:'testing'! |
1442 |
||
1443 |
isExternalBytes |
|
1444 |
^ true |
|
1445 |
! ! |
|
1446 |
||
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1447 |
!ExternalBytes class methodsFor:'documentation'! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1448 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1449 |
version |
18580 | 1450 |
^ '$Header$' |
12594
d7267a747c2f
changed: #copyCStringFromHeap
Claus Gittinger <cg@exept.de>
parents:
11854
diff
changeset
|
1451 |
! |
d7267a747c2f
changed: #copyCStringFromHeap
Claus Gittinger <cg@exept.de>
parents:
11854
diff
changeset
|
1452 |
|
d7267a747c2f
changed: #copyCStringFromHeap
Claus Gittinger <cg@exept.de>
parents:
11854
diff
changeset
|
1453 |
version_CVS |
18580 | 1454 |
^ '$Header$' |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1455 |
! ! |
7184 | 1456 |
|
14749 | 1457 |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1458 |
ExternalBytes initialize! |