56
56
import com .oracle .graal .python .builtins .objects .bytes .PBytes ;
57
57
import com .oracle .graal .python .lib .PyNumberAsSizeNode ;
58
58
import com .oracle .graal .python .lib .PyObjectCallMethodObjArgs ;
59
+ import com .oracle .graal .python .nodes .PNodeWithContext ;
59
60
import com .oracle .graal .python .nodes .PNodeWithRaise ;
61
+ import com .oracle .graal .python .nodes .PRaiseNode ;
60
62
import com .oracle .graal .python .nodes .object .BuiltinClassProfiles .IsBuiltinObjectProfile ;
61
63
import com .oracle .graal .python .runtime .exception .PException ;
62
64
import com .oracle .graal .python .runtime .object .PythonObjectFactory ;
63
65
import com .oracle .graal .python .util .PythonUtils ;
64
66
import com .oracle .truffle .api .dsl .Bind ;
65
67
import com .oracle .truffle .api .dsl .Cached ;
68
+ import com .oracle .truffle .api .dsl .GenerateCached ;
69
+ import com .oracle .truffle .api .dsl .GenerateInline ;
66
70
import com .oracle .truffle .api .dsl .Specialization ;
67
71
import com .oracle .truffle .api .frame .VirtualFrame ;
68
72
import com .oracle .truffle .api .library .CachedLibrary ;
@@ -79,16 +83,16 @@ private static void adjustPosition(PBuffered self, int newPos) {
79
83
80
84
abstract static class WriteNode extends PNodeWithRaise {
81
85
82
- public abstract int execute (VirtualFrame frame , PBuffered self , Object buffer );
86
+ public abstract int execute (VirtualFrame frame , Node inliningTarget , PBuffered self , Object buffer );
83
87
84
88
/**
85
89
* implementation of cpython/Modules/_io/bufferedio.c:_io_BufferedWriter_write_impl
86
90
*/
87
91
@ Specialization
88
- static int bufferedWriterWrite (VirtualFrame frame , PBuffered self , Object buffer ,
92
+ static int bufferedWriterWrite (VirtualFrame frame , @ SuppressWarnings ( "unused" ) Node ignored , PBuffered self , Object buffer ,
89
93
@ Bind ("this" ) Node inliningTarget ,
90
94
@ CachedLibrary (limit = "3" ) PythonBufferAccessLibrary bufferLib ,
91
- @ Cached AbstractBufferedIOBuiltins .RaiseBlockingIOError raiseBlockingIOError ,
95
+ @ Cached AbstractBufferedIOBuiltins .LazyRaiseBlockingIOError raiseBlockingIOError ,
92
96
@ Cached IsBuiltinObjectProfile isBuiltinClassProfile ,
93
97
@ Cached BufferedIONodes .RawSeekNode rawSeekNode ,
94
98
@ Cached RawWriteNode rawWriteNode ,
@@ -118,7 +122,7 @@ static int bufferedWriterWrite(VirtualFrame frame, PBuffered self, Object buffer
118
122
119
123
/* First write the current buffer */
120
124
try {
121
- flushUnlockedNode .execute (frame , self );
125
+ flushUnlockedNode .execute (frame , inliningTarget , self );
122
126
} catch (PException e ) {
123
127
e .expect (inliningTarget , BlockingIOError , isBuiltinClassProfile );
124
128
if (self .isReadable ()) {
@@ -150,7 +154,7 @@ static int bufferedWriterWrite(VirtualFrame frame, PBuffered self, Object buffer
150
154
* error.
151
155
*/
152
156
Object errno = e .getUnreifiedException ().getArgs ().getSequenceStorage ().getItemNormalized (0 );
153
- throw raiseBlockingIOError .raise (errno , WRITE_COULD_NOT_COMPLETE_WITHOUT_BLOCKING , avail );
157
+ throw raiseBlockingIOError .get ( inliningTarget ). raise (errno , WRITE_COULD_NOT_COMPLETE_WITHOUT_BLOCKING , avail );
154
158
}
155
159
/*
156
160
* Adjust the raw stream position if it is away from the logical stream position. This
@@ -171,15 +175,15 @@ static int bufferedWriterWrite(VirtualFrame frame, PBuffered self, Object buffer
171
175
// TODO use memoryview
172
176
byte [] buf = new byte [bufLen ];
173
177
bufferLib .readIntoByteArray (buffer , written , buf , 0 , bufLen - written );
174
- int n = rawWriteNode .execute (frame , self , buf , bufLen - written );
178
+ int n = rawWriteNode .execute (frame , inliningTarget , self , buf , bufLen - written );
175
179
if (n == -2 ) {
176
180
if (remaining > self .getBufferSize ()) {
177
181
bufferLib .readIntoByteArray (buffer , written , self .getBuffer (), 0 , self .getBufferSize ());
178
182
self .setRawPos (0 );
179
183
adjustPosition (self , self .getBufferSize ());
180
184
self .setWriteEnd (self .getBufferSize ());
181
185
written += self .getBufferSize ();
182
- throw raiseBlockingIOError .raiseEWOULDBLOCK (WRITE_COULD_NOT_COMPLETE_WITHOUT_BLOCKING , written );
186
+ throw raiseBlockingIOError .get ( inliningTarget ). raiseEWOULDBLOCK (WRITE_COULD_NOT_COMPLETE_WITHOUT_BLOCKING , written );
183
187
}
184
188
break ;
185
189
}
@@ -205,18 +209,21 @@ static int bufferedWriterWrite(VirtualFrame frame, PBuffered self, Object buffer
205
209
}
206
210
}
207
211
208
- abstract static class RawWriteNode extends PNodeWithRaise {
212
+ @ GenerateInline
213
+ @ GenerateCached (false )
214
+ abstract static class RawWriteNode extends PNodeWithContext {
209
215
210
- public abstract int execute (VirtualFrame frame , PBuffered self , byte [] buf , int len );
216
+ public abstract int execute (VirtualFrame frame , Node inliningTarget , PBuffered self , byte [] buf , int len );
211
217
212
218
/**
213
219
* implementation of cpython/Modules/_io/bufferedio.c:_bufferedwriter_raw_write
214
220
*/
215
221
@ Specialization
216
- int bufferedwriterRawWrite (VirtualFrame frame , PBuffered self , byte [] buf , int len ,
217
- @ Cached PythonObjectFactory factory ,
218
- @ Cached PyObjectCallMethodObjArgs callMethod ,
219
- @ Cached PyNumberAsSizeNode asSizeNode ) {
222
+ static int bufferedwriterRawWrite (VirtualFrame frame , Node inliningTarget , PBuffered self , byte [] buf , int len ,
223
+ @ Cached (inline = false ) PythonObjectFactory factory ,
224
+ @ Cached (inline = false ) PyObjectCallMethodObjArgs callMethod ,
225
+ @ Cached (inline = false ) PyNumberAsSizeNode asSizeNode ,
226
+ @ Cached PRaiseNode .Lazy lazyRaiseNode ) {
220
227
PBytes memobj = factory .createBytes (buf , len );
221
228
Object res = callMethod .execute (frame , self .getRaw (), T_WRITE , memobj );
222
229
if (res == PNone .NONE ) {
@@ -227,7 +234,7 @@ int bufferedwriterRawWrite(VirtualFrame frame, PBuffered self, byte[] buf, int l
227
234
}
228
235
int n = asSizeNode .executeExact (frame , res , ValueError );
229
236
if (n < 0 || n > len ) {
230
- throw raise (OSError , IO_S_INVALID_LENGTH , "write()" , n , len );
237
+ throw lazyRaiseNode . get ( inliningTarget ). raise (OSError , IO_S_INVALID_LENGTH , "write()" , n , len );
231
238
}
232
239
if (n > 0 && self .getAbsPos () != -1 ) {
233
240
self .incAbsPos (n );
@@ -236,17 +243,18 @@ int bufferedwriterRawWrite(VirtualFrame frame, PBuffered self, byte[] buf, int l
236
243
}
237
244
}
238
245
239
- abstract static class FlushUnlockedNode extends PNodeWithRaise {
246
+ @ GenerateInline
247
+ @ GenerateCached (false )
248
+ abstract static class FlushUnlockedNode extends PNodeWithContext {
240
249
241
- public abstract void execute (VirtualFrame frame , PBuffered self );
250
+ public abstract void execute (VirtualFrame frame , Node inliningTarget , PBuffered self );
242
251
243
252
/**
244
253
* implementation of cpython/Modules/_io/bufferedio.c:_bufferedwriter_flush_unlocked
245
254
*/
246
255
@ Specialization
247
- protected static void bufferedwriterFlushUnlocked (VirtualFrame frame , PBuffered self ,
248
- @ Bind ("this" ) Node inliningTarget ,
249
- @ Cached AbstractBufferedIOBuiltins .RaiseBlockingIOError raiseBlockingIOError ,
256
+ protected static void bufferedwriterFlushUnlocked (VirtualFrame frame , Node inliningTarget , PBuffered self ,
257
+ @ Cached AbstractBufferedIOBuiltins .LazyRaiseBlockingIOError raiseBlockingIOError ,
250
258
@ Cached RawWriteNode rawWriteNode ,
251
259
@ Cached BufferedIONodes .RawSeekNode rawSeekNode ) {
252
260
if (!isValidWriteBuffer (self ) || self .getWritePos () == self .getWriteEnd ()) {
@@ -261,9 +269,9 @@ protected static void bufferedwriterFlushUnlocked(VirtualFrame frame, PBuffered
261
269
}
262
270
while (self .getWritePos () < self .getWriteEnd ()) {
263
271
byte [] buf = PythonUtils .arrayCopyOfRange (self .getBuffer (), self .getWritePos (), self .getWriteEnd ());
264
- int n = rawWriteNode .execute (frame , self , buf , buf .length );
272
+ int n = rawWriteNode .execute (frame , inliningTarget , self , buf , buf .length );
265
273
if (n == -2 ) {
266
- throw raiseBlockingIOError .raiseEAGAIN (WRITE_COULD_NOT_COMPLETE_WITHOUT_BLOCKING , 0 );
274
+ throw raiseBlockingIOError .get ( inliningTarget ). raiseEAGAIN (WRITE_COULD_NOT_COMPLETE_WITHOUT_BLOCKING , 0 );
267
275
}
268
276
self .incWritePos (n );
269
277
self .setRawPos (self .getWritePos ());
0 commit comments