9343
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2006 by eXept Software AG
|
9350
|
3 |
All Rights Reserved
|
9343
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
"{ Package: 'stx:libbasic' }"
|
|
13 |
|
9350
|
14 |
ExternalBytes subclass:#ExternalStructure
|
9343
|
15 |
instanceVariableNames:''
|
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'System-Support'
|
|
19 |
!
|
|
20 |
|
|
21 |
ExternalStructure class instanceVariableNames:'cType'
|
|
22 |
|
|
23 |
"
|
|
24 |
No other class instance variables are inherited by this class.
|
|
25 |
"
|
|
26 |
!
|
|
27 |
|
|
28 |
!ExternalStructure class methodsFor:'documentation'!
|
|
29 |
|
|
30 |
copyright
|
|
31 |
"
|
|
32 |
COPYRIGHT (c) 2006 by eXept Software AG
|
9350
|
33 |
All Rights Reserved
|
9343
|
34 |
|
|
35 |
This software is furnished under a license and may be used
|
|
36 |
only in accordance with the terms of that license and with the
|
|
37 |
inclusion of the above copyright notice. This software may not
|
|
38 |
be provided or otherwise made available to, or used by, any
|
|
39 |
other person. No title to or ownership of the software is
|
|
40 |
hereby transferred.
|
|
41 |
"
|
|
42 |
!
|
|
43 |
|
|
44 |
documentation
|
|
45 |
"
|
|
46 |
Instances of this class represent external (non-Smalltalk) data,
|
|
47 |
typically C-structs or C++ instances.
|
9350
|
48 |
They are only useful to represent handles as returned by C functions as smalltalk objects.
|
9343
|
49 |
|
|
50 |
ExternallStructures are much like ExternalBytes - however, the latter
|
|
51 |
allow you to access bytes via indexed at:/at:put: messages, whilst instances of subclasses of me
|
|
52 |
allow access via the corresponding getter/setter methods of my C-type.
|
|
53 |
|
|
54 |
[author:]
|
9350
|
55 |
Claus Gittinger
|
9343
|
56 |
|
|
57 |
[see also:]
|
9350
|
58 |
ExternalBytes ExternalAddress
|
|
59 |
( how to write primitive code :html: programming/primitive.html )
|
9343
|
60 |
"
|
|
61 |
! !
|
|
62 |
|
9387
|
63 |
!ExternalStructure class methodsFor:'instance creation'!
|
|
64 |
|
|
65 |
fromExternalAddress:anExternalAddress
|
|
66 |
^ self new fromExternalAddress:anExternalAddress
|
14725
|
67 |
!
|
|
68 |
|
|
69 |
new
|
|
70 |
"allocate some memory usable for data;
|
|
71 |
the memory is not controlled by the garbage collector.
|
|
72 |
Return a corresponding ExternalBytes object or raise MallocFailure (if malloc fails).
|
|
73 |
|
|
74 |
Use this, if you have to pass a block of bytes to some
|
|
75 |
external destination (such as a C function) which does not copy the
|
|
76 |
data, but instead keeps a reference to it. For example, many functions
|
|
77 |
which expect strings simply keep a ref to the passed string - for those,
|
|
78 |
an ST/X string-pointer is not the right thing to pass, since ST/X objects
|
|
79 |
may change their address.
|
|
80 |
|
|
81 |
DANGER ALERT: the memory is NOT automatically freed until it is either
|
|
82 |
MANUALLY freed (see #free) or the returned externalBytes object
|
|
83 |
is unprotected or the classes releaseAllMemory method is called."
|
|
84 |
|
|
85 |
^ super new:(self sizeof)
|
|
86 |
|
|
87 |
"Modified: / 20-12-2010 / 16:22:51 / cg"
|
|
88 |
!
|
|
89 |
|
|
90 |
unprotectedNew
|
|
91 |
"allocate some memory usable for data;
|
|
92 |
the memory is under the control of the garbage collector.
|
|
93 |
Return a corresponding ExternalBytes object or raise MallocFailure (if malloc fails).
|
|
94 |
|
|
95 |
DANGER ALERT: the memory block as allocated will be automatically freed
|
|
96 |
as soon as the reference to the returned externalBytes object
|
|
97 |
is gone (by the next garbage collect).
|
|
98 |
If the memory has been passed to a C-function which
|
|
99 |
remembers this pointer, bad things may happen ...."
|
|
100 |
|
|
101 |
^ super unprotectedNew:(self sizeof)
|
9387
|
102 |
! !
|
|
103 |
|
9343
|
104 |
!ExternalStructure class methodsFor:'queries'!
|
|
105 |
|
|
106 |
cType
|
|
107 |
^ cType
|
14725
|
108 |
!
|
|
109 |
|
|
110 |
sizeof
|
|
111 |
"the sizeof my instances in bytes"
|
|
112 |
|
|
113 |
cType notNil ifTrue:[
|
|
114 |
^ cType sizeof
|
|
115 |
].
|
|
116 |
self subclassResponsibility
|
9343
|
117 |
! !
|
|
118 |
|
9387
|
119 |
!ExternalStructure methodsFor:'private'!
|
|
120 |
|
|
121 |
fromExternalAddress:anExternalAddress
|
|
122 |
self setAddress:(anExternalAddress address) size:(anExternalAddress size).
|
|
123 |
! !
|
|
124 |
|
9343
|
125 |
!ExternalStructure class methodsFor:'documentation'!
|
|
126 |
|
|
127 |
version
|
14725
|
128 |
^ '$Header: /cvs/stx/stx/libbasic/ExternalStructure.st,v 1.4 2013-01-28 18:01:20 cg Exp $'
|
9343
|
129 |
! !
|
14725
|
130 |
|