Skip to content

Commit 3a22625

Browse files
committed
FEAT: updated ZLIB to version 1.2.11. Enhanced COMPRESS and DECOMPRESS natives.
1 parent 00b1c9a commit 3a22625

File tree

9 files changed

+8420
-3469
lines changed

9 files changed

+8420
-3469
lines changed

src/core/a-lib.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ extern int Do_Callback(REBSER *obj, u32 name, RXIARG *args, RXIARG *result);
157157
if (bin) {
158158
spec.data = bin;
159159
spec.tail = len;
160-
ser = Decompress(&spec, 0, -1, 10000000, 0);
160+
ser = DecompressZlib(&spec, 0, -1, 0, 0);
161161
if (!ser) return 1;
162162

163163
val = BLK_SKIP(Sys_Context, SYS_CTX_BOOT_HOST);
@@ -307,7 +307,7 @@ extern int Do_Callback(REBSER *obj, u32 name, RXIARG *args, RXIARG *result);
307307
//Cloak(TRUE, code, NAT_SPEC_SIZE, &key[0], 20, TRUE);
308308
spec.data = bin;
309309
spec.tail = length;
310-
text = Decompress(&spec, 0, -1, 10000000, 0);
310+
text = DecompressZlib(&spec, 0, -1, 0, 0);
311311
if (!text) return FALSE;
312312
Append_Byte(text, 0);
313313

src/core/b-init.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ extern const REBYTE Str_Banner[];
172172
spec.tail = NAT_SPEC_SIZE;
173173

174174
textlen = Bytes_To_REBCNT(Native_Specs);
175-
text = Decompress(&spec, 0, -1, textlen, 0);
175+
text = DecompressZlib(&spec, 0, -1, textlen, 0);
176176
if (!text || (STR_LEN(text) != textlen)) Crash(RP_BOOT_DATA);
177177
boot = Scan_Source(STR_HEAD(text), textlen);
178178
//Dump_Block_Raw(boot, 0, 2);

src/core/n-strings.c

+31-19
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include "sys-core.h"
3131
#include "sys-deci-funcs.h"
3232

33-
3433
/***********************************************************************
3534
**
3635
** Hash Function Externs
@@ -291,19 +290,24 @@ static struct digest {
291290
*/ REBNATIVE(compress)
292291
/*
293292
// compress: native [
294-
// {Compresses data. Default is deflate with Adler32 checksum.}
293+
// {Compresses data. Default is deflate with Adler32 checksum and uncompressed size in last 4 bytes.}
295294
// data [binary! string!] {If string, it will be UTF8 encoded}
296-
// /part length {Length of data (elements)}
297-
// /gzip {Use deflate with GZIP checksum (CRC32)}
295+
// /part length {Length of source data}
296+
// /zlib {Use ZLIB (Adler32 checksum) without uncompressed length appended}
297+
// /gzip {Use ZLIB with GZIP envelope (using CRC32 checksum)}
298298
// /lzma {Use LZMA compression}
299+
// /level lvl [integer!] {Compression level 0-9}
299300
// ]
300301
***********************************************************************/
301302
{
302303
REBVAL *data = D_ARG(1);
303304
//REBOOL ref_part = D_REF(2);
304305
REBVAL *length = D_ARG(3);
305-
REBOOL ref_gzip = D_REF(4);
306-
REBOOL ref_lzma = D_REF(5);
306+
REBOOL ref_zlib = D_REF(4);
307+
REBOOL ref_gzip = D_REF(5);
308+
REBOOL ref_lzma = D_REF(6);
309+
REBOOL ref_level= D_REF(7);
310+
REBVAL *level = D_ARG(8);
307311

308312
REBSER *ser;
309313
REBCNT index;
@@ -314,12 +318,14 @@ static struct digest {
314318

315319
if(ref_lzma) {
316320
#ifdef USE_LZMA
317-
Set_Binary(D_RET, CompressLzma(ser, index, (REBINT)len));
321+
Set_Binary(D_RET, CompressLzma(ser, index, (REBINT)len, ref_level ? VAL_INT32(level) : -1));
318322
#else
319323
Trap0(RE_FEATURE_NA);
320324
#endif
321325
} else {
322-
Set_Binary(D_RET, Compress(ser, index, (REBINT)len, ref_gzip)); // /gzip
326+
int windowBits = MAX_WBITS;
327+
if (ref_gzip) windowBits |= 16;
328+
Set_Binary(D_RET, CompressZlib(ser, index, (REBINT)len, ref_level ? VAL_INT32(level) : -1, windowBits));
323329
}
324330

325331
return R_RET;
@@ -332,28 +338,32 @@ static struct digest {
332338
/*
333339
// decompress: native [
334340
// {Decompresses data. Result is binary.}
335-
// data [binary!] {Data to decompress}
336-
// /part length {Length of compressed data (must match end marker)}
337-
// /gzip {Use GZIP checksum}
338-
// /lzma {Use LZMA encoding}
339-
// /limit size {Error out if result is larger than this}
341+
// data [binary!] {Source data to decompress}
342+
// /part "Limits source data to a given length or position"
343+
// length [number! series!] {Length of compressed data (must match end marker)}
344+
// /zlib {Data are in ZLIB format with Adler32 checksum}
345+
// /gzip {Data are in ZLIB format with CRC32 checksum}
346+
// /lzma {Data are in LZMA format}
347+
// /size
348+
// bytes [integer!] {Number of decompressed bytes. If not used, size is detected from last 4 source data bytes.}
340349
]
341350
***********************************************************************/
342351
{
343352
REBVAL *data = D_ARG(1);
344353
//REBOOL ref_part = D_REF(2);
345354
REBVAL *length = D_ARG(3);
346-
REBOOL ref_gzip = D_REF(4);
347-
REBOOL ref_lzma = D_REF(5);
348-
REBOOL ref_limit = D_REF(6);
349-
REBVAL *size = D_ARG(7);
355+
REBOOL ref_zlib = D_REF(4);
356+
REBOOL ref_gzip = D_REF(5);
357+
REBOOL ref_lzma = D_REF(6);
358+
REBOOL ref_size = D_REF(7);
359+
REBVAL *size = D_ARG(8);
350360

351361
REBINT limit = 0;
352362
REBCNT len;
353363

354364
len = Partial1(D_ARG(1), D_ARG(3));
355365

356-
if (ref_limit) limit = Int32s(size, 1); // /limit size
366+
if (ref_size) limit = Int32s(size, 1); // /limit size
357367

358368
if (ref_lzma) {
359369
#ifdef USE_LZMA
@@ -362,7 +372,9 @@ static struct digest {
362372
Trap0(RE_FEATURE_NA);
363373
#endif
364374
} else {
365-
Set_Binary(D_RET, Decompress(VAL_SERIES(data), VAL_INDEX(data), (REBINT)len, limit, ref_gzip)); // /gzip
375+
int windowBits = MAX_WBITS;
376+
if (ref_gzip) windowBits |= 16;
377+
Set_Binary(D_RET, DecompressZlib(VAL_SERIES(data), VAL_INDEX(data), (REBINT)len, limit, windowBits));
366378
}
367379

368380

0 commit comments

Comments
 (0)