common.c   common.c 
skipping to change at line 36 skipping to change at line 36
lzma_version_string(void) lzma_version_string(void)
{ {
return LZMA_VERSION_STRING; return LZMA_VERSION_STRING;
} }
/////////////////////// ///////////////////////
// Memory allocation // // Memory allocation //
/////////////////////// ///////////////////////
extern void * lzma_attribute((__malloc__)) lzma_attr_alloc_size(1) extern void * lzma_attribute((__malloc__)) lzma_attr_alloc_size(1)
lzma_alloc(size_t size, lzma_allocator *allocator) lzma_alloc(size_t size, const lzma_allocator *allocator)
{ {
// Some malloc() variants return NULL if called with size == 0. // Some malloc() variants return NULL if called with size == 0.
if (size == 0) if (size == 0)
size = 1; size = 1;
void *ptr; void *ptr;
if (allocator != NULL && allocator->alloc != NULL) if (allocator != NULL && allocator->alloc != NULL)
ptr = allocator->alloc(allocator->opaque, 1, size); ptr = allocator->alloc(allocator->opaque, 1, size);
else else
ptr = malloc(size); ptr = malloc(size);
return ptr; return ptr;
} }
extern void * lzma_attribute((__malloc__)) lzma_attr_alloc_size(1)
lzma_alloc_zero(size_t size, const lzma_allocator *allocator)
{
// Some calloc() variants return NULL if called with size == 0.
if (size == 0)
size = 1;
void *ptr;
if (allocator != NULL && allocator->alloc != NULL) {
ptr = allocator->alloc(allocator->opaque, 1, size);
if (ptr != NULL)
memzero(ptr, size);
} else {
ptr = calloc(1, size);
}
return ptr;
}
extern void extern void
lzma_free(void *ptr, lzma_allocator *allocator) lzma_free(void *ptr, const lzma_allocator *allocator)
{ {
if (allocator != NULL && allocator->free != NULL) if (allocator != NULL && allocator->free != NULL)
allocator->free(allocator->opaque, ptr); allocator->free(allocator->opaque, ptr);
else else
free(ptr); free(ptr);
return; return;
} }
////////// //////////
skipping to change at line 85 skipping to change at line 105
memcpy(out + *out_pos, in + *in_pos, copy_size); memcpy(out + *out_pos, in + *in_pos, copy_size);
*in_pos += copy_size; *in_pos += copy_size;
*out_pos += copy_size; *out_pos += copy_size;
return copy_size; return copy_size;
} }
extern lzma_ret extern lzma_ret
lzma_next_filter_init(lzma_next_coder *next, lzma_allocator *allocator, lzma_next_filter_init(lzma_next_coder *next, const lzma_allocator *allocato r,
const lzma_filter_info *filters) const lzma_filter_info *filters)
{ {
lzma_next_coder_init(filters[0].init, next, allocator); lzma_next_coder_init(filters[0].init, next, allocator);
next->id = filters[0].id; next->id = filters[0].id;
return filters[0].init == NULL return filters[0].init == NULL
? LZMA_OK : filters[0].init(next, allocator, filters ); ? LZMA_OK : filters[0].init(next, allocator, filters );
} }
extern lzma_ret extern lzma_ret
lzma_next_filter_update(lzma_next_coder *next, lzma_allocator *allocator, lzma_next_filter_update(lzma_next_coder *next, const lzma_allocator *alloca tor,
const lzma_filter *reversed_filters) const lzma_filter *reversed_filters)
{ {
// Check that the application isn't trying to change the Filter ID. // Check that the application isn't trying to change the Filter ID.
// End of filters is indicated with LZMA_VLI_UNKNOWN in both // End of filters is indicated with LZMA_VLI_UNKNOWN in both
// reversed_filters[0].id and next->id. // reversed_filters[0].id and next->id.
if (reversed_filters[0].id != next->id) if (reversed_filters[0].id != next->id)
return LZMA_PROG_ERROR; return LZMA_PROG_ERROR;
if (reversed_filters[0].id == LZMA_VLI_UNKNOWN) if (reversed_filters[0].id == LZMA_VLI_UNKNOWN)
return LZMA_OK; return LZMA_OK;
assert(next->update != NULL); assert(next->update != NULL);
return next->update(next->coder, allocator, NULL, reversed_filters); return next->update(next->coder, allocator, NULL, reversed_filters);
} }
extern void extern void
lzma_next_end(lzma_next_coder *next, lzma_allocator *allocator) lzma_next_end(lzma_next_coder *next, const lzma_allocator *allocator)
{ {
if (next->init != (uintptr_t)(NULL)) { if (next->init != (uintptr_t)(NULL)) {
// To avoid tiny end functions that simply call // To avoid tiny end functions that simply call
// lzma_free(coder, allocator), we allow leaving next->end // lzma_free(coder, allocator), we allow leaving next->end
// NULL and call lzma_free() here. // NULL and call lzma_free() here.
if (next->end != NULL) if (next->end != NULL)
next->end(next->coder, allocator); next->end(next->coder, allocator);
else else
lzma_free(next->coder, allocator); lzma_free(next->coder, allocator);
skipping to change at line 169 skipping to change at line 189
} }
extern LZMA_API(lzma_ret) extern LZMA_API(lzma_ret)
lzma_code(lzma_stream *strm, lzma_action action) lzma_code(lzma_stream *strm, lzma_action action)
{ {
// Sanity checks // Sanity checks
if ((strm->next_in == NULL && strm->avail_in != 0) if ((strm->next_in == NULL && strm->avail_in != 0)
|| (strm->next_out == NULL && strm->avail_out != 0) || (strm->next_out == NULL && strm->avail_out != 0)
|| strm->internal == NULL || strm->internal == NULL
|| strm->internal->next.code == NULL || strm->internal->next.code == NULL
|| (unsigned int)(action) > LZMA_FINISH || (unsigned int)(action) > LZMA_ACTION_MAX
|| !strm->internal->supported_actions[action]) || !strm->internal->supported_actions[action])
return LZMA_PROG_ERROR; return LZMA_PROG_ERROR;
// Check if unsupported members have been set to non-zero or non-NUL L, // Check if unsupported members have been set to non-zero or non-NUL L,
// which would indicate that some new feature is wanted. // which would indicate that some new feature is wanted.
if (strm->reserved_ptr1 != NULL if (strm->reserved_ptr1 != NULL
|| strm->reserved_ptr2 != NULL || strm->reserved_ptr2 != NULL
|| strm->reserved_ptr3 != NULL || strm->reserved_ptr3 != NULL
|| strm->reserved_ptr4 != NULL || strm->reserved_ptr4 != NULL
|| strm->reserved_int1 != 0 || strm->reserved_int1 != 0
skipping to change at line 204 skipping to change at line 224
strm->internal->sequence = ISEQ_SYNC_FLUSH; strm->internal->sequence = ISEQ_SYNC_FLUSH;
break; break;
case LZMA_FULL_FLUSH: case LZMA_FULL_FLUSH:
strm->internal->sequence = ISEQ_FULL_FLUSH; strm->internal->sequence = ISEQ_FULL_FLUSH;
break; break;
case LZMA_FINISH: case LZMA_FINISH:
strm->internal->sequence = ISEQ_FINISH; strm->internal->sequence = ISEQ_FINISH;
break; break;
case LZMA_FULL_BARRIER:
strm->internal->sequence = ISEQ_FULL_BARRIER;
break;
} }
break; break;
case ISEQ_SYNC_FLUSH: case ISEQ_SYNC_FLUSH:
// The same action must be used until we return // The same action must be used until we return
// LZMA_STREAM_END, and the amount of input must not change. // LZMA_STREAM_END, and the amount of input must not change.
if (action != LZMA_SYNC_FLUSH if (action != LZMA_SYNC_FLUSH
|| strm->internal->avail_in != strm->avail_i n) || strm->internal->avail_in != strm->avail_i n)
return LZMA_PROG_ERROR; return LZMA_PROG_ERROR;
skipping to change at line 231 skipping to change at line 255
break; break;
case ISEQ_FINISH: case ISEQ_FINISH:
if (action != LZMA_FINISH if (action != LZMA_FINISH
|| strm->internal->avail_in != strm->avail_i n) || strm->internal->avail_in != strm->avail_i n)
return LZMA_PROG_ERROR; return LZMA_PROG_ERROR;
break; break;
case ISEQ_FULL_BARRIER:
if (action != LZMA_FULL_BARRIER
|| strm->internal->avail_in != strm->avail_i
n)
return LZMA_PROG_ERROR;
break;
case ISEQ_END: case ISEQ_END:
return LZMA_STREAM_END; return LZMA_STREAM_END;
case ISEQ_ERROR: case ISEQ_ERROR:
default: default:
return LZMA_PROG_ERROR; return LZMA_PROG_ERROR;
} }
size_t in_pos = 0; size_t in_pos = 0;
size_t out_pos = 0; size_t out_pos = 0;
skipping to change at line 281 skipping to change at line 312
} }
break; break;
case LZMA_TIMED_OUT: case LZMA_TIMED_OUT:
strm->internal->allow_buf_error = false; strm->internal->allow_buf_error = false;
ret = LZMA_OK; ret = LZMA_OK;
break; break;
case LZMA_STREAM_END: case LZMA_STREAM_END:
if (strm->internal->sequence == ISEQ_SYNC_FLUSH if (strm->internal->sequence == ISEQ_SYNC_FLUSH
|| strm->internal->sequence == ISEQ_FULL_FLU || strm->internal->sequence == ISEQ_FULL_FLU
SH) SH
|| strm->internal->sequence
== ISEQ_FULL_BARRIER)
strm->internal->sequence = ISEQ_RUN; strm->internal->sequence = ISEQ_RUN;
else else
strm->internal->sequence = ISEQ_END; strm->internal->sequence = ISEQ_END;
// Fall through // Fall through
case LZMA_NO_CHECK: case LZMA_NO_CHECK:
case LZMA_UNSUPPORTED_CHECK: case LZMA_UNSUPPORTED_CHECK:
case LZMA_GET_CHECK: case LZMA_GET_CHECK:
case LZMA_MEMLIMIT_ERROR: case LZMA_MEMLIMIT_ERROR:
skipping to change at line 319 skipping to change at line 352
{ {
if (strm != NULL && strm->internal != NULL) { if (strm != NULL && strm->internal != NULL) {
lzma_next_end(&strm->internal->next, strm->allocator); lzma_next_end(&strm->internal->next, strm->allocator);
lzma_free(strm->internal, strm->allocator); lzma_free(strm->internal, strm->allocator);
strm->internal = NULL; strm->internal = NULL;
} }
return; return;
} }
extern LZMA_API(void)
lzma_get_progress(lzma_stream *strm,
uint64_t *progress_in, uint64_t *progress_out)
{
if (strm->internal->next.get_progress != NULL) {
strm->internal->next.get_progress(strm->internal->next.coder
,
progress_in, progress_out);
} else {
*progress_in = strm->total_in;
*progress_out = strm->total_out;
}
return;
}
extern LZMA_API(lzma_check) extern LZMA_API(lzma_check)
lzma_get_check(const lzma_stream *strm) lzma_get_check(const lzma_stream *strm)
{ {
// Return LZMA_CHECK_NONE if we cannot know the check type. // Return LZMA_CHECK_NONE if we cannot know the check type.
// It's a bug in the application if this happens. // It's a bug in the application if this happens.
if (strm->internal->next.get_check == NULL) if (strm->internal->next.get_check == NULL)
return LZMA_CHECK_NONE; return LZMA_CHECK_NONE;
return strm->internal->next.get_check(strm->internal->next.coder); return strm->internal->next.get_check(strm->internal->next.coder);
} }
 End of changes. 11 change blocks. 
8 lines changed or deleted 58 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/