Giter Club home page Giter Club logo

Comments (2)

jdiggins avatar jdiggins commented on June 24, 2024 2

This appears to be a compiler / lifetime bug with the try/except block. When I run the above code on my setup, I get the following:

mojo(1451,0x1da6d1000) malloc: Double free of object 0x132a51660
mojo(1451,0x1da6d1000) malloc: *** set a breakpoint in malloc_error_break to debug
Please submit a bug report to https://github.com/modularml/mojo/issues and include the crash backtrace along with all the relevant source codes.
Stack dump:
0.      Program arguments: mojo run read-file.mojo
 #0 0x0000000102f7f7c8 llvm_strlcpy (/Users/john/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x1000bf7c8)
 #1 0x0000000102f7db70 llvm_strlcpy (/Users/john/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x1000bdb70)
 #2 0x0000000102f7fe68 llvm_strlcpy (/Users/john/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x1000bfe68)
 #3 0x0000000183f21a24 (/usr/lib/system/libsystem_platform.dylib+0x18046da24)
 #4 0x0000000183ef1cc0 (/usr/lib/system/libsystem_pthread.dylib+0x18043dcc0)
 #5 0x0000000183dfda40 (/usr/lib/system/libsystem_c.dylib+0x180349a40)
 #6 0x0000000183d14b08 (/usr/lib/system/libsystem_malloc.dylib+0x180260b08)
 #7 0x0000000183d3424c (/usr/lib/system/libsystem_malloc.dylib+0x18028024c)
 #8 0x0000000183d330a8 (/usr/lib/system/libsystem_malloc.dylib+0x18027f0a8)
 #9 0x000000010615f4ec KGEN_CompilerRT_AlignedFree (/Users/john/.modular/pkg/packages.modular.com_nightly_mojo/lib/libKGENCompilerRTShared.dylib+0xb4ec)
#10 0x0000000280004358 
#11 0x00000001033248a8 __jit_debug_register_code (/Users/john/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x1004648a8)
#12 0x0000000102edea04 _mh_execute_header (/Users/john/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x10001ea04)
#13 0x0000000102ede3f8 _mh_execute_header (/Users/john/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x10001e3f8)
#14 0x0000000102ec6634 _mh_execute_header (/Users/john/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x100006634)
#15 0x0000000183b710e0 
mojo crashed!
Please file a bug report.
[1453:7222129:20240615,151237.558235:WARNING crash_report_exception_handler.cc:257] UniversalExceptionRaise: (os/kern) failure (5)

Removing the the print from the finally block produces the same crash

fn t1(filename : Path):
    var bytes = List[UInt8]()
    try:
        with open(filename, "rb") as f:
            bytes = f.read_bytes()
    except:
        pass
    print(bytes[0],", ",bytes[1],", ",bytes[2],", ",bytes[3],", ",bytes[4],", ",bytes[5],", ",bytes[6],", ",bytes[7])

Interestingly, adding an except block with a return in it will get it working, when there is no finally block using bytes:

fn t1(filename : Path):
    var bytes = List[UInt8]()
    try:
        with open(filename, "rb") as f:
            bytes = f.read_bytes()
    except:
        return
    print(bytes[0],", ",bytes[1],", ",bytes[2],", ",bytes[3],", ",bytes[4],", ",bytes[5],", ",bytes[6],", ",bytes[7])

Introducing bytes back into the finally block re-introduces the crash. This makes me think the error has something to do with bytes being provided in the context of the finally block, even when one isn't used. The return in the unused except block appears to prevent this context from being created when we don't provide a finally block with the use of bytes.

fn t1(filename : Path):
    var bytes = List[UInt8]()
    try:
        with open(filename, "rb") as f:
            bytes = f.read_bytes()
    except:
        return
    finally:
        print(bytes[0],", ",bytes[1],", ",bytes[2],", ",bytes[3],", ",bytes[4],", ",bytes[5],", ",bytes[6],", ",bytes[7])
    print(bytes[0],", ",bytes[1],", ",bytes[2],", ",bytes[3],", ",bytes[4],", ",bytes[5],", ",bytes[6],", ",bytes[7])

System information

Apple M1 Pro, OS Sonoma 14.2.1
mojo 2024.6.1505 (238bad6d)
modular 0.8.0 (39a426b5)

from mojo.

f-saez avatar f-saez commented on June 24, 2024

that make sense.

from mojo.

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.