Skip to content

Commit cb3c1ac

Browse files
committed
[GR-49943] Fixes for pymongo
PullRequest: graalpython/3068
2 parents 539cacb + 6d03269 commit cb3c1ac

File tree

5 files changed

+69
-0
lines changed

5 files changed

+69
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ protected List<com.oracle.truffle.api.dsl.NodeFactory<? extends PythonBuiltinNod
6060
@Override
6161
public void initialize(Python3Core core) {
6262
addBuiltinConstant("DEBUG_LEAK", 0);
63+
addBuiltinConstant("DEBUG_UNCOLLECTABLE", 0);
6364
super.initialize(core);
6465
}
6566

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import static com.oracle.graal.python.runtime.PosixConstants.AF_INET;
5555
import static com.oracle.graal.python.runtime.PosixConstants.AF_INET6;
5656
import static com.oracle.graal.python.runtime.PosixConstants.AF_UNSPEC;
57+
import static com.oracle.graal.python.runtime.PosixConstants.AI_CANONNAME;
5758
import static com.oracle.graal.python.runtime.PosixConstants.AI_NUMERICHOST;
5859
import static com.oracle.graal.python.runtime.PosixConstants.INADDR_ANY;
5960
import static com.oracle.graal.python.runtime.PosixConstants.NI_DGRAM;
@@ -80,6 +81,7 @@
8081
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
8182
import com.oracle.graal.python.builtins.objects.exception.OSErrorEnum;
8283
import com.oracle.graal.python.builtins.objects.function.PKeyword;
84+
import com.oracle.graal.python.builtins.objects.list.PList;
8385
import com.oracle.graal.python.builtins.objects.module.PythonModule;
8486
import com.oracle.graal.python.builtins.objects.socket.SocketNodes;
8587
import com.oracle.graal.python.builtins.objects.socket.SocketNodes.IdnaFromStringOrBytesConverterNode;
@@ -371,6 +373,55 @@ protected static IdnaFromStringOrBytesConverterNode createIdnaConverter() {
371373
}
372374
}
373375

376+
@Builtin(name = "gethostbyname_ex", minNumOfPositionalArgs = 1)
377+
@GenerateNodeFactory
378+
public abstract static class GetHostByNameExNode extends PythonUnaryBuiltinNode {
379+
@Specialization
380+
Object get(VirtualFrame frame, Object nameObj,
381+
@CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
382+
@CachedLibrary(limit = "1") UniversalSockAddrLibrary addrLib,
383+
@CachedLibrary(limit = "1") AddrInfoCursorLibrary addrInfoCursorLib,
384+
@Bind("this") Node inliningTarget,
385+
@Cached("createIdnaConverter()") IdnaFromStringOrBytesConverterNode idnaConverter,
386+
@Cached SysModuleBuiltins.AuditNode auditNode,
387+
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
388+
@Cached PythonObjectFactory factory) {
389+
byte[] name = idnaConverter.execute(frame, nameObj);
390+
// The event name is really without the _ex, it's not a copy-paste error
391+
auditNode.audit(inliningTarget, "socket.gethostbyname", factory.createTuple(new Object[]{nameObj}));
392+
/*
393+
* TODO this uses getaddrinfo to emulate the legacy gethostbyname. It doesn't support
394+
* aliases and multiple addresses. We might want to use the legacy gethostbyname_r API
395+
* in the future
396+
*/
397+
try {
398+
AddrInfoCursor cursor = posixLib.getaddrinfo(getPosixSupport(), posixLib.createPathFromBytes(getPosixSupport(), name),
399+
null, AF_INET.value, 0, 0, AI_CANONNAME.value);
400+
try {
401+
TruffleString canonName = posixLib.getPathAsString(getPosixSupport(), addrInfoCursorLib.getCanonName(cursor));
402+
Inet4SockAddr inet4SockAddr = addrLib.asInet4SockAddr(addrInfoCursorLib.getSockAddr(cursor));
403+
TruffleString addr = posixLib.getPathAsString(getPosixSupport(), posixLib.inet_ntop(getPosixSupport(), AF_INET.value, inet4SockAddr.getAddressAsBytes()));
404+
// getaddrinfo doesn't support aliases
405+
PList aliases = factory.createList();
406+
// we support just one address for now
407+
PList addrs = factory.createList(new Object[]{addr});
408+
return factory.createTuple(new Object[]{canonName, aliases, addrs});
409+
} finally {
410+
addrInfoCursorLib.release(cursor);
411+
}
412+
} catch (GetAddrInfoException e) {
413+
throw constructAndRaiseNode.get(inliningTarget).executeWithArgsOnly(frame, SocketHError, new Object[]{e.getMessageAsTruffleString()});
414+
} catch (PosixException e) {
415+
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
416+
}
417+
}
418+
419+
@NeverDefault
420+
protected static IdnaFromStringOrBytesConverterNode createIdnaConverter() {
421+
return IdnaFromStringOrBytesConverterNode.create("gethostbyname_ex", 1);
422+
}
423+
}
424+
374425
@Builtin(name = "getservbyname", minNumOfPositionalArgs = 1, numOfPositionalOnlyArgs = 2, parameterNames = {"servicename", "protocolname"})
375426
@ArgumentClinic(name = "servicename", conversion = ArgumentClinic.ClinicConversion.TString)
376427
@ArgumentClinic(name = "protocolname", conversion = ArgumentClinic.ClinicConversion.TString, defaultValue = "PNone.NO_VALUE")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[[rules]]
2+
patch = 'pymongo.patch'
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/setup.py b/setup.py
2+
index a711e24..84d3aea 100644
3+
--- a/setup.py
4+
+++ b/setup.py
5+
@@ -125,7 +125,7 @@ if "--no_ext" in sys.argv or os.environ.get("NO_EXT"):
6+
except ValueError:
7+
pass
8+
ext_modules = []
9+
-elif sys.platform.startswith("java") or sys.platform == "cli" or "PyPy" in sys.version:
10+
+elif sys.platform.startswith("java") or sys.platform == "cli" or "PyPy" in sys.version or sys.implementation.name == 'graalpy':
11+
sys.stdout.write(
12+
"""
13+
*****************************************************\n

mx.graalpython/mx_graalpython.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,6 +2040,8 @@ def _python_checkpatchfiles():
20402040
'wheel-pre-0.35.patch',
20412041
# Empty license field. It's ASL 2.0 or BSD 2-Clause
20422042
'packaging.patch',
2043+
# pymongo puts the whole license in the field. It's ASL 2.0
2044+
'pymongo.patch',
20432045
# Empty license field. It's ASL 2.0
20442046
'tokenizers-0.13.3.patch',
20452047
# Empty license field. It's Apache 2

0 commit comments

Comments
 (0)