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