diff options
author | Patrik Nyblom <[email protected]> | 2013-06-11 14:50:00 +0200 |
---|---|---|
committer | Patrik Nyblom <[email protected]> | 2013-06-11 14:50:00 +0200 |
commit | 5dd13b1efead2a8101ff1fb46937fbfa00db5269 (patch) | |
tree | dd1de1385b7648e639614909e139ff86f92aff71 /erts/emulator/beam/erl_zlib.c | |
parent | fdd8705381fb3accd2c9becea902fe8754bbb0ec (diff) | |
parent | c013f8b647c29a41f351a91825906861f01d13ca (diff) | |
download | otp-5dd13b1efead2a8101ff1fb46937fbfa00db5269.tar.gz otp-5dd13b1efead2a8101ff1fb46937fbfa00db5269.tar.bz2 otp-5dd13b1efead2a8101ff1fb46937fbfa00db5269.zip |
Merge branch 'pan/happi/yield_in_term_to_binary' into maintOTP_R16B01_RC1
* pan/happi/yield_in_term_to_binary:
Add testcase to stress extra_root
term_to_binary: Remove debug code and set production trap levels
Teach erl_gc:offset_rootset about extra_root
Teach external.c to handle reallocs before compression
Make all steps ofterm_to_binary work in chunks and yield
Make term_to_binary yield (trap).
OTP-11163
Diffstat (limited to 'erts/emulator/beam/erl_zlib.c')
-rw-r--r-- | erts/emulator/beam/erl_zlib.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/erts/emulator/beam/erl_zlib.c b/erts/emulator/beam/erl_zlib.c index f73d48b6c2..c8f29a7ce4 100644 --- a/erts/emulator/beam/erl_zlib.c +++ b/erts/emulator/beam/erl_zlib.c @@ -44,6 +44,48 @@ void erl_zlib_zfree_callback (voidpf opaque, voidpf ptr) erts_free(ERTS_ALC_T_ZLIB, ptr); } +/* + * Initialize a z_stream with a source, to later *chunk* data into a destination + * Returns Z_OK or Error. + */ +int ZEXPORT erl_zlib_deflate_start(z_stream *streamp, const Bytef* source, + uLong sourceLen, int level) +{ + streamp->next_in = (Bytef*)source; + streamp->avail_in = (uInt)sourceLen; + streamp->total_out = streamp->avail_out = 0; + streamp->next_out = NULL; + erl_zlib_alloc_init(streamp); + return deflateInit(streamp, level); +} +/* + * Deflate a chunk, The destination length is the limit. + * Returns Z_OK if more to process, Z_STREAM_END if we are done. + */ +int ZEXPORT erl_zlib_deflate_chunk(z_stream *streamp, Bytef* dest, uLongf* destLen) +{ + int err; + uLongf last_tot = streamp->total_out; + + streamp->next_out = dest; + streamp->avail_out = (uInt)*destLen; + + if ((uLong)streamp->avail_out != *destLen) return Z_BUF_ERROR; + + err = deflate(streamp, Z_FINISH); + *destLen = streamp->total_out - last_tot; + return err; +} + + +/* + * When we are done, free up the deflate structure + * Retyurns Z_OK or Error + */ +int ZEXPORT erl_zlib_deflate_finish(z_stream *streamp) +{ + return deflateEnd(streamp); +} int ZEXPORT erl_zlib_compress2 (Bytef* dest, uLongf* destLen, const Bytef* source, uLong sourceLen, |