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