编程与软件工程immunant.com
把 Quake 3 翻译成 Rust
Translating Quake 3 into Rust
2020 — 2021,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
作者团队使用 c2rust 转译器把经典 FPS 游戏《雷神之锤3》的 C 源码自动转成 Rust,并逐步重构。过程中 Rust 编译器还发现了原 C 代码中一个真实的越界内存安全 bug。
为什么经久不衰:它展示了用自动化工具把大型遗留 C 代码迁移到内存安全语言的可行路径,且以广为人知的 Quake 3 为例,兼具工程参考价值与趣味性。
HN 评论精选
转译过程意外发现了原 C 代码中真实的越界 bug,印证了 Rust 编译器的安全检查价值
这篇文章的一个亮点是他们发现了原始源码中的一个内存安全错误:在 G_TryPushingEntity 中,条件判断用的是 > 而不是 >=,越界指针随后被解引用,这是一个真实的内存安全 bug。
floatingatoll查看英文原文
One highlight of this post is their work exposing a memory safety error in the original source code: > The Rust compiler also flagged a similar but actually buggy example in G_TryPushingEntity where the conditional is >, not >=. The out of bounds pointer was then dereferenced after the conditional, which is an actual memory safety bug.
作者补充了仓库分支,分别提供原始转译输出和重构后的代码
作者在此说明:我们对文本做了一些小修改,并在仓库中新增了两个分支:transpiled(原始转译器输出)和 refactored(经过若干重构命令处理后的代码)。
ahomescu1查看英文原文
Author here: I wanted to let everyone know we made some small edits to the text, and added two new branches to our repository: transpiled containing the raw transpiler output [1], and refactored containing the same code [2] after a few refactoring commands. 1. https://github.com/immunant/ioq3/tree/transpiled/quake3-rs 2. https://github.com/immunant/ioq3/tree/refactored/quake3-rs
看好 c2rust 的进展,建议下一个目标翻译 QEMU
很高兴看到 c2rust 进展顺利。我很好奇它生成惯用 Rust 代码的能力如何——这看起来很难但很有价值。建议下一个翻译 QEMU,它全是 C 写的,会是个有趣的项目。
wyldfire查看英文原文
I recall seeing a presentation of c2rust by Andrei at a conference a while back. It's great to hear that it's making good progress. I'm curious at how good c2rust is at producing idiomatic rust code. It seems like that would be difficult and yet very valuable. > we'd love to hear what you want to see translated next. qemu [1] is all in C (probably C89 or "gnu89") and would make an interesting project, IMO. [1] https://github.com/qemu/qemu
担忧自动转译会丢失源码中的信息与可读性,安全并非代码质量的全部
转译后的代码让我有点担心这种做法成为趋势:过程中丢失了信息。如果未来有 AI 能捕捉逻辑上下文辅助翻译,源代码教给我们的东西还能保留。我理解需要安全加固的 C 工具可以用这种方法,但输出代码难以阅读,人们还是得用 C 写代码,这削弱了在更安全环境中写代码的部分目标。安全只是众多考量维度之一。当然,这确实是最纯粹的黑客乐趣,向作者致敬。
oscargrouch查看英文原文
Reading at the transpiled code, theres something that make me a little worried if this becomes a trend. The lost information in the process. I guess if there's an AI in the middle, capturing the logical context and later helping into the translation process. In that way the power of the source code to teach us will still be there. I understand if some tool that is in C and need a boost in security might use this, but giving the output code is intractable, they would still have to code in C, so this kind of defeat the some of the goals of writing code in a more secure environment. Its important to understand that security is just one of the axis of a whole that have much more things to consider. Having said that, maybe there will be a good use for source code in C that needs a safety boost right away in critical places, or use something like this to spot dark corners and fix the code back in C. Also, great hacking points to whoever did this, as this is fun just because is hacking at its best.
历次讨论
同类还值得读
开源应用架构
The Architecture of Open Source Applications
《开源软件架构》(AOSA)是一本在线免费书,邀请知名开源项目的作者亲自剖析其内部设计,涵盖 SQLAlchemy、LLVM、Audacity、Apache、Bash 等系统。
编程与软件工程上首页 9 次 · 2011–2024aosabook.org编辑精选编程语言简史:简短、不完整且多半错误
A Brief, Incomplete, and Mostly Wrong History of Programming Languages
一篇以戏谑、故意不准确的方式回顾编程语言史的博客文章,用夸张轶事和讽刺定义串起 Lisp、C、C++、Java、JavaScript、PHP 等语言。
编程与软件工程上首页 8 次 · 2009–2021james-iry.blogspot.comSQLite 是如何测试的
How SQLite is tested
SQLite 官方文档页,系统介绍 SQLite 的测试体系:多种测试方法(TCL 测试、模糊测试、回归测试、静态分析等)和海量测试用例,展示了这个小型开源项目如何靠极致测试获得…
编程与软件工程上首页 8 次 · 2009–2025sqlite.org编辑精选高级编程语言(2009)
Advanced programming languages (2009)
Matt Might 的经典文章,按用途推荐“高级编程语言”:如果追求就业就选主流语言,如果追求表达力、学术研究或创业,则推荐 Haskell、OCaml、Scala 等函数式语…
编程与软件工程上首页 8 次 · 2009–2022matt.might.net我的 Forth 与栈机器经历
Yosefk - My history with Forth & stack machines
作者以亲身经历回顾了使用 Forth 语言和栈式机器的历程:既赞叹其简洁优雅、代码量小、可自举的优点,也坦率指出栈操作在实际编程中的痛苦,以及 Forth 社区文化中的问题。
编程与软件工程上首页 8 次 · 2010–2024yosefk.com编辑精选