Skip to content

Commit a9f82a8

Browse files
committed
[GR-48646][GR-37601] Fixes for typing-extensions and netCDF4
PullRequest: graalpython/2973
2 parents 4c13bfd + c4dc27d commit a9f82a8

File tree

8 files changed

+55
-68
lines changed

8 files changed

+55
-68
lines changed

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/SocketTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,8 @@ private UniversalSockAddr createUsa(FamilySpecificSockAddr src) {
10931093
try {
10941094
return lib.createUniversalSockAddrUnix(posixSupport, unixSockAddr);
10951095
} catch (InvalidUnixSocketPathException e) {
1096-
throw new RuntimeException(e);
1096+
assumeNoException(e);
1097+
return null; // unreachable
10971098
}
10981099
} else {
10991100
throw new AssertionError("Unexpected subclass of FamilySpecificSockAddr: " + src.getClass().getName());

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_unicode.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,14 +422,17 @@ def compile_module(self, name):
422422
)
423423

424424
test_PyUnicode_FromEncodedObject = CPyExtFunction(
425-
lambda args: args[0].decode(args[1], args[2]),
425+
lambda args: bytes(args[0]).decode(args[1], args[2]),
426426
lambda: (
427427
(b"hello", "ascii", "strict"),
428428
("hellö".encode(), "ascii", "strict"),
429429
("hellö".encode(), "ascii", "ignore"),
430430
("hellö".encode(), "ascii", "replace"),
431431
("hellö".encode(), "utf-8", "strict"),
432432
("hellö".encode(), "utf-8", "blah"),
433+
(memoryview(b"hello"), "ascii", "strict"),
434+
(memoryview(b'hell\xc3\xb6'), "utf-8", "strict"),
435+
(memoryview(b'hell\xc3\xb6'), "ascii", "strict"),
433436
),
434437
resultspec="O",
435438
argspec='Oss',

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/PHashingCollection.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -51,6 +51,7 @@ public abstract class PHashingCollection extends PythonBuiltinObject {
5151
public PHashingCollection(Object cls, Shape instanceShape, HashingStorage storage) {
5252
super(cls, instanceShape);
5353
this.storage = storage;
54+
assert storage != null;
5455
}
5556

5657
public final HashingStorage getDictStorage() {
@@ -59,6 +60,7 @@ public final HashingStorage getDictStorage() {
5960

6061
public final void setDictStorage(HashingStorage storage) {
6162
assert storage == this.storage || !(this instanceof PFrozenSet) : "frozenSet is unmodifiable";
63+
assert storage != null;
6264
this.storage = storage;
6365
}
6466
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/PDefaultDict.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -40,7 +40,6 @@
4040
*/
4141
package com.oracle.graal.python.builtins.objects.dict;
4242

43-
import com.oracle.graal.python.PythonLanguage;
4443
import com.oracle.graal.python.builtins.objects.common.HashingStorage;
4544
import com.oracle.graal.python.builtins.objects.function.PKeyword;
4645
import com.oracle.truffle.api.CompilerAsserts;
@@ -49,11 +48,6 @@
4948
public final class PDefaultDict extends PDict {
5049
private Object defaultFactory;
5150

52-
public PDefaultDict(PythonLanguage lang, Object defaultFactory) {
53-
super(lang);
54-
this.defaultFactory = defaultFactory;
55-
}
56-
5751
public PDefaultDict(Object cls, Shape instanceShape, HashingStorage dictStorage, Object defaultFactory) {
5852
super(cls, instanceShape, dictStorage);
5953
this.defaultFactory = defaultFactory;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/PDict.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import static com.oracle.graal.python.nodes.SpecialMethodNames.T_KEYS;
3030
import static com.oracle.graal.python.nodes.SpecialMethodNames.T_VALUES;
3131

32-
import com.oracle.graal.python.PythonLanguage;
3332
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
3433
import com.oracle.graal.python.builtins.objects.common.EconomicMapStorage;
3534
import com.oracle.graal.python.builtins.objects.common.EmptyStorage;
@@ -67,10 +66,6 @@
6766
@ExportLibrary(InteropLibrary.class)
6867
public class PDict extends PHashingCollection {
6968

70-
public PDict(PythonLanguage lang) {
71-
this(PythonBuiltinClassType.PDict, PythonBuiltinClassType.PDict.getInstanceShape(lang));
72-
}
73-
7469
public PDict(Object cls, Shape instanceShape, HashingStorage dictStorage) {
7570
super(ensurePBCT(cls), instanceShape, dictStorage);
7671
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/PythonManagedClass.java

Lines changed: 26 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
import com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol;
3636
import com.oracle.graal.python.builtins.objects.cext.capi.PythonClassNativeWrapper;
3737
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitionsFactory.PythonToNativeNodeGen;
38-
import com.oracle.graal.python.builtins.objects.common.HashingStorage;
39-
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageCopy;
4038
import com.oracle.graal.python.builtins.objects.dict.PDict;
4139
import com.oracle.graal.python.builtins.objects.object.PythonObject;
4240
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
@@ -287,12 +285,6 @@ private void unsafeSetSuperClass(PythonAbstractClass... newBaseClasses) {
287285

288286
@TruffleBoundary
289287
public final void setBases(Object newBaseClass, PythonAbstractClass[] newBaseClasses) {
290-
HashingStorage[] newBasesSubclasses = new HashingStorage[newBaseClasses.length];
291-
for (int i = 0; i < newBaseClasses.length; i++) {
292-
HashingStorage storage = GetSubclassesNode.executeUncached(newBaseClasses[i]).getDictStorage();
293-
newBasesSubclasses[i++] = HashingStorageCopy.executeUncached(storage);
294-
}
295-
296288
Object oldBase = getBase();
297289
PythonAbstractClass[] oldBaseClasses = getBaseClasses();
298290
PythonAbstractClass[] oldMRO = (PythonAbstractClass[]) this.methodResolutionOrder.getInternalArray();
@@ -314,47 +306,13 @@ public final void setBases(Object newBaseClass, PythonAbstractClass[] newBaseCla
314306
this.setMRO(ComputeMroNode.doSlowPath(this));
315307

316308
for (PythonAbstractClass scls : subclassesArray) {
317-
if (scls instanceof PythonManagedClass) {
318-
PythonManagedClass pmc = (PythonManagedClass) scls;
309+
if (scls instanceof PythonManagedClass pmc) {
319310
pmc.methodResolutionOrder.lookupChanged();
320311
pmc.setMRO(ComputeMroNode.doSlowPath(scls));
321312
}
322313
}
323-
324-
boolean isCtxInitialized = PythonContext.get(null).isInitialized();
325-
if (this.baseClasses == newBaseClasses) {
326-
// take no action if bases were replaced through reentrance
327-
for (PythonAbstractClass base : oldBaseClasses) {
328-
if (base instanceof PythonManagedClass) {
329-
if (isCtxInitialized) {
330-
GetSubclassesNode.executeUncached(base).delItem(this);
331-
} else {
332-
// slots aren't populated yet during context initialization
333-
GetSubclassesNode.unsafeRemoveSubclass(base, this);
334-
}
335-
}
336-
}
337-
for (PythonAbstractClass base : newBaseClasses) {
338-
if (base instanceof PythonManagedClass) {
339-
if (isCtxInitialized) {
340-
GetSubclassesNode.executeUncached(base).setItem(this, this);
341-
} else {
342-
// slots aren't populated yet during context initialization
343-
GetSubclassesNode.unsafeAddSubclass(base, this);
344-
}
345-
}
346-
}
347-
}
348-
349314
} catch (PException pe) {
350315
// undo
351-
for (int i = 0; i < newBaseClasses.length; i++) {
352-
PythonAbstractClass base = newBaseClasses[i];
353-
if (base != null) {
354-
PDict dict = GetSubclassesNode.executeUncached(base);
355-
dict.setDictStorage(newBasesSubclasses[i]);
356-
}
357-
}
358316
if (this.baseClasses == newBaseClasses) {
359317
// take no action if bases were replaced through reentrance
360318
// revert only if set in this call
@@ -375,6 +333,31 @@ public final void setBases(Object newBaseClass, PythonAbstractClass[] newBaseCla
375333
}
376334
throw pe;
377335
}
336+
337+
if (this.baseClasses == newBaseClasses) {
338+
// take no action if bases were replaced through reentrance
339+
boolean isCtxInitialized = PythonContext.get(null).isInitialized();
340+
for (PythonAbstractClass base : oldBaseClasses) {
341+
if (base instanceof PythonManagedClass) {
342+
if (isCtxInitialized) {
343+
GetSubclassesNode.executeUncached(base).delItem(this);
344+
} else {
345+
// slots aren't populated yet during context initialization
346+
GetSubclassesNode.unsafeRemoveSubclass(base, this);
347+
}
348+
}
349+
}
350+
for (PythonAbstractClass base : newBaseClasses) {
351+
if (base instanceof PythonManagedClass) {
352+
if (isCtxInitialized) {
353+
GetSubclassesNode.executeUncached(base).setItem(this, this);
354+
} else {
355+
// slots aren't populated yet during context initialization
356+
GetSubclassesNode.unsafeAddSubclass(base, this);
357+
}
358+
}
359+
}
360+
}
378361
}
379362

380363
final PDict getSubClasses() {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyUnicodeFromEncodedObject.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242

4343
import static com.oracle.graal.python.nodes.ErrorMessages.DECODING_STR_NOT_SUPPORTED;
4444
import static com.oracle.graal.python.nodes.StringLiterals.T_EMPTY_STRING;
45-
import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING;
4645

4746
import com.oracle.graal.python.PythonLanguage;
4847
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -54,6 +53,7 @@
5453
import com.oracle.graal.python.nodes.PNodeWithContext;
5554
import com.oracle.graal.python.nodes.PRaiseNode;
5655
import com.oracle.graal.python.runtime.PythonContext;
56+
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
5757
import com.oracle.truffle.api.dsl.Cached;
5858
import com.oracle.truffle.api.dsl.Cached.Exclusive;
5959
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -67,7 +67,6 @@
6767
import com.oracle.truffle.api.nodes.Node;
6868
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
6969
import com.oracle.truffle.api.strings.TruffleString;
70-
import com.oracle.truffle.api.strings.TruffleString.Encoding;
7170

7271
/**
7372
* Equivalent of CPython's {@code PyUnicode_FromEncodedObject}.
@@ -110,21 +109,18 @@ static Object doBuffer(VirtualFrame frame, Node inliningTarget, Object object, O
110109
@Exclusive @Cached InlinedConditionProfile emptyStringProfile,
111110
@CachedLibrary("object") PythonBufferAcquireLibrary bufferAcquireLib,
112111
@Exclusive @Cached PyUnicodeDecode decode,
113-
@CachedLibrary("object") PythonBufferAccessLibrary bufferLib,
114-
@Cached(inline = false) TruffleString.FromByteArrayNode fromByteArrayNode,
115-
@Cached(inline = false) TruffleString.SwitchEncodingNode switchEncodingNode) {
112+
@CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
113+
@Cached(inline = false) PythonObjectFactory factory) {
116114
Object buffer = bufferAcquireLib.acquireReadonly(object, frame, PythonContext.get(inliningTarget), PythonLanguage.get(inliningTarget), indirectCallNode);
117115
try {
118116
int len = bufferLib.getBufferLength(buffer);
119117
if (emptyStringProfile.profile(inliningTarget, len == 0)) {
120118
return T_EMPTY_STRING;
121119
}
122-
// TODO GR-37601: this is probably never executed
123-
TruffleString utf8 = fromByteArrayNode.execute(bufferLib.getInternalOrCopiedByteArray(object), 0, len, Encoding.UTF_8, true);
124-
final TruffleString unicode = switchEncodingNode.execute(utf8, TS_ENCODING);
125-
return decode.execute(frame, inliningTarget, unicode, encoding, errors);
120+
PBytes bytes = factory.createBytes(bufferLib.getInternalOrCopiedByteArray(buffer), len);
121+
return decode.execute(frame, inliningTarget, bytes, encoding, errors);
126122
} finally {
127-
bufferLib.release(object, frame, indirectCallNode);
123+
bufferLib.release(buffer, frame, indirectCallNode);
128124
}
129125
}
130126
}

graalpython/lib-graalpython/patches/scikit-learn/scikit-learn-1.1.3.patch

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,16 @@ index d8206a3..e7b7bf4 100644
1616

1717
# Additional checks for Cython
1818
cython_enable_debug_directives = (
19+
diff --git a/sklearn/datasets/_svmlight_format_fast.pyx b/sklearn/datasets/_svmlight_format_fast.pyx
20+
index 12d222f..89c249a 100644
21+
--- a/sklearn/datasets/_svmlight_format_fast.pyx
22+
+++ b/sklearn/datasets/_svmlight_format_fast.pyx
23+
@@ -84,7 +84,7 @@ def _load_svmlight_file(f, dtype, bint multilabel, bint zero_based,
24+
if n_features and features[0].startswith(qid_prefix):
25+
_, value = features[0].split(COLON, 1)
26+
if query_id:
27+
- query.resize(len(query) + 1)
28+
+ query.resize(len(query) + 1, refcheck=False)
29+
query[len(query) - 1] = np.int64(value)
30+
features.pop(0)
31+
n_features -= 1

0 commit comments

Comments
 (0)