Skip to content

Commit 05ef6b9

Browse files
committed
Make O_* constants optional when they should be
1 parent 520a021 commit 05ef6b9

File tree

5 files changed

+29
-27
lines changed

5 files changed

+29
-27
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,10 @@ int open(VirtualFrame frame, PosixPath path, int flags, int mode, int dirFd,
603603
@Cached SysModuleBuiltins.AuditNode auditNode,
604604
@Cached BranchProfile errorProfile,
605605
@Cached GilNode gil) {
606-
int fixedFlags = flags | O_CLOEXEC.value;
606+
int fixedFlags = flags;
607+
if (O_CLOEXEC.defined) {
608+
fixedFlags |= O_CLOEXEC.getValueIfDefined();
609+
}
607610
auditNode.audit("open", path.originalObject, PNone.NONE, fixedFlags);
608611
gil.release(true);
609612
try {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/EmulatedPosixSupport.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@
7777
import static com.oracle.graal.python.runtime.PosixConstants.NI_NAMEREQD;
7878
import static com.oracle.graal.python.runtime.PosixConstants.NI_NUMERICHOST;
7979
import static com.oracle.graal.python.runtime.PosixConstants.NI_NUMERICSERV;
80-
import static com.oracle.graal.python.runtime.PosixConstants.O_ACCMODE;
8180
import static com.oracle.graal.python.runtime.PosixConstants.O_APPEND;
8281
import static com.oracle.graal.python.runtime.PosixConstants.O_CREAT;
8382
import static com.oracle.graal.python.runtime.PosixConstants.O_DIRECT;
@@ -4168,7 +4167,7 @@ private static Set<PosixFilePermission> modeToPosixFilePermissions(int fileMode)
41684167
@TruffleBoundary(allowInlining = true)
41694168
private static Set<StandardOpenOption> flagsToOptions(int flags) {
41704169
Set<StandardOpenOption> options = new HashSet<>();
4171-
int maskedFlags = flags & O_ACCMODE.value;
4170+
int maskedFlags = flags & (O_RDONLY.value | O_WRONLY.value | O_RDWR.value);
41724171
if ((flags & O_APPEND.value) != 0) {
41734172
options.add(StandardOpenOption.WRITE);
41744173
options.add(StandardOpenOption.APPEND);
@@ -4197,10 +4196,10 @@ private static Set<StandardOpenOption> flagsToOptions(int flags) {
41974196
options.add(StandardOpenOption.WRITE);
41984197
options.add(StandardOpenOption.CREATE_NEW);
41994198
}
4200-
if ((flags & O_NDELAY.value) != 0 || (O_DIRECT.defined && (flags & O_DIRECT.getValueIfDefined()) != 0)) {
4199+
if ((O_NDELAY.defined && (flags & O_NDELAY.getValueIfDefined()) != 0) || (O_DIRECT.defined && (flags & O_DIRECT.getValueIfDefined()) != 0)) {
42014200
options.add(StandardOpenOption.DSYNC);
42024201
}
4203-
if ((flags & O_SYNC.value) != 0) {
4202+
if (O_SYNC.defined && (flags & O_SYNC.getValueIfDefined()) != 0) {
42044203
options.add(StandardOpenOption.SYNC);
42054204
}
42064205
if ((flags & O_TRUNC.value) != 0) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PosixConstants.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,20 @@ public final class PosixConstants {
9797
public static final OptionalIntConstant SEEK_HOLE;
9898
public static final MandatoryIntConstant SOMAXCONN;
9999
public static final OptionalIntConstant PIPE_BUF;
100-
public static final MandatoryIntConstant O_ACCMODE;
100+
public static final OptionalIntConstant O_ACCMODE;
101101
public static final MandatoryIntConstant O_RDONLY;
102102
public static final MandatoryIntConstant O_WRONLY;
103103
public static final MandatoryIntConstant O_RDWR;
104104
public static final MandatoryIntConstant O_CREAT;
105105
public static final MandatoryIntConstant O_EXCL;
106106
public static final MandatoryIntConstant O_TRUNC;
107107
public static final MandatoryIntConstant O_APPEND;
108-
public static final MandatoryIntConstant O_NONBLOCK;
109-
public static final MandatoryIntConstant O_NOCTTY;
110-
public static final MandatoryIntConstant O_NDELAY;
111-
public static final MandatoryIntConstant O_DSYNC;
112-
public static final MandatoryIntConstant O_CLOEXEC;
113-
public static final MandatoryIntConstant O_SYNC;
108+
public static final OptionalIntConstant O_NONBLOCK;
109+
public static final OptionalIntConstant O_NOCTTY;
110+
public static final OptionalIntConstant O_NDELAY;
111+
public static final OptionalIntConstant O_DSYNC;
112+
public static final OptionalIntConstant O_CLOEXEC;
113+
public static final OptionalIntConstant O_SYNC;
114114
public static final OptionalIntConstant O_DIRECT;
115115
public static final OptionalIntConstant O_RSYNC;
116116
public static final OptionalIntConstant O_TMPFILE;
@@ -351,20 +351,20 @@ public final class PosixConstants {
351351
SEEK_HOLE = reg.createOptionalInt("SEEK_HOLE");
352352
SOMAXCONN = reg.createMandatoryInt("SOMAXCONN");
353353
PIPE_BUF = reg.createOptionalInt("PIPE_BUF");
354-
O_ACCMODE = reg.createMandatoryInt("O_ACCMODE");
354+
O_ACCMODE = reg.createOptionalInt("O_ACCMODE");
355355
O_RDONLY = reg.createMandatoryInt("O_RDONLY");
356356
O_WRONLY = reg.createMandatoryInt("O_WRONLY");
357357
O_RDWR = reg.createMandatoryInt("O_RDWR");
358358
O_CREAT = reg.createMandatoryInt("O_CREAT");
359359
O_EXCL = reg.createMandatoryInt("O_EXCL");
360360
O_TRUNC = reg.createMandatoryInt("O_TRUNC");
361361
O_APPEND = reg.createMandatoryInt("O_APPEND");
362-
O_NONBLOCK = reg.createMandatoryInt("O_NONBLOCK");
363-
O_NOCTTY = reg.createMandatoryInt("O_NOCTTY");
364-
O_NDELAY = reg.createMandatoryInt("O_NDELAY");
365-
O_DSYNC = reg.createMandatoryInt("O_DSYNC");
366-
O_CLOEXEC = reg.createMandatoryInt("O_CLOEXEC");
367-
O_SYNC = reg.createMandatoryInt("O_SYNC");
362+
O_NONBLOCK = reg.createOptionalInt("O_NONBLOCK");
363+
O_NOCTTY = reg.createOptionalInt("O_NOCTTY");
364+
O_NDELAY = reg.createOptionalInt("O_NDELAY");
365+
O_DSYNC = reg.createOptionalInt("O_DSYNC");
366+
O_CLOEXEC = reg.createOptionalInt("O_CLOEXEC");
367+
O_SYNC = reg.createOptionalInt("O_SYNC");
368368
O_DIRECT = reg.createOptionalInt("O_DIRECT");
369369
O_RSYNC = reg.createOptionalInt("O_RSYNC");
370370
O_TMPFILE = reg.createOptionalInt("O_TMPFILE");

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PosixConstantsLinux.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
*/
4141
package com.oracle.graal.python.runtime;
4242

43-
// Auto generated by gen_native_cfg.py at 2023-03-16 16:22:03.201868
43+
// Auto generated by gen_native_cfg.py at 2023-03-17 10:24:55.349775
4444
// on Linux arisu 6.1.18-200.fc37.x86_64 #1 SMP PREEMPT_DYNAMIC Sat Mar 11 16:09:14 UTC 2023 x86_64 x86_64
4545
class PosixConstantsLinux {
4646

scripts/gen_native_cfg.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,20 +142,20 @@
142142
* i PIPE_BUF
143143
144144
[openFlags]
145-
0 x O_ACCMODE
145+
* x O_ACCMODE
146146
x O_RDONLY
147147
x O_WRONLY
148148
x O_RDWR
149149
x O_CREAT
150150
x O_EXCL
151151
x O_TRUNC
152152
x O_APPEND
153-
0 x O_NONBLOCK
154-
0 x O_NOCTTY
155-
0 x O_NDELAY
156-
0 x O_DSYNC
157-
0 x O_CLOEXEC
158-
0 x O_SYNC
153+
* x O_NONBLOCK
154+
* x O_NOCTTY
155+
* x O_NDELAY
156+
* x O_DSYNC
157+
* x O_CLOEXEC
158+
* x O_SYNC
159159
* x O_DIRECT
160160
* x O_RSYNC
161161
* x O_TMPFILE

0 commit comments

Comments
 (0)