mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-29 10:50:05 +00:00
Convert core:compress and core:image error checks to new union comparison.
No more need for `is_kind(err, Error_Value)`, just test err == Error_Value.
This commit is contained in:
@@ -33,7 +33,7 @@ main :: proc() {
|
||||
err := zlib.inflate(ODIN_DEMO, &buf);
|
||||
defer bytes.buffer_destroy(&buf);
|
||||
|
||||
if !zlib.is_kind(err, zlib.E_General.OK) {
|
||||
if err != zlib.E_General.OK {
|
||||
fmt.printf("\nError: %v\n", err);
|
||||
}
|
||||
s := bytes.buffer_to_string(&buf);
|
||||
|
||||
@@ -8,7 +8,7 @@ import "core:bytes"
|
||||
import "core:hash"
|
||||
/*
|
||||
zlib.inflate decompresses a ZLIB stream passed in as a []u8 or io.Stream.
|
||||
Returns: Error. You can use zlib.is_kind or compress.is_kind to easily test for OK.
|
||||
Returns: Error.
|
||||
*/
|
||||
|
||||
Context :: compress.Context;
|
||||
@@ -34,7 +34,6 @@ Error :: compress.Error;
|
||||
E_General :: compress.General_Error;
|
||||
E_ZLIB :: compress.ZLIB_Error;
|
||||
E_Deflate :: compress.Deflate_Error;
|
||||
is_kind :: compress.is_kind;
|
||||
|
||||
DEFLATE_MAX_CHUNK_SIZE :: 65535;
|
||||
DEFLATE_MAX_LITERAL_SIZE :: 65535;
|
||||
@@ -256,7 +255,7 @@ decode_huffman :: proc(z: ^Context, t: ^Huffman_Table) -> (r: u16, err: Error) #
|
||||
parse_huffman_block :: proc(z: ^Context, z_repeat, z_offset: ^Huffman_Table) -> (err: Error) #no_bounds_check {
|
||||
#no_bounds_check for {
|
||||
value, e := decode_huffman(z, z_repeat);
|
||||
if !is_kind(e, E_General.OK) {
|
||||
if e != E_General.OK {
|
||||
return err;
|
||||
}
|
||||
if value < 256 {
|
||||
@@ -277,7 +276,7 @@ parse_huffman_block :: proc(z: ^Context, z_repeat, z_offset: ^Huffman_Table) ->
|
||||
}
|
||||
|
||||
value, e = decode_huffman(z, z_offset);
|
||||
if !is_kind(e, E_General.OK) {
|
||||
if e != E_General.OK {
|
||||
return E_Deflate.Bad_Huffman_Code;
|
||||
}
|
||||
|
||||
@@ -390,7 +389,7 @@ inflate_from_stream :: proc(using ctx: ^Context, raw := false, allocator := cont
|
||||
|
||||
// Parse ZLIB stream without header.
|
||||
err = inflate_raw(ctx);
|
||||
if !is_kind(err, E_General.OK) {
|
||||
if err != E_General.OK {
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -418,15 +417,15 @@ inflate_from_stream_raw :: proc(z: ^Context, allocator := context.allocator) ->
|
||||
codelength_ht: ^Huffman_Table;
|
||||
|
||||
z_repeat, err = allocate_huffman_table(allocator=context.allocator);
|
||||
if !is_kind(err, E_General.OK) {
|
||||
if err != E_General.OK {
|
||||
return err;
|
||||
}
|
||||
z_offset, err = allocate_huffman_table(allocator=context.allocator);
|
||||
if !is_kind(err, E_General.OK) {
|
||||
if err != E_General.OK {
|
||||
return err;
|
||||
}
|
||||
codelength_ht, err = allocate_huffman_table(allocator=context.allocator);
|
||||
if !is_kind(err, E_General.OK) {
|
||||
if err != E_General.OK {
|
||||
return err;
|
||||
}
|
||||
defer free(z_repeat);
|
||||
@@ -482,11 +481,11 @@ inflate_from_stream_raw :: proc(z: ^Context, allocator := context.allocator) ->
|
||||
if type == 1 {
|
||||
// Use fixed code lengths.
|
||||
err = build_huffman(z_repeat, Z_FIXED_LENGTH[:]);
|
||||
if !is_kind(err, E_General.OK) {
|
||||
if err != E_General.OK {
|
||||
return err;
|
||||
}
|
||||
err = build_huffman(z_offset, Z_FIXED_DIST[:]);
|
||||
if !is_kind(err, E_General.OK) {
|
||||
if err != E_General.OK {
|
||||
return err;
|
||||
}
|
||||
} else {
|
||||
@@ -507,7 +506,7 @@ inflate_from_stream_raw :: proc(z: ^Context, allocator := context.allocator) ->
|
||||
codelength_sizes[Z_LENGTH_DEZIGZAG[i]] = u8(s);
|
||||
}
|
||||
err = build_huffman(codelength_ht, codelength_sizes[:]);
|
||||
if !is_kind(err, E_General.OK) {
|
||||
if err != E_General.OK {
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -516,7 +515,7 @@ inflate_from_stream_raw :: proc(z: ^Context, allocator := context.allocator) ->
|
||||
|
||||
for n < ntot {
|
||||
c, err = decode_huffman(z, codelength_ht);
|
||||
if !is_kind(err, E_General.OK) {
|
||||
if err != E_General.OK {
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -560,18 +559,18 @@ inflate_from_stream_raw :: proc(z: ^Context, allocator := context.allocator) ->
|
||||
}
|
||||
|
||||
err = build_huffman(z_repeat, lencodes[:hlit]);
|
||||
if !is_kind(err, E_General.OK) {
|
||||
if err != E_General.OK {
|
||||
return err;
|
||||
}
|
||||
|
||||
err = build_huffman(z_offset, lencodes[hlit:ntot]);
|
||||
if !is_kind(err, E_General.OK) {
|
||||
if err != E_General.OK {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
err = parse_huffman_block(z, z_repeat, z_offset);
|
||||
// log.debugf("Err: %v | Final: %v | Type: %v\n", err, final, type);
|
||||
if !is_kind(err, E_General.OK) {
|
||||
if err != E_General.OK {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user