@@ -324,7 +324,7 @@ public static OSErrorInitNode create() {
324
324
}
325
325
}
326
326
327
- @ Builtin (name = "errno" , minNumOfPositionalArgs = 1 , maxNumOfPositionalArgs = 2 , isGetter = true , isSetter = true , doc = "POSIX exception code" )
327
+ @ Builtin (name = "errno" , minNumOfPositionalArgs = 1 , maxNumOfPositionalArgs = 2 , isGetter = true , isSetter = true , allowsDelete = true , doc = "POSIX exception code" )
328
328
@ GenerateNodeFactory
329
329
public abstract static class OSErrorErrnoNode extends PythonBuiltinNode {
330
330
@ Specialization
@@ -334,7 +334,7 @@ Object generic(PBaseException self, Object value,
334
334
}
335
335
}
336
336
337
- @ Builtin (name = "strerror" , minNumOfPositionalArgs = 1 , maxNumOfPositionalArgs = 2 , isGetter = true , isSetter = true , doc = "exception strerror" )
337
+ @ Builtin (name = "strerror" , minNumOfPositionalArgs = 1 , maxNumOfPositionalArgs = 2 , isGetter = true , isSetter = true , allowsDelete = true , doc = "exception strerror" )
338
338
@ GenerateNodeFactory
339
339
public abstract static class OSErrorStrerrorNode extends PythonBuiltinNode {
340
340
@ Specialization
@@ -344,7 +344,7 @@ Object generic(PBaseException self, Object value,
344
344
}
345
345
}
346
346
347
- @ Builtin (name = "filename" , minNumOfPositionalArgs = 1 , maxNumOfPositionalArgs = 2 , isGetter = true , isSetter = true , doc = "exception filename" )
347
+ @ Builtin (name = "filename" , minNumOfPositionalArgs = 1 , maxNumOfPositionalArgs = 2 , isGetter = true , isSetter = true , allowsDelete = true , doc = "exception filename" )
348
348
@ GenerateNodeFactory
349
349
public abstract static class OSErrorFilenameNode extends PythonBuiltinNode {
350
350
@ Specialization
@@ -354,7 +354,7 @@ Object generic(PBaseException self, Object value,
354
354
}
355
355
}
356
356
357
- @ Builtin (name = "filename2" , minNumOfPositionalArgs = 1 , maxNumOfPositionalArgs = 2 , isGetter = true , isSetter = true , doc = "exception filename2" )
357
+ @ Builtin (name = "filename2" , minNumOfPositionalArgs = 1 , maxNumOfPositionalArgs = 2 , isGetter = true , isSetter = true , allowsDelete = true , doc = "exception filename2" )
358
358
@ GenerateNodeFactory
359
359
public abstract static class OSErrorFilename2Node extends PythonBuiltinNode {
360
360
@ Specialization
@@ -364,7 +364,7 @@ Object generic(PBaseException self, Object value,
364
364
}
365
365
}
366
366
367
- @ Builtin (name = "winerror" , os = PythonOS .PLATFORM_WIN32 , minNumOfPositionalArgs = 1 , maxNumOfPositionalArgs = 2 , isGetter = true , isSetter = true , doc = "Win32 exception code" )
367
+ @ Builtin (name = "winerror" , os = PythonOS .PLATFORM_WIN32 , minNumOfPositionalArgs = 1 , maxNumOfPositionalArgs = 2 , isGetter = true , isSetter = true , allowsDelete = true , doc = "Win32 exception code" )
368
368
@ GenerateNodeFactory
369
369
public abstract static class OSErrorWinerrorNode extends PythonBuiltinNode {
370
370
@ Specialization
@@ -374,7 +374,7 @@ Object generic(PBaseException self, Object value,
374
374
}
375
375
}
376
376
377
- @ Builtin (name = "characters_written" , minNumOfPositionalArgs = 1 , maxNumOfPositionalArgs = 2 , isGetter = true , isSetter = true , doc = "exception characters written" )
377
+ @ Builtin (name = "characters_written" , minNumOfPositionalArgs = 1 , maxNumOfPositionalArgs = 2 , isGetter = true , isSetter = true , allowsDelete = true , doc = "exception characters written" )
378
378
@ GenerateNodeFactory
379
379
public abstract static class OSErrorCharsWrittenNode extends PythonBuiltinNode {
380
380
protected boolean isInvalid (PBaseException self ) {
@@ -383,14 +383,20 @@ protected boolean isInvalid(PBaseException self) {
383
383
}
384
384
385
385
@ Specialization (guards = "isInvalid(self)" )
386
+ @ SuppressWarnings ("unused" )
386
387
Object generic (PBaseException self , Object value ) {
387
388
throw raise (PythonBuiltinClassType .AttributeError , "characters_written" );
388
389
}
389
390
390
391
@ Specialization (guards = "!isInvalid(self)" )
391
392
Object generic (PBaseException self , Object value ,
392
393
@ Cached BaseExceptionAttrNode attrNode ) {
393
- return attrNode .execute (self , value , IDX_WRITTEN , OS_ERROR_ATTR_FACTORY );
394
+ final Object retVal = attrNode .execute (self , value , IDX_WRITTEN , OS_ERROR_ATTR_FACTORY );
395
+ if (PGuards .isDeleteMarker (value )) {
396
+ // reset the internal state
397
+ self .getExceptionAttributes ()[IDX_WRITTEN ] = -1 ;
398
+ }
399
+ return retVal ;
394
400
}
395
401
}
396
402
@@ -399,15 +405,16 @@ Object generic(PBaseException self, Object value,
399
405
public abstract static class OSErrorStrNode extends PythonUnaryBuiltinNode {
400
406
@ Specialization
401
407
Object str (VirtualFrame frame , PBaseException self ,
408
+ @ Cached BaseExceptionAttrNode attrNode ,
402
409
@ Cached BaseExceptionBuiltins .StrNode baseStrNode ,
403
410
@ Cached PyObjectReprAsJavaStringNode reprNode ) {
404
411
// TODO: missing windows code
405
- final Object filename = self . getExceptionAttribute ( IDX_FILENAME );
406
- final Object filename2 = self . getExceptionAttribute ( IDX_FILENAME2 );
407
- final Object errno = self . getExceptionAttribute ( IDX_ERRNO );
408
- final Object strerror = self . getExceptionAttribute ( IDX_STRERROR );
409
- if (filename != null && filename != PNone .NONE ) {
410
- if (filename2 != null && filename2 != PNone .NONE ) {
412
+ final Object filename = attrNode . get ( self , IDX_FILENAME , OS_ERROR_ATTR_FACTORY );
413
+ final Object filename2 = attrNode . get ( self , IDX_FILENAME2 , OS_ERROR_ATTR_FACTORY );
414
+ final Object errno = attrNode . get ( self , IDX_ERRNO , OS_ERROR_ATTR_FACTORY );
415
+ final Object strerror = attrNode . get ( self , IDX_STRERROR , OS_ERROR_ATTR_FACTORY );
416
+ if (filename != PNone .NONE ) {
417
+ if (filename2 != PNone .NONE ) {
411
418
return PythonUtils .format ("[Errno %s] %s: %s -> %s" ,
412
419
errno != null ? errno : PNone .NONE ,
413
420
strerror != null ? strerror : PNone .NONE ,
@@ -420,7 +427,7 @@ Object str(VirtualFrame frame, PBaseException self,
420
427
reprNode .execute (frame , filename ));
421
428
}
422
429
}
423
- if (errno != null && strerror != null ) {
430
+ if (errno != PNone . NONE && strerror != PNone . NONE ) {
424
431
return PythonUtils .format ("[Errno %s] %s" , errno , strerror );
425
432
}
426
433
return baseStrNode .execute (frame , self );
@@ -432,13 +439,14 @@ Object str(VirtualFrame frame, PBaseException self,
432
439
public abstract static class OSErrorReduceNode extends PythonUnaryBuiltinNode {
433
440
@ Specialization
434
441
Object reduce (VirtualFrame frame , PBaseException self ,
442
+ @ Cached BaseExceptionAttrNode attrNode ,
435
443
@ Cached GetClassNode getClassNode ,
436
444
@ Cached GetDictIfExistsNode getDictNode ,
437
445
@ Cached SequenceStorageNodes .GetItemNode getItemNode ,
438
446
@ Cached SequenceStorageNodes .LenNode lenNode ) {
439
447
PTuple args = self .getArgs ();
440
- final Object filename = self . getExceptionAttribute ( IDX_FILENAME );
441
- final Object filename2 = self . getExceptionAttribute ( IDX_FILENAME2 );
448
+ final Object filename = attrNode . get ( self , IDX_FILENAME , OS_ERROR_ATTR_FACTORY );
449
+ final Object filename2 = attrNode . get ( self , IDX_FILENAME2 , OS_ERROR_ATTR_FACTORY );
442
450
if (lenNode .execute (args .getSequenceStorage ()) == 2 && filename != null ) {
443
451
Object [] argData = new Object [filename2 != null ? 5 : 3 ];
444
452
argData [0 ] = getItemNode .execute (frame , args .getSequenceStorage (), 0 );
0 commit comments