mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-07 08:08:50 +00:00
Fix struct #packed alignment calculation
This commit is contained in:
@@ -1,5 +1,15 @@
|
|||||||
import "mem.odin";
|
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 {
|
crc32 :: proc(data: []u8) -> u32 {
|
||||||
result := ~u32(0);
|
result := ~u32(0);
|
||||||
for b in data {
|
for b in data {
|
||||||
|
|||||||
+1
-1
@@ -38,7 +38,7 @@ read_entire_file :: proc(name: string) -> (data: []u8, success: bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
write_entire_file :: proc(name: string, data: []u8) -> (sucess: 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 {
|
if err != 0 {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1,8 +1,8 @@
|
|||||||
@echo off
|
@echo off
|
||||||
|
|
||||||
rem call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86 1> NUL
|
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 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
|
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" x86 1> NUL
|
||||||
rem call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 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
|
set _NO_DEBUG_HEAP=1
|
||||||
|
|||||||
+5
-6
@@ -1864,21 +1864,20 @@ i64 type_align_of_internal(gbAllocator allocator, Type *t, TypePath *path) {
|
|||||||
return max;
|
return max;
|
||||||
} else if (t->Struct.fields.count > 0) {
|
} else if (t->Struct.fields.count > 0) {
|
||||||
i64 max = 1;
|
i64 max = 1;
|
||||||
if (t->Struct.is_packed) {
|
// NOTE(bill): Check the fields to check for cyclic definitions
|
||||||
max = build_context.word_size;
|
|
||||||
}
|
|
||||||
for_array(i, t->Struct.fields) {
|
for_array(i, t->Struct.fields) {
|
||||||
Type *field_type = t->Struct.fields[i]->type;
|
Type *field_type = t->Struct.fields[i]->type;
|
||||||
type_path_push(path, field_type);
|
type_path_push(path, field_type);
|
||||||
if (path->failure) {
|
if (path->failure) return FAILURE_ALIGNMENT;
|
||||||
return FAILURE_ALIGNMENT;
|
|
||||||
}
|
|
||||||
i64 align = type_align_of_internal(allocator, field_type, path);
|
i64 align = type_align_of_internal(allocator, field_type, path);
|
||||||
type_path_pop(path);
|
type_path_pop(path);
|
||||||
if (max < align) {
|
if (max < align) {
|
||||||
max = align;
|
max = align;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (t->Struct.is_packed) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|||||||
Reference in New Issue
Block a user