Skip to content

Commit 9a245a1

Browse files
committed
[GR-59936] Support pydantic-core 2.26
PullRequest: graalpython/3585
2 parents 6a199e1 + f068ec4 commit 9a245a1

File tree

12 files changed

+232
-14
lines changed

12 files changed

+232
-14
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,3 +471,16 @@ class TestPyLong(CPyExtTestCase):
471471
arguments=["const char* bytes", "Py_ssize_t size", "int little_endian", "int is_signed"],
472472
cmpfunc=unhandled_error_compare,
473473
)
474+
475+
test__PyLong_NumBits = CPyExtFunction(
476+
lambda args: args[0].bit_length(),
477+
lambda: (
478+
(1,),
479+
(1230948701328090743,),
480+
(-1230948701328090743,),
481+
),
482+
resultspec="n",
483+
argspec="O",
484+
arguments=["PyObject* obj"],
485+
cmpfunc=unhandled_error_compare,
486+
)

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,16 @@ class TestPyUnicode(CPyExtTestCase):
11321132
cmpfunc=unhandled_error_compare,
11331133
)
11341134

1135+
test_PyUnicodeDecodeError_Create = CPyExtFunction(
1136+
lambda args: UnicodeDecodeError(*args),
1137+
lambda: (
1138+
("utf-8", b"asdf", 1, 2, "some reason"),
1139+
),
1140+
resultspec="O",
1141+
argspec="sy#nns",
1142+
arguments=["const char* encoding", "const char* object", "Py_ssize_t length", "Py_ssize_t start", "Py_ssize_t end", "const char* reason"]
1143+
)
1144+
11351145

11361146
class TestUnicodeObject(unittest.TestCase):
11371147
def test_intern(self):

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextLongBuiltins.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,4 +483,13 @@ static Object convert(Object charPtr, long size, int littleEndian, int signed,
483483
return fromByteArray.execute(inliningTarget, bytes, littleEndian != 0, signed != 0);
484484
}
485485
}
486+
487+
@CApiBuiltin(ret = SIZE_T, args = {PyObject}, call = Direct)
488+
abstract static class _PyLong_NumBits extends CApiUnaryBuiltinNode {
489+
@Specialization
490+
static long numBits(Object obj,
491+
@Cached IntBuiltins.BitLengthNode bitLengthNode) {
492+
return bitLengthNode.execute(obj);
493+
}
494+
}
486495
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextUnicodeBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,7 @@ static Object doNull(@SuppressWarnings("unused") PNone noValue) {
11771177
@CApiBuiltin(ret = PyObjectTransfer, args = {ConstCharPtrAsTruffleString, ConstCharPtr, Py_ssize_t, Py_ssize_t, Py_ssize_t, ConstCharPtrAsTruffleString}, call = Direct)
11781178
abstract static class PyUnicodeDecodeError_Create extends CApi6BuiltinNode {
11791179
@Specialization
1180-
static Object doit(Object encoding, Object object, int length, int start, int end, Object reason,
1180+
static Object doit(Object encoding, Object object, long length, long start, long end, Object reason,
11811181
@Bind("this") Node inliningTarget,
11821182
@Cached GetByteArrayNode getByteArrayNode,
11831183
@Cached CallNode callNode,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiFunction.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,6 @@ public final class CApiFunction {
10761076
@CApiBuiltin(name = "_PyLong_GCD", ret = PyObject, args = {PyObject, PyObject}, call = NotImplemented)
10771077
@CApiBuiltin(name = "_PyLong_Lshift", ret = PyObject, args = {PyObject, SIZE_T}, call = NotImplemented)
10781078
@CApiBuiltin(name = "_PyLong_New", ret = PyLongObject, args = {Py_ssize_t}, call = NotImplemented)
1079-
@CApiBuiltin(name = "_PyLong_NumBits", ret = SIZE_T, args = {PyObject}, call = NotImplemented)
10801079
@CApiBuiltin(name = "_PyLong_Rshift", ret = PyObject, args = {PyObject, SIZE_T}, call = NotImplemented)
10811080
@CApiBuiltin(name = "_PyLong_Size_t_Converter", ret = Int, args = {PyObject, Pointer}, call = NotImplemented)
10821081
@CApiBuiltin(name = "_PyLong_UnsignedInt_Converter", ret = Int, args = {PyObject, Pointer}, call = NotImplemented)

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ExternalFunctionNodes.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,13 +1379,18 @@ protected Object[] prepareCArguments(VirtualFrame frame) {
13791379
Object[] args = readVarargsNode.executeObjectArray(frame);
13801380
PKeyword[] kwargs = readKwargsNode.executePKeyword(frame);
13811381
Object[] fastcallArgs = new Object[args.length + kwargs.length];
1382-
Object[] fastcallKwnames = new Object[kwargs.length];
1382+
Object kwnamesTuple = PNone.NO_VALUE;
13831383
PythonUtils.arraycopy(args, 0, fastcallArgs, 0, args.length);
1384-
for (int i = 0; i < kwargs.length; i++) {
1385-
fastcallKwnames[i] = kwargs[i].getName();
1386-
fastcallArgs[args.length + i] = kwargs[i].getValue();
1384+
// Note: PyO3 doesn't like it when we put an empty tuple there if there are no args
1385+
if (kwargs.length > 0) {
1386+
Object[] fastcallKwnames = new Object[kwargs.length];
1387+
for (int i = 0; i < kwargs.length; i++) {
1388+
fastcallKwnames[i] = kwargs[i].getName();
1389+
fastcallArgs[args.length + i] = kwargs[i].getValue();
1390+
}
1391+
kwnamesTuple = factory.createTuple(fastcallKwnames);
13871392
}
1388-
return new Object[]{self, new CPyObjectArrayWrapper(fastcallArgs), args.length, factory.createTuple(fastcallKwnames)};
1393+
return new Object[]{self, new CPyObjectArrayWrapper(fastcallArgs), args.length, kwnamesTuple};
13891394
}
13901395

13911396
@Override

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/CoroutineBuiltins.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
package com.oracle.graal.python.builtins.objects.generator;
4242

4343
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___AWAIT__;
44+
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___REPR__;
4445

4546
import java.util.List;
4647

@@ -49,6 +50,8 @@
4950
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
5051
import com.oracle.graal.python.builtins.PythonBuiltins;
5152
import com.oracle.graal.python.builtins.objects.PNone;
53+
import com.oracle.graal.python.builtins.objects.PythonAbstractObject;
54+
import com.oracle.graal.python.builtins.objects.str.StringUtils.SimpleTruffleStringFormatNode;
5255
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
5356
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
5457
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
@@ -60,6 +63,7 @@
6063
import com.oracle.truffle.api.frame.VirtualFrame;
6164
import com.oracle.truffle.api.nodes.Node;
6265
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
66+
import com.oracle.truffle.api.strings.TruffleString;
6367

6468
@CoreFunctions(extendClasses = PythonBuiltinClassType.PCoroutine)
6569
public final class CoroutineBuiltins extends PythonBuiltins {
@@ -127,4 +131,14 @@ static Object await(PGenerator self,
127131
return factory.createCoroutineWrapper(self);
128132
}
129133
}
134+
135+
@Builtin(name = J___REPR__, minNumOfPositionalArgs = 1)
136+
@GenerateNodeFactory
137+
abstract static class ReprNode extends PythonUnaryBuiltinNode {
138+
@Specialization
139+
static TruffleString repr(PGenerator self,
140+
@Cached SimpleTruffleStringFormatNode simpleTruffleStringFormatNode) {
141+
return simpleTruffleStringFormatNode.format("<coroutine object %s at 0x%d>", self.getQualname(), PythonAbstractObject.objectHashCode(self));
142+
}
143+
}
130144
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/GeneratorBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ abstract static class ReprNode extends PythonUnaryBuiltinNode {
224224
@Specialization
225225
static TruffleString repr(PGenerator self,
226226
@Cached SimpleTruffleStringFormatNode simpleTruffleStringFormatNode) {
227-
return simpleTruffleStringFormatNode.format("<generator object %s at %d>", self.getName(), PythonAbstractObject.objectHashCode(self));
227+
return simpleTruffleStringFormatNode.format("<generator object %s at 0x%d>", self.getQualname(), PythonAbstractObject.objectHashCode(self));
228228
}
229229
}
230230

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3141,7 +3141,9 @@ static int bitCount(PInt i) {
31413141
@Builtin(name = "bit_length", minNumOfPositionalArgs = 1)
31423142
@GenerateNodeFactory
31433143
@TypeSystemReference(PythonArithmeticTypes.class)
3144-
abstract static class BitLengthNode extends PythonBuiltinNode {
3144+
public abstract static class BitLengthNode extends PythonUnaryBuiltinNode {
3145+
public abstract int execute(Object argument);
3146+
31453147
@Specialization
31463148
static int bitLength(int argument) {
31473149
return Integer.SIZE - Integer.numberOfLeadingZeros(Math.abs(argument));

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
import java.util.regex.Matcher;
7676
import java.util.regex.Pattern;
7777

78-
import com.oracle.truffle.api.dsl.Fallback;
7978
import org.graalvm.shadowed.com.ibm.icu.lang.UCharacter;
8079
import org.graalvm.shadowed.com.ibm.icu.lang.UProperty;
8180
import org.graalvm.shadowed.com.ibm.icu.text.CaseMap;
@@ -179,6 +178,7 @@
179178
import com.oracle.truffle.api.dsl.Cached;
180179
import com.oracle.truffle.api.dsl.Cached.Exclusive;
181180
import com.oracle.truffle.api.dsl.Cached.Shared;
181+
import com.oracle.truffle.api.dsl.Fallback;
182182
import com.oracle.truffle.api.dsl.GenerateCached;
183183
import com.oracle.truffle.api.dsl.GenerateInline;
184184
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -263,7 +263,7 @@ private static TruffleString formatString(Node raisingNode, Spec spec, String st
263263
private static Spec getAndValidateSpec(Node inliningTarget, TruffleString formatString, PRaiseNode.Lazy raiseNode) {
264264
Spec spec = InternalFormat.fromText(formatString, 's', '<', inliningTarget);
265265
if (Spec.specified(spec.type) && spec.type != 's') {
266-
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.UNKNOWN_FORMAT_CODE, spec.type, "str");
266+
throw raiseNode.get(inliningTarget).raise(ValueError, ErrorMessages.UNKNOWN_FORMAT_CODE, spec.type, "str");
267267
}
268268
if (Spec.specified(spec.sign)) {
269269
if (spec.sign == ' ') {

0 commit comments

Comments
 (0)