Skip to content

Commit 420e449

Browse files
committed
lower truffle boundary
1 parent 65e4d64 commit 420e449

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

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

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -289,30 +289,43 @@ String doGeneric() {
289289
@GenerateNodeFactory
290290
public abstract static class GetHostByAddrNode extends PythonBuiltinNode {
291291
@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());
295294
}
296295

297296
@Specialization
298-
@TruffleBoundary
299-
PTuple doGeneric(String ip_address) {
297+
PTuple doGeneric(VirtualFrame frame, String ip_address) {
300298
try {
301-
InetAddress[] adresses = InetAddress.getAllByName(ip_address);
302-
String hostname = null;
299+
InetAddress[] adresses = getAllAddresses(ip_address);
300+
Object hostname = PNone.NONE;
303301
Object[] strAdresses = new Object[adresses.length];
304302
for (int i = 0; i < adresses.length; i++) {
305303
if (hostname == null) {
306-
hostname = adresses[i].getCanonicalHostName();
304+
hostname = getCanonicalHostName(adresses, i);
307305
}
308-
strAdresses[i] = adresses[i].getHostAddress();
306+
strAdresses[i] = getHostAddress(adresses, i);
309307
}
310308
PList pAdresses = factory().createList(strAdresses);
311309
return factory().createTuple(new Object[]{hostname, factory().createList(), pAdresses});
312310
} catch (UnknownHostException e) {
313-
throw raise(PythonBuiltinClassType.OSError);
311+
throw raiseOSError(frame, OSErrorEnum.EHOSTUNREACH, e);
314312
}
315313
}
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+
}
316329
}
317330

318331
@Builtin(name = "gethostbyname", minNumOfPositionalArgs = 1)

0 commit comments

Comments
 (0)