aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/runtime/runtime_unix.go
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2021-05-05 14:49:55 +0200
committerRon Evans <[email protected]>2021-05-05 17:20:15 +0200
commitc1aa152a63683f21b163a8390ddb6db0a01aa59c (patch)
tree359f33db393f18df53f42f957589048b806870cb /src/runtime/runtime_unix.go
parentdd3d8a363aa4cfc27068ce379ba47edc451c57dd (diff)
downloadtinygo-c1aa152a63683f21b163a8390ddb6db0a01aa59c.tar.gz
tinygo-c1aa152a63683f21b163a8390ddb6db0a01aa59c.zip
unix: avoid possible heap allocation with -opt=0
This heap allocation would normally be optimized away, but with -opt=0 perhaps not. This is a problem if the conservative GC is used, because the conservative GC needs to be initialized before use.
Diffstat (limited to 'src/runtime/runtime_unix.go')
-rw-r--r--src/runtime/runtime_unix.go12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/runtime/runtime_unix.go b/src/runtime/runtime_unix.go
index dc6d74856..59a28682b 100644
--- a/src/runtime/runtime_unix.go
+++ b/src/runtime/runtime_unix.go
@@ -55,18 +55,16 @@ func main(argc int32, argv *unsafe.Pointer) int {
cap uintptr
})(unsafe.Pointer(&args))
argsSlice.ptr = malloc(uintptr(argc) * (unsafe.Sizeof(uintptr(0))) * 3)
- argsSlice.len = 0
+ argsSlice.len = uintptr(argc)
argsSlice.cap = uintptr(argc)
// Initialize command line parameters.
- for *argv != nil {
+ for i := 0; i < int(argc); i++ {
// Convert the C string to a Go string.
length := strlen(*argv)
- argString := _string{
- length: length,
- ptr: (*byte)(*argv),
- }
- args = append(args, *(*string)(unsafe.Pointer(&argString)))
+ arg := (*_string)(unsafe.Pointer(&args[i]))
+ arg.length = length
+ arg.ptr = (*byte)(*argv)
// This is the Go equivalent of "argc++" in C.
argv = (*unsafe.Pointer)(unsafe.Pointer(uintptr(unsafe.Pointer(argv)) + unsafe.Sizeof(argv)))
}