rust-lang / rust-lang/rust-bindgen

Feature request: option to mark function as safe

Open
#3,443 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-feature-request help wanted
Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

External functions are assumed to be unsafe (https://doc.rust-lang.org/reference/items/external-blocks.html#r-items.extern.fn.safety) but there should be an option to mark one as safe

For example, for FFI bindings for the PHP source, the function zend_html_putc (https://github.com/php/php-src/blob/d03163dc0af54f9c0687ab345f5db2584563b2a7/Zend/zend_highlight.c#L28) is always going to be safe - it just prints a character. Similarly, zend_gdb_present (https://github.com/php/php-src/blob/PHP-8.5.10/Zend/zend_gdb.c#L110) takes no parameters and returns a boolean reporting if GDB is present - this function is always going to be safe to call

There should be a way to indicate that a specific function should be marked as safe

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing bindgen's handling of external functions and its configuration options. Check how an explicit safe marker could be represented for selected functions, and add coverage for the PHP examples or equivalent generated bindings. Done means users can mark specific external functions as safe without changing the default for other externals.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, php, rust
Domain
devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.