Skip to content

Commit 3485bd2

Browse files
committed
style and svm fixes
1 parent f99271e commit 3485bd2

File tree

4 files changed

+48
-31
lines changed

4 files changed

+48
-31
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,13 @@ private static String[] cleanLine(String input) {
203203
public abstract static class SocketNode extends PythonBuiltinNode {
204204
@Specialization(guards = {"isNoValue(family)", "isNoValue(type)", "isNoValue(proto)", "isNoValue(fileno)"})
205205
Object socket(LazyPythonClass cls, @SuppressWarnings("unused") PNone family, @SuppressWarnings("unused") PNone type, @SuppressWarnings("unused") PNone proto,
206-
@SuppressWarnings("unused") PNone fileno) {
206+
@SuppressWarnings("unused") PNone fileno) {
207207
return createSocketInternal(cls, PSocket.AF_INET, PSocket.SOCK_STREAM, 0);
208208
}
209209

210210
@Specialization(guards = {"isNoValue(family)", "isNoValue(type)", "isNoValue(proto)", "!isNoValue(fileno)"})
211211
Object socket(VirtualFrame frame, LazyPythonClass cls, @SuppressWarnings("unused") PNone family, @SuppressWarnings("unused") PNone type, @SuppressWarnings("unused") PNone proto, Object fileno,
212-
@Cached CastToIndexNode cast) {
212+
@Cached CastToIndexNode cast) {
213213
return createSocketInternal(frame, cls, -1, -1, -1, cast.execute(fileno));
214214
}
215215

@@ -254,7 +254,8 @@ private Object createSocketInternal(VirtualFrame frame, LazyPythonClass cls, int
254254
if (oldSocket == null) {
255255
throw raiseOSError(frame, OSErrorEnum.EBADF.getNumber());
256256
}
257-
PSocket newSocket = factory().createSocket(cls, family == -1 ? oldSocket.getFamily() : family, type == -1 ? oldSocket.getType() : type, proto == -1 ? oldSocket.getProto() : proto, fileno);
257+
PSocket newSocket = factory().createSocket(cls, family == -1 ? oldSocket.getFamily() : family, type == -1 ? oldSocket.getType() : type, proto == -1 ? oldSocket.getProto() : proto,
258+
fileno);
258259
if (oldSocket.getSocket() != null) {
259260
newSocket.setSocket(oldSocket.getSocket());
260261
} else if (oldSocket.getServerSocket() != null) {
@@ -460,19 +461,19 @@ public abstract static class GetAddrInfoNode extends PythonBuiltinNode {
460461

461462
@Specialization
462463
Object getAddrInfoPString(PString host, Object port, Object family, Object type, Object proto, Object flags,
463-
@Cached CastToIndexNode cast) {
464+
@Cached CastToIndexNode cast) {
464465
return getAddrInfoString(host.getValue(), port, family, type, proto, flags, cast);
465466
}
466467

467468
@Specialization
468469
Object getAddrInfoNone(@SuppressWarnings("unused") PNone host, Object port, Object family, Object type, Object proto, Object flags,
469-
@Cached CastToIndexNode cast) {
470+
@Cached CastToIndexNode cast) {
470471
return getAddrInfoString("localhost", port, family, type, proto, flags, cast);
471472
}
472473

473474
@Specialization
474475
Object getAddrInfoString(String host, Object port, Object family, Object type, Object proto, Object flags,
475-
@Cached CastToIndexNode cast) {
476+
@Cached CastToIndexNode cast) {
476477
String stringPort = null;
477478
if (port instanceof PString) {
478479
stringPort = ((PString) port).getValue();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/ArrayBuiltins.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ Object getitem(PArray self) {
260260
}
261261
}
262262

263-
264263
@Builtin(name = "itemsize", minNumOfPositionalArgs = 1)
265264
@GenerateNodeFactory
266265
abstract static class ItemSizeNode extends PythonUnaryBuiltinNode {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/socket/PSocket.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,18 +155,19 @@ public ServerSocketChannel getServerSocket() {
155155
return serverSocket;
156156
}
157157

158-
public SocketChannel getSocket() { return socket; }
158+
public SocketChannel getSocket() {
159+
return socket;
160+
}
159161

160162
public void setServerSocket(ServerSocketChannel serverSocket) {
161-
if(this.getSocket() != null) {
163+
if (this.getSocket() != null) {
162164
throw new Error();
163165
}
164166
this.serverSocket = serverSocket;
165167
}
166168

167-
public void setSocket(SocketChannel socket)
168-
{
169-
if(this.getServerSocket() != null) {
169+
public void setSocket(SocketChannel socket) {
170+
if (this.getServerSocket() != null) {
170171
throw new Error();
171172
}
172173
this.socket = socket;
@@ -182,13 +183,15 @@ public void setBlocking(boolean blocking) {
182183

183184
@TruffleBoundary
184185
public boolean isOpen() {
185-
return getSocket() != null && getSocket().isOpen();
186+
return (getSocket() != null && getSocket().isOpen()) || (getServerSocket() != null && getServerSocket().isOpen());
186187
}
187188

188189
@TruffleBoundary
189190
public void close() throws IOException {
190191
if (getSocket() != null) {
191192
getSocket().close();
193+
} else if (getServerSocket() != null) {
194+
getServerSocket().close();
192195
}
193196
}
194197

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/socket/SocketBuiltins.java

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ abstract static class AcceptNode extends PythonUnaryBuiltinNode {
9090
Object accept(PSocket socket) {
9191
try {
9292
SocketChannel acceptSocket = socket.getServerSocket().accept();
93-
if (acceptSocket == null){
93+
if (acceptSocket == null) {
9494
throw raise(PythonBuiltinClassType.OSError);
9595
}
9696
SocketAddress addr = acceptSocket.getLocalAddress();
97-
if(!acceptSocket.socket().isBound() || addr == null) {
97+
if (!acceptSocket.socket().isBound() || addr == null) {
9898
throw raise(PythonBuiltinClassType.OSError);
9999
}
100-
PSocket newSocket = factory().createSocket(socket.getFamily(),socket.getType(),socket.getProto());
100+
PSocket newSocket = factory().createSocket(socket.getFamily(), socket.getType(), socket.getProto());
101101
int fd = getContext().getResources().openSocket(newSocket);
102102
newSocket.setFileno(fd);
103103
newSocket.setSocket(acceptSocket);
@@ -118,7 +118,7 @@ abstract static class BindNode extends PythonBinaryBuiltinNode {
118118
Object bind(PSocket socket, PTuple address) {
119119
Object[] hostAndPort = address.getArray();
120120

121-
int port = (int)hostAndPort[1];
121+
int port = (int) hostAndPort[1];
122122

123123
if (port >= 65536 || port < 0) {
124124
throw raise(PythonBuiltinClassType.OverflowError);
@@ -147,8 +147,7 @@ Object close(PSocket socket) {
147147
} catch (IOException e) {
148148
throw raise(PythonBuiltinClassType.OSError, "Bad file descriptor");
149149
}
150-
}
151-
else if (socket.getServerSocket() != null) {
150+
} else if (socket.getServerSocket() != null) {
152151
if (!socket.getServerSocket().isOpen()) {
153152
throw raise(PythonBuiltinClassType.OSError, "Bad file descriptor");
154153
}
@@ -191,7 +190,7 @@ abstract static class GetPeerNameNode extends PythonUnaryBuiltinNode {
191190
@Specialization
192191
@TruffleBoundary
193192
Object get(PSocket socket) {
194-
if (socket.getSocket() == null){
193+
if (socket.getSocket() == null) {
195194
throw raise(PythonBuiltinClassType.OSError, "[Errno 57] Socket is not connected");
196195
}
197196

@@ -220,7 +219,7 @@ Object get(PSocket socket) {
220219
}
221220
}
222221

223-
if (socket.getSocket() != null){
222+
if (socket.getSocket() != null) {
224223
try {
225224
InetSocketAddress addr = (InetSocketAddress) socket.getSocket().getLocalAddress();
226225
return factory().createTuple(new Object[]{addr.getAddress().getHostAddress(), addr.getPort()});
@@ -251,17 +250,27 @@ boolean get(PSocket socket) {
251250
@Builtin(name = "gettimeout", minNumOfPositionalArgs = 1)
252251
@GenerateNodeFactory
253252
abstract static class GetTimeoutNode extends PythonUnaryBuiltinNode {
253+
@TruffleBoundary
254+
private static int getSoTimeout(SocketChannel channel) throws SocketException {
255+
return channel.socket().getSoTimeout();
256+
}
257+
258+
@TruffleBoundary
259+
private static int getSoTimeout(ServerSocketChannel channel) throws IOException {
260+
return channel.socket().getSoTimeout();
261+
}
262+
254263
@Specialization
255264
Object get(PSocket socket) {
256265
try {
257266
if (socket.getSocket() != null) {
258-
socket.getSocket().socket().getSoTimeout();
267+
return getSoTimeout(socket.getSocket());
259268
}
260269

261270
if (socket.getServerSocket() != null) {
262-
socket.getServerSocket().socket().getSoTimeout();
271+
return getSoTimeout(socket.getServerSocket());
263272
}
264-
} catch (Exception e) {
273+
} catch (IOException e) {
265274
throw raise(PythonBuiltinClassType.OSError);
266275
}
267276
return PNone.NONE;
@@ -281,7 +290,8 @@ Object listen(PSocket socket, int backlog) {
281290

282291
ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
283292
// calling bind with port 0 will take the first available
284-
// for some reason this only works on the ServerSocket not on the ServerSocketChannel
293+
// for some reason this only works on the ServerSocket not on the
294+
// ServerSocketChannel
285295
serverSocketChannel.socket().bind(socketAddress, backlog);
286296
serverSocketChannel.configureBlocking(socket.isBlocking());
287297

@@ -305,8 +315,9 @@ Object listen(PSocket socket, PNone backlog) {
305315
abstract static class RecvNode extends PythonTernaryBuiltinNode {
306316
@Specialization
307317
Object recv(PSocket socket, int bufsize, int flags) {
308-
return recv(socket,bufsize,PNone.NONE);
318+
return recv(socket, bufsize, PNone.NONE);
309319
}
320+
310321
@Specialization
311322
@TruffleBoundary
312323
PBytes recv(PSocket socket, int bufsize, PNone flags) {
@@ -329,6 +340,7 @@ abstract static class RecvFromNode extends PythonTernaryBuiltinNode {
329340
Object recvFrom(PSocket socket, int bufsize, int flags) {
330341
return PNotImplemented.NOT_IMPLEMENTED;
331342
}
343+
332344
@Specialization
333345
Object recvFrom(PSocket socket, int bufsize, PNone flags) {
334346
return PNotImplemented.NOT_IMPLEMENTED;
@@ -373,10 +385,12 @@ abstract static class RecvMsgNode extends PythonBuiltinNode {
373385
Object recvFrom(PSocket socket, int bufsize, int ancbufsize, int flags) {
374386
return PNotImplemented.NOT_IMPLEMENTED;
375387
}
388+
376389
@Specialization
377390
Object recvFrom(PSocket socket, int bufsize, int ancbufsize, PNone flags) {
378391
return PNotImplemented.NOT_IMPLEMENTED;
379392
}
393+
380394
@Specialization
381395
Object recvFrom(PSocket socket, int bufsize, PNone ancbufsize, PNone flags) {
382396
return PNotImplemented.NOT_IMPLEMENTED;
@@ -389,7 +403,7 @@ Object recvFrom(PSocket socket, int bufsize, PNone ancbufsize, PNone flags) {
389403
abstract static class SendNode extends PythonTernaryBuiltinNode {
390404
@Specialization
391405
Object send(PSocket socket, PBytes bytes, int flags) {
392-
return send(socket,bytes,PNone.NONE);
406+
return send(socket, bytes, PNone.NONE);
393407
}
394408

395409
@Specialization
@@ -448,6 +462,7 @@ abstract static class SendToNode extends PythonBuiltinNode {
448462
Object sendTo(PSocket socket, Object bytes, int flags, Object address) {
449463
return PNotImplemented.NOT_IMPLEMENTED;
450464
}
465+
451466
@Specialization
452467
Object sendTo(PSocket socket, Object bytes, PNone flags, Object address) {
453468
return PNotImplemented.NOT_IMPLEMENTED;
@@ -509,6 +524,7 @@ Object setTimeout(PSocket socket, Integer value) {
509524

510525
return PNone.NONE;
511526
}
527+
512528
@Specialization
513529
Object setTimeout(PSocket socket, double value) {
514530
Integer intValue = (int) value;
@@ -531,12 +547,10 @@ Object family(PSocket socket, int how) {
531547
if (how == 1 || how == 2) {
532548
socket.getSocket().shutdownOutput();
533549
}
534-
}
535-
catch (IOException e) {
550+
} catch (IOException e) {
536551
throw raise(PythonBuiltinClassType.OSError);
537552
}
538-
}
539-
else {
553+
} else {
540554
throw raise(PythonBuiltinClassType.OSError);
541555
}
542556
return PNone.NO_VALUE;

0 commit comments

Comments
 (0)