Giter VIP home page Giter VIP logo

Comments (4)

Carotinobg avatar Carotinobg commented on May 26, 2024

unrelated: in the definition of read_any, line 70, shouldn't it be
new_read := r.read(mut b[read..]) or { 0 }
instead of
... or { return error('none') }
?

from v.

spytheman avatar spytheman commented on May 26, 2024

For me, passing -cflags -fno-inline-small-functions fixes the segfault, when the program was compiled using gcc:

#0 14:02:53 ᛋ master /v/oo❱v -cc gcc -prod run z.v
signal 11: segmentation fault
                                                        | 0x5555555673c1 | /space/v/oo/z(+0x133c1)
                                                        | 0x55555556a3e0 | /space/v/oo/z(+0x163e0)
                                                        | 0x55555556a718 | /space/v/oo/z(+0x16718)
                                                        | 0x555555556b94 | /space/v/oo/z(+0x2b94)
                                                        | 0x155555302083 | /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf3)
                                                        | 0x555555556c4e | /space/v/oo/z(+0x2c4e)
#139 14:03:05 ᛋ master /v/oo❱v -cflags -fno-inline-small-functions  -cc gcc -prod run z.v
#0 14:03:19 ᛋ master /v/oo❱

Using -cc clang also works, so I think it is gcc optimization specific.

from v.

spytheman avatar spytheman commented on May 26, 2024

This also can serve as a workaround:

#0 14:07:25 ᛋ master /v/oo❱git diff
diff --git vlib/os/file.c.v vlib/os/file.c.v
index cb3d1e235..6108974fe 100644
--- vlib/os/file.c.v
+++ vlib/os/file.c.v
@@ -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.
+@[noinline]
 pub fn open_file(path string, mode string, options ...int) !File {
        mut flags := 0
        mut seek_to_end := false
#0 14:07:27 ᛋ master /v/oo❱
#0 14:07:56 ᛋ master /v/oo❱
#0 14:07:56 ᛋ master /v/oo❱v -cc gcc -prod run x.v
os.File{
    cfile: 5555555ba2a0
    fd: 3
    is_opened: true
}
module main

import os
import io

fn main() {
        mut file := os.open_file(@FILE, 'r')!
        println(file)
        mut buff_reader := io.new_buffered_reader(reader: file)
        for {
                a := buff_reader.read_line() or { break }
                println(a)
        }
        println('done')
}
done
#0 14:08:03 ᛋ master /v/oo❱git stash
Saved working directory and index state WIP on master: 6f4d9aecf x.json2: minor performance improvement, update benchmark recommendations (#20954)
#0 14:08:12 ᛋ master /v/oo❱v -cc gcc -prod run x.v
os.File{
    cfile: 0
    fd: 0
    is_opened: false
}
signal 11: segmentation fault
                                                        | 0x555555567471 | /space/v/oo/x(+0x13471)
                                                        | 0x555555569163 | /space/v/oo/x(+0x15163)
                                                        | 0x555555556b94 | /space/v/oo/x(+0x2b94)
                                                        | 0x155555302083 | /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf3)
                                                        | 0x555555556c4e | /space/v/oo/x(+0x2c4e)
#139 14:08:20 ᛋ master /v/oo❱

from v.

spytheman avatar spytheman commented on May 26, 2024

I've also tried adding @[noinline] tags to new_buffered_reader and read_line, but those do not affect the outcome, only tagging open_file does.

from v.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.