close
Skip to content

transpile: support __attribute__((cleanup(func)))#1815

Merged
thedataking merged 7 commits into
masterfrom
perl/cleanup_attr
May 26, 2026
Merged

transpile: support __attribute__((cleanup(func)))#1815
thedataking merged 7 commits into
masterfrom
perl/cleanup_attr

Conversation

@thedataking
Copy link
Copy Markdown
Contributor

@thedataking thedataking commented May 20, 2026

Translate __attribute__((cleanup(func))) using a CleanupGuard<T> whose Drop calls the user's cleanup function on scope exit.

Closes #1814.

@thedataking thedataking changed the title transpile: support __attribute__((cleanup(func))) transpile: support __attribute__((cleanup(func))) May 20, 2026
@thedataking thedataking requested a review from fw-immunant May 20, 2026 03:54
Copy link
Copy Markdown
Contributor

@fw-immunant fw-immunant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall, except for concerns around constructing reference to obtain raw pointer. I would have liked more context on several changes (e.g. the first which appears to be a longstanding bug for which a reproducer would be good to see) but they do check out.

Comment thread c2rust-transpile/src/translator/mod.rs Outdated
@thedataking
Copy link
Copy Markdown
Contributor Author

I would have liked more context on [...] the first which appears to be a longstanding bug

Ack on your overall point. For the first commit, it turns out that def can never be null (it is initialized to VD, which is never null in this function), so I changed it to simply remove the dead code. The null guard was most likely carried over from the VisitFunctionDecl handler, where def comes from getDefinition() and the null case is real.

@thedataking thedataking merged commit 81fb423 into master May 26, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Transpile __cleanup__(func) compiler attribute

2 participants