56
56
import static com .oracle .graal .python .runtime .exception .PythonErrorType .RuntimeError ;
57
57
import static com .oracle .graal .python .runtime .exception .PythonErrorType .ValueError ;
58
58
59
+ import com .oracle .graal .python .PythonLanguage ;
59
60
import com .oracle .graal .python .builtins .objects .ints .PInt ;
60
- import com .oracle .graal .python .nodes .PNodeWithContext ;
61
+ import com .oracle .graal .python .nodes .PNodeWithRaise ;
61
62
import com .oracle .graal .python .nodes .PRaiseNode ;
62
63
import com .oracle .graal .python .runtime .NFIBz2Support ;
63
64
import com .oracle .graal .python .runtime .NativeLibrary ;
64
65
import com .oracle .graal .python .runtime .PythonContext ;
65
66
import com .oracle .graal .python .util .OverflowException ;
66
67
import com .oracle .graal .python .util .PythonUtils ;
67
68
import com .oracle .truffle .api .dsl .Cached ;
68
- import com .oracle .truffle .api .dsl .GenerateUncached ;
69
+ import com .oracle .truffle .api .dsl .CachedContext ;
69
70
import com .oracle .truffle .api .dsl .Specialization ;
70
71
import com .oracle .truffle .api .nodes .Node ;
71
72
import com .oracle .truffle .api .profiles .BranchProfile ;
@@ -92,8 +93,7 @@ public class Bz2Nodes {
92
93
protected static final int BZ_OUTBUFF_FULL = (-8 );
93
94
protected static final int BZ_CONFIG_ERROR = (-9 );
94
95
95
- @ GenerateUncached
96
- public abstract static class Bz2NativeCompress extends Node {
96
+ public abstract static class Bz2NativeCompress extends PNodeWithRaise {
97
97
98
98
public abstract byte [] execute (BZ2Object .BZ2Compressor self , PythonContext context , byte [] bytes , int len , int action );
99
99
@@ -109,26 +109,24 @@ public byte[] flush(BZ2Object.BZ2Compressor self, PythonContext context) {
109
109
byte [] nativeCompress (BZ2Object .BZ2Compressor self , PythonContext context , byte [] bytes , int len , int action ,
110
110
@ Cached NativeLibrary .InvokeNativeFunction compress ,
111
111
@ Cached GetOutputNativeBufferNode getBuffer ,
112
- @ Cached PRaiseNode raiseNode ,
113
112
@ Cached ConditionProfile errProfile ) {
114
113
NFIBz2Support bz2Support = context .getNFIBz2Support ();
115
114
Object inGuest = context .getEnv ().asGuestValue (bytes );
116
115
int err = bz2Support .compress (self .getBzs (), inGuest , len , action , INITIAL_BUFFER_SIZE , compress );
117
116
if (errProfile .profile (err != BZ_OK )) {
118
- errorHandling (err , raiseNode );
117
+ errorHandling (err , getRaiseNode () );
119
118
}
120
119
return getBuffer .execute (self .getBzs (), context );
121
120
}
122
121
123
122
}
124
123
125
- @ GenerateUncached
126
124
public abstract static class Bz2NativeDecompress extends Node {
127
125
128
- public abstract byte [] execute (BZ2Object .BZ2Decompressor self , PythonContext context , byte [] data , int len , int maxLength );
126
+ public abstract byte [] execute (BZ2Object .BZ2Decompressor self , byte [] data , int len , int maxLength );
129
127
130
128
@ Specialization
131
- byte [] nativeDecompress (BZ2Object .BZ2Decompressor self , PythonContext context , byte [] bytes , int len , int maxLength ,
129
+ byte [] nativeDecompress (BZ2Object .BZ2Decompressor self , byte [] bytes , int len , int maxLength ,
132
130
@ Cached Bz2NativeInternalDecompress decompress ) {
133
131
boolean inputBufferInUse ;
134
132
/* Prepend unconsumed input if necessary */
@@ -150,23 +148,23 @@ byte[] nativeDecompress(BZ2Object.BZ2Decompressor self, PythonContext context, b
150
148
* buffer if realloc fails
151
149
*/
152
150
self .resizeInputBuffer (newSize );
153
- self .setNextIn (self .getInputBuffer (), context );
151
+ self .setNextIn (self .getInputBuffer ());
154
152
} else if (availNow < len ) {
155
153
PythonUtils .arraycopy (self .getNextIn (), self .getNextInIndex (), self .getInputBuffer (), 0 , self .getBzsAvailInReal ());
156
- self .setNextIn (self .getInputBuffer (), context );
154
+ self .setNextIn (self .getInputBuffer ());
157
155
self .setNextInIndex (0 );
158
156
}
159
157
PythonUtils .arraycopy (bytes , 0 , self .getNextIn (), self .getNextInIndex () + self .getBzsAvailInReal (), len );
160
158
// memcpy((void*)(bzs->next_in + self.getBzsAvailInReal()), data, len);
161
159
self .incBzsAvailInReal (len );
162
160
inputBufferInUse = true ;
163
161
} else {
164
- self .setNextIn (bytes , context );
162
+ self .setNextIn (bytes );
165
163
self .setBzsAvailInReal (len );
166
164
inputBufferInUse = false ;
167
165
}
168
166
169
- byte [] result = decompress .execute (self , context , maxLength );
167
+ byte [] result = decompress .execute (self , maxLength );
170
168
171
169
if (self .isEOF ()) {
172
170
self .setNeedsInput (false );
@@ -202,7 +200,7 @@ byte[] nativeDecompress(BZ2Object.BZ2Decompressor self, PythonContext context, b
202
200
/* Copy tail */
203
201
// memcpy(d->input_buffer, bzs->next_in, self.getBzsAvailInReal());
204
202
PythonUtils .arraycopy (self .getNextIn (), self .getNextInIndex (), self .getInputBuffer (), 0 , self .getBzsAvailInReal ());
205
- self .setNextIn (self .getInputBuffer (), context );
203
+ self .setNextIn (self .getInputBuffer ());
206
204
self .setNextInIndex (0 );
207
205
}
208
206
}
@@ -211,22 +209,21 @@ byte[] nativeDecompress(BZ2Object.BZ2Decompressor self, PythonContext context, b
211
209
}
212
210
}
213
211
214
- @ GenerateUncached
215
- public abstract static class Bz2NativeInternalDecompress extends Node {
212
+ public abstract static class Bz2NativeInternalDecompress extends PNodeWithRaise {
216
213
217
- public abstract byte [] execute (BZ2Object .BZ2Decompressor self , PythonContext context , int maxLength );
214
+ public abstract byte [] execute (BZ2Object .BZ2Decompressor self , int maxLength );
218
215
219
216
@ Specialization
220
- byte [] nativeInternalDecompress (BZ2Object .BZ2Decompressor self , PythonContext context , int maxLength ,
217
+ byte [] nativeInternalDecompress (BZ2Object .BZ2Decompressor self , int maxLength ,
218
+ @ CachedContext (PythonLanguage .class ) PythonContext context ,
221
219
@ Cached NativeLibrary .InvokeNativeFunction decompress ,
222
220
@ Cached NativeLibrary .InvokeNativeFunction getBzsAvailInReal ,
223
221
@ Cached NativeLibrary .InvokeNativeFunction getNextInIndex ,
224
222
@ Cached GetOutputNativeBufferNode getBuffer ,
225
- @ Cached PRaiseNode raiseNode ,
226
223
@ Cached ConditionProfile errProfile ,
227
224
@ Cached BranchProfile ofProfile ) {
228
225
NFIBz2Support bz2Support = context .getNFIBz2Support ();
229
- Object inGuest = self .getNextInGuest ();
226
+ Object inGuest = self .getNextInGuest (context );
230
227
int offset = self .getNextInIndex ();
231
228
int err = bz2Support .decompress (self .getBzs (), inGuest , offset , maxLength , INITIAL_BUFFER_SIZE , self .getBzsAvailInReal (), decompress );
232
229
long nextInIdx = bz2Support .getNextInIndex (self .getBzs (), getNextInIndex );
@@ -236,35 +233,33 @@ byte[] nativeInternalDecompress(BZ2Object.BZ2Decompressor self, PythonContext co
236
233
self .setBzsAvailInReal (bzsAvailInReal );
237
234
} catch (OverflowException of ) {
238
235
ofProfile .enter ();
239
- raiseNode . raise (SystemError , VALUE_TOO_LARGE_TO_FIT_INTO_INDEX );
236
+ throw raise (SystemError , VALUE_TOO_LARGE_TO_FIT_INTO_INDEX );
240
237
}
241
238
if (err == BZ_STREAM_END ) {
242
239
self .setEOF ();
243
240
} else if (errProfile .profile (err != BZ_OK )) {
244
- errorHandling (err , raiseNode );
241
+ errorHandling (err , getRaiseNode () );
245
242
}
246
243
return getBuffer .execute (self .getBzs (), context );
247
244
}
248
245
}
249
246
250
- @ GenerateUncached
251
- public abstract static class GetOutputNativeBufferNode extends PNodeWithContext {
247
+ public abstract static class GetOutputNativeBufferNode extends PNodeWithRaise {
252
248
253
249
public abstract byte [] execute (Object bzst , PythonContext context );
254
250
255
251
@ Specialization
256
- static byte [] getBuffer (Object bzst , PythonContext context ,
252
+ byte [] getBuffer (Object bzst , PythonContext context ,
257
253
@ Cached NativeLibrary .InvokeNativeFunction getBufferSize ,
258
254
@ Cached NativeLibrary .InvokeNativeFunction getBuffer ,
259
- @ Cached PRaiseNode raiseNode ,
260
255
@ Cached BranchProfile ofProfile ) {
261
256
NFIBz2Support bz2Support = context .getNFIBz2Support ();
262
- int size = 0 ;
257
+ int size ;
263
258
try {
264
259
size = PInt .intValueExact (bz2Support .getOutputBufferSize (bzst , getBufferSize ));
265
260
} catch (OverflowException of ) {
266
261
ofProfile .enter ();
267
- raiseNode . raise (SystemError , VALUE_TOO_LARGE_TO_FIT_INTO_INDEX );
262
+ throw raise (SystemError , VALUE_TOO_LARGE_TO_FIT_INTO_INDEX );
268
263
}
269
264
if (size == 0 ) {
270
265
return PythonUtils .EMPTY_BYTE_ARRAY ;
0 commit comments