ExternalBytes.st
author Claus Gittinger <cg@exept.de>
Fri, 15 Dec 2000 17:48:21 +0100
changeset 5751 ceba525a9c2a
parent 5600 fc648a03d727
child 6242 3d1358719ab4
permissions -rw-r--r--
checkin from browser
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 1993 by Claus Gittinger
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
     3
              All Rights Reserved
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
5378
bc9f9e427fa7 oops - must synchronize accesses to AllocatedInstances
ps
parents: 5281
diff changeset
    13
"{ Package: 'stx:libbasic' }"
bc9f9e427fa7 oops - must synchronize accesses to AllocatedInstances
ps
parents: 5281
diff changeset
    14
3208
2d71538b9fd5 now subclass of UIBytes - which contains common protocol
Claus Gittinger <cg@exept.de>
parents: 3206
diff changeset
    15
UninterpretedBytes subclass:#ExternalBytes
3211
ef7a5411afa1 remove methods which are provided by my (new) superClass
Claus Gittinger <cg@exept.de>
parents: 3208
diff changeset
    16
	instanceVariableNames:'address* size'
5378
bc9f9e427fa7 oops - must synchronize accesses to AllocatedInstances
ps
parents: 5281
diff changeset
    17
	classVariableNames:'AllocatedInstances Lobby DebugMalloc TraceMalloc AccessLock'
3211
ef7a5411afa1 remove methods which are provided by my (new) superClass
Claus Gittinger <cg@exept.de>
parents: 3208
diff changeset
    18
	poolDictionaries:''
ef7a5411afa1 remove methods which are provided by my (new) superClass
Claus Gittinger <cg@exept.de>
parents: 3208
diff changeset
    19
	category:'System-Support'
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
!ExternalBytes primitiveFunctions!
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
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
struct mallocList {
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    26
        char *chunk;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    27
        unsigned size;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    28
        struct mallocList *next;
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
};
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
static struct mallocList *mallocList = (struct mallocList *)0;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
static mallocCount = 0;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
char *
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
__stx_malloc(nBytes) {
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    35
        char *ptr;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    36
        char *malloc();
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    37
        struct mallocList *e, *this;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    38
        int found;
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    40
        ptr = malloc(nBytes);
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    41
        if (@global(TraceMalloc) == true) {
2788
e4436755d153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2779
diff changeset
    42
#ifdef alpha64
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    43
            printf("EXTBYTES [info]: allocated %d bytes at: %016lx\n", nBytes, ptr);
2779
e895876895d3 64bit changes
Claus Gittinger <cg@exept.de>
parents: 2769
diff changeset
    44
#else
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    45
            printf("EXTBYTES [info]: allocated %d bytes at: %08x\n", nBytes, ptr);
2779
e895876895d3 64bit changes
Claus Gittinger <cg@exept.de>
parents: 2769
diff changeset
    46
#endif
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    47
        }
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    48
        if (@global(DebugMalloc) == true) {
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    49
            if (ptr) {
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    50
                found = 0;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    51
                for (this=mallocList; this; this=this->next) {
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    52
                    if (this->chunk == ptr) {
2788
e4436755d153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2779
diff changeset
    53
#ifdef alpha64
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    54
                        printf("EXTBYTES [warning]: **** %016lx already allocated (freed somewhere else ?)\n", ptr);
2779
e895876895d3 64bit changes
Claus Gittinger <cg@exept.de>
parents: 2769
diff changeset
    55
#else
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    56
                        printf("EXTBYTES [warning]: **** %08x already allocated (freed somewhere else ?)\n", ptr);
2779
e895876895d3 64bit changes
Claus Gittinger <cg@exept.de>
parents: 2769
diff changeset
    57
#endif
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    58
                        found++;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    59
                    }
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    60
                }
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    61
                if (! found) {
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    62
                    e = (struct mallocList *) malloc(sizeof(struct mallocList));
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    63
                    e->next = mallocList;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    64
                    e->chunk = ptr;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    65
                    e->size = nBytes;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    66
                    mallocList = e;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    67
                    mallocCount++;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    68
                }
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    69
            }
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    70
        }
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    71
        return ptr;
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
}
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
char *
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
__stx_calloc(n, size) {
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    76
        char *ptr;
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    78
        ptr = __stx_malloc(n * size);
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    79
        if (ptr != (char *)0) {
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    80
            bzero(ptr, (n * size));
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    81
        }
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    82
        return ptr;
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
}
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
char *
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
__stx_realloc(ptr, nBytes)
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
    char *ptr;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
{
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    89
        char *newPtr;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    90
        char *realloc(), *malloc();
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    91
        struct mallocList *this, *prev, *next, *e;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    92
        int foundOld, foundNew;
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    94
        newPtr = realloc(ptr, nBytes);
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    95
        if (@global(TraceMalloc) == true) {
2788
e4436755d153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2779
diff changeset
    96
#ifdef alpha64
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    97
            printf("EXTBYTES [info]: reallocated %d bytes for %016lx at: %016lx\n", nBytes, ptr, newPtr);
2779
e895876895d3 64bit changes
Claus Gittinger <cg@exept.de>
parents: 2769
diff changeset
    98
#else
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
    99
            printf("EXTBYTES [info]: reallocated %d bytes for %08x at: %08x\n", nBytes, ptr, newPtr);
2779
e895876895d3 64bit changes
Claus Gittinger <cg@exept.de>
parents: 2769
diff changeset
   100
#endif
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   101
        }
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   102
        if (@global(DebugMalloc) == true) {
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   103
            if (newPtr) {
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   104
                foundNew = 0;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   105
                for (this=mallocList; this; this=this->next) {
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   106
                    if (this->chunk == newPtr) {
2788
e4436755d153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2779
diff changeset
   107
#ifdef alpha64
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   108
                        printf("EXTBYTES [warning]: **** %016lx already allocated (freed somewhere else ?)\n", newPtr);
2779
e895876895d3 64bit changes
Claus Gittinger <cg@exept.de>
parents: 2769
diff changeset
   109
#else
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   110
                        printf("EXTBYTES [warning]: **** %08x already allocated (freed somewhere else ?)\n", newPtr);
2779
e895876895d3 64bit changes
Claus Gittinger <cg@exept.de>
parents: 2769
diff changeset
   111
#endif
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   112
                        foundNew = 1;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   113
                    }
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   114
                }
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   115
            }
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   117
            if (ptr) {
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   118
                foundOld = 0;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   119
                for (this=mallocList, prev=0; this; this=next) {
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   120
                    next = this->next;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   121
                    if (this->chunk == ptr) {
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   122
                        if (prev) {
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   123
                            prev->next = next;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   124
                        } else {
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   125
                            mallocList = next;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   126
                        }
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   127
                        free(this);
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   128
                        foundOld++;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   129
                    } else {
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   130
                        prev = this;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   131
                    }
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   132
                }
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   133
                if (! foundOld) {
2788
e4436755d153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2779
diff changeset
   134
#ifdef alpha64
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   135
                    printf("EXTBYTES [warning]: **** realloc alien %lx (allocated somewhere else ?)\n", ptr);
2779
e895876895d3 64bit changes
Claus Gittinger <cg@exept.de>
parents: 2769
diff changeset
   136
#else
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   137
                    printf("EXTBYTES [warning]: **** realloc alien %x (allocated somewhere else ?)\n", ptr);
2779
e895876895d3 64bit changes
Claus Gittinger <cg@exept.de>
parents: 2769
diff changeset
   138
#endif
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   139
                }
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   140
            }
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   142
            if (! foundNew) {
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   143
                e = (struct mallocList *) malloc(sizeof(struct mallocList));
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   144
                e->next = mallocList;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   145
                e->chunk = newPtr;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   146
                e->size = nBytes;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   147
                mallocList = e;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   148
                if (! ptr) {
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   149
                    mallocCount++;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   150
                }
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   151
            }
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   152
        }
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   154
        return newPtr;
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
}
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
__stx_free(ptr)
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
    char *ptr;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
{
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   160
        struct mallocList *this, *prev, *next;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   161
        int found;
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   163
        if (@global(TraceMalloc) == true) {
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   164
            printf("EXTBYTES: free bytes at: %08x\n", ptr);
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   165
        }
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   166
        if (@global(DebugMalloc) == true) {
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   167
            if (ptr) {
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   168
                found = 0;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   169
                for (this=mallocList, prev=0; this; this=next) {
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   170
                    next = this->next;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   171
                    if (this->chunk == ptr) {
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   172
                        if (prev) {
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   173
                            prev->next = next;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   174
                        } else {
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   175
                            mallocList = next;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   176
                        }
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   177
                        free(this);
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   178
                        found++;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   179
                        mallocCount--;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   180
                    } else {
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   181
                        prev = this;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   182
                    }
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   183
                }
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   184
                if (! found) {
2788
e4436755d153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2779
diff changeset
   185
#ifdef alpha64
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   186
                    printf("EXTBYTES [warning]: **** free: alien %lx (allocated somewhere else ?))\n", ptr);
2779
e895876895d3 64bit changes
Claus Gittinger <cg@exept.de>
parents: 2769
diff changeset
   187
#else
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   188
                    printf("EXTBYTES [warning]: **** free: alien %x (allocated somewhere else ?))\n", ptr);
2779
e895876895d3 64bit changes
Claus Gittinger <cg@exept.de>
parents: 2769
diff changeset
   189
#endif
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   190
                }
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   191
            }
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   192
        }
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   193
        return free(ptr);
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
}
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
3320
09eb32bbceaf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3211
diff changeset
   196
__stx_mallocStatistics() {
09eb32bbceaf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3211
diff changeset
   197
	struct mallocList *this;
09eb32bbceaf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3211
diff changeset
   198
	int amount = 0;
09eb32bbceaf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3211
diff changeset
   199
	int n = 0;
09eb32bbceaf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3211
diff changeset
   200
09eb32bbceaf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3211
diff changeset
   201
	for (this=mallocList; this; this=this->next) {
09eb32bbceaf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3211
diff changeset
   202
	    n++;
09eb32bbceaf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3211
diff changeset
   203
	    amount += this->size;
09eb32bbceaf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3211
diff changeset
   204
	}
09eb32bbceaf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3211
diff changeset
   205
	printf("EXTBYTES [info]: allocated %d blocks with %d bytes overall\n", n, amount);
09eb32bbceaf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3211
diff changeset
   206
}
09eb32bbceaf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3211
diff changeset
   207
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
%}
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
! !
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
!ExternalBytes class methodsFor:'documentation'!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   212
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
copyright
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
"
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
 COPYRIGHT (c) 1993 by Claus Gittinger
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   216
              All Rights Reserved
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
 This software is furnished under a license and may be used
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   219
 only in accordance with the terms of that license and with the
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
 inclusion of the above copyright notice.   This software may not
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   221
 be provided or otherwise made available to, or used by, any
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
 other person.  No title to or ownership of the software is
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
 hereby transferred.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
"
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   225
!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   226
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   227
documentation
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   228
"
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   229
    This class provides access to any memory in the system. Its main purpose
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
    is to provide a baseclass for objects referencing structured external data. 
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   231
    Normally, instances are created by primitive code which wants to pass C-data
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
    to Smalltalk AND grants smalltalk access to individual bytes afterwards.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   233
    Primitives which do not want to grant this access should return instances of
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   234
    ExternalAddress. See more info there. Also, have a look at ExternalFunction
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   235
    which is another similar class, but specialized to represent callable C-functions.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   236
 
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
    Since the memory address of an instance stays fixed (once allocated),
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
    it can also be used to share data with external C-parts 
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   239
    (which are not prepared for objects to change their address).
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   240
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   241
    Use with great care - access is not always checked for out-of-bounds 
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
    or valid addresses.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   243
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   244
    Since the data is allocated outside the garbage collected smalltalk space,
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   245
    its address stays fix. Thus, it can be passed to external C-functions without
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
    any danger. However, you have to take care for freeing the memory yourself.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   247
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   248
    To help in avoiding memory bugs, instances created with #new: are 
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   249
    registered in a local classvar and deregistered when the underlying memory
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   250
    is explicitely freed. Since a life reference (from that classvar) exists,
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   251
    the garbage collector will never find these to be reclaimable, and the
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   252
    underlying memory stays allocated (at a fix address) forever.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   253
    To release the memory, either #free it or #unprotect it.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   254
    The first will immediately release the memory, while the second will delay
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   255
    freeing until the next garbage collect occurs.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   256
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   257
    If you need memory which is automatically freed, create
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   258
    the instance via #unprotectedNew: right away; the underlying malloced-memory
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   259
    will be released as soon as no smalltalk reference to the ExtBytes object
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   260
    exists any more (however, you have to know for sure, that no C-references
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   261
    exist to this memory).
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   262
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   263
    To release all memory call #releaseAllMemory which simply sets the 
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   264
    AllocatedInstances class variable to nil (thus releasing those refs).
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   265
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   266
    Example (automatic freeing as soon as ref to buffer is gone):
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   267
        |buffer|
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   268
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   269
        buffer := ExternalBytes unprotectedNew:100.
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   270
        ...
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   271
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   272
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   273
    Example (manual freeing - never freed, if ref to buffer is gone):
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   274
        |buffer|
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   275
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   276
        buffer := ExternalBytes new:100.
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   277
        ...
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   278
        buffer free
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   279
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   280
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   281
    Example (delayed automatic freeing as soon as ref to buffer is gone):
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   282
        |buffer|
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   283
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   284
        buffer := ExternalBytes new:100.
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   285
        ...
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   286
        buffer unregister
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   287
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   288
    This class only supports unstructured external data 
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   289
    - see the companion class ExternalStructure for more.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   290
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   291
    Notice: support for external data is still being developed -
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   292
            a parser for C structure syntax and typedefs is on the way,
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   293
            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
   294
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   295
    Also notice, that this class may not be available or behave different
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   296
    in other smalltalk systems, making code using it very unportable.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   297
    It is provided for C interfacing only.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   298
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   299
    Finally note, that ST/X's memory system is much faster than malloc/free
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   300
    in the normal case - especially for short term temporary objects,
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   301
    automatically reclaimed object memory is about 5-10 times faster than
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   302
    malloc/free.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   303
    Things may be different for huge byte-valued objects, which are to be
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   304
    reclaimed by the oldspace colletor. 
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   305
    Anyway, for portability, we strongly warn from using this as a substitute 
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   306
    for byteArrays; it is meant for shared data with external C-functions ONLY.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   307
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   308
    Debugging: 
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   309
        since all manual memory systems are subject of obscure errors,
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   310
        you may want to turn malloc-tracing on; this traces all allocations/frees
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   311
        done here. To do this, evaluate: 'ExternalBytes mallocTrace:true'.
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   312
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   313
        In addition, you may turn on full debugging (with 'ExternalBytes mallocDebug:true');
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   314
        if turned on, all malloc/realloc requests are remembered and later free / realloc
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   315
        requests validated against this list (i.e. to detect freeing unallocated chunks).
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   316
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   317
        To benefit from this in C-code, we recommend you use __stx_malloc() / __stx_free()
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   318
        instead of malloc() / free(). To do so, redefine them in a header file (or cc comand line)
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   319
        and recompile your external c-libraries with this.
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   320
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   321
        I used this here to find memory leaks in the Xt libraries (there are still some in
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   322
        the HTML widget ...). If mallocDebug is on, #dumpMallocChunks will print out what is
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   323
        leftOver. This may help to find trouble spots in your C-code.
1286
4270a0b4917d documentation
Claus Gittinger <cg@exept.de>
parents: 1267
diff changeset
   324
4270a0b4917d documentation
Claus Gittinger <cg@exept.de>
parents: 1267
diff changeset
   325
    [author:]
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   326
        Claus Gittinger
1317
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
   327
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
   328
    [see also:]
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   329
        ExternalAddress ExternalFunction
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   330
        ByteArray
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   331
        ( how to write primitive code :html: programming/primitive.html )
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   332
"
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   333
!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   334
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   335
examples 
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
    These examples below are not directly executable;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   338
    some require primitive code to be compiled, or are simply given
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   339
    as sceletton.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   340
    Notice, that in C, indexing is 0-based, while in Smalltalk, indices start
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   341
    at 1.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   342
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   343
    allocating memory in ST, passing it to C:
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   344
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   345
      in smalltalk:
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   346
        ...
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   347
        bytes := ExternalBytes new:100.
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   348
        ...
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   349
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   350
      in C (assuming that the bytes-object has been passed):
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   351
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   352
        ...
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   353
        char *bytePtr;
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   354
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   355
        bytePtr = (char *)(__externalBytesAddress(bytes));
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   356
        if (bytePtr) {
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   357
            ... do something with bytes at bytePtr ...
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   358
        }
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   359
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   360
      freeing (in ST):
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   361
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   362
        ...
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   363
        bytes free.
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   364
        ...
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   365
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   366
    allocating memory in C, passing it to ST:
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   367
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   368
      in C:
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   369
        ...
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   370
        char *bytePtr;
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   371
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   372
        bytePtr = (char *)(malloc(100));
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   373
        ...
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   374
        RETURN (__MKEXTERNALBYTES(bytePtr));
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
      in Smalltalk (extracting bytes, integers or strings):
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   377
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   378
        byteVal := bytes byteAt:1.
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   379
        ...
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   380
        intVal := bytes doubleWordAt:1 MSB:true.
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   381
        ...
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   382
        string := bytes stringAt:20.    
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   383
        ...
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   384
"
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   385
! !
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   386
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   387
!ExternalBytes class methodsFor:'initialization'!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   388
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   389
initialize
913
7d9881f9c908 only initialize once
Claus Gittinger <cg@exept.de>
parents: 848
diff changeset
   390
    Lobby isNil ifTrue:[
5378
bc9f9e427fa7 oops - must synchronize accesses to AllocatedInstances
ps
parents: 5281
diff changeset
   391
        Lobby := Registry new.
bc9f9e427fa7 oops - must synchronize accesses to AllocatedInstances
ps
parents: 5281
diff changeset
   392
        AccessLock := Semaphore forMutualExclusion.
913
7d9881f9c908 only initialize once
Claus Gittinger <cg@exept.de>
parents: 848
diff changeset
   393
    ]
848
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
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   396
!ExternalBytes class methodsFor:'instance creation'!
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
address:aNumber
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   399
    "return a new ExternalBytes object to access bytes starting at aNumber.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   400
     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
   401
     therefore byte accesses will NOT be checked for valid index.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   402
     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
   403
     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
   404
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   405
     DANGER ALERT: this method allows very bad things to be done to the
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   406
                   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
   407
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   408
    ^ self basicNew setAddress:aNumber size:nil
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   409
!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   410
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   411
address:aNumber size:size
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   412
    "return a new ExternalBytes object to access bytes starting at aNumber.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   413
     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
   414
     which allows byte accesses to be checked for valid index.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   415
     Use this, if you get a pointer to a structure from some external source 
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   416
     (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
   417
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   418
     DANGER ALERT: this method allows very bad things to be done to the
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   419
                   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
   420
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   421
    ^ self basicNew setAddress:aNumber size:size 
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   422
!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   423
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   424
new:numberOfBytes
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   425
    "allocate some memory usable for data;
3486
bbd47c3011e5 comment
Claus Gittinger <cg@exept.de>
parents: 3321
diff changeset
   426
     the memory is not controlled by the garbage collector.
bbd47c3011e5 comment
Claus Gittinger <cg@exept.de>
parents: 3321
diff changeset
   427
     Return a corresponding ExternalBytes object or nil (if malloc fails).
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   428
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   429
     Use this, if you have to pass a block of bytes to some 
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   430
     external destination (such as a C function) which does not copy the
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   431
     data, but instead keeps a reference to it. For example, many functions
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   432
     which expect strings simply keep a ref to the passed string - for those,
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   433
     an ST/X string-pointer is not the right thing to pass, since ST/X objects
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   434
     may change their address.
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
     DANGER ALERT: the memory is NOT automatically freed until it is either
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   437
                   MANUALLY freed (see #free) or the returned externalBytes object
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   438
                   is unprotected or the classes releaseAllMemory method is called."
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   439
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   440
    |newInst|
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   441
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   442
    newInst := self unprotectedNew:numberOfBytes.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   443
    newInst protectFromGC.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   444
    ^ newInst
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   445
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   446
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   447
     |bytes|
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   448
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   449
     bytes := ExternalBytes new:100.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   450
     bytes wordAt:1 put:1.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   451
     bytes doubleWordAt:3 put:16r12345678.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   452
     bytes inspect
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   453
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   454
!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   455
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   456
unprotectedNew:numberOfBytes
3486
bbd47c3011e5 comment
Claus Gittinger <cg@exept.de>
parents: 3321
diff changeset
   457
    "allocate some memory usable for data; 
bbd47c3011e5 comment
Claus Gittinger <cg@exept.de>
parents: 3321
diff changeset
   458
     the memory is under the control of the garbage collector.
bbd47c3011e5 comment
Claus Gittinger <cg@exept.de>
parents: 3321
diff changeset
   459
     Return a corresponding ExternalBytes object or nil (if malloc fails).
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   460
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   461
     DANGER ALERT: the memory block as allocated will be automatically freed
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   462
                   as soon as the reference to the returned externalBytes object
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   463
                   is gone (by the next garbage collect).
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   464
                   If the memory has been passed to a C-function which 
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   465
                   remembers this pointer, bad things may happen ...."
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   466
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   467
    |newInst|
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   468
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   469
    newInst := self newForData:numberOfBytes.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   470
    Lobby register:newInst.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   471
    ^ newInst
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   472
! !
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   473
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   474
!ExternalBytes class methodsFor:'instance release'!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   475
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   476
releaseAllMemory
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   477
    AllocatedInstances := nil
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   478
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   479
     ... the next GC will get 'em
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   480
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   481
! !
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   482
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   483
!ExternalBytes class methodsFor:'malloc debug'!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   484
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   485
dumpMallocChunks
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   486
%{  /* NOCONTEXT */
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   487
    struct mallocList *entry;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   488
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   489
    for (entry = mallocList; entry; entry=entry->next) {
2788
e4436755d153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2779
diff changeset
   490
#ifdef alpha64
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   491
        printf("  %016lx (%d)\n", entry->chunk, entry->size);
2779
e895876895d3 64bit changes
Claus Gittinger <cg@exept.de>
parents: 2769
diff changeset
   492
#else
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   493
        printf("  %08x (%d)\n", entry->chunk, entry->size);
2779
e895876895d3 64bit changes
Claus Gittinger <cg@exept.de>
parents: 2769
diff changeset
   494
#endif
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   495
    }
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   496
%}
3321
4abefa756c45 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3320
diff changeset
   497
    "
4abefa756c45 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3320
diff changeset
   498
     self dumpMallocChunks
4abefa756c45 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3320
diff changeset
   499
    "
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   500
!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   501
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   502
freeAllMallocChunks
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   503
    "free all stx_malloc'd memory. Be careful, this does no validation at all;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   504
     It simply walks through all chunks and frees them unconditionally.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   505
     This may be helpful during debugging memory-leaks, to release memory which
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   506
     was not correctly freed by C-code. Howeve, only memory which was allocated
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   507
     by __stx_malloc() is freed here - so you better compile your primitive code with
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   508
     malloc redefined to stx_malloc.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   509
     Also, mallocDebug has to be on to do this."
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   510
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   511
    "first free my own memory ..."
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   512
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   513
    self releaseAllMemory.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   514
    ObjectMemory garbageCollect.
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
    struct mallocList *entry;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   517
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   518
    while ((entry = mallocList) != (struct mallocList *)0) {
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   519
        if (@global(TraceMalloc) == true ) {
2788
e4436755d153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2779
diff changeset
   520
#ifdef alpha64
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   521
            printf("EXTBYTES [info]: **** forced free of %016lx (%d)\n", entry->chunk, entry->size);
2779
e895876895d3 64bit changes
Claus Gittinger <cg@exept.de>
parents: 2769
diff changeset
   522
#else
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   523
            printf("EXTBYTES [info]: **** forced free of %08x (%d)\n", entry->chunk, entry->size);
2779
e895876895d3 64bit changes
Claus Gittinger <cg@exept.de>
parents: 2769
diff changeset
   524
#endif
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   525
        }
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   526
        __stx_free(entry->chunk);
848
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
!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   530
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   531
mallocDebug:aBoolean
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   532
    DebugMalloc := aBoolean
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   533
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   534
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   535
     ExternalBytes mallocDebug:true
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   536
     ExternalBytes mallocDebug:false 
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
!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   539
3486
bbd47c3011e5 comment
Claus Gittinger <cg@exept.de>
parents: 3321
diff changeset
   540
mallocStatistics
bbd47c3011e5 comment
Claus Gittinger <cg@exept.de>
parents: 3321
diff changeset
   541
%{
bbd47c3011e5 comment
Claus Gittinger <cg@exept.de>
parents: 3321
diff changeset
   542
    __stx_mallocStatistics();
bbd47c3011e5 comment
Claus Gittinger <cg@exept.de>
parents: 3321
diff changeset
   543
%}
bbd47c3011e5 comment
Claus Gittinger <cg@exept.de>
parents: 3321
diff changeset
   544
    "
bbd47c3011e5 comment
Claus Gittinger <cg@exept.de>
parents: 3321
diff changeset
   545
     self mallocStatistics
bbd47c3011e5 comment
Claus Gittinger <cg@exept.de>
parents: 3321
diff changeset
   546
    "
bbd47c3011e5 comment
Claus Gittinger <cg@exept.de>
parents: 3321
diff changeset
   547
!
bbd47c3011e5 comment
Claus Gittinger <cg@exept.de>
parents: 3321
diff changeset
   548
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   549
mallocTrace:aBoolean
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   550
    TraceMalloc := aBoolean
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   551
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   552
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   553
     ExternalBytes mallocTrace:true
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   554
     ExternalBytes mallocTrace:false
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   555
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   556
!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   557
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   558
numberOfAllocatedChunks
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   559
%{  /* NOCONTEXT */
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   560
    RETURN ( __MKSMALLINT(mallocCount) );
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   561
%}
3321
4abefa756c45 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3320
diff changeset
   562
    "
4abefa756c45 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3320
diff changeset
   563
     self numberOfAllocatedChunks
4abefa756c45 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3320
diff changeset
   564
    "
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   565
! !
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   566
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   567
!ExternalBytes class methodsFor:'private instance creation/release'!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   568
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   569
newForData:numberOfBytes
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   570
    "allocate some memory usable for data;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   571
     return a corresponding ExternalBytes object or nil (if malloc fails).
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   572
     This is a private entry - no setup for memory reclamation is done here."
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   573
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   574
    |addr|
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
    char *space;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   577
    unsigned long _addr = 0;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   578
    unsigned int nBytes;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   579
    char *__stx_malloc();
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   580
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   581
    /*
4273
3909c6029215 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3803
diff changeset
   582
     * this one is not at all critical - simply ret some space
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   583
     * to be used for data space of loaded-in binaries.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   584
     */
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   585
    if (__isSmallInteger(numberOfBytes)) {
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   586
        nBytes = __intVal(numberOfBytes);
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   587
        if (nBytes > 0) {
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   588
            space = __stx_malloc(nBytes);
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   589
            _addr = (unsigned long) space;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   590
        }
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   591
    }
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   592
    if (_addr > 0) {
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   593
        addr = __MKUINT(_addr);
848
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
%}.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   596
    addr isNil ifTrue:[
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   597
        "
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   598
         memory allocation failed
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   599
        "
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   600
        ^ ObjectMemory mallocFailureSignal raise
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
    ^ self basicNew setAddress:addr size:numberOfBytes
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   603
!
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
newForText:numberOfBytes
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   606
    "EXPERIMENTAL; do NEVER use this private method.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   607
     Allocate some memory usable to put machine executable instructions into;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   608
     return a corresponding ExternalBytes object or nil. 
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   609
     These bytes are NOT subject to garbage collection; therefore someone
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   610
     must take care of freeing the memory when its no longer needed.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   611
     This method may not be available on all architectures 
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   612
     (i.e. those that do not allow allocating text-memory).
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   613
     This is a private entry - no setup for memory reclamation is done here.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   614
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   615
     OBSOLETE: this method will vanish soon"
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
%{
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   618
#if ! defined(CAN_USE_DATA_FOR_TEXT)
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
     * this one should allocate some space, into which we can put
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   621
     * some code to be executed. You are in bad luck, if running on
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   622
     * a SepId machine or if data space cannot be executed.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   623
     * All you can do then, is to look for any OS-hooks and add more code here.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   624
     */
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   625
#endif
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   626
%}.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   627
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   628
     assume data is ok for instructions as well ...
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   629
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   630
    ^ self newForData:numberOfBytes
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   631
! !
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   632
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   633
!ExternalBytes class methodsFor:'queries'!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   634
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   635
isBuiltInClass
1267
e285a3a94d9e commentary
Claus Gittinger <cg@exept.de>
parents: 1242
diff changeset
   636
    "return true if this class is known by the run-time-system.
e285a3a94d9e commentary
Claus Gittinger <cg@exept.de>
parents: 1242
diff changeset
   637
     Here, true is returned."
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   638
3553
0c9663682120 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
   639
    ^ self == ExternalBytes
1267
e285a3a94d9e commentary
Claus Gittinger <cg@exept.de>
parents: 1242
diff changeset
   640
3553
0c9663682120 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
   641
    "Modified: / 11.6.1998 / 17:12:51 / cg"
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   642
!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   643
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   644
sizeofDouble
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   645
    "return the number of bytes used by the machines native doubles"
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   646
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   647
%{  /* NOCONTEXT */
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   648
    RETURN (__MKSMALLINT( sizeof(double)));
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   649
%}
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   650
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   651
     ExternalBytes sizeofDouble   
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   652
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   653
!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   654
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   655
sizeofFloat
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   656
    "return the number of bytes used by the machines native floats"
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   657
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   658
%{  /* NOCONTEXT */
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   659
    RETURN (__MKSMALLINT( sizeof(float)));
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   660
%}
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
     ExternalBytes sizeofFloat
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   663
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   664
!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   665
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   666
sizeofInt
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   667
    "return the number of bytes used by the machines native integer"
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   668
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   669
%{  /* NOCONTEXT */
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   670
    RETURN (__MKSMALLINT( sizeof(int)));
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   671
%}
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   672
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   673
     ExternalBytes sizeofInt
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   674
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   675
!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   676
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   677
sizeofLong
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   678
    "return the number of bytes used by the machines native longs"
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   679
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   680
%{  /* NOCONTEXT */
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   681
    RETURN (__MKSMALLINT( sizeof(long)));
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   682
%}
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   683
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   684
     ExternalBytes sizeofLong
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   685
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   686
!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   687
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   688
sizeofPointer
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   689
    "return the number of bytes used by the machines native pointer"
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
%{  /* NOCONTEXT */
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   692
    RETURN (__MKSMALLINT( sizeof(char *)));
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   693
%}
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   694
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   695
     ExternalBytes sizeofPointer
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
!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   698
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   699
sizeofShort
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   700
    "return the number of bytes used by the machines native short"
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   701
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   702
%{  /* NOCONTEXT */
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   703
    RETURN (__MKSMALLINT( sizeof(short)));
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   704
%}
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   705
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   706
     ExternalBytes sizeofShort
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   707
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   708
! !
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   709
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   710
!ExternalBytes methodsFor:'accessing'!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   711
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   712
address
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   713
    "return the start address as an integer"
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   714
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   715
%{  /* NOCONTEXT */
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
    int addr;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   718
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 913
diff changeset
   719
    if (__INST(address_) != nil) {
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   720
        addr = (INT)__INST(address_);
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   721
        if (addr <= _MAX_INT) {
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   722
            RETURN ( __MKSMALLINT(addr) );
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   723
        }
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   724
        RETURN ( __MKUINT(addr));
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   725
    }
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   726
%}.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   727
    ^ nil
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   728
!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   729
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   730
basicAt:index
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   731
    "return the byte at index, anInteger;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   732
     Indices are 1-based, therefore
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   733
     this is the byte at (address + index - 1)"
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   734
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   735
%{  /* NOCONTEXT */
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   736
1822
e7b977512062 type casts
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   737
    unsigned char *cp = (unsigned char *)(__INST(address_));
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   738
    int idx;
1997
4c5a80c2d570 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1822
diff changeset
   739
    OBJ sz;
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   740
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   741
    if (cp && __isSmallInteger(index)) {
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   742
        idx = __intVal(index);
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   743
        if (idx > 0) {
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   744
            if (((sz = __INST(size)) == nil)
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   745
             || (__intVal(sz) >= idx)) {
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   746
                cp = cp + idx - 1;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   747
                RETURN ( __MKSMALLINT(*cp) );
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   748
            }
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   749
        }
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   750
    }
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   751
%}.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   752
    (size notNil and:[self address notNil]) ifTrue:[
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   753
        ^ self subscriptBoundsError:index
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   754
    ].
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   755
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   756
     invalid index or unallocated
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
    self primitiveFailed
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   759
!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   760
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   761
basicAt:index put:value
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   762
    "set the byte at index, anInteger to value which must be 0..255.
1220
99990bbb561f commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   763
     Returns value (sigh).
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   764
     Indices are 1-based, therefore
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   765
     this is the byte at (address + index - 1)"
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   766
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   767
%{  /* NOCONTEXT */
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   768
1822
e7b977512062 type casts
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   769
    unsigned char *cp = (unsigned char *)(__INST(address_));
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   770
    int val;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   771
    int idx;
1997
4c5a80c2d570 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1822
diff changeset
   772
    OBJ sz;
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   773
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   774
    if (cp && __bothSmallInteger(index, value)) {
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   775
        idx = __intVal(index);
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   776
        if (idx > 0) {
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   777
            if (((sz = __INST(size)) == nil)
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   778
             || (__intVal(sz) >= idx)) {
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   779
                val = __intVal(value);
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   780
                if ((val & ~0xFF) == 0) /* i.e. (val >= 0) && (val <= 255) */  {
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   781
                    cp[idx-1] = val;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   782
                    RETURN ( value );
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   783
                }
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   784
            }
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   785
        }
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   786
    }
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   787
%}.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   788
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   789
    (size notNil and:[self address notNil]) ifTrue:[
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   790
        ^ self subscriptBoundsError:index
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   791
    ].
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   792
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   793
     invalid index, invalid value or unallocated
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   794
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   795
    self primitiveFailed
1220
99990bbb561f commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   796
99990bbb561f commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   797
    "Modified: 19.4.1996 / 11:15:05 / cg"
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   798
!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   799
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   800
byteAt:index
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   801
    "return the unsigned byte at index, anInteger.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   802
     Indices are 1-based, therefore
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   803
     this is the byte at (address + index - 1)"
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   804
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   805
    ^ self basicAt:index
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   806
!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   807
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   808
byteAt:index put:aByteValuedInteger
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   809
    "set the byte at index.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   810
     Indices are 1-based, therefore
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   811
     this is the byte at (address + index - 1)"
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   812
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   813
    ^ self basicAt:index put:aByteValuedInteger
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   814
!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   815
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   816
instVarAt:index
3186
16e7ba00e786 added type decls for performance and as documentation
Claus Gittinger <cg@exept.de>
parents: 3117
diff changeset
   817
    "redefined to suppress direct access to my address, which is a non-object"
16e7ba00e786 added type decls for performance and as documentation
Claus Gittinger <cg@exept.de>
parents: 3117
diff changeset
   818
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   819
    index == 1 ifTrue:[
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   820
        ^ self address
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   821
    ].
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   822
    ^ super instVarAt:index
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   823
! !
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   824
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   825
!ExternalBytes methodsFor:'freeing'!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   826
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   827
free
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   828
    "free a previously allocated piece of memory - be very careful, there
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   829
     are no checks done here. All dangers you usually have with malloc/free
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   830
     are present here ..."
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   831
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   832
    "at least, we check for double freeing the same chunk"
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   833
    self address isNil ifTrue:[
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   834
        self error:'freeing memory twice'.
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   835
        ^ self
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   836
    ].
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   837
    Lobby unregister:self.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   838
    self disposed.  "/ does what we need here ..
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   839
    self unprotectFromGC
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   840
! !
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   841
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   842
!ExternalBytes methodsFor:'instance release'!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   843
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   844
disposed 
2779
e895876895d3 64bit changes
Claus Gittinger <cg@exept.de>
parents: 2769
diff changeset
   845
    "some ExternalBytes object was finalized;
e895876895d3 64bit changes
Claus Gittinger <cg@exept.de>
parents: 2769
diff changeset
   846
     free the associated heap memory with it"
e895876895d3 64bit changes
Claus Gittinger <cg@exept.de>
parents: 2769
diff changeset
   847
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   848
%{  /* NOCONTEXT */
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   849
    char *mem = (char *)0;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   850
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 913
diff changeset
   851
    mem = (char *)(__INST(address_));
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   852
    if (mem) {
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   853
        __stx_free(mem);
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   854
    }
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 913
diff changeset
   855
    __INST(address_) = __INST(size) = nil;
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   856
%}
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   857
!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   858
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   859
shallowCopyForFinalization
1242
701be0be8681 commentary
Claus Gittinger <cg@exept.de>
parents: 1220
diff changeset
   860
    "redefined to return a lightweight copy 
701be0be8681 commentary
Claus Gittinger <cg@exept.de>
parents: 1220
diff changeset
   861
     - all we need is the memory handle"
701be0be8681 commentary
Claus Gittinger <cg@exept.de>
parents: 1220
diff changeset
   862
5399
370a31cfdae7 oops - shallow copy was wrong (for subclasses)
ps
parents: 5378
diff changeset
   863
    ^ self class basicNew setAddress:self address size:size
1242
701be0be8681 commentary
Claus Gittinger <cg@exept.de>
parents: 1220
diff changeset
   864
701be0be8681 commentary
Claus Gittinger <cg@exept.de>
parents: 1220
diff changeset
   865
    "Modified: 20.4.1996 / 23:23:28 / cg"
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   866
! !
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   867
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   868
!ExternalBytes methodsFor:'printing & storing'!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   869
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   870
displayString
2957
46015145c398 comments
Claus Gittinger <cg@exept.de>
parents: 2788
diff changeset
   871
    "return a printed representation of the receiver for displaying"
46015145c398 comments
Claus Gittinger <cg@exept.de>
parents: 2788
diff changeset
   872
5281
0cdeb2d0d30c displayString fix (care for nil-address)
Claus Gittinger <cg@exept.de>
parents: 4273
diff changeset
   873
    |addr addrString|
2957
46015145c398 comments
Claus Gittinger <cg@exept.de>
parents: 2788
diff changeset
   874
5281
0cdeb2d0d30c displayString fix (care for nil-address)
Claus Gittinger <cg@exept.de>
parents: 4273
diff changeset
   875
    (addr := self address) isNil ifTrue:[
0cdeb2d0d30c displayString fix (care for nil-address)
Claus Gittinger <cg@exept.de>
parents: 4273
diff changeset
   876
        addrString := '[free]'
0cdeb2d0d30c displayString fix (care for nil-address)
Claus Gittinger <cg@exept.de>
parents: 4273
diff changeset
   877
    ] ifFalse:[
0cdeb2d0d30c displayString fix (care for nil-address)
Claus Gittinger <cg@exept.de>
parents: 4273
diff changeset
   878
        addrString := '[at:' , (self address printStringRadix:16) , ']'
0cdeb2d0d30c displayString fix (care for nil-address)
Claus Gittinger <cg@exept.de>
parents: 4273
diff changeset
   879
    ].
0cdeb2d0d30c displayString fix (care for nil-address)
Claus Gittinger <cg@exept.de>
parents: 4273
diff changeset
   880
    ^ self class name , addrString
0cdeb2d0d30c displayString fix (care for nil-address)
Claus Gittinger <cg@exept.de>
parents: 4273
diff changeset
   881
0cdeb2d0d30c displayString fix (care for nil-address)
Claus Gittinger <cg@exept.de>
parents: 4273
diff changeset
   882
    "Modified: / 24.2.2000 / 19:02:19 / cg"
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   883
! !
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   884
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   885
!ExternalBytes methodsFor:'private accessing'!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   886
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   887
setAddress:aNumber size:sz 
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   888
    "set the start address and size"
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   889
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   890
%{  /* NOCONTEXT */
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 913
diff changeset
   891
    if (__INST(address_) == nil) {
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   892
        if (aNumber == nil) {
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   893
            __INST(address_) = nil;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   894
        } else {
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   895
            if (__isSmallInteger(aNumber)) {
5600
fc648a03d727 Use __unsignedLongIntVal instead of deprecated __longIntVal.
Stefan Vogel <sv@exept.de>
parents: 5557
diff changeset
   896
                __INST(address_) = (OBJ) __intVal(aNumber);
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   897
            } else {
5600
fc648a03d727 Use __unsignedLongIntVal instead of deprecated __longIntVal.
Stefan Vogel <sv@exept.de>
parents: 5557
diff changeset
   898
                __INST(address_) = (OBJ) __unsignedLongIntVal(aNumber);
3206
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   899
            }
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   900
        }
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   901
        __INST(size) = sz;
493628974815 added floatAt / doubleAt stuff
dq
parents: 3186
diff changeset
   902
        RETURN (self);
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   903
    }
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   904
%}.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   905
    ^ self error:'cannot change address'
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   906
! !
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   907
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5399
diff changeset
   908
!ExternalBytes methodsFor:'queries'!
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5399
diff changeset
   909
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5399
diff changeset
   910
basicSize
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5399
diff changeset
   911
    "we do not know how many bytes are valid"
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5399
diff changeset
   912
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5399
diff changeset
   913
    size isNil ifTrue:[^ 0].
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5399
diff changeset
   914
    ^ size
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5399
diff changeset
   915
! !
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5399
diff changeset
   916
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   917
!ExternalBytes methodsFor:'registration'!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   918
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   919
protectFromGC 
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   920
    "enter a reference to the receiver into the AllocatedInstances
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   921
     class variable - this prevents it from ever being finalized by
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   922
     the garbage collector, thus protecting the underlying memory."
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   923
5378
bc9f9e427fa7 oops - must synchronize accesses to AllocatedInstances
ps
parents: 5281
diff changeset
   924
    AccessLock critical:[
bc9f9e427fa7 oops - must synchronize accesses to AllocatedInstances
ps
parents: 5281
diff changeset
   925
        AllocatedInstances isNil ifTrue:[
bc9f9e427fa7 oops - must synchronize accesses to AllocatedInstances
ps
parents: 5281
diff changeset
   926
            AllocatedInstances := IdentitySet new
bc9f9e427fa7 oops - must synchronize accesses to AllocatedInstances
ps
parents: 5281
diff changeset
   927
        ].
bc9f9e427fa7 oops - must synchronize accesses to AllocatedInstances
ps
parents: 5281
diff changeset
   928
        AllocatedInstances add:self
bc9f9e427fa7 oops - must synchronize accesses to AllocatedInstances
ps
parents: 5281
diff changeset
   929
    ]
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   930
!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   931
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   932
unprotectFromGC 
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   933
    "remove the receiver from the AllocatedInstances
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   934
     class variable - if there is no other reference to the receiver,
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   935
     the next garbage collect will finalize the receiver and the underlying
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   936
     memory be freed."
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   937
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   938
    AllocatedInstances notNil ifTrue:[
5378
bc9f9e427fa7 oops - must synchronize accesses to AllocatedInstances
ps
parents: 5281
diff changeset
   939
        AccessLock critical:[
bc9f9e427fa7 oops - must synchronize accesses to AllocatedInstances
ps
parents: 5281
diff changeset
   940
            AllocatedInstances remove:self ifAbsent:nil
bc9f9e427fa7 oops - must synchronize accesses to AllocatedInstances
ps
parents: 5281
diff changeset
   941
        ]
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   942
    ]
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   943
! !
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   944
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   945
!ExternalBytes class methodsFor:'documentation'!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   946
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   947
version
5600
fc648a03d727 Use __unsignedLongIntVal instead of deprecated __longIntVal.
Stefan Vogel <sv@exept.de>
parents: 5557
diff changeset
   948
    ^ '$Header: /cvs/stx/stx/libbasic/ExternalBytes.st,v 1.31 2000-09-12 06:26:23 stefan Exp $'
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   949
! !
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   950
ExternalBytes initialize!