Skip to content

Commit 92c38d5

Browse files
committed
support int-like objects in socket constructor
1 parent 96a370b commit 92c38d5

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@
5353
import com.oracle.graal.python.builtins.objects.type.LazyPythonClass;
5454
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
5555
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
56+
import com.oracle.graal.python.nodes.util.CastToIndexNode;
5657
import com.oracle.graal.python.runtime.exception.PythonErrorType;
5758
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
59+
import com.oracle.truffle.api.dsl.Cached;
5860
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
5961
import com.oracle.truffle.api.dsl.NodeFactory;
6062
import com.oracle.truffle.api.dsl.Specialization;
@@ -77,18 +79,21 @@ Object socket(LazyPythonClass cls, @SuppressWarnings("unused") PNone family, @Su
7779
}
7880

7981
@Specialization(guards = {"isNoValue(type)", "isNoValue(proto)", "isNoValue(fileno)"})
80-
Object socket(LazyPythonClass cls, int family, @SuppressWarnings("unused") PNone type, @SuppressWarnings("unused") PNone proto, @SuppressWarnings("unused") PNone fileno) {
81-
return createSocketInternal(cls, family, PSocket.SOCK_STREAM, 0);
82+
Object socket(LazyPythonClass cls, Object family, @SuppressWarnings("unused") PNone type, @SuppressWarnings("unused") PNone proto, @SuppressWarnings("unused") PNone fileno,
83+
@Cached CastToIndexNode cast) {
84+
return createSocketInternal(cls, cast.execute(family), PSocket.SOCK_STREAM, 0);
8285
}
8386

8487
@Specialization(guards = {"isNoValue(proto)", "isNoValue(fileno)"})
85-
Object socket(LazyPythonClass cls, int family, int type, @SuppressWarnings("unused") PNone proto, @SuppressWarnings("unused") PNone fileno) {
86-
return createSocketInternal(cls, family, type, 0);
88+
Object socket(LazyPythonClass cls, Object family, Object type, @SuppressWarnings("unused") PNone proto, @SuppressWarnings("unused") PNone fileno,
89+
@Cached CastToIndexNode cast) {
90+
return createSocketInternal(cls, cast.execute(family), cast.execute(type), 0);
8791
}
8892

8993
@Specialization(guards = {"isNoValue(fileno)"})
90-
Object socket(LazyPythonClass cls, int family, int type, int proto, @SuppressWarnings("unused") PNone fileno) {
91-
return createSocketInternal(cls, family, type, proto);
94+
Object socket(LazyPythonClass cls, Object family, Object type, Object proto, @SuppressWarnings("unused") PNone fileno,
95+
@Cached CastToIndexNode cast) {
96+
return createSocketInternal(cls, cast.execute(family), cast.execute(type), cast.execute(proto));
9297
}
9398

9499
private Object createSocketInternal(LazyPythonClass cls, int family, int type, int proto) {

0 commit comments

Comments
 (0)