diff --git a/lib/std/collections/list.c3 b/lib/std/collections/list.c3 index 0c740a3dc..c6e47ffcb 100644 --- a/lib/std/collections/list.c3 +++ b/lib/std/collections/list.c3 @@ -123,7 +123,7 @@ fn String List.to_tstring(&self) fn void List.push(&self, Type element) @inline { - self.ensure_capacity(); + self.reserve(1); self.entries[self.size++] = element; } @@ -244,7 +244,7 @@ fn void List.push_front(&self, Type type) @inline **/ fn void List.insert_at(&self, usz index, Type type) { - self.ensure_capacity(); + self.reserve(1); for (usz i = self.size; i > index; i--) { self.entries[i] = self.entries[i - 1]; @@ -401,10 +401,7 @@ macro usz List._remove_using_test(&self, ElementTest filter, bool $invert, ctx) return size - self.size; } -/** - * Reserve at least min_capacity - **/ -fn void List.reserve(&self, usz min_capacity) +fn void List.ensure_capacity(&self, usz min_capacity) @local { if (!min_capacity) return; if (self.capacity >= min_capacity) return; @@ -433,7 +430,7 @@ fn void List.set(&self, usz index, Type value) @operator([]=) self.entries[index] = value; } -fn void List.ensure_capacity(&self, usz added = 1) @inline @private +fn void List.reserve(&self, usz added) { usz new_size = self.size + added; if (self.capacity >= new_size) return; @@ -441,7 +438,7 @@ fn void List.ensure_capacity(&self, usz added = 1) @inline @private assert(new_size < usz.max / 2U); usz new_capacity = self.capacity ? 2U * self.capacity : 16U; while (new_capacity < new_size) new_capacity *= 2U; - self.reserve(new_capacity); + self.ensure_capacity(new_capacity); } // Functions for equatable types diff --git a/releasenotes.md b/releasenotes.md index 7ffeff338..fa60eb8ba 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -37,6 +37,7 @@ - Distinct func type would not accept direct function address assign. #1287 - Distinct inline would not implement protocol if the inlined implemented it. #1292 - Distinct inline can now be called if it is aliasing a function pointer. +- Bug in List add_array when reserving memory. ### Stdlib changes diff --git a/src/compiler/subprocess.c b/src/compiler/subprocess.c index 3d7646a97..f1ea84cc7 100644 --- a/src/compiler/subprocess.c +++ b/src/compiler/subprocess.c @@ -99,38 +99,42 @@ int run_subprocess(const char *name, const char **args) return exit_status; #else pid_t cpid = fork(); - if (cpid < 0) { - eprintf("Could not fork child process %s: %s", name, strerror(errno)); + if (cpid < 0) + { + eprintf("Could not fork child process %s: %s\n", name, strerror(errno)); return -1; } - if (cpid == 0) { + if (cpid == 0) + { const char **args_null = NULL; vec_add(args_null, name); - for (uint32_t i = 0; i < vec_size(args); ++i) { + for (uint32_t i = 0; i < vec_size(args); ++i) + { vec_add(args_null, args[i]); } vec_add(args_null, NULL); - - if (execvp(name, (char * const*)args_null) < 0) { - eprintf("Could not exec child process %s: %s", name, strerror(errno)); + if (execvp(name, (char *const *)args_null) < 0) + { + eprintf("Could not exec child process %s: %s\n", name, strerror(errno)); exit(1); } - UNREACHABLE + exit(0); } - for (;;) { + for (;;) + { int wstatus = 0; - if (waitpid(cpid, &wstatus, 0) < 0) { - eprintf("Could not wait on %s (pid %d): %s", name, cpid, strerror(errno)); + if (waitpid(cpid, &wstatus, 0) < 0) + { + eprintf("Could not wait on %s (pid %d): %s\n", name, cpid, strerror(errno)); return -1; } - if (WIFEXITED(wstatus)) { - return WEXITSTATUS(wstatus); - } + if (WIFEXITED(wstatus)) return WEXITSTATUS(wstatus); - if (WIFSIGNALED(wstatus)) { + if (WIFSIGNALED(wstatus)) + { eprintf("Program interrupted by signal %d.\n", WTERMSIG(wstatus)); return -1; }