1
1
/*
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.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* The Universal Permissive License (UPL), Version 1.0
58
58
import com .oracle .graal .python .builtins .Builtin ;
59
59
import com .oracle .graal .python .builtins .CoreFunctions ;
60
60
import com .oracle .graal .python .builtins .PythonBuiltins ;
61
+ import com .oracle .graal .python .builtins .modules .zlib .ZlibNodes .JavaCompressNode ;
61
62
import com .oracle .graal .python .builtins .objects .PNone ;
62
63
import com .oracle .graal .python .builtins .objects .bytes .BytesNodes ;
63
64
import com .oracle .graal .python .builtins .objects .bytes .PBytes ;
76
77
import com .oracle .graal .python .runtime .PythonContext ;
77
78
import com .oracle .graal .python .runtime .object .PythonObjectFactory ;
78
79
import com .oracle .graal .python .util .PythonUtils ;
80
+ import com .oracle .truffle .api .dsl .Bind ;
79
81
import com .oracle .truffle .api .dsl .Cached ;
80
82
import com .oracle .truffle .api .dsl .Cached .Shared ;
81
83
import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
82
84
import com .oracle .truffle .api .dsl .ImportStatic ;
83
85
import com .oracle .truffle .api .dsl .NodeFactory ;
84
86
import com .oracle .truffle .api .dsl .Specialization ;
85
87
import com .oracle .truffle .api .frame .VirtualFrame ;
88
+ import com .oracle .truffle .api .nodes .Node ;
86
89
87
90
@ CoreFunctions (extendClasses = ZlibCompress )
88
91
public class ZlibCompressBuiltins extends PythonBuiltins {
@@ -97,35 +100,36 @@ abstract static class CompressNode extends PythonBinaryBuiltinNode {
97
100
98
101
@ Specialization (guards = "self.isInitialized()" )
99
102
PBytes doNativeBytes (ZLibCompObject .NativeZlibCompObject self , PBytesLike data ,
103
+ @ Bind ("this" ) Node inliningTarget ,
100
104
@ Cached SequenceStorageNodes .GetInternalByteArrayNode toBytes ,
101
105
@ Shared ("co" ) @ Cached ZlibNodes .ZlibNativeCompressObj compressObj ) {
102
106
synchronized (self ) {
103
107
assert self .isInitialized ();
104
108
byte [] bytes = toBytes .execute (data .getSequenceStorage ());
105
109
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 ));
107
111
}
108
112
}
109
113
110
114
@ Specialization (guards = {"self.isInitialized()" , "!isBytes(data)" })
111
115
PBytes doNativeObject (VirtualFrame frame , ZLibCompObject .NativeZlibCompObject self , Object data ,
116
+ @ Bind ("this" ) Node inliningTarget ,
112
117
@ Shared ("bb" ) @ Cached BytesNodes .ToBytesNode toBytes ,
113
118
@ Shared ("co" ) @ Cached ZlibNodes .ZlibNativeCompressObj compressObj ) {
114
119
synchronized (self ) {
115
120
assert self .isInitialized ();
116
121
byte [] bytes = toBytes .execute (frame , data );
117
122
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 ));
119
124
}
120
125
}
121
126
122
127
@ Specialization (guards = "self.isInitialized()" )
123
128
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 ) {
126
130
byte [] bytes = toBytes .execute (frame , data );
127
131
self .setDeflaterInput (bytes );
128
- return compressNode .execute (self , Z_NO_FLUSH , factory ());
132
+ return JavaCompressNode .execute (self , Z_NO_FLUSH , factory ());
129
133
}
130
134
131
135
@ SuppressWarnings ("unused" )
@@ -141,6 +145,7 @@ abstract static class BaseCopyNode extends PNodeWithContext {
141
145
142
146
@ Specialization (guards = "self.isInitialized()" )
143
147
Object doNative (ZLibCompObject .NativeZlibCompObject self , PythonContext ctxt , PythonObjectFactory factory ,
148
+ @ Bind ("this" ) Node inliningTarget ,
144
149
@ Cached NativeLibrary .InvokeNativeFunction createCompObject ,
145
150
@ Cached NativeLibrary .InvokeNativeFunction compressObjCopy ,
146
151
@ Cached NativeLibrary .InvokeNativeFunction deallocateStream ,
@@ -152,7 +157,7 @@ Object doNative(ZLibCompObject.NativeZlibCompObject self, PythonContext ctxt, Py
152
157
int err = zlibSupport .compressObjCopy (self .getZst (), zstNewCopy , compressObjCopy );
153
158
if (err != Z_OK ) {
154
159
zlibSupport .deallocateStream (zstNewCopy , deallocateStream );
155
- errorHandling .execute (self .getZst (), err , zlibSupport , false );
160
+ errorHandling .execute (inliningTarget , self .getZst (), err , zlibSupport , false );
156
161
}
157
162
return factory .createNativeZLibCompObject (ZlibCompress , zstNewCopy , zlibSupport );
158
163
}
@@ -222,6 +227,7 @@ PBytes empty(ZLibCompObject self, int mode) {
222
227
223
228
@ Specialization (guards = {"mode != Z_NO_FLUSH" , "self.isInitialized()" })
224
229
PBytes doit (ZLibCompObject .NativeZlibCompObject self , int mode ,
230
+ @ Bind ("this" ) Node inliningTarget ,
225
231
@ Cached NativeLibrary .InvokeNativeFunction compressObjFlush ,
226
232
@ Cached ZlibNodes .GetNativeBufferNode getBuffer ,
227
233
@ Cached NativeLibrary .InvokeNativeFunction getIsInitialised ,
@@ -243,20 +249,19 @@ PBytes doit(ZLibCompObject.NativeZlibCompObject self, int mode,
243
249
}
244
250
int err = zlibSupport .compressObjFlush (self .getZst (), lastInput , DEF_BUF_SIZE , mode , compressObjFlush );
245
251
if (err != Z_OK ) {
246
- errorHandling .execute (self .getZst (), err , zlibSupport , false );
252
+ errorHandling .execute (inliningTarget , self .getZst (), err , zlibSupport , false );
247
253
}
248
- byte [] resultArray = getBuffer .getOutputBuffer (self .getZst (), ctxt );
254
+ byte [] resultArray = getBuffer .getOutputBuffer (inliningTarget , self .getZst (), ctxt );
249
255
if (zlibSupport .getIsInitialised (self .getZst (), getIsInitialised ) == 0 ) {
250
- processDeallocation .execute (self , ctxt , factory (), true );
256
+ processDeallocation .execute (inliningTarget , self , ctxt , factory (), true );
251
257
}
252
258
return factory ().createBytes (resultArray );
253
259
}
254
260
}
255
261
256
262
@ 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 ());
260
265
}
261
266
262
267
@ SuppressWarnings ("unused" )
0 commit comments