From 4262c125c5c56db61c57e090ea76db61c16bcebc Mon Sep 17 00:00:00 2001 From: Ginger Bill Date: Sat, 12 Aug 2017 20:04:35 +0100 Subject: [PATCH] Fix struct #packed alignment calculation --- core/hash.odin | 10 ++++++++++ core/os.odin | 2 +- misc/shell.bat | 4 ++-- src/types.cpp | 11 +++++------ 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/core/hash.odin b/core/hash.odin index 0f04a7dc8..44a4b69fd 100644 --- a/core/hash.odin +++ b/core/hash.odin @@ -1,5 +1,15 @@ import "mem.odin"; +adler32 :: proc(data: []u8) -> u32 { + ADLER_CONST :: 65521; + a, b: u32 = 1, 0; + for x in data { + a = (a + u32(x)) % ADLER_CONST; + b = (b + a) % ADLER_CONST; + } + return (b << 16) | a; +} + crc32 :: proc(data: []u8) -> u32 { result := ~u32(0); for b in data { diff --git a/core/os.odin b/core/os.odin index 798bf299e..1ae1c9e84 100644 --- a/core/os.odin +++ b/core/os.odin @@ -38,7 +38,7 @@ read_entire_file :: proc(name: string) -> (data: []u8, success: bool) { } write_entire_file :: proc(name: string, data: []u8) -> (sucess: bool) { - fd, err := open(name, O_WRONLY, 0); + fd, err := open(name, O_WRONLY|O_CREAT, 0); if err != 0 { return false; } diff --git a/misc/shell.bat b/misc/shell.bat index 36db84570..85a7949c6 100644 --- a/misc/shell.bat +++ b/misc/shell.bat @@ -1,8 +1,8 @@ @echo off rem call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86 1> NUL -call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x64 1> NUL -rem call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x64 1> NUL +rem call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x64 1> NUL +call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x64 1> NUL rem call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x86 1> NUL rem call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 1> NUL set _NO_DEBUG_HEAP=1 diff --git a/src/types.cpp b/src/types.cpp index dd05f3238..dec7428eb 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -1864,21 +1864,20 @@ i64 type_align_of_internal(gbAllocator allocator, Type *t, TypePath *path) { return max; } else if (t->Struct.fields.count > 0) { i64 max = 1; - if (t->Struct.is_packed) { - max = build_context.word_size; - } + // NOTE(bill): Check the fields to check for cyclic definitions for_array(i, t->Struct.fields) { Type *field_type = t->Struct.fields[i]->type; type_path_push(path, field_type); - if (path->failure) { - return FAILURE_ALIGNMENT; - } + if (path->failure) return FAILURE_ALIGNMENT; i64 align = type_align_of_internal(allocator, field_type, path); type_path_pop(path); if (max < align) { max = align; } } + if (t->Struct.is_packed) { + return 1; + } return max; } } break;