Skip to content

Commit d997c3c

Browse files
committed
Resolve more DSL warnings in the zlib module
1 parent a46f13f commit d997c3c

File tree

4 files changed

+134
-104
lines changed

4 files changed

+134
-104
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZLibModuleBuiltins.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -495,20 +495,22 @@ protected boolean useNative() {
495495

496496
@Specialization(guards = {"useNative()"})
497497
PBytes doNativeBytes(PBytesLike data, int level,
498+
@Bind("this") Node inliningTarget,
498499
@Cached SequenceStorageNodes.GetInternalBytesNode toByte,
499500
@Shared @Cached ZlibNodes.ZlibNativeCompress nativeCompress) {
500501
byte[] bytes = toByte.execute(data);
501502
int len = data.getSequenceStorage().length();
502-
byte[] resultArray = nativeCompress.execute(bytes, len, level, getContext());
503+
byte[] resultArray = nativeCompress.execute(inliningTarget, bytes, len, level, getContext());
503504
return factory().createBytes(resultArray);
504505
}
505506

506507
@Specialization(guards = {"useNative()", "!isBytes(data)"})
507508
PBytes doNativeObject(VirtualFrame frame, Object data, int level,
509+
@Bind("this") Node inliningTarget,
508510
@Shared("bb") @Cached ToBytesNode toBytesNode,
509511
@Shared @Cached ZlibNodes.ZlibNativeCompress nativeCompress) {
510512
byte[] bytes = toBytesNode.execute(frame, data);
511-
return factory().createBytes(nativeCompress.execute(bytes, bytes.length, level, getContext()));
513+
return factory().createBytes(nativeCompress.execute(inliningTarget, bytes, bytes.length, level, getContext()));
512514
}
513515

514516
@Specialization(guards = {"!useNative()"})
@@ -564,20 +566,22 @@ protected boolean useNative() {
564566

565567
@Specialization(guards = {"bufsize >= 0", "useNative()"})
566568
PBytes doNativeBytes(PBytesLike data, int wbits, int bufsize,
569+
@Bind("this") Node inliningTarget,
567570
@Cached SequenceStorageNodes.GetInternalBytesNode toByte,
568571
@Shared @Cached ZlibNodes.ZlibNativeDecompress nativeDecompress) {
569572
byte[] bytes = toByte.execute(data);
570573
int len = data.getSequenceStorage().length();
571-
return factory().createBytes(nativeDecompress.execute(bytes, len, wbits, bufsize, PythonContext.get(this)));
574+
return factory().createBytes(nativeDecompress.execute(inliningTarget, bytes, len, wbits, bufsize, PythonContext.get(this)));
572575
}
573576

574577
@Specialization(guards = {"bufsize >= 0", "useNative()", "!isBytes(data)"})
575578
PBytes doNativeObject(VirtualFrame frame, Object data, int wbits, int bufsize,
579+
@Bind("this") Node inliningTarget,
576580
@Shared("bb") @Cached ToBytesNode toBytesNode,
577581
@Shared @Cached ZlibNodes.ZlibNativeDecompress nativeDecompress) {
578582
byte[] bytes = toBytesNode.execute(frame, data);
579583
int len = bytes.length;
580-
return factory().createBytes(nativeDecompress.execute(bytes, len, wbits, bufsize, PythonContext.get(this)));
584+
return factory().createBytes(nativeDecompress.execute(inliningTarget, bytes, len, wbits, bufsize, PythonContext.get(this)));
581585
}
582586

583587
@Specialization(guards = {"bufsize >= 0", "!useNative()"})
@@ -653,6 +657,7 @@ protected static boolean isValidWBitRange(int wbits) {
653657

654658
@Specialization(guards = {"method == DEFLATED", "useNative()"})
655659
Object doNative(int level, int method, int wbits, int memLevel, int strategy, byte[] zdict,
660+
@Bind("this") Node inliningTarget,
656661
@Cached NativeLibrary.InvokeNativeFunction createCompObject,
657662
@Cached NativeLibrary.InvokeNativeFunction compressObjInit,
658663
@Cached ZlibNodes.ZlibNativeErrorHandling errorHandling) {
@@ -667,7 +672,7 @@ Object doNative(int level, int method, int wbits, int memLevel, int strategy, by
667672
err = zlibSupport.compressObjInit(zst, level, method, wbits, memLevel, strategy, compressObjInit);
668673
}
669674
if (err != Z_OK) {
670-
errorHandling.execute(zst, err, zlibSupport, true);
675+
errorHandling.execute(inliningTarget, zst, err, zlibSupport, true);
671676
}
672677
return factory().createNativeZLibCompObject(ZlibCompress, zst, zlibSupport);
673678
}
@@ -725,6 +730,7 @@ protected static boolean isValidWBitRange(int wbits) {
725730

726731
@Specialization(guards = {"useNative()"})
727732
Object doNative(int wbits, byte[] zdict,
733+
@Bind("this") Node inliningTarget,
728734
@Cached NativeLibrary.InvokeNativeFunction createCompObject,
729735
@Cached NativeLibrary.InvokeNativeFunction decompressObjInit,
730736
@Cached ZlibNodes.ZlibNativeErrorHandling errorHandling) {
@@ -738,7 +744,7 @@ Object doNative(int wbits, byte[] zdict,
738744
err = zlibSupport.decompressObjInit(zst, wbits, decompressObjInit);
739745
}
740746
if (err != Z_OK) {
741-
errorHandling.execute(zst, err, zlibSupport, true);
747+
errorHandling.execute(inliningTarget, zst, err, zlibSupport, true);
742748
}
743749
return factory().createNativeZLibCompObject(ZlibDecompress, zst, zlibSupport);
744750
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZlibCompressBuiltins.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 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
@@ -58,6 +58,7 @@
5858
import com.oracle.graal.python.builtins.Builtin;
5959
import com.oracle.graal.python.builtins.CoreFunctions;
6060
import com.oracle.graal.python.builtins.PythonBuiltins;
61+
import com.oracle.graal.python.builtins.modules.zlib.ZlibNodes.JavaCompressNode;
6162
import com.oracle.graal.python.builtins.objects.PNone;
6263
import com.oracle.graal.python.builtins.objects.bytes.BytesNodes;
6364
import com.oracle.graal.python.builtins.objects.bytes.PBytes;
@@ -76,13 +77,15 @@
7677
import com.oracle.graal.python.runtime.PythonContext;
7778
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
7879
import com.oracle.graal.python.util.PythonUtils;
80+
import com.oracle.truffle.api.dsl.Bind;
7981
import com.oracle.truffle.api.dsl.Cached;
8082
import com.oracle.truffle.api.dsl.Cached.Shared;
8183
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
8284
import com.oracle.truffle.api.dsl.ImportStatic;
8385
import com.oracle.truffle.api.dsl.NodeFactory;
8486
import com.oracle.truffle.api.dsl.Specialization;
8587
import com.oracle.truffle.api.frame.VirtualFrame;
88+
import com.oracle.truffle.api.nodes.Node;
8689

8790
@CoreFunctions(extendClasses = ZlibCompress)
8891
public class ZlibCompressBuiltins extends PythonBuiltins {
@@ -97,35 +100,36 @@ abstract static class CompressNode extends PythonBinaryBuiltinNode {
97100

98101
@Specialization(guards = "self.isInitialized()")
99102
PBytes doNativeBytes(ZLibCompObject.NativeZlibCompObject self, PBytesLike data,
103+
@Bind("this") Node inliningTarget,
100104
@Cached SequenceStorageNodes.GetInternalByteArrayNode toBytes,
101105
@Shared("co") @Cached ZlibNodes.ZlibNativeCompressObj compressObj) {
102106
synchronized (self) {
103107
assert self.isInitialized();
104108
byte[] bytes = toBytes.execute(data.getSequenceStorage());
105109
int len = data.getSequenceStorage().length();
106-
return factory().createBytes(compressObj.execute(self, PythonContext.get(this), bytes, len));
110+
return factory().createBytes(compressObj.execute(inliningTarget, self, PythonContext.get(this), bytes, len));
107111
}
108112
}
109113

110114
@Specialization(guards = {"self.isInitialized()", "!isBytes(data)"})
111115
PBytes doNativeObject(VirtualFrame frame, ZLibCompObject.NativeZlibCompObject self, Object data,
116+
@Bind("this") Node inliningTarget,
112117
@Shared("bb") @Cached BytesNodes.ToBytesNode toBytes,
113118
@Shared("co") @Cached ZlibNodes.ZlibNativeCompressObj compressObj) {
114119
synchronized (self) {
115120
assert self.isInitialized();
116121
byte[] bytes = toBytes.execute(frame, data);
117122
int len = bytes.length;
118-
return factory().createBytes(compressObj.execute(self, PythonContext.get(this), bytes, len));
123+
return factory().createBytes(compressObj.execute(inliningTarget, self, PythonContext.get(this), bytes, len));
119124
}
120125
}
121126

122127
@Specialization(guards = "self.isInitialized()")
123128
PBytes doit(VirtualFrame frame, ZLibCompObject.JavaZlibCompObject self, Object data,
124-
@Shared("bb") @Cached BytesNodes.ToBytesNode toBytes,
125-
@Cached ZlibNodes.JavaCompressNode compressNode) {
129+
@Shared("bb") @Cached BytesNodes.ToBytesNode toBytes) {
126130
byte[] bytes = toBytes.execute(frame, data);
127131
self.setDeflaterInput(bytes);
128-
return compressNode.execute(self, Z_NO_FLUSH, factory());
132+
return JavaCompressNode.execute(self, Z_NO_FLUSH, factory());
129133
}
130134

131135
@SuppressWarnings("unused")
@@ -141,6 +145,7 @@ abstract static class BaseCopyNode extends PNodeWithContext {
141145

142146
@Specialization(guards = "self.isInitialized()")
143147
Object doNative(ZLibCompObject.NativeZlibCompObject self, PythonContext ctxt, PythonObjectFactory factory,
148+
@Bind("this") Node inliningTarget,
144149
@Cached NativeLibrary.InvokeNativeFunction createCompObject,
145150
@Cached NativeLibrary.InvokeNativeFunction compressObjCopy,
146151
@Cached NativeLibrary.InvokeNativeFunction deallocateStream,
@@ -152,7 +157,7 @@ Object doNative(ZLibCompObject.NativeZlibCompObject self, PythonContext ctxt, Py
152157
int err = zlibSupport.compressObjCopy(self.getZst(), zstNewCopy, compressObjCopy);
153158
if (err != Z_OK) {
154159
zlibSupport.deallocateStream(zstNewCopy, deallocateStream);
155-
errorHandling.execute(self.getZst(), err, zlibSupport, false);
160+
errorHandling.execute(inliningTarget, self.getZst(), err, zlibSupport, false);
156161
}
157162
return factory.createNativeZLibCompObject(ZlibCompress, zstNewCopy, zlibSupport);
158163
}
@@ -222,6 +227,7 @@ PBytes empty(ZLibCompObject self, int mode) {
222227

223228
@Specialization(guards = {"mode != Z_NO_FLUSH", "self.isInitialized()"})
224229
PBytes doit(ZLibCompObject.NativeZlibCompObject self, int mode,
230+
@Bind("this") Node inliningTarget,
225231
@Cached NativeLibrary.InvokeNativeFunction compressObjFlush,
226232
@Cached ZlibNodes.GetNativeBufferNode getBuffer,
227233
@Cached NativeLibrary.InvokeNativeFunction getIsInitialised,
@@ -243,20 +249,19 @@ PBytes doit(ZLibCompObject.NativeZlibCompObject self, int mode,
243249
}
244250
int err = zlibSupport.compressObjFlush(self.getZst(), lastInput, DEF_BUF_SIZE, mode, compressObjFlush);
245251
if (err != Z_OK) {
246-
errorHandling.execute(self.getZst(), err, zlibSupport, false);
252+
errorHandling.execute(inliningTarget, self.getZst(), err, zlibSupport, false);
247253
}
248-
byte[] resultArray = getBuffer.getOutputBuffer(self.getZst(), ctxt);
254+
byte[] resultArray = getBuffer.getOutputBuffer(inliningTarget, self.getZst(), ctxt);
249255
if (zlibSupport.getIsInitialised(self.getZst(), getIsInitialised) == 0) {
250-
processDeallocation.execute(self, ctxt, factory(), true);
256+
processDeallocation.execute(inliningTarget, self, ctxt, factory(), true);
251257
}
252258
return factory().createBytes(resultArray);
253259
}
254260
}
255261

256262
@Specialization(guards = {"mode != Z_NO_FLUSH", "self.isInitialized()"})
257-
PBytes doit(ZLibCompObject.JavaZlibCompObject self, int mode,
258-
@Cached ZlibNodes.JavaCompressNode compressNode) {
259-
return compressNode.execute(self, mode, factory());
263+
PBytes doit(ZLibCompObject.JavaZlibCompObject self, int mode) {
264+
return ZlibNodes.JavaCompressNode.execute(self, mode, factory());
260265
}
261266

262267
@SuppressWarnings("unused")

0 commit comments

Comments
 (0)