4669
|
1 |
"{ Encoding: utf8 }"
|
|
2 |
|
1926
|
3 |
"
|
|
4 |
COPYRIGHT (c) 1998 by eXept Software AG
|
2964
|
5 |
All Rights Reserved
|
1926
|
6 |
|
|
7 |
This software is furnished under a license and may be used
|
|
8 |
only in accordance with the terms of that license and with the
|
|
9 |
inclusion of the above copyright notice. This software may not
|
|
10 |
be provided or otherwise made available to, or used by, any
|
|
11 |
other person. No title to or ownership of the software is
|
|
12 |
hereby transferred.
|
|
13 |
"
|
|
14 |
"{ Package: 'stx:libbasic2' }"
|
|
15 |
|
3543
|
16 |
"{ NameSpace: Smalltalk }"
|
|
17 |
|
605
|
18 |
ExternalBytes subclass:#ExternalLong
|
|
19 |
instanceVariableNames:''
|
|
20 |
classVariableNames:''
|
|
21 |
poolDictionaries:''
|
623
|
22 |
category:'System-Support'
|
605
|
23 |
!
|
|
24 |
|
1926
|
25 |
!ExternalLong class methodsFor:'documentation'!
|
|
26 |
|
|
27 |
copyright
|
|
28 |
"
|
|
29 |
COPYRIGHT (c) 1998 by eXept Software AG
|
2964
|
30 |
All Rights Reserved
|
1926
|
31 |
|
|
32 |
This software is furnished under a license and may be used
|
|
33 |
only in accordance with the terms of that license and with the
|
|
34 |
inclusion of the above copyright notice. This software may not
|
|
35 |
be provided or otherwise made available to, or used by, any
|
|
36 |
other person. No title to or ownership of the software is
|
|
37 |
hereby transferred.
|
|
38 |
"
|
2329
|
39 |
!
|
|
40 |
|
|
41 |
documentation
|
|
42 |
"
|
2957
|
43 |
mostly added for odbc, which uses instances of me as container in which values
|
3773
|
44 |
(pointers) are returned.
|
|
45 |
The name is very misleading: it should be ExternalPointer,
|
2957
|
46 |
because on machines where sizeof(long) !!= sizeof(void *), that makes a difference.
|
3773
|
47 |
However, over time, others started to use this class,
|
|
48 |
and renaming it would break some code.
|
2329
|
49 |
"
|
1926
|
50 |
! !
|
605
|
51 |
|
|
52 |
!ExternalLong class methodsFor:'instance creation'!
|
|
53 |
|
|
54 |
new
|
2517
|
55 |
"allocate some memory usable for data;
|
|
56 |
the memory is not controlled by the garbage collector.
|
|
57 |
Return a corresponding ExternalBytes object or raise MallocFailure (if malloc fails).
|
|
58 |
|
|
59 |
Use this, if you have to pass a block of bytes to some
|
|
60 |
external destination (such as a C function) which does not copy the
|
|
61 |
data, but instead keeps a reference to it. For example, many functions
|
|
62 |
which expect strings simply keep a ref to the passed string - for those,
|
|
63 |
an ST/X string-pointer is not the right thing to pass, since ST/X objects
|
|
64 |
may change their address.
|
|
65 |
|
|
66 |
DANGER ALERT: the memory is NOT automatically freed until it is either
|
4669
|
67 |
MANUALLY freed (see #free) or the returned externalBytes object
|
|
68 |
is unprotected or the classes releaseAllMemory method is called."
|
2517
|
69 |
|
4669
|
70 |
^ super new:(ExternalBytes sizeofPointer)
|
605
|
71 |
|
|
72 |
"
|
|
73 |
ExternalLong new
|
|
74 |
"
|
2517
|
75 |
|
|
76 |
"Modified: / 20-12-2010 / 16:22:51 / cg"
|
605
|
77 |
!
|
|
78 |
|
|
79 |
unprotectedNew
|
2517
|
80 |
"allocate some memory usable for data;
|
|
81 |
the memory is under the control of the garbage collector.
|
|
82 |
Return a corresponding ExternalBytes object or raise MallocFailure (if malloc fails).
|
|
83 |
|
|
84 |
DANGER ALERT: the memory block as allocated will be automatically freed
|
4669
|
85 |
as soon as the reference to the returned externalBytes object
|
|
86 |
is gone (by the next garbage collect).
|
|
87 |
If the memory has been passed to a C-function which
|
|
88 |
remembers this pointer, bad things may happen ...."
|
2517
|
89 |
|
4669
|
90 |
^ super unprotectedNew:(ExternalBytes sizeofPointer)
|
605
|
91 |
|
|
92 |
"
|
|
93 |
ExternalLong new
|
|
94 |
"
|
2517
|
95 |
|
|
96 |
"Modified: / 20-12-2010 / 16:22:39 / cg"
|
605
|
97 |
! !
|
|
98 |
|
|
99 |
!ExternalLong methodsFor:'accessing'!
|
|
100 |
|
|
101 |
asBoolean
|
4303
|
102 |
^ (self byteAt:1) ~~ 0.
|
605
|
103 |
|
4303
|
104 |
"Modified: / 07-02-2017 / 23:40:51 / stefan"
|
605
|
105 |
!
|
|
106 |
|
2521
|
107 |
asExternalBytes
|
|
108 |
^ ExternalBytes address:(self value)
|
|
109 |
|
|
110 |
"
|
2964
|
111 |
(ExternalLong new value:10) asExternalBytes
|
|
112 |
(ExternalLong new value:0) asExternalBytes
|
2521
|
113 |
"
|
|
114 |
!
|
|
115 |
|
605
|
116 |
asInteger
|
3773
|
117 |
"warning: retrieves a signed integer with the size of the native machine's
|
2964
|
118 |
pointer (i.e. either 32 or 64bit)"
|
2958
|
119 |
|
4669
|
120 |
ExternalBytes sizeofPointer == 8 ifTrue:[
|
3773
|
121 |
^ self signedInt64At:1 MSB:IsBigEndian
|
2964
|
122 |
] ifFalse:[
|
3773
|
123 |
^ self signedInt32At:1 MSB:IsBigEndian
|
2964
|
124 |
]
|
605
|
125 |
|
|
126 |
"
|
2519
|
127 |
ExternalLong new value:10
|
|
128 |
(ExternalLong new value:16rFFFFFF) asInteger
|
605
|
129 |
"
|
2519
|
130 |
|
|
131 |
"Modified: / 22-12-2010 / 18:34:02 / cg"
|
605
|
132 |
!
|
|
133 |
|
|
134 |
asNullStatus
|
2964
|
135 |
"cg: whoever added this here should move it to the sql package"
|
|
136 |
|
605
|
137 |
|result|
|
|
138 |
|
3753
|
139 |
result := self unsignedInt16At:1 MSB:false.
|
2329
|
140 |
result = 0 ifTrue:[ ^ #SQL_NO_NULLS ].
|
|
141 |
result = 1 ifTrue:[ ^ #SQL_NULLABLE ].
|
|
142 |
^ #SQL_NULLABLE_UNKNOWN
|
|
143 |
!
|
|
144 |
|
|
145 |
asPointer
|
2964
|
146 |
"fetch my cell's pointer value
|
2958
|
147 |
(use this if you passed me to a C function as out parameter, to fetch the returned value)"
|
|
148 |
|
|
149 |
"/ ^ ExternalAddress new setAddress:(self value address)
|
|
150 |
^ self pointerAt:1.
|
2329
|
151 |
|
|
152 |
"
|
|
153 |
(ExternalLong new value:10) asPointer
|
|
154 |
"
|
605
|
155 |
!
|
|
156 |
|
2519
|
157 |
asUnsignedInteger
|
2964
|
158 |
"warning: retrieves an integer with the size of the native machine's
|
|
159 |
pointer (i.e. either 32 or 64bit)"
|
|
160 |
|
4669
|
161 |
ExternalBytes sizeofPointer == 8 ifTrue:[
|
3773
|
162 |
^ self unsignedInt64At:1 MSB:IsBigEndian
|
2964
|
163 |
] ifFalse:[
|
3773
|
164 |
^ self unsignedInt32At:1 MSB:IsBigEndian
|
2964
|
165 |
]
|
2519
|
166 |
|
|
167 |
"
|
2964
|
168 |
(ExternalLong new value:10) asUnsignedInteger
|
2519
|
169 |
"
|
|
170 |
|
|
171 |
"Created: / 22-12-2010 / 18:31:03 / cg"
|
|
172 |
!
|
|
173 |
|
609
|
174 |
boolean:bool
|
4303
|
175 |
bool ifTrue:[
|
|
176 |
self byteAt:1 put:1
|
|
177 |
] ifFalse:[
|
|
178 |
self byteAt:1 put:0.
|
|
179 |
]
|
|
180 |
|
|
181 |
"Modified: / 07-02-2017 / 23:42:15 / stefan"
|
609
|
182 |
!
|
|
183 |
|
605
|
184 |
value
|
2958
|
185 |
^ (self pointerAt:1) address
|
605
|
186 |
|
|
187 |
"
|
2958
|
188 |
(ExternalLong new value:10) value
|
605
|
189 |
"
|
623
|
190 |
|
|
191 |
"Modified: / 30.3.1998 / 17:07:57 / cg"
|
605
|
192 |
!
|
|
193 |
|
|
194 |
value:anInteger
|
2958
|
195 |
"/ self doubleWordAt:1 put:anInteger
|
2964
|
196 |
self pointerAt:1 put:anInteger
|
605
|
197 |
! !
|
|
198 |
|
2462
|
199 |
!ExternalLong methodsFor:'printing & storing'!
|
|
200 |
|
|
201 |
printOn:aStream
|
|
202 |
aStream nextPutAll:self className; nextPut:$(.
|
|
203 |
self asInteger printOn:aStream.
|
|
204 |
aStream nextPut:$)
|
|
205 |
! !
|
|
206 |
|
605
|
207 |
!ExternalLong class methodsFor:'documentation'!
|
|
208 |
|
|
209 |
version
|
3753
|
210 |
^ '$Header$'
|
2329
|
211 |
!
|
|
212 |
|
|
213 |
version_CVS
|
3753
|
214 |
^ '$Header$'
|
605
|
215 |
! !
|
3543
|
216 |
|