mirror of
https://github.com/odin-lang/Odin.git
synced 2026-06-04 01:34:39 +00:00
Fix struct #packed alignment calculation
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user