tls: add GC-safe TLS helper - #1
Conversation
make lib/c don't use cgo for minimal wasm support
emb/runtime/volatile, emb/machine
c/clang: remove wrap
c/os: fix for drawin amd64
Summary of ChangesHello @cpunion, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a robust, garbage collector-aware Thread Local Storage (TLS) utility, refines C type mappings for enhanced cross-platform compatibility, and overhauls the Highlights
Ignored Files
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a GC-safe TLS helper in the c/tls package, which is a significant enhancement for managing thread-local storage in a garbage-collected environment. The changes also include substantial refactoring in the c/clang and c/os packages to improve portability and simplify C interoperability, moving away from CGo-style wrappers to more direct llgo:link directives. The addition of platform-specific type definitions is a good step towards better cross-platform compatibility. Overall, the changes are well-structured and improve the codebase. I have a few minor suggestions for improvement.
| func TestAllocSetGetClear(t *testing.T) { | ||
| var mu sync.Mutex | ||
| var destructCount int | ||
| handle := tls.Alloc[*slotValue](func(v **slotValue) { |
There was a problem hiding this comment.
The destructor's signature func(v **slotValue) is a bit confusing. While correct because T is *slotValue, it might be clearer to define T as slotValue and then use *slotValue in the destructor. This would make the API more intuitive for users who might not expect a double pointer. However, if the goal is to allow modification of the pointer itself (like nilling it out), the current approach is valid but could benefit from a comment explaining why a double pointer is used.
| //go:linkname Syscall C.syscall | ||
| func Syscall(sysno c.Long, __llgo_va_list ...any) c.Long |
There was a problem hiding this comment.
The Syscall function is a powerful but potentially unsafe feature. It would be beneficial to add a prominent warning in the documentation about its platform-dependent nature and the risks associated with its use, such as kernel panics or security vulnerabilities if used incorrectly. This will help prevent misuse by developers who may not be fully aware of the implications.
| //go:linkname Clearenv C.llgoClearenv | ||
| func Clearenv() c.Int |
There was a problem hiding this comment.
The function Clearenv is linked to C.llgoClearenv here, but in c/os/os_other.go it's linked to C.clearenv. This inconsistency could lead to confusion or maintenance issues. It would be better to use the same C function name across all platforms if possible, or if not, to document the reason for the difference.
0e64df5 to
d7433ee
Compare
Summary
Testing