Fix loads of indentation issues with mixing spaces and tabs

This commit is contained in:
gingerBill
2024-06-29 19:50:51 +01:00
parent 90244a0849
commit e296d6fb90
34 changed files with 760 additions and 763 deletions
+2 -2
View File
@@ -83,7 +83,7 @@ default_random_generator_proc :: proc(data: rawptr, mode: Random_Generator_Mode,
switch mode { switch mode {
case .Read: case .Read:
if r.state == 0 && r.inc == 0 { if r.state == 0 && r.inc == 0 {
init(r, 0) init(r, 0)
} }
switch len(p) { switch len(p) {
@@ -108,7 +108,7 @@ default_random_generator_proc :: proc(data: rawptr, mode: Random_Generator_Mode,
case .Reset: case .Reset:
seed: u64 seed: u64
mem_copy_non_overlapping(&seed, raw_data(p), min(size_of(seed), len(p))) mem_copy_non_overlapping(&seed, raw_data(p), min(size_of(seed), len(p)))
init(r, seed) init(r, seed)
case .Query_Info: case .Query_Info:
if len(p) != size_of(Random_Generator_Query_Info) { if len(p) != size_of(Random_Generator_Query_Info) {
+3 -3
View File
@@ -34,13 +34,13 @@ COMPRESS_OUTPUT_ALLOCATE_MIN :: int(#config(COMPRESS_OUTPUT_ALLOCATE_MIN, 1 << 2
*/ */
when size_of(uintptr) == 8 { when size_of(uintptr) == 8 {
// For 64-bit platforms, we set the default max buffer size to 4 GiB, // For 64-bit platforms, we set the default max buffer size to 4 GiB,
// which is GZIP and PKZIP's max payload size. // which is GZIP and PKZIP's max payload size.
COMPRESS_OUTPUT_ALLOCATE_MAX :: int(#config(COMPRESS_OUTPUT_ALLOCATE_MAX, 1 << 32)) COMPRESS_OUTPUT_ALLOCATE_MAX :: int(#config(COMPRESS_OUTPUT_ALLOCATE_MAX, 1 << 32))
} else { } else {
// For 32-bit platforms, we set the default max buffer size to 512 MiB. // For 32-bit platforms, we set the default max buffer size to 512 MiB.
COMPRESS_OUTPUT_ALLOCATE_MAX :: int(#config(COMPRESS_OUTPUT_ALLOCATE_MAX, 1 << 29)) COMPRESS_OUTPUT_ALLOCATE_MAX :: int(#config(COMPRESS_OUTPUT_ALLOCATE_MAX, 1 << 29))
} }
+4 -4
View File
@@ -119,20 +119,20 @@ consume :: proc "odin" (a: ^$A/Small_Array($N, $T), count: int, loc := #caller_l
} }
ordered_remove :: proc "contextless" (a: ^$A/Small_Array($N, $T), index: int, loc := #caller_location) #no_bounds_check { ordered_remove :: proc "contextless" (a: ^$A/Small_Array($N, $T), index: int, loc := #caller_location) #no_bounds_check {
runtime.bounds_check_error_loc(loc, index, a.len) runtime.bounds_check_error_loc(loc, index, a.len)
if index+1 < a.len { if index+1 < a.len {
copy(a.data[index:], a.data[index+1:]) copy(a.data[index:], a.data[index+1:])
} }
a.len -= 1 a.len -= 1
} }
unordered_remove :: proc "contextless" (a: ^$A/Small_Array($N, $T), index: int, loc := #caller_location) #no_bounds_check { unordered_remove :: proc "contextless" (a: ^$A/Small_Array($N, $T), index: int, loc := #caller_location) #no_bounds_check {
runtime.bounds_check_error_loc(loc, index, a.len) runtime.bounds_check_error_loc(loc, index, a.len)
n := a.len-1 n := a.len-1
if index != n { if index != n {
a.data[index] = a.data[n] a.data[index] = a.data[n]
} }
a.len -= 1 a.len -= 1
} }
clear :: proc "contextless" (a: ^$A/Small_Array($N, $T)) { clear :: proc "contextless" (a: ^$A/Small_Array($N, $T)) {
@@ -61,7 +61,7 @@ add_dependency :: proc(sorter: ^$S/Sorter($K), key, dependency: K) -> bool {
} }
find.dependents[key] = true find.dependents[key] = true
find = &sorter.relations[key] find = &sorter.relations[key]
if find == nil { if find == nil {
find = map_insert(&sorter.relations, key, make_relations(sorter)) find = map_insert(&sorter.relations, key, make_relations(sorter))
} }
+2 -2
View File
@@ -11,7 +11,7 @@ HAS_RAND_BYTES :: true
_rand_bytes :: proc(dst: []byte) { _rand_bytes :: proc(dst: []byte) {
err := Sec.RandomCopyBytes(count=len(dst), bytes=raw_data(dst)) err := Sec.RandomCopyBytes(count=len(dst), bytes=raw_data(dst))
if err != .Success { if err != .Success {
msg := CF.StringCopyToOdinString(Sec.CopyErrorMessageString(err)) msg := CF.StringCopyToOdinString(Sec.CopyErrorMessageString(err))
fmt.panicf("crypto/rand_bytes: SecRandomCopyBytes returned non-zero result: %v %s", err, msg) fmt.panicf("crypto/rand_bytes: SecRandomCopyBytes returned non-zero result: %v %s", err, msg)
} }
} }
+15 -15
View File
@@ -423,7 +423,7 @@ _decode_bytes :: proc(d: Decoder, add: Add, type: Major = .Bytes, allocator := c
_encode_bytes :: proc(e: Encoder, val: Bytes, major: Major = .Bytes) -> (err: Encode_Error) { _encode_bytes :: proc(e: Encoder, val: Bytes, major: Major = .Bytes) -> (err: Encode_Error) {
assert(len(val) >= 0) assert(len(val) >= 0)
_encode_u64(e, u64(len(val)), major) or_return _encode_u64(e, u64(len(val)), major) or_return
_, err = io.write_full(e.writer, val[:]) _, err = io.write_full(e.writer, val[:])
return return
} }
@@ -440,7 +440,7 @@ _decode_text :: proc(d: Decoder, add: Add, allocator := context.allocator, loc :
} }
_encode_text :: proc(e: Encoder, val: Text) -> Encode_Error { _encode_text :: proc(e: Encoder, val: Text) -> Encode_Error {
return _encode_bytes(e, transmute([]byte)val, .Text) return _encode_bytes(e, transmute([]byte)val, .Text)
} }
_decode_array_ptr :: proc(d: Decoder, add: Add, allocator := context.allocator, loc := #caller_location) -> (v: ^Array, err: Decode_Error) { _decode_array_ptr :: proc(d: Decoder, add: Add, allocator := context.allocator, loc := #caller_location) -> (v: ^Array, err: Decode_Error) {
@@ -480,10 +480,10 @@ _decode_array :: proc(d: Decoder, add: Add, allocator := context.allocator, loc
_encode_array :: proc(e: Encoder, arr: Array) -> Encode_Error { _encode_array :: proc(e: Encoder, arr: Array) -> Encode_Error {
assert(len(arr) >= 0) assert(len(arr) >= 0)
_encode_u64(e, u64(len(arr)), .Array) _encode_u64(e, u64(len(arr)), .Array)
for val in arr { for val in arr {
encode(e, val) or_return encode(e, val) or_return
} }
return nil return nil
} }
_decode_map_ptr :: proc(d: Decoder, add: Add, allocator := context.allocator, loc := #caller_location) -> (v: ^Map, err: Decode_Error) { _decode_map_ptr :: proc(d: Decoder, add: Add, allocator := context.allocator, loc := #caller_location) -> (v: ^Map, err: Decode_Error) {
@@ -576,7 +576,7 @@ _encode_map :: proc(e: Encoder, m: Map) -> (err: Encode_Error) {
encode(e, entry.entry.value) or_return encode(e, entry.entry.value) or_return
} }
return nil return nil
} }
_decode_tag_ptr :: proc(d: Decoder, add: Add, allocator := context.allocator, loc := #caller_location) -> (v: Value, err: Decode_Error) { _decode_tag_ptr :: proc(d: Decoder, add: Add, allocator := context.allocator, loc := #caller_location) -> (v: Value, err: Decode_Error) {
@@ -626,7 +626,7 @@ _decode_uint_as_u64 :: proc(r: io.Reader, add: Add) -> (nr: u64, err: Decode_Err
_encode_tag :: proc(e: Encoder, val: Tag) -> Encode_Error { _encode_tag :: proc(e: Encoder, val: Tag) -> Encode_Error {
_encode_u64(e, val.number, .Tag) or_return _encode_u64(e, val.number, .Tag) or_return
return encode(e, val.value) return encode(e, val.value)
} }
_decode_simple :: proc(r: io.Reader) -> (v: Simple, err: io.Error) { _decode_simple :: proc(r: io.Reader) -> (v: Simple, err: io.Error) {
@@ -739,16 +739,16 @@ _encode_nil :: proc(w: io.Writer) -> io.Error {
// Streaming // Streaming
encode_stream_begin :: proc(w: io.Writer, major: Major) -> (err: io.Error) { encode_stream_begin :: proc(w: io.Writer, major: Major) -> (err: io.Error) {
assert(major >= Major(.Bytes) && major <= Major(.Map), "illegal stream type") assert(major >= Major(.Bytes) && major <= Major(.Map), "illegal stream type")
header := (u8(major) << 5) | u8(Add.Length_Unknown) header := (u8(major) << 5) | u8(Add.Length_Unknown)
_, err = io.write_full(w, {header}) _, err = io.write_full(w, {header})
return return
} }
encode_stream_end :: proc(w: io.Writer) -> io.Error { encode_stream_end :: proc(w: io.Writer) -> io.Error {
header := (u8(Major.Other) << 5) | u8(Add.Break) header := (u8(Major.Other) << 5) | u8(Add.Break)
_, err := io.write_full(w, {header}) _, err := io.write_full(w, {header})
return err return err
} }
@@ -757,8 +757,8 @@ encode_stream_text :: _encode_text
encode_stream_array_item :: encode encode_stream_array_item :: encode
encode_stream_map_entry :: proc(e: Encoder, key: Value, val: Value) -> Encode_Error { encode_stream_map_entry :: proc(e: Encoder, key: Value, val: Value) -> Encode_Error {
encode(e, key) or_return encode(e, key) or_return
return encode(e, val) return encode(e, val)
} }
// For `Bytes` and `Text` strings: Decodes the number of items the header says follows. // For `Bytes` and `Text` strings: Decodes the number of items the header says follows.
+7 -7
View File
@@ -273,13 +273,13 @@ _unmarshal_value :: proc(d: Decoder, v: any, hdr: Header, allocator := context.a
// NOTE: Because this is a special type and not to be treated as a general integer, // NOTE: Because this is a special type and not to be treated as a general integer,
// We only put the value of it in fields that are explicitly of type `Simple`. // We only put the value of it in fields that are explicitly of type `Simple`.
switch &dst in v { switch &dst in v {
case Simple: case Simple:
dst = decoded dst = decoded
return return
case: case:
return _unsupported(v, hdr, add) return _unsupported(v, hdr, add)
} }
case .Tag: case .Tag:
switch &dst in v { switch &dst in v {
+4 -4
View File
@@ -387,17 +387,17 @@ marshal_to_writer :: proc(w: io.Writer, v: any, opt: ^Marshal_Options) -> (err:
case runtime.Type_Info_Pointer, case runtime.Type_Info_Pointer,
runtime.Type_Info_Multi_Pointer, runtime.Type_Info_Multi_Pointer,
runtime.Type_Info_Procedure: runtime.Type_Info_Procedure:
return (^rawptr)(v.data)^ == nil return (^rawptr)(v.data)^ == nil
case runtime.Type_Info_Dynamic_Array: case runtime.Type_Info_Dynamic_Array:
return (^runtime.Raw_Dynamic_Array)(v.data).len == 0 return (^runtime.Raw_Dynamic_Array)(v.data).len == 0
case runtime.Type_Info_Slice: case runtime.Type_Info_Slice:
return (^runtime.Raw_Slice)(v.data).len == 0 return (^runtime.Raw_Slice)(v.data).len == 0
case runtime.Type_Info_Union, case runtime.Type_Info_Union,
runtime.Type_Info_Bit_Set, runtime.Type_Info_Bit_Set,
runtime.Type_Info_Soa_Pointer: runtime.Type_Info_Soa_Pointer:
return reflect.is_nil(v) return reflect.is_nil(v)
case runtime.Type_Info_Map: case runtime.Type_Info_Map:
return (^runtime.Raw_Map)(v.data).len == 0 return (^runtime.Raw_Map)(v.data).len == 0
} }
return false return false
} }
+5 -5
View File
@@ -33,7 +33,7 @@ print :: proc(writer: io.Writer, doc: ^Document) -> (written: int, err: io.Error
written += fmt.wprintf(writer, "[DOCTYPE] %v\n", doc.doctype.ident) written += fmt.wprintf(writer, "[DOCTYPE] %v\n", doc.doctype.ident)
if len(doc.doctype.rest) > 0 { if len(doc.doctype.rest) > 0 {
fmt.wprintf(writer, "\t%v\n", doc.doctype.rest) fmt.wprintf(writer, "\t%v\n", doc.doctype.rest)
} }
} }
@@ -42,10 +42,10 @@ print :: proc(writer: io.Writer, doc: ^Document) -> (written: int, err: io.Error
} }
if len(doc.elements) > 0 { if len(doc.elements) > 0 {
fmt.wprintln(writer, " --- ") fmt.wprintln(writer, " --- ")
print_element(writer, doc, 0) print_element(writer, doc, 0)
fmt.wprintln(writer, " --- ") fmt.wprintln(writer, " --- ")
} }
return written, .None return written, .None
} }
+8 -8
View File
@@ -92,7 +92,7 @@ _user_formatters: ^map[typeid]User_Formatter
// //
set_user_formatters :: proc(m: ^map[typeid]User_Formatter) { set_user_formatters :: proc(m: ^map[typeid]User_Formatter) {
assert(_user_formatters == nil, "set_user_formatters must not be called more than once.") assert(_user_formatters == nil, "set_user_formatters must not be called more than once.")
_user_formatters = m _user_formatters = m
} }
// Registers a user-defined formatter for a specific typeid // Registers a user-defined formatter for a specific typeid
// //
@@ -1229,10 +1229,10 @@ _fmt_memory :: proc(fi: ^Info, u: u64, is_signed: bool, bit_size: int, units: st
// Add the unit at the end. // Add the unit at the end.
copy(buf[len(str):], units[off:off+unit_len]) copy(buf[len(str):], units[off:off+unit_len])
str = string(buf[:len(str)+unit_len]) str = string(buf[:len(str)+unit_len])
if !fi.plus { if !fi.plus {
// Strip sign from "+<value>" but not "+Inf". // Strip sign from "+<value>" but not "+Inf".
if str[0] == '+' && str[1] != 'I' { if str[0] == '+' && str[1] != 'I' {
str = str[1:] str = str[1:]
} }
} }
@@ -1765,7 +1765,7 @@ fmt_bit_set :: proc(fi: ^Info, v: any, name: string = "", verb: rune = 'v') {
if is_enum { if is_enum {
enum_name: string enum_name: string
if ti_named, is_named := info.elem.variant.(runtime.Type_Info_Named); is_named { if ti_named, is_named := info.elem.variant.(runtime.Type_Info_Named); is_named {
enum_name = ti_named.name enum_name = ti_named.name
} }
for ev, evi in e.values { for ev, evi in e.values {
@@ -2709,7 +2709,7 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) {
return return
} }
if fi.indirection_level < 1 { if fi.indirection_level < 1 {
fi.indirection_level += 1 fi.indirection_level += 1
defer fi.indirection_level -= 1 defer fi.indirection_level -= 1
io.write_byte(fi.writer, '&') io.write_byte(fi.writer, '&')
fmt_value(fi, a, verb) fmt_value(fi, a, verb)
@@ -2778,7 +2778,7 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) {
runtime.Type_Info_Dynamic_Array, runtime.Type_Info_Dynamic_Array,
runtime.Type_Info_Map: runtime.Type_Info_Map:
if fi.indirection_level < 1 { if fi.indirection_level < 1 {
fi.indirection_level += 1 fi.indirection_level += 1
defer fi.indirection_level -= 1 defer fi.indirection_level -= 1
io.write_byte(fi.writer, '&', &fi.n) io.write_byte(fi.writer, '&', &fi.n)
fmt_value(fi, a, verb) fmt_value(fi, a, verb)
+2 -2
View File
@@ -71,7 +71,7 @@ save_to_buffer :: proc(output: ^bytes.Buffer, img: ^Image, options := Options{}
written := 0 written := 0
if resize(&output.buf, int(header.size)) != nil { if resize(&output.buf, int(header.size)) != nil {
return .Unable_To_Allocate_Or_Resize return .Unable_To_Allocate_Or_Resize
} }
header_bytes := transmute([size_of(image.BMP_Header)]u8)header header_bytes := transmute([size_of(image.BMP_Header)]u8)header
@@ -735,7 +735,7 @@ destroy :: proc(img: ^Image) {
bytes.buffer_destroy(&img.pixels) bytes.buffer_destroy(&img.pixels)
if v, ok := img.metadata.(^image.BMP_Info); ok { if v, ok := img.metadata.(^image.BMP_Info); ok {
free(v) free(v)
} }
free(img) free(img)
} }
+2 -2
View File
@@ -230,7 +230,7 @@ load_from_context :: proc(ctx: ^$C, options := Options{}, allocator := context.a
bytes_needed := image.compute_buffer_size(int(header.width), int(header.height), img.channels, 8) bytes_needed := image.compute_buffer_size(int(header.width), int(header.height), img.channels, 8)
if resize(&img.pixels.buf, bytes_needed) != nil { if resize(&img.pixels.buf, bytes_needed) != nil {
return img, .Unable_To_Allocate_Or_Resize return img, .Unable_To_Allocate_Or_Resize
} }
/* /*
@@ -341,7 +341,7 @@ destroy :: proc(img: ^Image) {
bytes.buffer_destroy(&img.pixels) bytes.buffer_destroy(&img.pixels)
if v, ok := img.metadata.(^image.QOI_Info); ok { if v, ok := img.metadata.(^image.QOI_Info); ok {
free(v) free(v)
} }
free(img) free(img)
} }
+23 -23
View File
@@ -787,8 +787,8 @@ _private_int_sqr_comba :: proc(dest, src: ^Int, allocator := context.allocator)
/* /*
Karatsuba squaring, computes `dest` = `src` * `src` using three half-size squarings. Karatsuba squaring, computes `dest` = `src` * `src` using three half-size squarings.
See comments of `_private_int_mul_karatsuba` for details. See comments of `_private_int_mul_karatsuba` for details.
It is essentially the same algorithm but merely tuned to perform recursive squarings. It is essentially the same algorithm but merely tuned to perform recursive squarings.
*/ */
_private_int_sqr_karatsuba :: proc(dest, src: ^Int, allocator := context.allocator) -> (err: Error) { _private_int_sqr_karatsuba :: proc(dest, src: ^Int, allocator := context.allocator) -> (err: Error) {
context.allocator = allocator context.allocator = allocator
@@ -967,7 +967,7 @@ _private_int_div_3 :: proc(quotient, numerator: ^Int, allocator := context.alloc
/* /*
b = 2^_DIGIT_BITS / 3 b = 2^_DIGIT_BITS / 3
*/ */
b := _WORD(1) << _WORD(_DIGIT_BITS) / _WORD(3) b := _WORD(1) << _WORD(_DIGIT_BITS) / _WORD(3)
q := &Int{} q := &Int{}
internal_grow(q, numerator.used) or_return internal_grow(q, numerator.used) or_return
@@ -1007,8 +1007,8 @@ _private_int_div_3 :: proc(quotient, numerator: ^Int, allocator := context.alloc
*/ */
if quotient != nil { if quotient != nil {
err = clamp(q) err = clamp(q)
internal_swap(q, quotient) internal_swap(q, quotient)
} }
internal_destroy(q) internal_destroy(q)
return remainder, nil return remainder, nil
} }
@@ -1555,24 +1555,24 @@ _private_int_gcd_lcm :: proc(res_gcd, res_lcm, a, b: ^Int, allocator := context.
/* /*
If neither `a` or `b` was zero, we need to compute `gcd`. If neither `a` or `b` was zero, we need to compute `gcd`.
Get copies of `a` and `b` we can modify. Get copies of `a` and `b` we can modify.
*/ */
u, v := &Int{}, &Int{} u, v := &Int{}, &Int{}
defer internal_destroy(u, v) defer internal_destroy(u, v)
internal_copy(u, a) or_return internal_copy(u, a) or_return
internal_copy(v, b) or_return internal_copy(v, b) or_return
/* /*
Must be positive for the remainder of the algorithm. Must be positive for the remainder of the algorithm.
*/ */
u.sign = .Zero_or_Positive; v.sign = .Zero_or_Positive u.sign = .Zero_or_Positive; v.sign = .Zero_or_Positive
/* /*
B1. Find the common power of two for `u` and `v`. B1. Find the common power of two for `u` and `v`.
*/ */
u_lsb, _ := internal_count_lsb(u) u_lsb, _ := internal_count_lsb(u)
v_lsb, _ := internal_count_lsb(v) v_lsb, _ := internal_count_lsb(v)
k := min(u_lsb, v_lsb) k := min(u_lsb, v_lsb)
if k > 0 { if k > 0 {
/* /*
@@ -1615,11 +1615,11 @@ _private_int_gcd_lcm :: proc(res_gcd, res_lcm, a, b: ^Int, allocator := context.
internal_shr(v, v, b) or_return internal_shr(v, v, b) or_return
} }
/* /*
Multiply by 2**k which we divided out at the beginning. Multiply by 2**k which we divided out at the beginning.
*/ */
internal_shl(temp_gcd_res, u, k) or_return internal_shl(temp_gcd_res, u, k) or_return
temp_gcd_res.sign = .Zero_or_Positive temp_gcd_res.sign = .Zero_or_Positive
/* /*
We've computed `gcd`, either the long way, or because one of the inputs was zero. We've computed `gcd`, either the long way, or because one of the inputs was zero.
@@ -1786,8 +1786,8 @@ _private_montgomery_reduce_comba :: proc(x, n: ^Int, rho: DIGIT, allocator := co
`a = a + mu * m * b**i` `a = a + mu * m * b**i`
This is computed in place and on the fly. The multiplication This is computed in place and on the fly. The multiplication
by b**i is handled by offseting which columns the results by b**i is handled by offseting which columns the results
are added to. are added to.
Note the comba method normally doesn't handle carries in the Note the comba method normally doesn't handle carries in the
inner loop In this case we fix the carry from the previous inner loop In this case we fix the carry from the previous
+1 -1
View File
@@ -214,7 +214,7 @@ block_next :: proc(block: ^Block_Header) -> (next: ^Block_Header) {
block_link_next :: proc(block: ^Block_Header) -> (next: ^Block_Header) { block_link_next :: proc(block: ^Block_Header) -> (next: ^Block_Header) {
next = block_next(block) next = block_next(block)
next.prev_phys_block = block next.prev_phys_block = block
return return
} }
block_mark_as_free :: proc(block: ^Block_Header) { block_mark_as_free :: proc(block: ^Block_Header) {
+13 -16
View File
@@ -59,24 +59,21 @@ _enumerate_interfaces :: proc(allocator := context.allocator) -> (interfaces: []
switch int(ifaddr.address.family) { switch int(ifaddr.address.family) {
case os.AF_INET, os.AF_INET6: case os.AF_INET, os.AF_INET6:
address = _sockaddr_basic_to_endpoint(ifaddr.address).address address = _sockaddr_basic_to_endpoint(ifaddr.address).address
case:
} }
} }
if ifaddr.netmask != nil { if ifaddr.netmask != nil {
switch int(ifaddr.netmask.family) { switch int(ifaddr.netmask.family) {
case os.AF_INET, os.AF_INET6: case os.AF_INET, os.AF_INET6:
netmask = Netmask(_sockaddr_basic_to_endpoint(ifaddr.netmask).address) netmask = Netmask(_sockaddr_basic_to_endpoint(ifaddr.netmask).address)
case:
} }
} }
if ifaddr.broadcast_or_dest != nil && .BROADCAST in ifaddr.flags { if ifaddr.broadcast_or_dest != nil && .BROADCAST in ifaddr.flags {
switch int(ifaddr.broadcast_or_dest.family) { switch int(ifaddr.broadcast_or_dest.family) {
case os.AF_INET, os.AF_INET6: case os.AF_INET, os.AF_INET6:
broadcast := _sockaddr_basic_to_endpoint(ifaddr.broadcast_or_dest).address broadcast := _sockaddr_basic_to_endpoint(ifaddr.broadcast_or_dest).address
append(&iface.multicast, broadcast) append(&iface.multicast, broadcast)
case:
} }
} }
@@ -91,19 +88,19 @@ _enumerate_interfaces :: proc(allocator := context.allocator) -> (interfaces: []
/* /*
TODO: Refine this based on the type of adapter. TODO: Refine this based on the type of adapter.
*/ */
state := Link_State{} state := Link_State{}
if .UP in ifaddr.flags { if .UP in ifaddr.flags {
state += {.Up} state += {.Up}
} }
/*if .DORMANT in ifaddr.flags { /*if .DORMANT in ifaddr.flags {
state |= {.Dormant} state |= {.Dormant}
}*/ }*/
if .LOOPBACK in ifaddr.flags { if .LOOPBACK in ifaddr.flags {
state += {.Loopback} state += {.Loopback}
} }
iface.link.state = state iface.link.state = state
} }
+78 -78
View File
@@ -24,42 +24,42 @@ import strings "core:strings"
_enumerate_interfaces :: proc(allocator := context.allocator) -> (interfaces: []Network_Interface, err: Network_Error) { _enumerate_interfaces :: proc(allocator := context.allocator) -> (interfaces: []Network_Interface, err: Network_Error) {
context.allocator = allocator context.allocator = allocator
buf: []u8 buf: []u8
defer delete(buf) defer delete(buf)
buf_size: u32 buf_size: u32
res: u32 res: u32
gaa: for _ in 1..=MAX_INTERFACE_ENUMERATION_TRIES { gaa: for _ in 1..=MAX_INTERFACE_ENUMERATION_TRIES {
res = sys.get_adapters_addresses( res = sys.get_adapters_addresses(
.Unspecified, // Return both IPv4 and IPv6 adapters. .Unspecified, // Return both IPv4 and IPv6 adapters.
sys.GAA_Flags{ sys.GAA_Flags{
.Include_Prefix, // (XP SP1+) Return a list of IP address prefixes on this adapter. When this flag is set, IP address prefixes are returned for both IPv6 and IPv4 addresses. .Include_Prefix, // (XP SP1+) Return a list of IP address prefixes on this adapter. When this flag is set, IP address prefixes are returned for both IPv6 and IPv4 addresses.
.Include_Gateways, // (Vista+) Return the addresses of default gateways. .Include_Gateways, // (Vista+) Return the addresses of default gateways.
.Include_Tunnel_Binding_Order, // (Vista+) Return the adapter addresses sorted in tunnel binding order. .Include_Tunnel_Binding_Order, // (Vista+) Return the adapter addresses sorted in tunnel binding order.
}, },
nil, // Reserved nil, // Reserved
(^sys.IP_Adapter_Addresses)(raw_data(buf)), (^sys.IP_Adapter_Addresses)(raw_data(buf)),
&buf_size, &buf_size,
) )
switch res { switch res {
case 111: // ERROR_BUFFER_OVERFLOW: case 111: // ERROR_BUFFER_OVERFLOW:
delete(buf) delete(buf)
buf = make([]u8, buf_size) buf = make([]u8, buf_size)
case 0: case 0:
break gaa break gaa
case: case:
return {}, Platform_Error(res) return {}, Platform_Error(res)
} }
} }
if res != 0 { if res != 0 {
return {}, .Unable_To_Enumerate_Network_Interfaces return {}, .Unable_To_Enumerate_Network_Interfaces
} }
_interfaces := make([dynamic]Network_Interface, 0, allocator) _interfaces := make([dynamic]Network_Interface, 0, allocator)
for adapter := (^sys.IP_Adapter_Addresses)(raw_data(buf)); adapter != nil; adapter = adapter.Next { for adapter := (^sys.IP_Adapter_Addresses)(raw_data(buf)); adapter != nil; adapter = adapter.Next {
friendly_name, err1 := sys.wstring_to_utf8(sys.wstring(adapter.FriendlyName), 256, allocator) friendly_name, err1 := sys.wstring_to_utf8(sys.wstring(adapter.FriendlyName), 256, allocator)
if err1 != nil { return {}, Platform_Error(err1) } if err1 != nil { return {}, Platform_Error(err1) }
@@ -71,74 +71,74 @@ _enumerate_interfaces :: proc(allocator := context.allocator) -> (interfaces: []
interface := Network_Interface{ interface := Network_Interface{
adapter_name = strings.clone(string(adapter.AdapterName)), adapter_name = strings.clone(string(adapter.AdapterName)),
friendly_name = friendly_name, friendly_name = friendly_name,
description = description, description = description,
dns_suffix = dns_suffix, dns_suffix = dns_suffix,
mtu = adapter.MTU, mtu = adapter.MTU,
link = { link = {
transmit_speed = adapter.TransmitLinkSpeed, transmit_speed = adapter.TransmitLinkSpeed,
receive_speed = adapter.ReceiveLinkSpeed, receive_speed = adapter.ReceiveLinkSpeed,
}, },
} }
if adapter.PhysicalAddressLength > 0 && adapter.PhysicalAddressLength <= len(adapter.PhysicalAddress) { if adapter.PhysicalAddressLength > 0 && adapter.PhysicalAddressLength <= len(adapter.PhysicalAddress) {
interface.physical_address = physical_address_to_string(adapter.PhysicalAddress[:adapter.PhysicalAddressLength]) interface.physical_address = physical_address_to_string(adapter.PhysicalAddress[:adapter.PhysicalAddressLength])
} }
for u_addr := (^sys.IP_ADAPTER_UNICAST_ADDRESS_LH)(adapter.FirstUnicastAddress); u_addr != nil; u_addr = u_addr.Next { for u_addr := (^sys.IP_ADAPTER_UNICAST_ADDRESS_LH)(adapter.FirstUnicastAddress); u_addr != nil; u_addr = u_addr.Next {
win_addr := parse_socket_address(u_addr.Address) win_addr := parse_socket_address(u_addr.Address)
lease := Lease{ lease := Lease{
address = win_addr.address, address = win_addr.address,
origin = { origin = {
prefix = Prefix_Origin(u_addr.PrefixOrigin), prefix = Prefix_Origin(u_addr.PrefixOrigin),
suffix = Suffix_Origin(u_addr.SuffixOrigin), suffix = Suffix_Origin(u_addr.SuffixOrigin),
}, },
lifetime = { lifetime = {
valid = u_addr.ValidLifetime, valid = u_addr.ValidLifetime,
preferred = u_addr.PreferredLifetime, preferred = u_addr.PreferredLifetime,
lease = u_addr.LeaseLifetime, lease = u_addr.LeaseLifetime,
}, },
address_duplication = Address_Duplication(u_addr.DadState), address_duplication = Address_Duplication(u_addr.DadState),
} }
append(&interface.unicast, lease) append(&interface.unicast, lease)
} }
for a_addr := (^sys.IP_ADAPTER_ANYCAST_ADDRESS_XP)(adapter.FirstAnycastAddress); a_addr != nil; a_addr = a_addr.Next { for a_addr := (^sys.IP_ADAPTER_ANYCAST_ADDRESS_XP)(adapter.FirstAnycastAddress); a_addr != nil; a_addr = a_addr.Next {
addr := parse_socket_address(a_addr.Address) addr := parse_socket_address(a_addr.Address)
append(&interface.anycast, addr.address) append(&interface.anycast, addr.address)
} }
for m_addr := (^sys.IP_ADAPTER_MULTICAST_ADDRESS_XP)(adapter.FirstMulticastAddress); m_addr != nil; m_addr = m_addr.Next { for m_addr := (^sys.IP_ADAPTER_MULTICAST_ADDRESS_XP)(adapter.FirstMulticastAddress); m_addr != nil; m_addr = m_addr.Next {
addr := parse_socket_address(m_addr.Address) addr := parse_socket_address(m_addr.Address)
append(&interface.multicast, addr.address) append(&interface.multicast, addr.address)
} }
for g_addr := (^sys.IP_ADAPTER_GATEWAY_ADDRESS_LH)(adapter.FirstGatewayAddress); g_addr != nil; g_addr = g_addr.Next { for g_addr := (^sys.IP_ADAPTER_GATEWAY_ADDRESS_LH)(adapter.FirstGatewayAddress); g_addr != nil; g_addr = g_addr.Next {
addr := parse_socket_address(g_addr.Address) addr := parse_socket_address(g_addr.Address)
append(&interface.gateways, addr.address) append(&interface.gateways, addr.address)
} }
interface.dhcp_v4 = parse_socket_address(adapter.Dhcpv4Server).address interface.dhcp_v4 = parse_socket_address(adapter.Dhcpv4Server).address
interface.dhcp_v6 = parse_socket_address(adapter.Dhcpv6Server).address interface.dhcp_v6 = parse_socket_address(adapter.Dhcpv6Server).address
switch adapter.OperStatus { switch adapter.OperStatus {
case .Up: interface.link.state = {.Up} case .Up: interface.link.state = {.Up}
case .Down: interface.link.state = {.Down} case .Down: interface.link.state = {.Down}
case .Testing: interface.link.state = {.Testing} case .Testing: interface.link.state = {.Testing}
case .Dormant: interface.link.state = {.Dormant} case .Dormant: interface.link.state = {.Dormant}
case .NotPresent: interface.link.state = {.Not_Present} case .NotPresent: interface.link.state = {.Not_Present}
case .LowerLayerDown: interface.link.state = {.Lower_Layer_Down} case .LowerLayerDown: interface.link.state = {.Lower_Layer_Down}
case .Unknown: fallthrough case .Unknown: fallthrough
case: interface.link.state = {} case: interface.link.state = {}
} }
interface.tunnel_type = Tunnel_Type(adapter.TunnelType) interface.tunnel_type = Tunnel_Type(adapter.TunnelType)
append(&_interfaces, interface) append(&_interfaces, interface)
} }
return _interfaces[:], {} return _interfaces[:], {}
} }
+9 -9
View File
@@ -308,7 +308,7 @@ consume_comment_group :: proc(p: ^Parser, n: int) -> (comments: ^ast.Comment_Gro
end_line = p.curr_tok.pos.line end_line = p.curr_tok.pos.line
for p.curr_tok.kind == .Comment && for p.curr_tok.kind == .Comment &&
p.curr_tok.pos.line <= end_line+n { p.curr_tok.pos.line <= end_line+n {
comment: tokenizer.Token comment: tokenizer.Token
comment, end_line = consume_comment(p) comment, end_line = consume_comment(p)
append(&list, comment) append(&list, comment)
} }
@@ -1315,8 +1315,8 @@ parse_stmt :: proc(p: ^Parser) -> ^ast.Stmt {
// Unary Expressions // Unary Expressions
.Add, .Sub, .Xor, .Not, .And: .Add, .Sub, .Xor, .Not, .And:
s := parse_simple_stmt(p, {Stmt_Allow_Flag.Label}) s := parse_simple_stmt(p, {Stmt_Allow_Flag.Label})
expect_semicolon(p, s) expect_semicolon(p, s)
return s return s
@@ -1853,7 +1853,7 @@ parse_ident_list :: proc(p: ^Parser, allow_poly_names: bool) -> []^ast.Expr {
} }
if p.curr_tok.kind != .Comma || if p.curr_tok.kind != .Comma ||
p.curr_tok.kind == .EOF { p.curr_tok.kind == .EOF {
break break
} }
advance_token(p) advance_token(p)
} }
@@ -2216,10 +2216,10 @@ parse_operand :: proc(p: ^Parser, lhs: bool) -> ^ast.Expr {
case .Integer, .Float, .Imag, case .Integer, .Float, .Imag,
.Rune, .String: .Rune, .String:
tok := advance_token(p) tok := advance_token(p)
bl := ast.new(ast.Basic_Lit, tok.pos, end_pos(tok)) bl := ast.new(ast.Basic_Lit, tok.pos, end_pos(tok))
bl.tok = tok bl.tok = tok
return bl return bl
case .Open_Brace: case .Open_Brace:
if !lhs { if !lhs {
@@ -3007,7 +3007,7 @@ parse_literal_value :: proc(p: ^Parser, type: ^ast.Expr) -> ^ast.Comp_Lit {
} }
p.expr_level -= 1 p.expr_level -= 1
skip_possible_newline(p) skip_possible_newline(p)
close := expect_closing_brace_of_field_list(p) close := expect_closing_brace_of_field_list(p)
pos := type.pos if type != nil else open.pos pos := type.pos if type != nil else open.pos
+2 -2
View File
@@ -111,7 +111,7 @@ read_entire_file_from_handle :: proc(fd: Handle, allocator := context.allocator,
length: i64 length: i64
err: Errno err: Errno
if length, err = file_size(fd); err != 0 { if length, err = file_size(fd); err != 0 {
return nil, false return nil, false
} }
if length <= 0 { if length <= 0 {
@@ -120,7 +120,7 @@ read_entire_file_from_handle :: proc(fd: Handle, allocator := context.allocator,
data = make([]byte, int(length), allocator, loc) data = make([]byte, int(length), allocator, loc)
if data == nil { if data == nil {
return nil, false return nil, false
} }
bytes_read, read_err := read_full(fd, data) bytes_read, read_err := read_full(fd, data)
+1 -1
View File
@@ -896,7 +896,7 @@ access :: proc(path: string, mask: int) -> bool {
} }
flush :: proc(fd: Handle) -> Errno { flush :: proc(fd: Handle) -> Errno {
return cast(Errno)_unix_fsync(fd) return cast(Errno)_unix_fsync(fd)
} }
lookup_env :: proc(key: string, allocator := context.allocator) -> (value: string, found: bool) { lookup_env :: proc(key: string, allocator := context.allocator) -> (value: string, found: bool) {
+2 -2
View File
@@ -178,8 +178,8 @@ WINDOWS_11_BUILD_CUTOFF :: 22_000
get_windows_version_w :: proc() -> win32.OSVERSIONINFOEXW { get_windows_version_w :: proc() -> win32.OSVERSIONINFOEXW {
osvi : win32.OSVERSIONINFOEXW osvi : win32.OSVERSIONINFOEXW
osvi.dwOSVersionInfoSize = size_of(win32.OSVERSIONINFOEXW) osvi.dwOSVersionInfoSize = size_of(win32.OSVERSIONINFOEXW)
win32.RtlGetVersion(&osvi) win32.RtlGetVersion(&osvi)
return osvi return osvi
} }
is_windows_xp :: proc() -> bool { is_windows_xp :: proc() -> bool {
+1 -1
View File
@@ -432,7 +432,7 @@ rel :: proc(base_path, target_path: string, allocator := context.allocator) -> (
then `"."` is returned. then `"."` is returned.
*/ */
dir :: proc(path: string, allocator := context.allocator) -> string { dir :: proc(path: string, allocator := context.allocator) -> string {
context.allocator = allocator context.allocator = allocator
vol := volume_name(path) vol := volume_name(path)
i := len(path) - 1 i := len(path) - 1
for i >= len(vol) && !is_separator(path[i]) { for i >= len(vol) && !is_separator(path[i]) {
+2 -2
View File
@@ -114,7 +114,7 @@ are_types_identical :: proc(a, b: ^Type_Info) -> bool {
case Type_Info_Struct: case Type_Info_Struct:
y := b.variant.(Type_Info_Struct) or_return y := b.variant.(Type_Info_Struct) or_return
switch { switch {
case len(x.types) != len(y.types), case len(x.types) != len(y.types),
x.is_packed != y.is_packed, x.is_packed != y.is_packed,
x.is_raw_union != y.is_raw_union, x.is_raw_union != y.is_raw_union,
@@ -122,7 +122,7 @@ are_types_identical :: proc(a, b: ^Type_Info) -> bool {
x.soa_kind != y.soa_kind, x.soa_kind != y.soa_kind,
x.soa_base_type != y.soa_base_type, x.soa_base_type != y.soa_base_type,
x.soa_len != y.soa_len: x.soa_len != y.soa_len:
return false return false
} }
for _, i in x.types { for _, i in x.types {
xn, yn := x.names[i], y.names[i] xn, yn := x.names[i], y.names[i]
+1 -1
View File
@@ -37,7 +37,7 @@ Returns:
intern_init :: proc(m: ^Intern, allocator := context.allocator, map_allocator := context.allocator, loc := #caller_location) -> (err: mem.Allocator_Error) { intern_init :: proc(m: ^Intern, allocator := context.allocator, map_allocator := context.allocator, loc := #caller_location) -> (err: mem.Allocator_Error) {
m.allocator = allocator m.allocator = allocator
m.entries = make(map[string]^Intern_Entry, 16, map_allocator, loc) or_return m.entries = make(map[string]^Intern_Entry, 16, map_allocator, loc) or_return
return nil return nil
} }
/* /*
Frees the map and all its content allocated using the `.allocator`. Frees the map and all its content allocated using the `.allocator`.
+1 -1
View File
@@ -304,7 +304,7 @@ try_recv_raw :: proc "contextless" (c: ^Raw_Chan, msg_out: rawptr) -> bool {
if sync.atomic_load(&c.closed) || if sync.atomic_load(&c.closed) ||
sync.atomic_load(&c.w_waiting) == 0 { sync.atomic_load(&c.w_waiting) == 0 {
return false return false
} }
mem.copy(msg_out, c.unbuffered_data, int(c.msg_size)) mem.copy(msg_out, c.unbuffered_data, int(c.msg_size))
+1 -1
View File
@@ -169,7 +169,7 @@ atomic_rw_mutex_shared_unlock :: proc "contextless" (rw: ^Atomic_RW_Mutex) {
if (state & Atomic_RW_Mutex_State_Reader_Mask == Atomic_RW_Mutex_State_Reader) && if (state & Atomic_RW_Mutex_State_Reader_Mask == Atomic_RW_Mutex_State_Reader) &&
(state & Atomic_RW_Mutex_State_Is_Writing != 0) { (state & Atomic_RW_Mutex_State_Is_Writing != 0) {
atomic_sema_post(&rw.sema) atomic_sema_post(&rw.sema)
} }
} }
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -48,7 +48,7 @@ WCOREDUMP :: #force_inline proc "contextless" (s: u32) -> bool {
return 1 << ((cast(uint)(sig) - 1) % (8*size_of(uint))) return 1 << ((cast(uint)(sig) - 1) % (8*size_of(uint)))
} }
@private _sigword :: proc "contextless" (sig: Signal) -> (uint) { @private _sigword :: proc "contextless" (sig: Signal) -> (uint) {
return (cast(uint)sig - 1) / (8*size_of(uint)) return (cast(uint)sig - 1) / (8*size_of(uint))
} }
// TODO: sigaddset etc // TODO: sigaddset etc
+1 -1
View File
@@ -242,7 +242,7 @@ is_enclosing_mark :: proc(r: rune) -> bool {
0x20DD ..= 0x20E0, 0x20DD ..= 0x20E0,
0x20E2 ..= 0x20E4, 0x20E2 ..= 0x20E4,
0xA670 ..= 0xA672: 0xA670 ..= 0xA672:
return true return true
} }
return false return false
+1 -1
View File
@@ -2275,7 +2275,7 @@ arbitrary_precision_mathematics :: proc() {
} }
fmt.printf(as) fmt.printf(as)
if print_extra_info { if print_extra_info {
fmt.printf(" (base: %v, bits: %v, digits: %v)", base, cb, a.used) fmt.printf(" (base: %v, bits: %v, digits: %v)", base, cb, a.used)
} }
if newline { if newline {
fmt.println() fmt.println()
+9 -9
View File
@@ -781,17 +781,17 @@ when !GL_DEBUG {
{ {
// add input arguments // add input arguments
for arg, arg_index in args[num_ret:] { for arg, arg_index in args[num_ret:] {
if arg_index > 0 { fmt.printf(", ") } if arg_index > 0 { fmt.printf(", ") }
if v, ok := arg.(u32); ok { // TODO: Assumes all u32 are GLenum (they're not, GLbitfield and GLuint are also mapped to u32), fix later by better typing if v, ok := arg.(u32); ok { // TODO: Assumes all u32 are GLenum (they're not, GLbitfield and GLuint are also mapped to u32), fix later by better typing
if err == .INVALID_ENUM { if err == .INVALID_ENUM {
fmt.printf("INVALID_ENUM=%d", v) fmt.printf("INVALID_ENUM=%d", v)
} else {
fmt.printf("GL_%v=%d", GL_Enum(v), v)
}
} else { } else {
fmt.printf("GL_%v=%d", GL_Enum(v), v) fmt.printf("%v", arg)
} }
} else {
fmt.printf("%v", arg)
}
} }
// add return arguments // add return arguments
@@ -810,7 +810,7 @@ when !GL_DEBUG {
} }
// add location // add location
fmt.printf(" in: %s(%d:%d)\n", from_loc.file_path, from_loc.line, from_loc.column) fmt.printf(" in: %s(%d:%d)\n", from_loc.file_path, from_loc.line, from_loc.column)
} }
} }
+3 -3
View File
@@ -494,15 +494,15 @@ free_cstring :: proc "c" (str: cstring) {
free_rawptr(rawptr(str)) free_rawptr(rawptr(str))
} }
free_string :: proc "c" (s: string) { free_string :: proc "c" (s: string) {
free_rawptr(raw_data(s)) free_rawptr(raw_data(s))
} }
free :: proc{free_rawptr, free_cstring} free :: proc{free_rawptr, free_cstring}
// Wrap CMark allocator as Odin allocator // Wrap CMark allocator as Odin allocator
@(private) @(private)
cmark_allocator_proc :: proc(allocator_data: rawptr, mode: runtime.Allocator_Mode, cmark_allocator_proc :: proc(allocator_data: rawptr, mode: runtime.Allocator_Mode,
size, alignment: int, size, alignment: int,
old_memory: rawptr, old_size: int, loc := #caller_location) -> (res: []byte, err: runtime.Allocator_Error) { old_memory: rawptr, old_size: int, loc := #caller_location) -> (res: []byte, err: runtime.Allocator_Error) {
cmark_alloc := cast(^Allocator)allocator_data cmark_alloc := cast(^Allocator)allocator_data
switch mode { switch mode {
+2 -2
View File
@@ -235,8 +235,8 @@ foreign lib {
// quit // quit
QuitRequested :: #force_inline proc "c" () -> bool { QuitRequested :: #force_inline proc "c" () -> bool {
PumpEvents() PumpEvents()
return bool(PeepEvents(nil, 0, .PEEKEVENT, .QUIT, .QUIT) > 0) return bool(PeepEvents(nil, 0, .PEEKEVENT, .QUIT, .QUIT) > 0)
} }
+1 -1
View File
@@ -798,7 +798,7 @@ API_VERSION_1_2 :: (1<<22) | (2<<12) | (0)
API_VERSION_1_3 :: (1<<22) | (3<<12) | (0) API_VERSION_1_3 :: (1<<22) | (3<<12) | (0)
MAKE_VERSION :: proc(major, minor, patch: u32) -> u32 { MAKE_VERSION :: proc(major, minor, patch: u32) -> u32 {
return (major<<22) | (minor<<12) | (patch) \treturn (major<<22) | (minor<<12) | (patch)
} }
// Base types // Base types
+1 -1
View File
@@ -8,7 +8,7 @@ API_VERSION_1_2 :: (1<<22) | (2<<12) | (0)
API_VERSION_1_3 :: (1<<22) | (3<<12) | (0) API_VERSION_1_3 :: (1<<22) | (3<<12) | (0)
MAKE_VERSION :: proc(major, minor, patch: u32) -> u32 { MAKE_VERSION :: proc(major, minor, patch: u32) -> u32 {
return (major<<22) | (minor<<12) | (patch) return (major<<22) | (minor<<12) | (patch)
} }
// Base types // Base types