Python is memory safe? Can’t you access/address memory with C bindings?

  • BatmanAoD@programming.dev
    link
    fedilink
    arrow-up
    25
    arrow-down
    3
    ·
    8 months ago

    That’s true in C as well, though. This is what people mean when they say things like “undefined behavior can result in time travel”.

    The difference is twofold:

    • Rust’s rules for valid unsafe code are not completely formalized yet. This means that there are open questions about whether particularly complex patterns in unsafe code will be guaranteed by future versions of the compiler to be sound. Conversely, the C and C++ spec are generally sufficient to determine whether any particular piece of code has undefined behavior, even if actually analyzing it to find out is not possible automatically using existing static analysis tools.
    • Because safe Rust is so strict about what it permits, the compiler is able to make more aggressive optimizations; in theory, this could indeed cause undefined behavior to be “worse” at runtime than a comparable situation in a globally-unsafe language. I’m unaware of any actual examples of that phenomenon, though.