60
60
import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
61
61
import com .oracle .graal .python .builtins .PythonBuiltins ;
62
62
import com .oracle .graal .python .builtins .objects .PNone ;
63
+ import com .oracle .graal .python .builtins .objects .common .SequenceStorageNodes ;
63
64
import com .oracle .graal .python .builtins .objects .exception .OSErrorEnum ;
64
65
import com .oracle .graal .python .builtins .objects .ints .PInt ;
65
66
import com .oracle .graal .python .builtins .objects .list .PList ;
69
70
import com .oracle .graal .python .builtins .objects .type .LazyPythonClass ;
70
71
import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
71
72
import com .oracle .graal .python .nodes .function .PythonBuiltinNode ;
72
- import com .oracle .graal .python .nodes .util .CastToIndexNode ;
73
+ import com .oracle .graal .python .nodes .util .CastToJavaIntNode ;
74
+ import com .oracle .graal .python .nodes .util .CastToStringNode ;
73
75
import com .oracle .graal .python .runtime .exception .PythonErrorType ;
74
76
import com .oracle .graal .python .runtime .sequence .storage .SequenceStorage ;
75
77
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
@@ -209,31 +211,31 @@ Object socket(LazyPythonClass cls, @SuppressWarnings("unused") PNone family, @Su
209
211
210
212
@ Specialization (guards = {"isNoValue(family)" , "isNoValue(type)" , "isNoValue(proto)" , "!isNoValue(fileno)" })
211
213
Object socket (VirtualFrame frame , LazyPythonClass cls , @ SuppressWarnings ("unused" ) PNone family , @ SuppressWarnings ("unused" ) PNone type , @ SuppressWarnings ("unused" ) PNone proto , Object fileno ,
212
- @ Cached CastToIndexNode cast ) {
214
+ @ Cached CastToJavaIntNode cast ) {
213
215
return createSocketInternal (frame , cls , -1 , -1 , -1 , cast .execute (fileno ));
214
216
}
215
217
216
218
@ Specialization (guards = {"!isNoValue(family)" , "isNoValue(type)" , "isNoValue(proto)" , "isNoValue(fileno)" })
217
219
Object socket (LazyPythonClass cls , Object family , @ SuppressWarnings ("unused" ) PNone type , @ SuppressWarnings ("unused" ) PNone proto , @ SuppressWarnings ("unused" ) PNone fileno ,
218
- @ Cached CastToIndexNode cast ) {
220
+ @ Cached CastToJavaIntNode cast ) {
219
221
return createSocketInternal (cls , cast .execute (family ), PSocket .SOCK_STREAM , 0 );
220
222
}
221
223
222
224
@ Specialization (guards = {"!isNoValue(family)" , "!isNoValue(type)" , "isNoValue(proto)" , "isNoValue(fileno)" })
223
225
Object socket (LazyPythonClass cls , Object family , Object type , @ SuppressWarnings ("unused" ) PNone proto , @ SuppressWarnings ("unused" ) PNone fileno ,
224
- @ Cached CastToIndexNode cast ) {
226
+ @ Cached CastToJavaIntNode cast ) {
225
227
return createSocketInternal (cls , cast .execute (family ), cast .execute (type ), 0 );
226
228
}
227
229
228
230
@ Specialization (guards = {"!isNoValue(family)" , "!isNoValue(type)" , "!isNoValue(proto)" , "isNoValue(fileno)" })
229
231
Object socket (LazyPythonClass cls , Object family , Object type , Object proto , @ SuppressWarnings ("unused" ) PNone fileno ,
230
- @ Cached CastToIndexNode cast ) {
232
+ @ Cached CastToJavaIntNode cast ) {
231
233
return createSocketInternal (cls , cast .execute (family ), cast .execute (type ), cast .execute (proto ));
232
234
}
233
235
234
236
@ Specialization (guards = {"!isNoValue(family)" , "!isNoValue(type)" , "!isNoValue(proto)" , "!isNoValue(fileno)" })
235
237
Object socket (VirtualFrame frame , LazyPythonClass cls , Object family , Object type , Object proto , Object fileno ,
236
- @ Cached CastToIndexNode cast ) {
238
+ @ Cached CastToJavaIntNode cast ) {
237
239
return createSocketInternal (frame , cls , cast .execute (family ), cast .execute (type ), cast .execute (proto ), cast .execute (fileno ));
238
240
}
239
241
@@ -415,24 +417,24 @@ Object getServByPort(int port, String protocolName) {
415
417
@ GenerateNodeFactory
416
418
public abstract static class GetNameInfoNode extends PythonBuiltinNode {
417
419
@ Specialization
418
- Object getNameInfo (PTuple sockaddr , PInt flags ) {
419
- return getNameInfo ( sockaddr , flags . intValue ());
420
- }
421
-
422
- @ Specialization
423
- @ TruffleBoundary
424
- Object getNameInfo ( PTuple sockaddr , int flags ) {
420
+ Object getNameInfo (VirtualFrame frame , PTuple sockaddr , Object flagArg ,
421
+ @ Cached CastToJavaIntNode castFlags ,
422
+ @ Cached SequenceStorageNodes . LenNode lenNode ,
423
+ @ Cached SequenceStorageNodes . GetItemNode getItem ,
424
+ @ Cached CastToStringNode castAddress ,
425
+ @ Cached CastToJavaIntNode castPort ) {
426
+ int flags = castFlags . execute ( flagArg );
425
427
SequenceStorage addr = sockaddr .getSequenceStorage ();
426
- if (addr .length () != 2 && addr .length () != 4 ) {
428
+ int addLen = lenNode .execute (addr );
429
+ if (addLen != 2 && addLen != 4 ) {
427
430
throw raise (PythonBuiltinClassType .OSError );
428
431
}
429
- String address = ( String ) addr . getItemNormalized ( 0 );
430
- int port = ( int ) addr . getItemNormalized ( 1 );
432
+ String address = castAddress . execute ( frame , getItem . execute ( addr , 0 ) );
433
+ int port = castPort . execute ( getItem . execute ( addr , 1 ) );
431
434
432
435
if ((flags & PSocket .NI_NUMERICHOST ) != PSocket .NI_NUMERICHOST ) {
433
436
try {
434
- InetAddress inetAddress = InetAddress .getByName (address );
435
- address = inetAddress .getHostName ();
437
+ address = getHostName (address );
436
438
} catch (UnknownHostException e ) {
437
439
throw raise (PythonBuiltinClassType .OSError );
438
440
}
@@ -448,6 +450,13 @@ Object getNameInfo(PTuple sockaddr, int flags) {
448
450
449
451
return factory ().createTuple (new Object []{address , portServ });
450
452
}
453
+
454
+ @ TruffleBoundary
455
+ private String getHostName (String address ) throws UnknownHostException {
456
+ InetAddress inetAddress = InetAddress .getByName (address );
457
+ address = inetAddress .getHostName ();
458
+ return address ;
459
+ }
451
460
}
452
461
453
462
@ Builtin (name = "getaddrinfo" , parameterNames = {"host" , "port" , "family" , "type" , "proto" , "flags" })
@@ -459,19 +468,19 @@ public abstract static class GetAddrInfoNode extends PythonBuiltinNode {
459
468
460
469
@ Specialization
461
470
Object getAddrInfoPString (PString host , Object port , Object family , Object type , Object proto , Object flags ,
462
- @ Cached CastToIndexNode cast ) {
471
+ @ Cached CastToJavaIntNode cast ) {
463
472
return getAddrInfoString (host .getValue (), port , family , type , proto , flags , cast );
464
473
}
465
474
466
475
@ Specialization
467
476
Object getAddrInfoNone (@ SuppressWarnings ("unused" ) PNone host , Object port , Object family , Object type , Object proto , Object flags ,
468
- @ Cached CastToIndexNode cast ) {
477
+ @ Cached CastToJavaIntNode cast ) {
469
478
return getAddrInfoString ("localhost" , port , family , type , proto , flags , cast );
470
479
}
471
480
472
481
@ Specialization
473
482
Object getAddrInfoString (String host , Object port , Object family , Object type , Object proto , Object flags ,
474
- @ Cached CastToIndexNode cast ) {
483
+ @ Cached CastToJavaIntNode cast ) {
475
484
String stringPort = null ;
476
485
if (port instanceof PString ) {
477
486
stringPort = ((PString ) port ).getValue ();
0 commit comments