@@ -289,30 +289,43 @@ String doGeneric() {
289
289
@ GenerateNodeFactory
290
290
public abstract static class GetHostByAddrNode extends PythonBuiltinNode {
291
291
@ Specialization
292
- @ TruffleBoundary
293
- PTuple doGeneric (PString ip_address ) {
294
- return doGeneric (ip_address .getValue ());
292
+ PTuple doGeneric (VirtualFrame frame , PString ip_address ) {
293
+ return doGeneric (frame , ip_address .getValue ());
295
294
}
296
295
297
296
@ Specialization
298
- @ TruffleBoundary
299
- PTuple doGeneric (String ip_address ) {
297
+ PTuple doGeneric (VirtualFrame frame , String ip_address ) {
300
298
try {
301
- InetAddress [] adresses = InetAddress . getAllByName (ip_address );
302
- String hostname = null ;
299
+ InetAddress [] adresses = getAllAddresses (ip_address );
300
+ Object hostname = PNone . NONE ;
303
301
Object [] strAdresses = new Object [adresses .length ];
304
302
for (int i = 0 ; i < adresses .length ; i ++) {
305
303
if (hostname == null ) {
306
- hostname = adresses [ i ]. getCanonicalHostName ();
304
+ hostname = getCanonicalHostName (adresses , i );
307
305
}
308
- strAdresses [i ] = adresses [ i ]. getHostAddress ();
306
+ strAdresses [i ] = getHostAddress (adresses , i );
309
307
}
310
308
PList pAdresses = factory ().createList (strAdresses );
311
309
return factory ().createTuple (new Object []{hostname , factory ().createList (), pAdresses });
312
310
} catch (UnknownHostException e ) {
313
- throw raise ( PythonBuiltinClassType . OSError );
311
+ throw raiseOSError ( frame , OSErrorEnum . EHOSTUNREACH , e );
314
312
}
315
313
}
314
+
315
+ @ TruffleBoundary
316
+ private static String getHostAddress (InetAddress [] adresses , int i ) {
317
+ return adresses [i ].getHostAddress ();
318
+ }
319
+
320
+ @ TruffleBoundary
321
+ private static String getCanonicalHostName (InetAddress [] adresses , int i ) {
322
+ return adresses [i ].getCanonicalHostName ();
323
+ }
324
+
325
+ @ TruffleBoundary
326
+ private static InetAddress [] getAllAddresses (String ip_address ) throws UnknownHostException {
327
+ return InetAddress .getAllByName (ip_address );
328
+ }
316
329
}
317
330
318
331
@ Builtin (name = "gethostbyname" , minNumOfPositionalArgs = 1 )
0 commit comments