Mistakes to avoid when writing a wrapper around a C library
summary
Shows the top 9 common pitfalls and concrete fixes when wrapping a C library: how to use catch_unwind for callbacks, when to mark types with repr(C), why mem::forget and leak checks break invariants, and why hidden globals (OpenAL, OpenGL, Windows thread state) defeat per-crate mutexes. Recommends writing a thin low-level wrapper first, illustrates live bugs from iterator/Ref implementations and panics, and gives practical runtime checks and API shapes that actually work.
AI-written summary · about
chapters (24)
- 0:00Intro
- 0:30What is a wrapper
- 1:20Not catching rust panics
- 2:40Not testing on a large scale
- 3:40Assuming a certain layout
- 4:45Transmute tuples
- 5:27Highlevel abstraction
- 7:44When to view
- 11:27Lock API
- 13:00How to fix this
- 14:22Mistake 4 Hidden global variables
- 15:55New text mutex
- 16:47Why it doesnt work
- 18:02Conclusion
- 19:59Read primitives from memory
- 22:11Mistake 2 assuming threat implementations are bugfree
- 24:05The problem
- 24:43Why would someone do this
- 26:00How to solve this
- 27:17Other examples
- 28:21Mistake 1 API related
- 29:23Mistake 2 API related
- 31:17Conclusions
- 32:10Question








