os: workaround a -prod -cc gcc bug, affecting os.open_file (fix #20923) (related to #20872) (#20960)

This commit is contained in:
Delyan Angelov 2024-03-04 18:15:28 +02:00 committed by GitHub
parent 6f4d9aecf3
commit a58f980b02
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 32 additions and 1 deletions

View File

@ -315,7 +315,7 @@ fn (a string) clone_static() string {
// clone returns a copy of the V string `a`. // clone returns a copy of the V string `a`.
pub fn (a string) clone() string { pub fn (a string) clone() string {
if a.len == 0 { if a.len <= 0 {
return '' return ''
} }
mut b := string{ mut b := string{

View File

@ -47,6 +47,7 @@ fn fix_windows_path(path string) string {
} }
// open_file tries to open or create a file with custom flags and permissions. // open_file tries to open or create a file with custom flags and permissions.
@[noinline]
pub fn open_file(path string, mode string, options ...int) !File { pub fn open_file(path string, mode string, options ...int) !File {
mut flags := 0 mut flags := 0
mut seek_to_end := false mut seek_to_end := false

View File

@ -0,0 +1,15 @@
// vtest vflags: -prod -skip-unused
// See https://github.com/vlang/v/issues/20923
module main
import os
import io
fn main() {
mut file := os.open_file(@FILE, 'r')!
mut buff_reader := io.new_buffered_reader(reader: file)
for {
a := buff_reader.read_line() or { break }
println(a)
}
}

View File

@ -0,0 +1,15 @@
// vtest vflags: -prod -skip-unused
// See https://github.com/vlang/v/issues/20923
module main
import os
import io
fn main() {
mut file := os.open_file(@FILE, 'r')!
mut buff_reader := io.new_buffered_reader(reader: file)
for {
a := buff_reader.read_line() or { break }
println(a)
}
}