liblzma: Avoid defining a 'restrict' macro

Any "#define restrict ..." line may conflict with MSVC header files
that use "__declspec(restrict)".  Define our own LZMA_RESTRICT macro
in "Utilities/cmliblzma/config.h.in" and transform liblzma code to
use it:

 git grep -lE '\<restrict\>' Utilities/cmliblzma/liblzma |
   xargs sed -i 's/\<restrict\>/LZMA_RESTRICT/g'
This commit is contained in:
Brad King 2014-07-24 10:51:21 -04:00
parent 90e7a4d41f
commit 73eab246fb
31 changed files with 103 additions and 101 deletions

View File

@ -188,10 +188,12 @@ typedef uint64_t uintmax_t;
#ifndef HAVE_RESTRICT
# ifdef HAVE___RESTRICT
# define restrict __restrict
# define LZMA_RESTRICT __restrict
# else
# define restrict
# define LZMA_RESTRICT
# endif
#else
# define LZMA_RESTRICT restrict
#endif /* HAVE_RESTRICT */
#ifndef HAVE_INLINE

View File

@ -52,9 +52,9 @@ struct lzma_coder_s {
static lzma_ret
alone_decode(lzma_coder *coder,
lzma_allocator *allocator lzma_attribute((__unused__)),
const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size, uint8_t *restrict out,
size_t *restrict out_pos, size_t out_size,
const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
size_t in_size, uint8_t *LZMA_RESTRICT out,
size_t *LZMA_RESTRICT out_pos, size_t out_size,
lzma_action action)
{
while (*out_pos < out_size

View File

@ -33,9 +33,9 @@ struct lzma_coder_s {
static lzma_ret
alone_encode(lzma_coder *coder,
lzma_allocator *allocator lzma_attribute((__unused__)),
const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size, uint8_t *restrict out,
size_t *restrict out_pos, size_t out_size,
const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
size_t in_size, uint8_t *LZMA_RESTRICT out,
size_t *LZMA_RESTRICT out_pos, size_t out_size,
lzma_action action)
{
while (*out_pos < out_size)

View File

@ -31,9 +31,9 @@ struct lzma_coder_s {
static lzma_ret
auto_decode(lzma_coder *coder, lzma_allocator *allocator,
const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size, uint8_t *restrict out,
size_t *restrict out_pos, size_t out_size, lzma_action action)
const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
size_t in_size, uint8_t *LZMA_RESTRICT out,
size_t *LZMA_RESTRICT out_pos, size_t out_size, lzma_action action)
{
switch (coder->sequence) {
case SEQ_INIT:

View File

@ -72,9 +72,9 @@ is_size_valid(lzma_vli size, lzma_vli reference)
static lzma_ret
block_decode(lzma_coder *coder, lzma_allocator *allocator,
const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size, uint8_t *restrict out,
size_t *restrict out_pos, size_t out_size, lzma_action action)
const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
size_t in_size, uint8_t *LZMA_RESTRICT out,
size_t *LZMA_RESTRICT out_pos, size_t out_size, lzma_action action)
{
switch (coder->sequence) {
case SEQ_CODE: {

View File

@ -46,9 +46,9 @@ struct lzma_coder_s {
static lzma_ret
block_encode(lzma_coder *coder, lzma_allocator *allocator,
const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size, uint8_t *restrict out,
size_t *restrict out_pos, size_t out_size, lzma_action action)
const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
size_t in_size, uint8_t *LZMA_RESTRICT out,
size_t *LZMA_RESTRICT out_pos, size_t out_size, lzma_action action)
{
// Check that our amount of input stays in proper limits.
if (LZMA_VLI_MAX - coder->uncompressed_size < in_size - *in_pos)

View File

@ -70,9 +70,9 @@ lzma_free(void *ptr, lzma_allocator *allocator)
//////////
extern size_t
lzma_bufcpy(const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size, uint8_t *restrict out,
size_t *restrict out_pos, size_t out_size)
lzma_bufcpy(const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
size_t in_size, uint8_t *LZMA_RESTRICT out,
size_t *LZMA_RESTRICT out_pos, size_t out_size)
{
const size_t in_avail = in_size - *in_pos;
const size_t out_avail = out_size - *out_pos;

View File

@ -88,9 +88,9 @@ typedef lzma_ret (*lzma_init_function)(
/// function prototype.
typedef lzma_ret (*lzma_code_function)(
lzma_coder *coder, lzma_allocator *allocator,
const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size, uint8_t *restrict out,
size_t *restrict out_pos, size_t out_size,
const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
size_t in_size, uint8_t *LZMA_RESTRICT out,
size_t *LZMA_RESTRICT out_pos, size_t out_size,
lzma_action action);
/// Type of a function to free the memory allocated for the coder
@ -234,9 +234,9 @@ extern void lzma_next_end(lzma_next_coder *next, lzma_allocator *allocator);
/// Copy as much data as possible from in[] to out[] and update *in_pos
/// and *out_pos accordingly. Returns the number of bytes copied.
extern size_t lzma_bufcpy(const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size, uint8_t *restrict out,
size_t *restrict out_pos, size_t out_size);
extern size_t lzma_bufcpy(const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
size_t in_size, uint8_t *LZMA_RESTRICT out,
size_t *LZMA_RESTRICT out_pos, size_t out_size);
/// \brief Return if expression doesn't evaluate to LZMA_OK

View File

@ -780,7 +780,7 @@ index_cat_helper(const index_cat_info *info, index_stream *this)
extern LZMA_API(lzma_ret)
lzma_index_cat(lzma_index *restrict dest, lzma_index *restrict src,
lzma_index_cat(lzma_index *LZMA_RESTRICT dest, lzma_index *LZMA_RESTRICT src,
lzma_allocator *allocator)
{
index_cat_info info;

View File

@ -55,10 +55,10 @@ struct lzma_coder_s {
static lzma_ret
index_decode(lzma_coder *coder, lzma_allocator *allocator,
const uint8_t *restrict in, size_t *restrict in_pos,
const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
size_t in_size,
uint8_t *restrict out lzma_attribute((__unused__)),
size_t *restrict out_pos lzma_attribute((__unused__)),
uint8_t *LZMA_RESTRICT out lzma_attribute((__unused__)),
size_t *LZMA_RESTRICT out_pos lzma_attribute((__unused__)),
size_t out_size lzma_attribute((__unused__)),
lzma_action action lzma_attribute((__unused__)))
{

View File

@ -43,10 +43,10 @@ struct lzma_coder_s {
static lzma_ret
index_encode(lzma_coder *coder,
lzma_allocator *allocator lzma_attribute((__unused__)),
const uint8_t *restrict in lzma_attribute((__unused__)),
size_t *restrict in_pos lzma_attribute((__unused__)),
const uint8_t *LZMA_RESTRICT in lzma_attribute((__unused__)),
size_t *LZMA_RESTRICT in_pos lzma_attribute((__unused__)),
size_t in_size lzma_attribute((__unused__)),
uint8_t *restrict out, size_t *restrict out_pos,
uint8_t *LZMA_RESTRICT out, size_t *LZMA_RESTRICT out_pos,
size_t out_size,
lzma_action action lzma_attribute((__unused__)))
{

View File

@ -97,9 +97,9 @@ stream_decoder_reset(lzma_coder *coder, lzma_allocator *allocator)
static lzma_ret
stream_decode(lzma_coder *coder, lzma_allocator *allocator,
const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size, uint8_t *restrict out,
size_t *restrict out_pos, size_t out_size, lzma_action action)
const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
size_t in_size, uint8_t *LZMA_RESTRICT out,
size_t *LZMA_RESTRICT out_pos, size_t out_size, lzma_action action)
{
// When decoding the actual Block, it may be able to produce more
// output even if we don't give it any new input.

View File

@ -80,9 +80,9 @@ block_encoder_init(lzma_coder *coder, lzma_allocator *allocator)
static lzma_ret
stream_encode(lzma_coder *coder, lzma_allocator *allocator,
const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size, uint8_t *restrict out,
size_t *restrict out_pos, size_t out_size, lzma_action action)
const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
size_t in_size, uint8_t *LZMA_RESTRICT out,
size_t *LZMA_RESTRICT out_pos, size_t out_size, lzma_action action)
{
// Main loop
while (*out_pos < out_size)

View File

@ -14,8 +14,8 @@
extern LZMA_API(lzma_ret)
lzma_vli_decode(lzma_vli *restrict vli, size_t *vli_pos,
const uint8_t *restrict in, size_t *restrict in_pos,
lzma_vli_decode(lzma_vli *LZMA_RESTRICT vli, size_t *vli_pos,
const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
size_t in_size)
{
// If we haven't been given vli_pos, work in single-call mode.

View File

@ -15,7 +15,7 @@
extern LZMA_API(lzma_ret)
lzma_vli_encode(lzma_vli vli, size_t *vli_pos,
uint8_t *restrict out, size_t *restrict out_pos,
uint8_t *LZMA_RESTRICT out, size_t *LZMA_RESTRICT out_pos,
size_t out_size)
{
// If we haven't been given vli_pos, work in single-call mode.

View File

@ -29,9 +29,9 @@ decode_buffer(lzma_coder *coder, uint8_t *buffer, size_t size)
static lzma_ret
delta_decode(lzma_coder *coder, lzma_allocator *allocator,
const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size, uint8_t *restrict out,
size_t *restrict out_pos, size_t out_size, lzma_action action)
const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
size_t in_size, uint8_t *LZMA_RESTRICT out,
size_t *LZMA_RESTRICT out_pos, size_t out_size, lzma_action action)
{
const size_t out_start = *out_pos;
lzma_ret ret;

View File

@ -19,7 +19,7 @@
/// encoder's filter stack).
static void
copy_and_encode(lzma_coder *coder,
const uint8_t *restrict in, uint8_t *restrict out, size_t size)
const uint8_t *LZMA_RESTRICT in, uint8_t *LZMA_RESTRICT out, size_t size)
{
size_t i;
const size_t distance = coder->distance;
@ -52,9 +52,9 @@ encode_in_place(lzma_coder *coder, uint8_t *buffer, size_t size)
static lzma_ret
delta_encode(lzma_coder *coder, lzma_allocator *allocator,
const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size, uint8_t *restrict out,
size_t *restrict out_pos, size_t out_size, lzma_action action)
const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
size_t in_size, uint8_t *LZMA_RESTRICT out,
size_t *LZMA_RESTRICT out_pos, size_t out_size, lzma_action action)
{
lzma_ret ret;

View File

@ -64,9 +64,9 @@ lz_decoder_reset(lzma_coder *coder)
static lzma_ret
decode_buffer(lzma_coder *coder,
const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size, uint8_t *restrict out,
size_t *restrict out_pos, size_t out_size)
const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
size_t in_size, uint8_t *LZMA_RESTRICT out,
size_t *LZMA_RESTRICT out_pos, size_t out_size)
{
while (true) {
size_t copy_size;
@ -131,9 +131,9 @@ decode_buffer(lzma_coder *coder,
static lzma_ret
lz_decode(lzma_coder *coder,
lzma_allocator *allocator lzma_attribute((__unused__)),
const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size, uint8_t *restrict out,
size_t *restrict out_pos, size_t out_size,
const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
size_t in_size, uint8_t *LZMA_RESTRICT out,
size_t *LZMA_RESTRICT out_pos, size_t out_size,
lzma_action action)
{
if (coder->next.code == NULL)

View File

@ -56,9 +56,9 @@ typedef struct {
lzma_coder *coder;
/// Function to decode from in[] to *dict
lzma_ret (*code)(lzma_coder *restrict coder,
lzma_dict *restrict dict, const uint8_t *restrict in,
size_t *restrict in_pos, size_t in_size);
lzma_ret (*code)(lzma_coder *LZMA_RESTRICT coder,
lzma_dict *LZMA_RESTRICT dict, const uint8_t *LZMA_RESTRICT in,
size_t *LZMA_RESTRICT in_pos, size_t in_size);
void (*reset)(lzma_coder *coder, const void *options);
@ -202,9 +202,9 @@ dict_put(lzma_dict *dict, uint8_t byte)
/// Copies arbitrary amount of data into the dictionary.
static inline void
dict_write(lzma_dict *restrict dict, const uint8_t *restrict in,
size_t *restrict in_pos, size_t in_size,
size_t *restrict left)
dict_write(lzma_dict *LZMA_RESTRICT dict, const uint8_t *LZMA_RESTRICT in,
size_t *LZMA_RESTRICT in_pos, size_t in_size,
size_t *LZMA_RESTRICT left)
{
// NOTE: If we are being given more data than the size of the
// dictionary, it could be possible to optimize the LZ decoder

View File

@ -153,9 +153,9 @@ fill_window(lzma_coder *coder, lzma_allocator *allocator, const uint8_t *in,
static lzma_ret
lz_encode(lzma_coder *coder, lzma_allocator *allocator,
const uint8_t *restrict in, size_t *restrict in_pos,
const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
size_t in_size,
uint8_t *restrict out, size_t *restrict out_pos,
uint8_t *LZMA_RESTRICT out, size_t *LZMA_RESTRICT out_pos,
size_t out_size, lzma_action action)
{
while (*out_pos < out_size

View File

@ -194,9 +194,9 @@ typedef struct {
lzma_coder *coder;
/// Function to encode from *dict to out[]
lzma_ret (*code)(lzma_coder *restrict coder,
lzma_mf *restrict mf, uint8_t *restrict out,
size_t *restrict out_pos, size_t out_size);
lzma_ret (*code)(lzma_coder *LZMA_RESTRICT coder,
lzma_mf *LZMA_RESTRICT mf, uint8_t *LZMA_RESTRICT out,
size_t *LZMA_RESTRICT out_pos, size_t out_size);
/// Free allocated resources
void (*end)(lzma_coder *coder, lzma_allocator *allocator);

View File

@ -54,8 +54,8 @@ struct lzma_coder_s {
static lzma_ret
lzma2_decode(lzma_coder *restrict coder, lzma_dict *restrict dict,
const uint8_t *restrict in, size_t *restrict in_pos,
lzma2_decode(lzma_coder *LZMA_RESTRICT coder, lzma_dict *LZMA_RESTRICT dict,
const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
size_t in_size)
{
// With SEQ_LZMA it is possible that no new input is needed to do

View File

@ -134,8 +134,8 @@ lzma2_header_uncompressed(lzma_coder *coder)
static lzma_ret
lzma2_encode(lzma_coder *restrict coder, lzma_mf *restrict mf,
uint8_t *restrict out, size_t *restrict out_pos,
lzma2_encode(lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT mf,
uint8_t *LZMA_RESTRICT out, size_t *LZMA_RESTRICT out_pos,
size_t out_size)
{
while (*out_pos < out_size)

View File

@ -281,9 +281,9 @@ struct lzma_coder_s {
static lzma_ret
lzma_decode(lzma_coder *restrict coder, lzma_dict *restrict dictptr,
const uint8_t *restrict in,
size_t *restrict in_pos, size_t in_size)
lzma_decode(lzma_coder *LZMA_RESTRICT coder, lzma_dict *LZMA_RESTRICT dictptr,
const uint8_t *LZMA_RESTRICT in,
size_t *LZMA_RESTRICT in_pos, size_t in_size)
{
///////////////
// Variables //

View File

@ -318,8 +318,8 @@ encode_eopm(lzma_coder *coder, uint32_t position)
extern lzma_ret
lzma_lzma_encode(lzma_coder *restrict coder, lzma_mf *restrict mf,
uint8_t *restrict out, size_t *restrict out_pos,
lzma_lzma_encode(lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT mf,
uint8_t *LZMA_RESTRICT out, size_t *LZMA_RESTRICT out_pos,
size_t out_size, uint32_t limit)
{
uint32_t position;
@ -414,8 +414,8 @@ lzma_lzma_encode(lzma_coder *restrict coder, lzma_mf *restrict mf,
static lzma_ret
lzma_encode(lzma_coder *restrict coder, lzma_mf *restrict mf,
uint8_t *restrict out, size_t *restrict out_pos,
lzma_encode(lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT mf,
uint8_t *LZMA_RESTRICT out, size_t *LZMA_RESTRICT out_pos,
size_t out_size)
{
// Plain LZMA has no support for sync-flushing.

View File

@ -44,9 +44,9 @@ extern lzma_ret lzma_lzma_encoder_reset(
lzma_coder *coder, const lzma_options_lzma *options);
extern lzma_ret lzma_lzma_encode(lzma_coder *restrict coder,
lzma_mf *restrict mf, uint8_t *restrict out,
size_t *restrict out_pos, size_t out_size,
extern lzma_ret lzma_lzma_encode(lzma_coder *LZMA_RESTRICT coder,
lzma_mf *LZMA_RESTRICT mf, uint8_t *LZMA_RESTRICT out,
size_t *LZMA_RESTRICT out_pos, size_t out_size,
uint32_t read_limit);
#endif

View File

@ -17,8 +17,8 @@
extern void
lzma_lzma_optimum_fast(lzma_coder *restrict coder, lzma_mf *restrict mf,
uint32_t *restrict back_res, uint32_t *restrict len_res)
lzma_lzma_optimum_fast(lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT mf,
uint32_t *LZMA_RESTRICT back_res, uint32_t *LZMA_RESTRICT len_res)
{
const uint8_t *buf;
uint32_t buf_avail;

View File

@ -230,8 +230,8 @@ make_short_rep(lzma_optimal *optimal)
static void
backward(lzma_coder *restrict coder, uint32_t *restrict len_res,
uint32_t *restrict back_res, uint32_t cur)
backward(lzma_coder *LZMA_RESTRICT coder, uint32_t *LZMA_RESTRICT len_res,
uint32_t *LZMA_RESTRICT back_res, uint32_t cur)
{
uint32_t pos_mem = coder->opts[cur].pos_prev;
uint32_t back_mem = coder->opts[cur].back_prev;
@ -278,8 +278,8 @@ backward(lzma_coder *restrict coder, uint32_t *restrict len_res,
//////////
static inline uint32_t
helper1(lzma_coder *restrict coder, lzma_mf *restrict mf,
uint32_t *restrict back_res, uint32_t *restrict len_res,
helper1(lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT mf,
uint32_t *LZMA_RESTRICT back_res, uint32_t *LZMA_RESTRICT len_res,
uint32_t position)
{
uint32_t buf_avail;
@ -865,8 +865,8 @@ helper2(lzma_coder *coder, uint32_t *reps, const uint8_t *buf,
extern void
lzma_lzma_optimum_normal(lzma_coder *restrict coder, lzma_mf *restrict mf,
uint32_t *restrict back_res, uint32_t *restrict len_res,
lzma_lzma_optimum_normal(lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT mf,
uint32_t *LZMA_RESTRICT back_res, uint32_t *LZMA_RESTRICT len_res,
uint32_t position)
{
uint32_t reps[REP_DISTANCES];

View File

@ -138,11 +138,11 @@ struct lzma_coder_s {
extern void lzma_lzma_optimum_fast(
lzma_coder *restrict coder, lzma_mf *restrict mf,
uint32_t *restrict back_res, uint32_t *restrict len_res);
lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT mf,
uint32_t *LZMA_RESTRICT back_res, uint32_t *LZMA_RESTRICT len_res);
extern void lzma_lzma_optimum_normal(lzma_coder *restrict coder,
lzma_mf *restrict mf, uint32_t *restrict back_res,
uint32_t *restrict len_res, uint32_t position);
extern void lzma_lzma_optimum_normal(lzma_coder *LZMA_RESTRICT coder,
lzma_mf *LZMA_RESTRICT mf, uint32_t *LZMA_RESTRICT back_res,
uint32_t *LZMA_RESTRICT len_res, uint32_t position);
#endif

View File

@ -26,8 +26,8 @@ typedef struct {
/// Reads the first five bytes to initialize the range decoder.
static inline bool
rc_read_init(lzma_range_decoder *rc, const uint8_t *restrict in,
size_t *restrict in_pos, size_t in_size)
rc_read_init(lzma_range_decoder *rc, const uint8_t *LZMA_RESTRICT in,
size_t *LZMA_RESTRICT in_pos, size_t in_size)
{
while (rc->init_bytes_left > 0) {
if (*in_pos == in_size)

View File

@ -19,9 +19,9 @@
/// Copied or encodes/decodes more data to out[].
static lzma_ret
copy_or_code(lzma_coder *coder, lzma_allocator *allocator,
const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size, uint8_t *restrict out,
size_t *restrict out_pos, size_t out_size, lzma_action action)
const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
size_t in_size, uint8_t *LZMA_RESTRICT out,
size_t *LZMA_RESTRICT out_pos, size_t out_size, lzma_action action)
{
assert(!coder->end_was_reached);
@ -67,9 +67,9 @@ call_filter(lzma_coder *coder, uint8_t *buffer, size_t size)
static lzma_ret
simple_code(lzma_coder *coder, lzma_allocator *allocator,
const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size, uint8_t *restrict out,
size_t *restrict out_pos, size_t out_size, lzma_action action)
const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
size_t in_size, uint8_t *LZMA_RESTRICT out,
size_t *LZMA_RESTRICT out_pos, size_t out_size, lzma_action action)
{
size_t out_avail;
size_t buf_avail;