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