Skip to content

Commit 67d8bf3

Browse files
committed
[GR-45741][GR-44293] Add patches for lazy-object-proxy and grpcio
PullRequest: graalpython/2743
2 parents 5b8b07b + ca32a73 commit 67d8bf3

File tree

12 files changed

+123
-177
lines changed

12 files changed

+123
-177
lines changed

ci.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "overlay": "611cf7e3305ab126110f20f214e055abbbb1df54" }
1+
{ "overlay": "8420cf6f76e0b00296fe95aab7cbdeedb17a9994" }

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,8 @@ private static void initCodecClasses(PythonModule codecsTruffleModule, PythonMod
256256
// return _codecs.__truffle_decode__(input, self.encoding, errors, True)
257257
codecsTruffleBuiltins.truffleCodecClass = initClass(T_TRUFFLE_CODEC, (PythonClass) codecsModule.getAttribute(T_CODEC),
258258
new BuiltinDescr[]{
259-
new BuiltinDescr(() -> EncodeNodeGen.create(), EncodeNode.class, false),
260-
new BuiltinDescr(() -> CodecDecodeNodeGen.create(), CodecDecodeNode.class, true)},
259+
new BuiltinDescr(EncodeNodeGen::create, EncodeNode.class, false),
260+
new BuiltinDescr(CodecDecodeNodeGen::create, CodecDecodeNode.class, true)},
261261
codecsTruffleModule, language, factory);
262262

263263
// class TruffleIncrementalEncoder(codecs.IncrementalEncoder):
@@ -268,8 +268,8 @@ private static void initCodecClasses(PythonModule codecsTruffleModule, PythonMod
268268
// return _codecs.__truffle_encode__(input, self.encoding, self.errors)[0]
269269
codecsTruffleBuiltins.truffleIncrementalEncoderClass = initClass(T_TRUFFLE_INCREMENTAL_ENCODER, T_INCREMENTAL_ENCODER,
270270
new BuiltinDescr[]{
271-
new BuiltinDescr(() -> CodecInitNodeGen.create(), CodecInitNode.class, false),
272-
new BuiltinDescr(() -> IncrementalEncodeNodeGen.create(), IncrementalEncodeNode.class, true)},
271+
new BuiltinDescr(CodecInitNodeGen::create, CodecInitNode.class, false),
272+
new BuiltinDescr(IncrementalEncodeNodeGen::create, IncrementalEncodeNode.class, true)},
273273
codecsTruffleModule, codecsModule, language, factory);
274274

275275
// class TruffleIncrementalDecoder(codecs.BufferedIncrementalDecoder):
@@ -280,8 +280,8 @@ private static void initCodecClasses(PythonModule codecsTruffleModule, PythonMod
280280
// return _codecs.__truffle_decode__(input, self.encoding, errors, final)
281281
codecsTruffleBuiltins.truffleIncrementalDecoderClass = initClass(T_TRUFFLE_INCREMENTAL_DECODER, T_BUFFERED_INCREMENTAL_DECODER,
282282
new BuiltinDescr[]{
283-
new BuiltinDescr(() -> CodecInitNodeGen.create(), CodecInitNode.class, false),
284-
new BuiltinDescr(() -> IncrementalDecodeNodeGen.create(), IncrementalDecodeNode.class, true)},
283+
new BuiltinDescr(CodecInitNodeGen::create, CodecInitNode.class, false),
284+
new BuiltinDescr(IncrementalDecodeNodeGen::create, IncrementalDecodeNode.class, true)},
285285
codecsTruffleModule, codecsModule, language, factory);
286286

287287
// class TruffleStreamWriter(codecs.StreamWriter):
@@ -292,8 +292,8 @@ private static void initCodecClasses(PythonModule codecsTruffleModule, PythonMod
292292
// return _codecs.__truffle_encode__(input, self.encoding, errors)
293293
codecsTruffleBuiltins.truffleStreamWriterClass = initClass(T_TRUFFLE_STREAM_WRITER, T_STREAM_WRITER,
294294
new BuiltinDescr[]{
295-
new BuiltinDescr(() -> CodecInitNodeGen.create(), CodecInitNode.class, false),
296-
new BuiltinDescr(() -> EncodeNodeGen.create(), EncodeNode.class, true)},
295+
new BuiltinDescr(CodecInitNodeGen::create, CodecInitNode.class, false),
296+
new BuiltinDescr(EncodeNodeGen::create, EncodeNode.class, true)},
297297
codecsTruffleModule, codecsModule, language, factory);
298298

299299
// class TruffleStreamReader(codecs.StreamReader):
@@ -304,16 +304,16 @@ private static void initCodecClasses(PythonModule codecsTruffleModule, PythonMod
304304
// return _codecs.__truffle_decode__(input, self.encoding, errors)
305305
codecsTruffleBuiltins.truffleStreamReaderClass = initClass(T_TRUFFLE_STREAM_READER, T_STREAM_READER,
306306
new BuiltinDescr[]{
307-
new BuiltinDescr(() -> CodecInitNodeGen.create(), CodecInitNode.class, false),
308-
new BuiltinDescr(() -> StreamDecodeNodeGen.create(), StreamDecodeNode.class, true)},
307+
new BuiltinDescr(CodecInitNodeGen::create, CodecInitNode.class, false),
308+
new BuiltinDescr(StreamDecodeNodeGen::create, StreamDecodeNode.class, true)},
309309
codecsTruffleModule, codecsModule, language, factory);
310310

311311
// serves as factory function for CodecInfo-s incrementalencoder/decode and streamwriter/reader
312312
// class apply_encoding:
313313
// def __call__(self, *args, **kwargs):
314314
// return self.fn(self.encoding, *args, **kwargs)
315315
codecsTruffleBuiltins.applyEncodingClass = initClass(T_APPLY_ENCODING, context.lookupType(PythonBuiltinClassType.PythonObject),
316-
new BuiltinDescr[]{new BuiltinDescr(() -> CallApplyNodeGen.create(), CallApplyNode.class, false)},
316+
new BuiltinDescr[]{new BuiltinDescr(CallApplyNodeGen::create, CallApplyNode.class, false)},
317317
codecsTruffleModule, language, factory);
318318
}
319319
// @formatter:on
@@ -360,7 +360,7 @@ Object call(VirtualFrame frame, PythonObject self, Object[] args, PKeyword[] kw,
360360
}
361361
}
362362

363-
@Builtin(name = J_ENCODE, minNumOfPositionalArgs = 2, maxNumOfPositionalArgs = 3)
363+
@Builtin(name = J_ENCODE, minNumOfPositionalArgs = 2, parameterNames = {"self", "input", "errors"})
364364
protected abstract static class EncodeNode extends PythonTernaryBuiltinNode {
365365
@Specialization
366366
Object encode(VirtualFrame frame, PythonObject self, Object input, Object errors,
@@ -370,7 +370,7 @@ Object encode(VirtualFrame frame, PythonObject self, Object input, Object errors
370370
}
371371
}
372372

373-
@Builtin(name = J_DECODE, minNumOfPositionalArgs = 1, maxNumOfPositionalArgs = 3)
373+
@Builtin(name = J_DECODE, minNumOfPositionalArgs = 1, parameterNames = {"self", "input", "errors"})
374374
protected abstract static class CodecDecodeNode extends PythonTernaryBuiltinNode {
375375
@Specialization
376376
Object decode(VirtualFrame frame, PythonObject self, Object input, Object errors,
@@ -380,7 +380,7 @@ Object decode(VirtualFrame frame, PythonObject self, Object input, Object errors
380380
}
381381
}
382382

383-
@Builtin(name = J_ENCODE, minNumOfPositionalArgs = 2, maxNumOfPositionalArgs = 3)
383+
@Builtin(name = J_ENCODE, minNumOfPositionalArgs = 2, parameterNames = {"self", "input", "final"})
384384
protected abstract static class IncrementalEncodeNode extends PythonTernaryBuiltinNode {
385385
@Specialization
386386
Object encode(VirtualFrame frame, PythonObject self, Object input, @SuppressWarnings("unused") Object ffinal,
@@ -392,7 +392,7 @@ Object encode(VirtualFrame frame, PythonObject self, Object input, @SuppressWarn
392392
}
393393
}
394394

395-
@Builtin(name = J_BUFFER_DECODE, minNumOfPositionalArgs = 1, maxNumOfPositionalArgs = 4)
395+
@Builtin(name = J_BUFFER_DECODE, minNumOfPositionalArgs = 1, parameterNames = {"self", "input", "errors", "final"})
396396
protected abstract static class IncrementalDecodeNode extends PythonQuaternaryBuiltinNode {
397397
@Specialization
398398
Object decode(VirtualFrame frame, PythonObject self, Object input, Object errors, Object ffinal,
@@ -402,13 +402,13 @@ Object decode(VirtualFrame frame, PythonObject self, Object input, Object errors
402402
}
403403
}
404404

405-
@Builtin(name = J_DECODE, minNumOfPositionalArgs = 1, maxNumOfPositionalArgs = 4)
406-
protected abstract static class StreamDecodeNode extends PythonQuaternaryBuiltinNode {
405+
@Builtin(name = J_DECODE, minNumOfPositionalArgs = 1, parameterNames = {"self", "input", "errors"})
406+
protected abstract static class StreamDecodeNode extends PythonTernaryBuiltinNode {
407407
@Specialization
408-
Object decode(VirtualFrame frame, PythonObject self, Object input, Object errors, Object ffinal,
408+
Object decode(VirtualFrame frame, PythonObject self, Object input, Object errors,
409409
@Cached PyObjectGetAttr getAttrNode,
410410
@Cached CodecsDecodeNode decode) {
411-
return decode.execute(frame, input, getAttrNode.execute(frame, self, T_ATTR_ENCODING), errors, ffinal);
411+
return decode.execute(frame, input, getAttrNode.execute(frame, self, T_ATTR_ENCODING), errors, false);
412412
}
413413
}
414414

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

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import static com.oracle.graal.python.nodes.StringLiterals.T_EXT_PYD;
5252
import static com.oracle.graal.python.nodes.StringLiterals.T_EXT_SO;
5353
import static com.oracle.graal.python.nodes.StringLiterals.T_HPY_SUFFIX;
54-
import static com.oracle.graal.python.nodes.StringLiterals.T_LITTLE;
5554
import static com.oracle.graal.python.nodes.StringLiterals.T_NAME;
5655
import static com.oracle.graal.python.nodes.StringLiterals.T_SITE;
5756
import static com.oracle.graal.python.runtime.exception.PythonErrorType.ImportError;
@@ -92,7 +91,6 @@
9291
import com.oracle.graal.python.builtins.objects.code.CodeNodes;
9392
import com.oracle.graal.python.builtins.objects.code.PCode;
9493
import com.oracle.graal.python.builtins.objects.function.PArguments;
95-
import com.oracle.graal.python.builtins.objects.ints.IntBuiltins;
9694
import com.oracle.graal.python.builtins.objects.memoryview.PMemoryView;
9795
import com.oracle.graal.python.builtins.objects.module.FrozenModules;
9896
import com.oracle.graal.python.builtins.objects.module.PythonFrozenModule;
@@ -128,12 +126,12 @@
128126
import com.oracle.truffle.api.dsl.Cached;
129127
import com.oracle.truffle.api.dsl.Fallback;
130128
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
131-
import com.oracle.truffle.api.dsl.NeverDefault;
132129
import com.oracle.truffle.api.dsl.NodeFactory;
133130
import com.oracle.truffle.api.dsl.Specialization;
134131
import com.oracle.truffle.api.frame.VirtualFrame;
135132
import com.oracle.truffle.api.interop.InteropLibrary;
136133
import com.oracle.truffle.api.library.CachedLibrary;
134+
import com.oracle.truffle.api.memory.ByteArraySupport;
137135
import com.oracle.truffle.api.nodes.Node;
138136
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
139137
import com.oracle.truffle.api.strings.TruffleString;
@@ -254,31 +252,26 @@ public boolean run() {
254252
@GenerateNodeFactory
255253
public abstract static class GetMagic extends PythonBuiltinNode {
256254
static final int MAGIC_NUMBER = 21000 + Compiler.BYTECODE_VERSION * 10;
257-
258-
@Child private IntBuiltins.ToBytesNode toBytesNode = IntBuiltins.ToBytesNode.create();
259-
@Child private PythonBufferAccessLibrary bufferLib = PythonBufferAccessLibrary.getFactory().createDispatched(1);
255+
static final byte[] MAGIC_NUMBER_BYTES = new byte[4];
256+
static {
257+
ByteArraySupport.littleEndian().putInt(MAGIC_NUMBER_BYTES, 0, MAGIC_NUMBER);
258+
MAGIC_NUMBER_BYTES[2] = '\r';
259+
MAGIC_NUMBER_BYTES[3] = '\n';
260+
}
260261

261262
@Specialization(guards = "isSingleContext()")
262-
public PBytes runCachedSingleContext(@SuppressWarnings("unused") VirtualFrame frame,
263-
@Cached(value = "getMagicNumberPBytes(frame)", weak = true) PBytes magicBytes) {
263+
public PBytes runCachedSingleContext(
264+
@Cached(value = "getMagicNumberPBytes()", weak = true) PBytes magicBytes) {
264265
return magicBytes;
265266
}
266267

267268
@Specialization(replaces = "runCachedSingleContext")
268-
public PBytes run(@SuppressWarnings("unused") VirtualFrame frame,
269-
@Cached(value = "getMagicNumberBytes(frame)", dimensions = 1) byte[] magicBytes) {
270-
return factory().createBytes(magicBytes);
271-
}
272-
273-
protected PBytes getMagicNumberPBytes(VirtualFrame frame) {
274-
return factory().createBytes(getMagicNumberBytes(frame));
269+
public PBytes run() {
270+
return factory().createBytes(MAGIC_NUMBER_BYTES);
275271
}
276272

277-
@NeverDefault
278-
protected byte[] getMagicNumberBytes(VirtualFrame frame) {
279-
PBytes magic = toBytesNode.execute(frame, MAGIC_NUMBER, 2, T_LITTLE, false);
280-
byte[] magicBytes = bufferLib.getInternalOrCopiedByteArray(magic);
281-
return new byte[]{magicBytes[0], magicBytes[1], '\r', '\n'};
273+
protected PBytes getMagicNumberPBytes() {
274+
return factory().createBytes(MAGIC_NUMBER_BYTES);
282275
}
283276
}
284277

0 commit comments

Comments
 (0)