@@ -139,13 +139,13 @@ public class PosixModuleBuiltins extends PythonBuiltins {
139
139
private static final int DSYNC = 4096 ;
140
140
private static final int NDELAY = 2048 ;
141
141
private static final int NONBLOCK = 2048 ;
142
- private static final int APPEND = 1024 ;
143
- private static final int TRUNC = 512 ;
144
- private static final int EXCL = 128 ;
145
- private static final int CREAT = 64 ;
146
- private static final int RDWR = 2 ;
147
- private static final int WRONLY = 1 ;
148
- private static final int RDONLY = 0 ;
142
+ private static final int APPEND = PosixSupportLibrary . O_APPEND ;
143
+ private static final int TRUNC = PosixSupportLibrary . O_TRUNC ;
144
+ private static final int EXCL = PosixSupportLibrary . O_EXCL ;
145
+ private static final int CREAT = PosixSupportLibrary . O_CREAT ;
146
+ private static final int RDWR = PosixSupportLibrary . O_RDWR ;
147
+ private static final int WRONLY = PosixSupportLibrary . O_WRONLY ;
148
+ private static final int RDONLY = PosixSupportLibrary . O_RDONLY ;
149
149
150
150
// TODO map Python's SEEK_SET, SEEK_CUR, SEEK_END values to the underlying OS values if they are
151
151
// different
@@ -434,7 +434,7 @@ static long getSystemUid() {
434
434
@ ArgumentClinic (name = "mode" , conversion = ClinicConversion .Int , defaultValue = "0777" )
435
435
@ ArgumentClinic (name = "dir_fd" , conversionClass = DirFdConversionNode .class )
436
436
@ GenerateNodeFactory
437
- abstract static class OpenNode extends PythonClinicBuiltinNode {
437
+ public abstract static class OpenNode extends PythonClinicBuiltinNode {
438
438
439
439
@ Override
440
440
protected ArgumentClinicProvider getArgumentClinic () {
@@ -466,7 +466,7 @@ int open(VirtualFrame frame, PosixPath path, int flags, int mode, int dirFd,
466
466
@ Builtin (name = "close" , minNumOfPositionalArgs = 1 , parameterNames = {"fd" })
467
467
@ ArgumentClinic (name = "fd" , conversion = ClinicConversion .Int )
468
468
@ GenerateNodeFactory
469
- abstract static class CloseNode extends PythonUnaryClinicBuiltinNode {
469
+ public abstract static class CloseNode extends PythonUnaryClinicBuiltinNode {
470
470
471
471
@ Override
472
472
protected ArgumentClinicProvider getArgumentClinic () {
@@ -489,17 +489,28 @@ PNone close(VirtualFrame frame, int fd,
489
489
@ ArgumentClinic (name = "fd" , conversion = ClinicConversion .Int )
490
490
@ ArgumentClinic (name = "length" , conversion = ClinicConversion .Index )
491
491
@ GenerateNodeFactory
492
- abstract static class ReadNode extends PythonBinaryClinicBuiltinNode {
492
+ public abstract static class ReadNode extends PythonBinaryClinicBuiltinNode {
493
493
494
494
@ Override
495
495
protected ArgumentClinicProvider getArgumentClinic () {
496
496
return PosixModuleBuiltinsClinicProviders .ReadNodeClinicProviderGen .INSTANCE ;
497
497
}
498
498
499
499
@ Specialization
500
- PBytes read (VirtualFrame frame , int fd , int length ,
500
+ PBytes doRead (VirtualFrame frame , int fd , int length ,
501
501
@ CachedLibrary ("getPosixSupport()" ) PosixSupportLibrary posixLib ,
502
502
@ Cached BranchProfile errorProfile ) {
503
+ try {
504
+ return read (frame , fd , length , posixLib , errorProfile );
505
+ } catch (PosixException e ) {
506
+ errorProfile .enter ();
507
+ throw raiseOSErrorFromPosixException (frame , e );
508
+ }
509
+ }
510
+
511
+ public PBytes read (VirtualFrame frame , int fd , int length ,
512
+ PosixSupportLibrary posixLib ,
513
+ BranchProfile errorProfile ) throws PosixException {
503
514
if (length < 0 ) {
504
515
int error = OSErrorEnum .EINVAL .getNumber ();
505
516
throw raiseOSError (frame , error , posixLib .strerror (getPosixSupport (), error ));
@@ -518,7 +529,7 @@ PBytes read(VirtualFrame frame, int fd, int length,
518
529
if (e .getErrorCode () == OSErrorEnum .EINTR .getNumber ()) {
519
530
getContext ().triggerAsyncActions (frame );
520
531
} else {
521
- throw raiseOSErrorFromPosixException ( frame , e ) ;
532
+ throw e ;
522
533
}
523
534
}
524
535
}
@@ -529,17 +540,28 @@ PBytes read(VirtualFrame frame, int fd, int length,
529
540
@ ArgumentClinic (name = "fd" , conversion = ClinicConversion .Int )
530
541
@ ArgumentClinic (name = "data" , conversion = ClinicConversion .Buffer )
531
542
@ GenerateNodeFactory
532
- abstract static class WriteNode extends PythonBinaryClinicBuiltinNode {
543
+ public abstract static class WriteNode extends PythonBinaryClinicBuiltinNode {
533
544
534
545
@ Override
535
546
protected ArgumentClinicProvider getArgumentClinic () {
536
547
return PosixModuleBuiltinsClinicProviders .WriteNodeClinicProviderGen .INSTANCE ;
537
548
}
538
549
539
550
@ Specialization
540
- long write (VirtualFrame frame , int fd , byte [] data ,
551
+ long doWrite (VirtualFrame frame , int fd , byte [] data ,
541
552
@ CachedLibrary ("getPosixSupport()" ) PosixSupportLibrary posixLib ,
542
553
@ Cached BranchProfile errorProfile ) {
554
+ try {
555
+ return write (frame , fd , data , posixLib , errorProfile );
556
+ } catch (PosixException e ) {
557
+ errorProfile .enter ();
558
+ throw raiseOSErrorFromPosixException (frame , e );
559
+ }
560
+ }
561
+
562
+ public long write (VirtualFrame frame , int fd , byte [] data ,
563
+ PosixSupportLibrary posixLib ,
564
+ BranchProfile errorProfile ) throws PosixException {
543
565
while (true ) {
544
566
try {
545
567
return posixLib .write (getPosixSupport (), fd , Buffer .wrap (data ));
@@ -548,7 +570,7 @@ long write(VirtualFrame frame, int fd, byte[] data,
548
570
if (e .getErrorCode () == OSErrorEnum .EINTR .getNumber ()) {
549
571
getContext ().triggerAsyncActions (frame );
550
572
} else {
551
- throw raiseOSErrorFromPosixException ( frame , e ) ;
573
+ throw e ;
552
574
}
553
575
}
554
576
}
@@ -673,7 +695,7 @@ PTuple pipe(VirtualFrame frame,
673
695
@ ArgumentClinic (name = "pos" , conversionClass = OffsetConversionNode .class )
674
696
@ ArgumentClinic (name = "how" , conversion = ClinicConversion .Int )
675
697
@ GenerateNodeFactory
676
- abstract static class LseekNode extends PythonTernaryClinicBuiltinNode {
698
+ public abstract static class LseekNode extends PythonTernaryClinicBuiltinNode {
677
699
678
700
@ Override
679
701
protected ArgumentClinicProvider getArgumentClinic () {
@@ -682,10 +704,12 @@ protected ArgumentClinicProvider getArgumentClinic() {
682
704
683
705
@ Specialization
684
706
long lseek (VirtualFrame frame , int fd , long pos , int how ,
685
- @ CachedLibrary ("getPosixSupport()" ) PosixSupportLibrary posixLib ) {
707
+ @ CachedLibrary ("getPosixSupport()" ) PosixSupportLibrary posixLib ,
708
+ @ Cached BranchProfile errorProfile ) {
686
709
try {
687
710
return posixLib .lseek (getPosixSupport (), fd , pos , how );
688
711
} catch (PosixException e ) {
712
+ errorProfile .enter ();
689
713
throw raiseOSErrorFromPosixException (frame , e );
690
714
}
691
715
}
@@ -695,7 +719,7 @@ long lseek(VirtualFrame frame, int fd, long pos, int how,
695
719
@ ArgumentClinic (name = "fd" , conversion = ClinicConversion .Int )
696
720
@ ArgumentClinic (name = "length" , conversionClass = OffsetConversionNode .class )
697
721
@ GenerateNodeFactory
698
- abstract static class FtruncateNode extends PythonBinaryClinicBuiltinNode {
722
+ public abstract static class FtruncateNode extends PythonBinaryClinicBuiltinNode {
699
723
700
724
@ Override
701
725
protected ArgumentClinicProvider getArgumentClinic () {
0 commit comments