1 ///////////////////////////////////////////////////////////////////////////////
4 /// \brief Initializing and freeing the next coder in the chain
6 // Copyright (C) 2007 Lasse Collin
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
18 ///////////////////////////////////////////////////////////////////////////////
23 lzma_next_filter_init(lzma_next_coder *next, lzma_allocator *allocator,
24 const lzma_filter_info *filters)
26 lzma_ret ret = LZMA_OK;
28 // Free the existing coder if it is different than the current one.
29 if ((uintptr_t)(filters[0].init) != next->init)
30 lzma_next_coder_end(next, allocator);
32 if (filters[0].init != NULL) {
33 // Initialize the new coder.
34 ret = filters[0].init(next, allocator, filters);
36 // Set the init function pointer if initialization was
37 // successful. next->code and next->end are set by the
38 // initialization function itself.
40 next->init = (uintptr_t)(filters[0].init);
41 assert(next->code != NULL);
42 assert(next->end != NULL);
44 lzma_next_coder_end(next, allocator);
53 lzma_next_coder_end(lzma_next_coder *next, lzma_allocator *allocator)
56 if (next->end != NULL)
57 next->end(next->coder, allocator);
59 // Reset the variables so the we don't accidentally think
60 // that it is an already initialized coder.
61 *next = LZMA_NEXT_CODER_INIT;