108
108
import com .oracle .graal .python .runtime .PosixSupportLibrary ;
109
109
import com .oracle .graal .python .runtime .PosixSupportLibrary .AddrInfoCursor ;
110
110
import com .oracle .graal .python .runtime .PosixSupportLibrary .AddrInfoCursorLibrary ;
111
- import com .oracle .graal .python .runtime .PosixSupportLibrary .FamilySpecificSockAddr ;
112
111
import com .oracle .graal .python .runtime .PosixSupportLibrary .GetAddrInfoException ;
113
112
import com .oracle .graal .python .runtime .PosixSupportLibrary .Inet4SockAddr ;
114
113
import com .oracle .graal .python .runtime .PosixSupportLibrary .Inet6SockAddr ;
@@ -276,16 +275,16 @@ TruffleString doGeneric(VirtualFrame frame,
276
275
}
277
276
}
278
277
279
- @ Builtin (name = "gethostbyaddr" , minNumOfPositionalArgs = 1 , numOfPositionalOnlyArgs = 1 , parameterNames = {"ip" })
280
- @ ArgumentClinic (name = "ip" , conversion = ArgumentClinic .ClinicConversion .TString )
278
+ @ Builtin (name = "gethostbyaddr" , minNumOfPositionalArgs = 1 )
281
279
@ GenerateNodeFactory
282
- public abstract static class GetHostByAddrNode extends PythonUnaryClinicBuiltinNode {
280
+ public abstract static class GetHostByAddrNode extends PythonUnaryBuiltinNode {
283
281
@ Specialization
284
- Object doGeneric (VirtualFrame frame , TruffleString ip ,
282
+ Object doGeneric (VirtualFrame frame , Object ip ,
285
283
@ CachedLibrary ("getPosixSupport()" ) PosixSupportLibrary posixLib ,
286
284
@ CachedLibrary (limit = "1" ) AddrInfoCursorLibrary addrInfoCursorLib ,
287
285
@ CachedLibrary (limit = "1" ) UniversalSockAddrLibrary sockAddrLibrary ,
288
286
@ Bind ("this" ) Node inliningTarget ,
287
+ @ Cached ("createIdnaConverter()" ) IdnaFromStringOrBytesConverterNode idnaConverter ,
289
288
@ Cached SocketNodes .SetIpAddrNode setIpAddrNode ,
290
289
@ Cached SequenceStorageNodes .AppendNode appendNode ,
291
290
@ Cached SocketNodes .MakeIpAddrNode makeIpAddrNode ,
@@ -298,7 +297,7 @@ Object doGeneric(VirtualFrame frame, TruffleString ip,
298
297
* might want to use the legacy API in the future
299
298
*/
300
299
auditNode .audit (inliningTarget , "socket.gethostbyaddr" , ip );
301
- UniversalSockAddr addr = setIpAddrNode .execute (frame , ip , AF_UNSPEC .value );
300
+ UniversalSockAddr addr = setIpAddrNode .execute (frame , idnaConverter . execute ( frame , ip ) , AF_UNSPEC .value );
302
301
int family = sockAddrLibrary .getFamily (addr );
303
302
try {
304
303
Object [] getnameinfoResult = posixLib .getnameinfo (getPosixSupport (), addr , NI_NAMEREQD .value );
@@ -333,9 +332,9 @@ Object doGeneric(VirtualFrame frame, TruffleString ip,
333
332
}
334
333
}
335
334
336
- @ Override
337
- protected ArgumentClinicProvider getArgumentClinic () {
338
- return SocketModuleBuiltinsClinicProviders . GetHostByAddrNodeClinicProviderGen . INSTANCE ;
335
+ @ NeverDefault
336
+ protected static IdnaFromStringOrBytesConverterNode createIdnaConverter () {
337
+ return IdnaFromStringOrBytesConverterNode . create ( "gethostbyname" , 1 ) ;
339
338
}
340
339
}
341
340
@@ -352,7 +351,7 @@ TruffleString getHostByName(VirtualFrame frame, Object nameObj,
352
351
@ Cached SocketNodes .SetIpAddrNode setIpAddrNode ,
353
352
@ Cached PConstructAndRaiseNode .Lazy constructAndRaiseNode ,
354
353
@ Cached PythonObjectFactory factory ) {
355
- TruffleString name = idnaConverter .execute (frame , nameObj );
354
+ byte [] name = idnaConverter .execute (frame , nameObj );
356
355
auditNode .audit (inliningTarget , "socket.gethostbyname" , factory .createTuple (new Object []{nameObj }));
357
356
UniversalSockAddr addr = setIpAddrNode .execute (frame , name , AF_INET .value );
358
357
Inet4SockAddr inet4SockAddr = addrLib .asInet4SockAddr (addr );
@@ -464,7 +463,7 @@ Object getServByPort(int port, Object protocolNameObj,
464
463
try {
465
464
gil .release (true );
466
465
try {
467
- UniversalSockAddr addr = posixLib .createUniversalSockAddr (getPosixSupport (), new Inet4SockAddr (port , INADDR_ANY .value ));
466
+ UniversalSockAddr addr = posixLib .createUniversalSockAddrInet4 (getPosixSupport (), new Inet4SockAddr (port , INADDR_ANY .value ));
468
467
int flags = 0 ;
469
468
if (protocolName != null && equalNode .execute (protocolName , T_UDP , TS_ENCODING )) {
470
469
flags |= NI_DGRAM .value ;
@@ -561,19 +560,19 @@ Object getNameInfo(VirtualFrame frame, PTuple sockaddr, int flags,
561
560
gil .acquire ();
562
561
}
563
562
564
- FamilySpecificSockAddr queryAddr ;
563
+ UniversalSockAddr queryAddr ;
565
564
if (family == AF_INET .value ) {
566
565
if (addrLen != 2 ) {
567
566
throw raise (OSError , ErrorMessages .IPV4_MUST_BE_2_TUPLE );
568
567
}
569
- queryAddr = new Inet4SockAddr (port , sockAddrLibrary .asInet4SockAddr (resolvedAddr ).getAddress ());
568
+ queryAddr = posixLib . createUniversalSockAddrInet4 ( getPosixSupport (), new Inet4SockAddr (port , sockAddrLibrary .asInet4SockAddr (resolvedAddr ).getAddress () ));
570
569
} else if (family == AF_INET6 .value ) {
571
- queryAddr = new Inet6SockAddr (port , sockAddrLibrary .asInet6SockAddr (resolvedAddr ).getAddress (), flowinfo , scopeid );
570
+ queryAddr = posixLib . createUniversalSockAddrInet6 ( getPosixSupport (), new Inet6SockAddr (port , sockAddrLibrary .asInet6SockAddr (resolvedAddr ).getAddress (), flowinfo , scopeid ) );
572
571
} else {
573
572
throw raise (OSError , ErrorMessages .UNKNOWN_FAMILY );
574
573
}
575
574
576
- Object [] getnameinfo = posixLib .getnameinfo (getPosixSupport (), posixLib . createUniversalSockAddr ( getPosixSupport (), queryAddr ) , flags );
575
+ Object [] getnameinfo = posixLib .getnameinfo (getPosixSupport (), queryAddr , flags );
577
576
TruffleString host = posixLib .getPathAsString (getPosixSupport (), getnameinfo [0 ]);
578
577
TruffleString service = posixLib .getPathAsString (getPosixSupport (), getnameinfo [1 ]);
579
578
return factory .createTuple (new Object []{host , service });
@@ -620,7 +619,7 @@ Object getAddrInfo(VirtualFrame frame, Object hostObject, Object portObject, int
620
619
@ Cached PythonObjectFactory factory ) {
621
620
Object host = null ;
622
621
if (hostObject != PNone .NONE ) {
623
- host = posixLib .createPathFromString (getPosixSupport (), idna .execute (frame , hostObject ));
622
+ host = posixLib .createPathFromBytes (getPosixSupport (), idna .execute (frame , hostObject ));
624
623
}
625
624
626
625
Object port ;
0 commit comments