1
0
mirror of https://github.com/upx/upx synced 2025-09-28 19:06:07 +08:00

Minor cleanup of callback code.

This commit is contained in:
Markus F.X.J. Oberhumer 2006-12-05 17:09:18 +01:00
parent 7015d616b4
commit 6e52364bcb
2 changed files with 11 additions and 11 deletions

View File

@ -211,7 +211,9 @@ typedef void (__acc_cdecl *upx_progress_func_t)
struct upx_callback_t struct upx_callback_t
{ {
upx_progress_func_t nprogress; upx_progress_func_t nprogress;
void * user1; void *user;
void reset() { memset(this, 0, sizeof(*this)); }
}; };

View File

@ -92,8 +92,6 @@ long UiPacker::update_u_len = 0;
long UiPacker::update_fc_len = 0; long UiPacker::update_fc_len = 0;
long UiPacker::update_fu_len = 0; long UiPacker::update_fu_len = 0;
#define clear_cb() memset(&cb, 0, sizeof(cb))
/************************************************************************* /*************************************************************************
// constants // constants
@ -182,7 +180,7 @@ UiPacker::UiPacker(const Packer *p_) :
{ {
init_global_constants(); init_global_constants();
clear_cb(); cb.reset();
s = new State; s = new State;
memset(s,0,sizeof(*s)); memset(s,0,sizeof(*s));
@ -208,7 +206,7 @@ UiPacker::UiPacker(const Packer *p_) :
UiPacker::~UiPacker() UiPacker::~UiPacker()
{ {
clear_cb(); cb.reset();
delete s; s = NULL; delete s; s = NULL;
} }
@ -246,7 +244,7 @@ void UiPacker::startCallback(unsigned u_len, unsigned step,
s->bar_pos = 1; // because of the leading `\r' s->bar_pos = 1; // because of the leading `\r'
s->pass_digits = 0; s->pass_digits = 0;
clear_cb(); cb.reset();
if (s->pass < 0) // no callback wanted if (s->pass < 0) // no callback wanted
return; return;
@ -269,7 +267,7 @@ void UiPacker::startCallback(unsigned u_len, unsigned step,
#else #else
cb.nprogress = progress_callback; cb.nprogress = progress_callback;
#endif #endif
cb.user1 = this; cb.user = this; // parameter for static function UiPacker::progress_callback()
if (s->mode == M_CB_TERM) if (s->mode == M_CB_TERM)
{ {
@ -386,7 +384,7 @@ void UiPacker::endCallback()
} }
#endif /* UI_USE_SCREEN */ #endif /* UI_USE_SCREEN */
clear_cb(); cb.reset();
#if 0 #if 0
printf("callback: pass %d, step %6d, updates %6d\n", printf("callback: pass %d, step %6d, updates %6d\n",
s->pass, s->step, s->spin_counter); s->pass, s->step, s->spin_counter);
@ -401,8 +399,8 @@ void UiPacker::endCallback()
void __acc_cdecl UiPacker::progress_callback(upx_callback_p cb, unsigned isize, unsigned osize) void __acc_cdecl UiPacker::progress_callback(upx_callback_p cb, unsigned isize, unsigned osize)
{ {
//printf("%6d %6d %d\n", isize, osize, state); //printf("%6d %6d %d\n", isize, osize, state);
UiPacker *uip = (UiPacker *) cb->user1; UiPacker *self = (UiPacker *) cb->user;
uip->doCallback(isize, osize); self->doCallback(isize, osize);
} }
@ -459,7 +457,7 @@ void UiPacker::doCallback(unsigned isize, unsigned osize)
upx_snprintf(m, buflen, " %3d.%1d%% %c ", upx_snprintf(m, buflen, " %3d.%1d%% %c ",
ratio / 10000, (ratio % 10000) / 1000, ratio / 10000, (ratio % 10000) / 1000,
spinner[s->spin_counter & 3]); spinner[s->spin_counter & 3]);
assert((int)strlen(s->msg_buf) < 1 + 80); assert(strlen(s->msg_buf) < 1 + 80);
s->pos = pos; s->pos = pos;
s->spin_counter++; s->spin_counter++;