Skip to content

Commit 75fcd50

Browse files
committed
Merge branch 'master' of https://github.com/odin-lang/Odin
2 parents c6a446f + f5719ae commit 75fcd50

File tree

6 files changed

+63
-18
lines changed

6 files changed

+63
-18
lines changed

core/fmt/fmt.odin

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,7 +1900,7 @@ fmt_struct :: proc(fi: ^Info, v: any, the_verb: rune, info: runtime.Type_Info_St
19001900
// fi.hash = false;
19011901
fi.indent += 1
19021902

1903-
if hash {
1903+
if !is_soa && hash {
19041904
io.write_byte(fi.writer, '\n', &fi.n)
19051905
}
19061906
defer {
@@ -1934,6 +1934,9 @@ fmt_struct :: proc(fi: ^Info, v: any, the_verb: rune, info: runtime.Type_Info_St
19341934
n = uintptr((^int)(uintptr(v.data) + info.offsets[actual_field_count])^)
19351935
}
19361936

1937+
if hash && n > 0 {
1938+
io.write_byte(fi.writer, '\n', &fi.n)
1939+
}
19371940

19381941
for index in 0..<n {
19391942
if !hash && index > 0 { io.write_string(fi.writer, ", ", &fi.n) }
@@ -1942,9 +1945,23 @@ fmt_struct :: proc(fi: ^Info, v: any, the_verb: rune, info: runtime.Type_Info_St
19421945

19431946
if !hash && field_count > 0 { io.write_string(fi.writer, ", ", &fi.n) }
19441947

1948+
if hash {
1949+
fi.indent -= 1
1950+
fmt_write_indent(fi)
1951+
fi.indent += 1
1952+
}
19451953
io.write_string(fi.writer, base_type_name, &fi.n)
19461954
io.write_byte(fi.writer, '{', &fi.n)
1947-
defer io.write_byte(fi.writer, '}', &fi.n)
1955+
if hash { io.write_byte(fi.writer, '\n', &fi.n) }
1956+
defer {
1957+
if hash {
1958+
fi.indent -= 1
1959+
fmt_write_indent(fi)
1960+
fi.indent += 1
1961+
}
1962+
io.write_byte(fi.writer, '}', &fi.n)
1963+
if hash { io.write_string(fi.writer, ",\n", &fi.n) }
1964+
}
19481965
fi.record_level += 1
19491966
defer fi.record_level -= 1
19501967

core/fmt/fmt_js.odin

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,14 @@ print :: proc(args: ..any, sep := " ", flush := true) -> int { return wprint(w
3737
println :: proc(args: ..any, sep := " ", flush := true) -> int { return wprintln(w=stdout, args=args, sep=sep, flush=flush) }
3838
// printf formats according to the specififed format string and writes to stdout
3939
printf :: proc(fmt: string, args: ..any, flush := true) -> int { return wprintf(stdout, fmt, ..args, flush=flush) }
40+
// printfln formats according to the specified format string and writes to stdout, followed by a newline.
41+
printfln :: proc(fmt: string, args: ..any, flush := true) -> int { return wprintf(stdout, fmt, ..args, flush=flush, newline=true) }
4042

4143
// eprint formats using the default print settings and writes to stderr
4244
eprint :: proc(args: ..any, sep := " ", flush := true) -> int { return wprint(w=stderr, args=args, sep=sep, flush=flush) }
4345
// eprintln formats using the default print settings and writes to stderr
4446
eprintln :: proc(args: ..any, sep := " ", flush := true) -> int { return wprintln(w=stderr, args=args, sep=sep, flush=flush) }
4547
// eprintf formats according to the specififed format string and writes to stderr
4648
eprintf :: proc(fmt: string, args: ..any, flush := true) -> int { return wprintf(stderr, fmt, ..args, flush=flush) }
49+
// eprintfln formats according to the specified format string and writes to stderr, followed by a newline.
50+
eprintfln :: proc(fmt: string, args: ..any, flush := true) -> int { return wprintf(stdout, fmt, ..args, flush=flush, newline=true) }

core/net/socket_linux.odin

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,12 @@ _send_tcp :: proc(tcp_sock: TCP_Socket, buf: []byte) -> (int, Network_Error) {
258258
for total_written < len(buf) {
259259
limit := min(int(max(i32)), len(buf) - total_written)
260260
remaining := buf[total_written:][:limit]
261-
res, errno := linux.send(linux.Fd(tcp_sock), remaining, {})
262-
if errno != .NONE {
261+
res, errno := linux.send(linux.Fd(tcp_sock), remaining, {.NOSIGNAL})
262+
if errno == .EPIPE {
263+
// If the peer is disconnected when we are trying to send we will get an `EPIPE` error,
264+
// so we turn that into a clearer error
265+
return total_written, TCP_Send_Error.Connection_Closed
266+
} else if errno != .NONE {
263267
return total_written, TCP_Send_Error(errno)
264268
}
265269
total_written += int(res)

src/build_settings.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -840,13 +840,11 @@ gb_internal String odin_root_dir(void) {
840840
char const *found = gb_get_env("ODIN_ROOT", a);
841841
if (found) {
842842
String path = path_to_full_path(a, make_string_c(found));
843-
if (path[path.len-1] != '/' && path[path.len-1] != '\\') {
844843
#if defined(GB_SYSTEM_WINDOWS)
845-
path = concatenate_strings(a, path, WIN32_SEPARATOR_STRING);
844+
path = normalize_path(a, path, WIN32_SEPARATOR_STRING);
846845
#else
847-
path = concatenate_strings(a, path, NIX_SEPARATOR_STRING);
846+
path = normalize_path(a, path, NIX_SEPARATOR_STRING);
848847
#endif
849-
}
850848

851849
global_module_path = path;
852850
global_module_path_set = true;

src/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,12 @@ struct BuildFlag {
342342
String name;
343343
BuildFlagParamKind param_kind;
344344
u32 command_support;
345-
bool allow_mulitple;
345+
bool allow_multiple;
346346
};
347347

348348

349-
gb_internal void add_flag(Array<BuildFlag> *build_flags, BuildFlagKind kind, String name, BuildFlagParamKind param_kind, u32 command_support, bool allow_mulitple=false) {
350-
BuildFlag flag = {kind, name, param_kind, command_support, allow_mulitple};
349+
gb_internal void add_flag(Array<BuildFlag> *build_flags, BuildFlagKind kind, String name, BuildFlagParamKind param_kind, u32 command_support, bool allow_multiple=false) {
350+
BuildFlag flag = {kind, name, param_kind, command_support, allow_multiple};
351351
array_add(build_flags, flag);
352352
}
353353

@@ -1363,7 +1363,7 @@ gb_internal bool parse_build_flags(Array<String> args) {
13631363
}
13641364
}
13651365

1366-
if (!bf.allow_mulitple) {
1366+
if (!bf.allow_multiple) {
13671367
set_flags[bf.kind] = ok;
13681368
}
13691369
}

src/string.cpp

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,16 @@ gb_internal String string_split_iterator(String_Iterator *it, const char sep) {
237237
return substring(it->str, start, end);
238238
}
239239

240+
gb_internal gb_inline bool is_separator(u8 const &ch) {
241+
return (ch == '/' || ch == '\\');
242+
}
243+
244+
240245
gb_internal gb_inline isize string_extension_position(String const &str) {
241246
isize dot_pos = -1;
242247
isize i = str.len;
243248
while (i --> 0) {
244-
if (str[i] == '\\' || str[i] == '/')
249+
if (is_separator(str[i]))
245250
break;
246251
if (str[i] == '.') {
247252
dot_pos = i;
@@ -332,8 +337,7 @@ gb_internal String filename_from_path(String s) {
332337
if (i > 0) {
333338
isize j = 0;
334339
for (j = s.len-1; j >= 0; j--) {
335-
if (s[j] == '/' ||
336-
s[j] == '\\') {
340+
if (is_separator(s[j])) {
337341
break;
338342
}
339343
}
@@ -346,8 +350,7 @@ gb_internal String filename_from_path(String s) {
346350
gb_internal String filename_without_directory(String s) {
347351
isize j = 0;
348352
for (j = s.len-1; j >= 0; j--) {
349-
if (s[j] == '/' ||
350-
s[j] == '\\') {
353+
if (is_separator(s[j])) {
351354
break;
352355
}
353356
}
@@ -410,7 +413,26 @@ gb_internal String copy_string(gbAllocator a, String const &s) {
410413
return make_string(data, s.len);
411414
}
412415

413-
416+
gb_internal String normalize_path(gbAllocator a, String const &path, String const &sep) {
417+
String s;
418+
if (sep.len < 1) {
419+
return path;
420+
}
421+
if (path.len < 1) {
422+
s = STR_LIT("");
423+
} else if (is_separator(path[path.len-1])) {
424+
s = copy_string(a, path);
425+
} else {
426+
s = concatenate_strings(a, path, sep);
427+
}
428+
isize i;
429+
for (i = 0; i < s.len; i++) {
430+
if (is_separator(s.text[i])) {
431+
s.text[i] = sep.text[0];
432+
}
433+
}
434+
return s;
435+
}
414436

415437

416438
#if defined(GB_SYSTEM_WINDOWS)

0 commit comments

Comments
 (0)