@@ -101,10 +101,10 @@ public class ZLibModuleBuiltins extends PythonBuiltins {
101
101
protected static final byte Z_FINISH = 4 ;
102
102
protected static final byte Z_BLOCK = 5 ;
103
103
protected static final byte Z_TREES = 6 ;
104
-
104
+
105
105
// errors
106
106
protected static final byte Z_BUF_ERROR = -5 ;
107
-
107
+
108
108
protected static final String MODULE_NAME = "zlib" ;
109
109
110
110
@ Override
@@ -119,95 +119,93 @@ public void initialize(PythonCore core) {
119
119
builtinConstants .put ("DEFLATED" , DEFLATED );
120
120
builtinConstants .put ("DEF_MEM_LEVEL" , DEF_MEM_LEVEL );
121
121
builtinConstants .put ("DEF_BUF_SIZE" , DEF_BUF_SIZE );
122
-
122
+
123
123
builtinConstants .put ("Z_NO_COMPRESSION" , Z_NO_COMPRESSION );
124
124
builtinConstants .put ("Z_BEST_SPEED" , Z_BEST_SPEED );
125
125
builtinConstants .put ("Z_BEST_COMPRESSION" , Z_BEST_COMPRESSION );
126
126
builtinConstants .put ("Z_DEFAULT_COMPRESSION" , Z_DEFAULT_COMPRESSION );
127
-
127
+
128
128
builtinConstants .put ("Z_FILTERED" , Z_FILTERED );
129
129
builtinConstants .put ("Z_HUFFMAN_ONLY" , Z_HUFFMAN_ONLY );
130
130
builtinConstants .put ("Z_RLE" , Z_RLE );
131
131
builtinConstants .put ("Z_FIXED" , Z_FIXED );
132
132
builtinConstants .put ("Z_DEFAULT_STRATEGY" , Z_DEFAULT_STRATEGY );
133
-
133
+
134
134
builtinConstants .put ("Z_NO_FLUSH" , Z_NO_FLUSH );
135
135
builtinConstants .put ("Z_PARTIAL_FLUSH" , Z_PARTIAL_FLUSH );
136
136
builtinConstants .put ("Z_SYNC_FLUSH" , Z_SYNC_FLUSH );
137
137
builtinConstants .put ("Z_FULL_FLUSH" , Z_FULL_FLUSH );
138
138
builtinConstants .put ("Z_FINISH" , Z_FINISH );
139
139
builtinConstants .put ("Z_BLOCK" , Z_BLOCK );
140
140
builtinConstants .put ("Z_TREES" , Z_TREES );
141
-
141
+
142
142
}
143
-
143
+
144
144
// zlib.crc32(data[, value])
145
145
@ Builtin (name = "crc32" , minNumOfPositionalArgs = 1 , maxNumOfPositionalArgs = 2 )
146
146
@ TypeSystemReference (PythonArithmeticTypes .class )
147
147
@ GenerateNodeFactory
148
148
public abstract static class Crc32Node extends PythonBinaryBuiltinNode {
149
149
150
- @ Child
151
- private SequenceStorageNodes .ToByteArrayNode toArrayNode ;
152
- @ Child
153
- private CastToIntegerFromIntNode castToIntNode ;
150
+ @ Child private SequenceStorageNodes .ToByteArrayNode toArrayNode ;
151
+ @ Child private CastToIntegerFromIntNode castToIntNode ;
154
152
155
153
public abstract long execute (PIBytesLike data , Object value );
156
154
157
155
// we can't use jdk Crc32 class, if there is done init value of crc
158
156
private final static int [] CRC32_TABLE = {
159
- 0x00000000 , 0x77073096 , 0xee0e612c , 0x990951ba , 0x076dc419 ,
160
- 0x706af48f , 0xe963a535 , 0x9e6495a3 , 0x0edb8832 , 0x79dcb8a4 ,
161
- 0xe0d5e91e , 0x97d2d988 , 0x09b64c2b , 0x7eb17cbd , 0xe7b82d07 ,
162
- 0x90bf1d91 , 0x1db71064 , 0x6ab020f2 , 0xf3b97148 , 0x84be41de ,
163
- 0x1adad47d , 0x6ddde4eb , 0xf4d4b551 , 0x83d385c7 , 0x136c9856 ,
164
- 0x646ba8c0 , 0xfd62f97a , 0x8a65c9ec , 0x14015c4f , 0x63066cd9 ,
165
- 0xfa0f3d63 , 0x8d080df5 , 0x3b6e20c8 , 0x4c69105e , 0xd56041e4 ,
166
- 0xa2677172 , 0x3c03e4d1 , 0x4b04d447 , 0xd20d85fd , 0xa50ab56b ,
167
- 0x35b5a8fa , 0x42b2986c , 0xdbbbc9d6 , 0xacbcf940 , 0x32d86ce3 ,
168
- 0x45df5c75 , 0xdcd60dcf , 0xabd13d59 , 0x26d930ac , 0x51de003a ,
169
- 0xc8d75180 , 0xbfd06116 , 0x21b4f4b5 , 0x56b3c423 , 0xcfba9599 ,
170
- 0xb8bda50f , 0x2802b89e , 0x5f058808 , 0xc60cd9b2 , 0xb10be924 ,
171
- 0x2f6f7c87 , 0x58684c11 , 0xc1611dab , 0xb6662d3d , 0x76dc4190 ,
172
- 0x01db7106 , 0x98d220bc , 0xefd5102a , 0x71b18589 , 0x06b6b51f ,
173
- 0x9fbfe4a5 , 0xe8b8d433 , 0x7807c9a2 , 0x0f00f934 , 0x9609a88e ,
174
- 0xe10e9818 , 0x7f6a0dbb , 0x086d3d2d , 0x91646c97 , 0xe6635c01 ,
175
- 0x6b6b51f4 , 0x1c6c6162 , 0x856530d8 , 0xf262004e , 0x6c0695ed ,
176
- 0x1b01a57b , 0x8208f4c1 , 0xf50fc457 , 0x65b0d9c6 , 0x12b7e950 ,
177
- 0x8bbeb8ea , 0xfcb9887c , 0x62dd1ddf , 0x15da2d49 , 0x8cd37cf3 ,
178
- 0xfbd44c65 , 0x4db26158 , 0x3ab551ce , 0xa3bc0074 , 0xd4bb30e2 ,
179
- 0x4adfa541 , 0x3dd895d7 , 0xa4d1c46d , 0xd3d6f4fb , 0x4369e96a ,
180
- 0x346ed9fc , 0xad678846 , 0xda60b8d0 , 0x44042d73 , 0x33031de5 ,
181
- 0xaa0a4c5f , 0xdd0d7cc9 , 0x5005713c , 0x270241aa , 0xbe0b1010 ,
182
- 0xc90c2086 , 0x5768b525 , 0x206f85b3 , 0xb966d409 , 0xce61e49f ,
183
- 0x5edef90e , 0x29d9c998 , 0xb0d09822 , 0xc7d7a8b4 , 0x59b33d17 ,
184
- 0x2eb40d81 , 0xb7bd5c3b , 0xc0ba6cad , 0xedb88320 , 0x9abfb3b6 ,
185
- 0x03b6e20c , 0x74b1d29a , 0xead54739 , 0x9dd277af , 0x04db2615 ,
186
- 0x73dc1683 , 0xe3630b12 , 0x94643b84 , 0x0d6d6a3e , 0x7a6a5aa8 ,
187
- 0xe40ecf0b , 0x9309ff9d , 0x0a00ae27 , 0x7d079eb1 , 0xf00f9344 ,
188
- 0x8708a3d2 , 0x1e01f268 , 0x6906c2fe , 0xf762575d , 0x806567cb ,
189
- 0x196c3671 , 0x6e6b06e7 , 0xfed41b76 , 0x89d32be0 , 0x10da7a5a ,
190
- 0x67dd4acc , 0xf9b9df6f , 0x8ebeeff9 , 0x17b7be43 , 0x60b08ed5 ,
191
- 0xd6d6a3e8 , 0xa1d1937e , 0x38d8c2c4 , 0x4fdff252 , 0xd1bb67f1 ,
192
- 0xa6bc5767 , 0x3fb506dd , 0x48b2364b , 0xd80d2bda , 0xaf0a1b4c ,
193
- 0x36034af6 , 0x41047a60 , 0xdf60efc3 , 0xa867df55 , 0x316e8eef ,
194
- 0x4669be79 , 0xcb61b38c , 0xbc66831a , 0x256fd2a0 , 0x5268e236 ,
195
- 0xcc0c7795 , 0xbb0b4703 , 0x220216b9 , 0x5505262f , 0xc5ba3bbe ,
196
- 0xb2bd0b28 , 0x2bb45a92 , 0x5cb36a04 , 0xc2d7ffa7 , 0xb5d0cf31 ,
197
- 0x2cd99e8b , 0x5bdeae1d , 0x9b64c2b0 , 0xec63f226 , 0x756aa39c ,
198
- 0x026d930a , 0x9c0906a9 , 0xeb0e363f , 0x72076785 , 0x05005713 ,
199
- 0x95bf4a82 , 0xe2b87a14 , 0x7bb12bae , 0x0cb61b38 , 0x92d28e9b ,
200
- 0xe5d5be0d , 0x7cdcefb7 , 0x0bdbdf21 , 0x86d3d2d4 , 0xf1d4e242 ,
201
- 0x68ddb3f8 , 0x1fda836e , 0x81be16cd , 0xf6b9265b , 0x6fb077e1 ,
202
- 0x18b74777 , 0x88085ae6 , 0xff0f6a70 , 0x66063bca , 0x11010b5c ,
203
- 0x8f659eff , 0xf862ae69 , 0x616bffd3 , 0x166ccf45 , 0xa00ae278 ,
204
- 0xd70dd2ee , 0x4e048354 , 0x3903b3c2 , 0xa7672661 , 0xd06016f7 ,
205
- 0x4969474d , 0x3e6e77db , 0xaed16a4a , 0xd9d65adc , 0x40df0b66 ,
206
- 0x37d83bf0 , 0xa9bcae53 , 0xdebb9ec5 , 0x47b2cf7f , 0x30b5ffe9 ,
207
- 0xbdbdf21c , 0xcabac28a , 0x53b39330 , 0x24b4a3a6 , 0xbad03605 ,
208
- 0xcdd70693 , 0x54de5729 , 0x23d967bf , 0xb3667a2e , 0xc4614ab8 ,
209
- 0x5d681b02 , 0x2a6f2b94 , 0xb40bbe37 , 0xc30c8ea1 , 0x5a05df1b ,
210
- 0x2d02ef8d
157
+ 0x00000000 , 0x77073096 , 0xee0e612c , 0x990951ba , 0x076dc419 ,
158
+ 0x706af48f , 0xe963a535 , 0x9e6495a3 , 0x0edb8832 , 0x79dcb8a4 ,
159
+ 0xe0d5e91e , 0x97d2d988 , 0x09b64c2b , 0x7eb17cbd , 0xe7b82d07 ,
160
+ 0x90bf1d91 , 0x1db71064 , 0x6ab020f2 , 0xf3b97148 , 0x84be41de ,
161
+ 0x1adad47d , 0x6ddde4eb , 0xf4d4b551 , 0x83d385c7 , 0x136c9856 ,
162
+ 0x646ba8c0 , 0xfd62f97a , 0x8a65c9ec , 0x14015c4f , 0x63066cd9 ,
163
+ 0xfa0f3d63 , 0x8d080df5 , 0x3b6e20c8 , 0x4c69105e , 0xd56041e4 ,
164
+ 0xa2677172 , 0x3c03e4d1 , 0x4b04d447 , 0xd20d85fd , 0xa50ab56b ,
165
+ 0x35b5a8fa , 0x42b2986c , 0xdbbbc9d6 , 0xacbcf940 , 0x32d86ce3 ,
166
+ 0x45df5c75 , 0xdcd60dcf , 0xabd13d59 , 0x26d930ac , 0x51de003a ,
167
+ 0xc8d75180 , 0xbfd06116 , 0x21b4f4b5 , 0x56b3c423 , 0xcfba9599 ,
168
+ 0xb8bda50f , 0x2802b89e , 0x5f058808 , 0xc60cd9b2 , 0xb10be924 ,
169
+ 0x2f6f7c87 , 0x58684c11 , 0xc1611dab , 0xb6662d3d , 0x76dc4190 ,
170
+ 0x01db7106 , 0x98d220bc , 0xefd5102a , 0x71b18589 , 0x06b6b51f ,
171
+ 0x9fbfe4a5 , 0xe8b8d433 , 0x7807c9a2 , 0x0f00f934 , 0x9609a88e ,
172
+ 0xe10e9818 , 0x7f6a0dbb , 0x086d3d2d , 0x91646c97 , 0xe6635c01 ,
173
+ 0x6b6b51f4 , 0x1c6c6162 , 0x856530d8 , 0xf262004e , 0x6c0695ed ,
174
+ 0x1b01a57b , 0x8208f4c1 , 0xf50fc457 , 0x65b0d9c6 , 0x12b7e950 ,
175
+ 0x8bbeb8ea , 0xfcb9887c , 0x62dd1ddf , 0x15da2d49 , 0x8cd37cf3 ,
176
+ 0xfbd44c65 , 0x4db26158 , 0x3ab551ce , 0xa3bc0074 , 0xd4bb30e2 ,
177
+ 0x4adfa541 , 0x3dd895d7 , 0xa4d1c46d , 0xd3d6f4fb , 0x4369e96a ,
178
+ 0x346ed9fc , 0xad678846 , 0xda60b8d0 , 0x44042d73 , 0x33031de5 ,
179
+ 0xaa0a4c5f , 0xdd0d7cc9 , 0x5005713c , 0x270241aa , 0xbe0b1010 ,
180
+ 0xc90c2086 , 0x5768b525 , 0x206f85b3 , 0xb966d409 , 0xce61e49f ,
181
+ 0x5edef90e , 0x29d9c998 , 0xb0d09822 , 0xc7d7a8b4 , 0x59b33d17 ,
182
+ 0x2eb40d81 , 0xb7bd5c3b , 0xc0ba6cad , 0xedb88320 , 0x9abfb3b6 ,
183
+ 0x03b6e20c , 0x74b1d29a , 0xead54739 , 0x9dd277af , 0x04db2615 ,
184
+ 0x73dc1683 , 0xe3630b12 , 0x94643b84 , 0x0d6d6a3e , 0x7a6a5aa8 ,
185
+ 0xe40ecf0b , 0x9309ff9d , 0x0a00ae27 , 0x7d079eb1 , 0xf00f9344 ,
186
+ 0x8708a3d2 , 0x1e01f268 , 0x6906c2fe , 0xf762575d , 0x806567cb ,
187
+ 0x196c3671 , 0x6e6b06e7 , 0xfed41b76 , 0x89d32be0 , 0x10da7a5a ,
188
+ 0x67dd4acc , 0xf9b9df6f , 0x8ebeeff9 , 0x17b7be43 , 0x60b08ed5 ,
189
+ 0xd6d6a3e8 , 0xa1d1937e , 0x38d8c2c4 , 0x4fdff252 , 0xd1bb67f1 ,
190
+ 0xa6bc5767 , 0x3fb506dd , 0x48b2364b , 0xd80d2bda , 0xaf0a1b4c ,
191
+ 0x36034af6 , 0x41047a60 , 0xdf60efc3 , 0xa867df55 , 0x316e8eef ,
192
+ 0x4669be79 , 0xcb61b38c , 0xbc66831a , 0x256fd2a0 , 0x5268e236 ,
193
+ 0xcc0c7795 , 0xbb0b4703 , 0x220216b9 , 0x5505262f , 0xc5ba3bbe ,
194
+ 0xb2bd0b28 , 0x2bb45a92 , 0x5cb36a04 , 0xc2d7ffa7 , 0xb5d0cf31 ,
195
+ 0x2cd99e8b , 0x5bdeae1d , 0x9b64c2b0 , 0xec63f226 , 0x756aa39c ,
196
+ 0x026d930a , 0x9c0906a9 , 0xeb0e363f , 0x72076785 , 0x05005713 ,
197
+ 0x95bf4a82 , 0xe2b87a14 , 0x7bb12bae , 0x0cb61b38 , 0x92d28e9b ,
198
+ 0xe5d5be0d , 0x7cdcefb7 , 0x0bdbdf21 , 0x86d3d2d4 , 0xf1d4e242 ,
199
+ 0x68ddb3f8 , 0x1fda836e , 0x81be16cd , 0xf6b9265b , 0x6fb077e1 ,
200
+ 0x18b74777 , 0x88085ae6 , 0xff0f6a70 , 0x66063bca , 0x11010b5c ,
201
+ 0x8f659eff , 0xf862ae69 , 0x616bffd3 , 0x166ccf45 , 0xa00ae278 ,
202
+ 0xd70dd2ee , 0x4e048354 , 0x3903b3c2 , 0xa7672661 , 0xd06016f7 ,
203
+ 0x4969474d , 0x3e6e77db , 0xaed16a4a , 0xd9d65adc , 0x40df0b66 ,
204
+ 0x37d83bf0 , 0xa9bcae53 , 0xdebb9ec5 , 0x47b2cf7f , 0x30b5ffe9 ,
205
+ 0xbdbdf21c , 0xcabac28a , 0x53b39330 , 0x24b4a3a6 , 0xbad03605 ,
206
+ 0xcdd70693 , 0x54de5729 , 0x23d967bf , 0xb3667a2e , 0xc4614ab8 ,
207
+ 0x5d681b02 , 0x2a6f2b94 , 0xb40bbe37 , 0xc30c8ea1 , 0x5a05df1b ,
208
+ 0x2d02ef8d
211
209
};
212
210
213
211
private static int computeCRC32 (byte [] bytes , int value ) {
@@ -256,15 +254,15 @@ public long doit(PIBytesLike data, long value) {
256
254
257
255
@ Specialization
258
256
public long doPInt (PIBytesLike data , PInt value ) {
259
- // lost magnitude is ok here.
257
+ // lost magnitude is ok here.
260
258
int initValue = value .intValue ();
261
259
byte [] array = getToArrayNode ().execute (data .getSequenceStorage ());
262
260
return ((long ) computeCRC32 (array , initValue ) & 0xFFFFFFFFL );
263
261
}
264
262
265
263
@ Specialization
266
264
public long doObject (PIBytesLike data , Object value ,
267
- @ Cached ("create()" ) Crc32Node recursiveNode ) {
265
+ @ Cached ("create()" ) Crc32Node recursiveNode ) {
268
266
return recursiveNode .execute (data , getCastToIntNode ().execute (value ));
269
267
}
270
268
@@ -347,15 +345,15 @@ public long doit(PIBytesLike data, long value) {
347
345
348
346
@ Specialization
349
347
public long doPInt (PIBytesLike data , PInt value ) {
350
- // lost magnitude is ok here.
348
+ // lost magnitude is ok here.
351
349
int initValue = value .intValue ();
352
350
byte [] array = getToArrayNode ().execute (data .getSequenceStorage ());
353
351
return ((long ) computeAdler32 (array , initValue ) & 0xFFFFFFFFL );
354
352
}
355
353
356
354
@ Specialization
357
355
public long doObject (PIBytesLike data , Object value ,
358
- @ Cached ("create()" ) Adler32Node recursiveNode ) {
356
+ @ Cached ("create()" ) Adler32Node recursiveNode ) {
359
357
return recursiveNode .execute (data , getCastToIntNode ().execute (value ));
360
358
}
361
359
@@ -375,8 +373,7 @@ protected static Adler32Node create() {
375
373
@ GenerateNodeFactory
376
374
public abstract static class CompressNode extends PythonBinaryBuiltinNode {
377
375
378
- @ Child
379
- private SequenceStorageNodes .ToByteArrayNode toArrayNode ;
376
+ @ Child private SequenceStorageNodes .ToByteArrayNode toArrayNode ;
380
377
381
378
private SequenceStorageNodes .ToByteArrayNode getToArrayNode () {
382
379
if (toArrayNode == null ) {
@@ -409,7 +406,7 @@ public PBytes doit(PIBytesLike data, PNone level) {
409
406
410
407
@ Specialization
411
408
public PBytes doit (PIBytesLike data , long level ,
412
- @ Cached ("createBinaryProfile()" ) ConditionProfile wrongLevelProfile ) {
409
+ @ Cached ("createBinaryProfile()" ) ConditionProfile wrongLevelProfile ) {
413
410
if (wrongLevelProfile .profile (level < -1 || 9 < level )) {
414
411
throw raise (ZLibError , "Bad compression level" );
415
412
}
@@ -424,12 +421,12 @@ public PBytes doit(PIBytesLike data, long level,
424
421
@ TypeSystemReference (PythonArithmeticTypes .class )
425
422
@ GenerateNodeFactory
426
423
public abstract static class DecompressNode extends PythonTernaryBuiltinNode {
427
-
424
+
428
425
@ Child private CastToIntegerFromIntNode castToIntNode ;
429
426
@ Child private SequenceStorageNodes .ToByteArrayNode toArrayNode ;
430
427
431
428
private final ConditionProfile bufSizeProfile = ConditionProfile .createBinaryProfile ();
432
-
429
+
433
430
private SequenceStorageNodes .ToByteArrayNode getToArrayNode () {
434
431
if (toArrayNode == null ) {
435
432
CompilerDirectives .transferToInterpreterAndInvalidate ();
@@ -447,11 +444,11 @@ private CastToIntegerFromIntNode getCastToIntNode() {
447
444
}
448
445
return castToIntNode ;
449
446
}
450
-
447
+
451
448
@ TruffleBoundary
452
449
private byte [] decompress (byte [] input , @ SuppressWarnings ("unused" ) int wbits , int bufsize ) {
453
450
// decompress
454
- // We don't use wbits currently. There is no easy way how to map to java Inflater.
451
+ // We don't use wbits currently. There is no easy way how to map to java Inflater.
455
452
Inflater decompresser = new Inflater ();
456
453
decompresser .setInput (input );
457
454
byte [] resultArray = new byte [bufsize ];
@@ -470,19 +467,19 @@ private byte[] decompress(byte[] input, @SuppressWarnings("unused") int wbits, i
470
467
decompresser .end ();
471
468
return baos .toByteArray ();
472
469
}
473
-
470
+
474
471
@ Specialization
475
472
@ TruffleBoundary
476
473
public PBytes doit (PIBytesLike data , PNone wbits , PNone bufsize ) {
477
474
byte [] array = getToArrayNode ().execute (data .getSequenceStorage ());
478
475
return factory ().createBytes (decompress (array , MAX_WBITS , DEF_BUF_SIZE ));
479
476
}
480
-
477
+
481
478
@ Specialization
482
479
public PBytes decompress (PIBytesLike data , byte wbits , int bufsize ) {
483
- return decompress (data , (long )wbits , bufsize );
480
+ return decompress (data , (long ) wbits , bufsize );
484
481
}
485
-
482
+
486
483
@ Specialization
487
484
public PBytes decompress (PIBytesLike data , long wbits , int bufsize ) {
488
485
// checking bufsize
@@ -492,16 +489,16 @@ public PBytes decompress(PIBytesLike data, long wbits, int bufsize) {
492
489
bufsize = 1 ;
493
490
}
494
491
byte [] array = getToArrayNode ().execute (data .getSequenceStorage ());
495
- return factory ().createBytes (decompress (array , (int )wbits , bufsize ));
492
+ return factory ().createBytes (decompress (array , (int ) wbits , bufsize ));
496
493
}
497
-
494
+
498
495
@ Specialization
499
496
public PBytes decompress (PIBytesLike data , long wbits , Object bufsize ,
500
- @ Cached ("create()" ) DecompressNode recursiveNode ) {
497
+ @ Cached ("create()" ) DecompressNode recursiveNode ) {
501
498
Object bufferLen = getCastToIntNode ().execute (bufsize );
502
- return (PBytes )recursiveNode .execute (data , wbits , bufferLen );
499
+ return (PBytes ) recursiveNode .execute (data , wbits , bufferLen );
503
500
}
504
-
501
+
505
502
protected static DecompressNode create () {
506
503
return ZLibModuleBuiltinsFactory .DecompressNodeFactory .create ();
507
504
}
0 commit comments