Fix opening file without close; Minor fixes

This commit is contained in:
gingerBill
2017-11-09 22:58:44 +00:00
parent eb4b3f5976
commit e5c39fb2a9
4 changed files with 22 additions and 30 deletions

View File

@@ -207,7 +207,7 @@ __Map_Header :: struct #ordered {
is_key_string: bool,
entry_size: int,
entry_align: int,
value_offset: int,
value_offset: uintptr,
value_size: int,
}
@@ -217,8 +217,11 @@ type_info_base :: proc(info: ^Type_Info) -> ^Type_Info {
if info == nil do return nil;
base := info;
switch i in base.variant {
case Type_Info_Named: base = i.base;
loop: for {
switch i in base.variant {
case Type_Info_Named: base = i.base;
case: break loop;
}
}
return base;
}
@@ -228,9 +231,12 @@ type_info_base_without_enum :: proc(info: ^Type_Info) -> ^Type_Info {
if info == nil do return nil;
base := info;
switch i in base.variant {
case Type_Info_Named: base = i.base;
case Type_Info_Enum: base = i.base;
loop: for {
switch i in base.variant {
case Type_Info_Named: base = i.base;
case Type_Info_Enum: base = i.base;
case: break loop;
}
}
return base;
}
@@ -877,24 +883,6 @@ __dynamic_array_append_nothing :: proc(array_: rawptr, elem_size, elem_align: in
return array.len;
}
__slice_append :: proc(slice_: rawptr, elem_size, elem_align: int,
items: rawptr, item_count: int) -> int {
slice := cast(^raw.Slice)slice_;
if item_count <= 0 || items == nil {
return slice.len;
}
item_count = min(slice.cap-slice.len, item_count);
if item_count > 0 {
data := cast(^u8)slice.data;
assert(data != nil);
__mem_copy(data + (elem_size*slice.len), items, elem_size * item_count);
slice.len += item_count;
}
return slice.len;
}
// Map stuff
__default_hash :: proc(data: []u8) -> u128 {

View File

@@ -26,19 +26,19 @@ compare :: proc "contextless" (a, b: []u8) -> int {
slice_ptr :: proc "contextless" (ptr: ^$T, len: int) -> []T {
assert(len >= 0);
slice := raw.Slice{data = ptr, len = len, cap = len};
return (cast(^[]T)&slice)^;
return transmute([]T)slice;
}
slice_ptr :: proc "contextless" (ptr: ^$T, len, cap: int) -> []T {
assert(0 <= len && len <= cap);
slice := raw.Slice{data = ptr, len = len, cap = cap};
return (cast(^[]T)&slice)^;
return transmute([]T)slice;
}
slice_to_bytes :: proc "contextless" (slice: []$T) -> []u8 {
s := cast(^raw.Slice)&slice;
slice_to_bytes :: proc "contextless" (slice: $E/[]$T) -> []u8 {
s := transmute(raw.Slice)slice;
s.len *= size_of(T);
s.cap *= size_of(T);
return (cast(^[]u8)s)^;
return transmute([]u8)s;
}

View File

@@ -2865,6 +2865,7 @@ void check_add_foreign_import_decl(Checker *c, AstNode *decl) {
gbFile f = {};
gbFileError file_err = gb_file_open(&f, c_str);
defer (gb_file_close(&f));
switch (file_err) {
case gbFileError_Invalid:

View File

@@ -1129,6 +1129,9 @@ irValue *ir_emit(irProcedure *proc, irValue *instr) {
irValue *ir_const_int(gbAllocator a, i64 i) {
return ir_value_constant(a, t_int, exact_value_i64(i));
}
irValue *ir_const_uintptr(gbAllocator a, u64 i) {
return ir_value_constant(a, t_uintptr, exact_value_i64(i));
}
irValue *ir_const_i32(gbAllocator a, i32 i) {
return ir_value_constant(a, t_i32, exact_value_i64(i));
}
@@ -1735,7 +1738,7 @@ irValue *ir_gen_map_header(irProcedure *proc, irValue *map_val, Type *map_type)
ir_emit_store(proc, ir_emit_struct_ep(proc, h, 2), ir_const_int(a, entry_size));
ir_emit_store(proc, ir_emit_struct_ep(proc, h, 3), ir_const_int(a, entry_align));
ir_emit_store(proc, ir_emit_struct_ep(proc, h, 4), ir_const_int(a, value_offset));
ir_emit_store(proc, ir_emit_struct_ep(proc, h, 4), ir_const_uintptr(a, value_offset));
ir_emit_store(proc, ir_emit_struct_ep(proc, h, 5), ir_const_int(a, value_size));