From 930f07d15eeb81d73f4448c58936599cd952b406 Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Thu, 29 Jun 2006 06:24:24 +0200 Subject: [PATCH] Move upx_compress_result_t handling into right place. --- src/compress.cpp | 10 ------- src/compress_ucl.cpp | 9 +++++++ src/packer.cpp | 64 ++++++++++++++++++++++++-------------------- 3 files changed, 44 insertions(+), 39 deletions(-) diff --git a/src/compress.cpp b/src/compress.cpp index bf16a2a1..c6260523 100644 --- a/src/compress.cpp +++ b/src/compress.cpp @@ -105,16 +105,6 @@ int upx_compress ( const upx_bytep src, unsigned src_len, cresult->u_len = src_len; cresult->c_len = 0; #endif - // assume no info available - fill in worst case results - ucl_uint *res = cresult->result_ucl.result; - //res[0] = 1; // min_offset_found - NOT USED - res[1] = src_len - 1; // max_offset_found - //res[2] = 2; // min_match_found - NOT USED - res[3] = src_len - 1; // max_match_found - //res[4] = 1; // min_run_found - NOT USED - res[5] = src_len; // max_run_found - res[6] = 1; // first_offset_found - //res[7] = 999999; // same_match_offsets_found - NOT USED if (method < 0) { } diff --git a/src/compress_ucl.cpp b/src/compress_ucl.cpp index db685570..705e558b 100644 --- a/src/compress_ucl.cpp +++ b/src/compress_ucl.cpp @@ -121,6 +121,15 @@ int upx_ucl_compress ( const upx_bytep src, unsigned src_len, cconf = cconf_parm->conf_ucl; // struct copy ucl_uint *res = cresult->result_ucl.result; + // assume no info available - fill in worst case results + //res[0] = 1; // min_offset_found - NOT USED + res[1] = src_len - 1; // max_offset_found + //res[2] = 2; // min_match_found - NOT USED + res[3] = src_len - 1; // max_match_found + //res[4] = 1; // min_run_found - NOT USED + res[5] = src_len; // max_run_found + res[6] = 1; // first_offset_found + //res[7] = 999999; // same_match_offsets_found - NOT USED // prepare bit-buffer settings cconf.bb_endian = 0; diff --git a/src/packer.cpp b/src/packer.cpp index 9e9064be..ef96c87c 100644 --- a/src/packer.cpp +++ b/src/packer.cpp @@ -154,7 +154,7 @@ bool Packer::skipVerify() const /************************************************************************* -// compress +// compress - wrap call to low-level upx_compress() **************************************************************************/ bool Packer::compress(upx_bytep in, upx_bytep out, @@ -163,6 +163,9 @@ bool Packer::compress(upx_bytep in, upx_bytep out, ph.c_len = 0; assert(ph.level >= 1); assert(ph.level <= 10); + // Avoid too many progress bar updates. 64 is s->bar_len in ui.cpp. + unsigned step = (ph.u_len < 64*1024) ? 0 : ph.u_len / 64; + // save current checksums ph.saved_u_adler = ph.u_adler; ph.saved_c_adler = ph.c_adler; @@ -173,24 +176,24 @@ bool Packer::compress(upx_bytep in, upx_bytep out, upx_compress_config_t cconf; cconf.reset(); if (cconf_parm) cconf = *cconf_parm; - // options - if (opt->crp.crp_ucl.c_flags != -1) - cconf.conf_ucl.c_flags = opt->crp.crp_ucl.c_flags; - if (opt->crp.crp_ucl.p_level != -1) - cconf.conf_ucl.p_level = opt->crp.crp_ucl.p_level; - if (opt->crp.crp_ucl.h_level != -1) - cconf.conf_ucl.h_level = opt->crp.crp_ucl.h_level; - if (opt->crp.crp_ucl.max_offset != UINT_MAX && opt->crp.crp_ucl.max_offset < cconf.conf_ucl.max_offset) - cconf.conf_ucl.max_offset = opt->crp.crp_ucl.max_offset; - if (opt->crp.crp_ucl.max_match != UINT_MAX && opt->crp.crp_ucl.max_match < cconf.conf_ucl.max_match) - cconf.conf_ucl.max_match = opt->crp.crp_ucl.max_match; - - // Avoid too many progress bar updates. 64 is s->bar_len in ui.cpp. - unsigned step = (ph.u_len < 64*1024) ? 0 : ph.u_len / 64; + // cconf options + if (M_IS_NRV2B(ph.method) || M_IS_NRV2D(ph.method) || M_IS_NRV2E(ph.method)) + { + if (opt->crp.crp_ucl.c_flags != -1) + cconf.conf_ucl.c_flags = opt->crp.crp_ucl.c_flags; + if (opt->crp.crp_ucl.p_level != -1) + cconf.conf_ucl.p_level = opt->crp.crp_ucl.p_level; + if (opt->crp.crp_ucl.h_level != -1) + cconf.conf_ucl.h_level = opt->crp.crp_ucl.h_level; + if (opt->crp.crp_ucl.max_offset != UINT_MAX && opt->crp.crp_ucl.max_offset < cconf.conf_ucl.max_offset) + cconf.conf_ucl.max_offset = opt->crp.crp_ucl.max_offset; + if (opt->crp.crp_ucl.max_match != UINT_MAX && opt->crp.crp_ucl.max_match < cconf.conf_ucl.max_match) + cconf.conf_ucl.max_match = opt->crp.crp_ucl.max_match; #if defined(WITH_NRV) - if (ph.level >= 7 || (ph.level >= 4 && ph.u_len >= 512*1024)) - step = 0; + if (ph.level >= 7 || (ph.level >= 4 && ph.u_len >= 512*1024)) + step = 0; #endif + } if (ui_pass >= 0) ui_pass++; uip->startCallback(ph.u_len, step, ui_pass, ui_total_passes); @@ -211,19 +214,22 @@ bool Packer::compress(upx_bytep in, upx_bytep out, if (r != UPX_E_OK) throwInternalError("compression failed"); - ucl_uint *res = ph.compress_result.result_ucl.result; - //ph.min_offset_found = res[0]; - ph.max_offset_found = res[1]; - //ph.min_match_found = res[2]; - ph.max_match_found = res[3]; - //ph.min_run_found = res[4]; - ph.max_run_found = res[5]; - ph.first_offset_found = res[6]; - //ph.same_match_offsets_found = res[7]; - if (cconf_parm) + if (M_IS_NRV2B(ph.method) || M_IS_NRV2D(ph.method) || M_IS_NRV2E(ph.method)) { - assert(cconf.conf_ucl.max_offset == 0 || cconf.conf_ucl.max_offset >= ph.max_offset_found); - assert(cconf.conf_ucl.max_match == 0 || cconf.conf_ucl.max_match >= ph.max_match_found); + ucl_uint *res = ph.compress_result.result_ucl.result; + //ph.min_offset_found = res[0]; + ph.max_offset_found = res[1]; + //ph.min_match_found = res[2]; + ph.max_match_found = res[3]; + //ph.min_run_found = res[4]; + ph.max_run_found = res[5]; + ph.first_offset_found = res[6]; + //ph.same_match_offsets_found = res[7]; + if (cconf_parm) + { + assert(cconf.conf_ucl.max_offset == 0 || cconf.conf_ucl.max_offset >= ph.max_offset_found); + assert(cconf.conf_ucl.max_match == 0 || cconf.conf_ucl.max_match >= ph.max_match_found); + } } //printf("\nPacker::compress: %d/%d: %7d -> %7d\n", ph.method, ph.level, ph.u_len, ph.c_len);