Oxidizing bmap-tools: rewriting a Python project in Rust
collabora.com
collabora.com
It also seems to have been done independently of the upstream, so it's not really an "oxidation" in the usual terms, more of a pseudo-fork of the specific `bmaptool copy` subcommand (though TBF it only has one other subcommand which is `create`, and the implementation in the upstream is about 1/3rd that of copy, so copy is clearly the "meat" of the project).
Sorry for the unsubstantive comment.
What about python’s memory model is unsafe?
Making a language that banned them outright would be making a language that couldn't do things that people wanted to do.
But allow for memory unsafety? No, not if every ordering of the "critical sections" (chunks of code run as a unit while the interpreter is locked) is valid and upholds the invariants Python expects.
It is conceivable (but extremely unlikely, 'cos it was really, really hard) that after a GILectomy Python follows the Java path, in which data races are technically safe†. However it is most likely Python with a GILectomy will behave like Go or C# or numerous other languages and lose memory safety properties if a data race occurs.
† Data races can happen in Java, and astonishing things might happen, but objects always remain in some valid state, so there is no loss of memory safety whereas in most languages with data races you can e.g. race a hash table and mess up its internals and cause chaos.
Rather than memory safety per se, I'd actually value Rust's type safety over Python's. Yes, strictly speaking Python is dynamically typed rather than untyped, but Rust will shift a lot of your mistakes "hard left" (ie report your goof during compilation not during execution) compared to Python because it gets to do these checks up front, and it is also able to catch a lot more of them because it's much stricter about what types are.
In Python we can write "if foo" and it doesn't matter too much what type foo actually has, Python will try to decide if it's "truthy" at runtime. In Rust either foo is a boolean, in which case this is a reasonable thing to do, or it isn't, that's a type mismatch, your program doesn't compile. Not everyone loves this, but I certainly do.
[0] https://www.merriam-webster.com/words-at-play/sealioning-int....
Edit: Just realized you said "even with garbage collection", so you weren't talking about Rust. Never mind.
https://jcp.org/aboutJava/communityprocess/final/jsr133/inde...
(section 17.4 of the full specification)
However in a sense Rust is cheating. Java has to do a lot of work because they can't stop you writing a data race in Java, so they want that to be safe anyway if it happens. (Safe) Rust just won't emit the data race in the first place.
A data race requires (as mentioned below in the thread about Python concurrency) that there's mutation concurrently with access to the same memory. In Java that's a bad idea, but it does happen, usually by mistake. In (Safe) Rust mutation requires that nobody else has a shared (immutable) reference to the object, so the data race can't occur because if we can mutate something by definition nobody else has a reference to it - programs with this mistake won't compile.
I know of two big ones: ruff (linting) and pyflow (dependency management). The standard lib crypto module uses rust, too.
Are there other ones I should know about? Maybe replacements for mypy, pre-commit, tox/nox?
This couldn't matter less, but I think you're confused with the third-party Cryptography package, which uses Rust.
- https://pypi.org/project/polars/
Because bmap files are independent of the filesystem and OS, and thus would probably like to work even with filesystems which don't support sparse files, and OS which don't expose holes?
For instance until NFS 4.2 in 2016 you could write sparse files to an NFS volume, but there was no way to detect holes when reading. exfat doesn't support sparse files at all. And according to their man pages, OpenBSD and NetBSD have yet to support SEEK_HOLE/SEEK_DATA (which are non-standard extensions of POSIX lseek(2)).
Plus according to its history the bmaptools project was created about a year after the release of kernel 3.1, which introduced support for SEEK_HOLE and SEEK_DATA. Doesn't take much of a leap to assume that the project's creator didn't consider that widespread enough to be reliable (Debian wouldn't release a 3.x-based version until the following year).
We have a Yocto build that results in about 120MB worth of files that make up our app and Yocto. Originally we had a script that would write a bootloader, partition and format ext4 our target's eMMC, and decompress a 120MB tarball to that filesystem.
That worked well, but we wanted our script to become OS-independent, as our field team ran Windows laptops. It's quite difficult to get Windows to do an ext4 format, and I wanted our tool to have a minimal number of dependencies (e2fsprogs requirement? some proprietary thing from Paragon? no thanks)
So instead, have Yocto produce an image containing the bootloader and all four pre-formatted ext4 filesystems. No operating system needs to do the format if the filesystem already exits within, it's just a raw block write. But now the image is 4GB, the size of our eMMC, and writing all of it would be painfully slow.
Thankfully Yocto also outputs a bmap file which maps the parts of that 4GB which are empty space -- blocks we don't need to write when commissioning our target device. So our commissioning tool was rewritten in Go, and I wrote a bmap implementation in Go to do the write. Flashing our target is as fast as it used to be, but now that tool can be easily made to work on multiple operating systems.