Skip to content

check for void return FFI functions, fix incorrect cases#6043

Merged
davidhewitt merged 2 commits into
PyO3:mainfrom
davidhewitt:void-return-ffi
May 14, 2026
Merged

check for void return FFI functions, fix incorrect cases#6043
davidhewitt merged 2 commits into
PyO3:mainfrom
davidhewitt:void-return-ffi

Conversation

@davidhewitt
Copy link
Copy Markdown
Member

This PR attempts to check whether pyo3-ffi and the C headers agree on functions having no return value. The more general case of type checking is hard (pyo3-ffi and bindgen may have different logical types; what we really need to check is ABI compatibility), but checking for void return turns out to be easy enough.

Subsequently I fix two cases which turned out to be wrong in pyo3-ffi.


pub fn PyUnstable_TryIncRef(obj: *mut PyObject) -> c_int;

pub fn PyUnstable_EnableTryIncRef(obj: *mut PyObject) -> c_void;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Need no changelog entry for this one as it'll be newly released in 0.29.

@davidhewitt davidhewitt mentioned this pull request May 13, 2026
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 13, 2026

Merging this PR will improve performance by 27.92%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 29 improved benchmarks
✅ 96 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
test_class_attribute 16 µs 12.6 µs +27.44%
test_class_method 18.4 µs 15.6 µs +18.62%
test_empty_class_init 24.7 µs 15.8 µs +56.09%
test_empty_class_init_py 14.4 µs 10.8 µs +33.18%
test_getter 18.3 µs 15.2 µs +20.45%
test_method_call 17.3 µs 13.9 µs +24.35%
test_method_call_py 14.9 µs 11 µs +35.88%
test_proto_call 14 µs 10.4 µs +35.15%
test_proto_call_py 15.3 µs 11.6 µs +31.74%
test_setter 18.1 µs 14.7 µs +22.84%
test_static_method 17.6 µs 14.6 µs +20.61%
test_args_kwargs_py 18.6 µs 15.1 µs +23.65%
test_args_kwargs_rs 14.8 µs 11.2 µs +32.11%
test_many_keyword_arguments_py 19.3 µs 16.2 µs +19.15%
test_many_keyword_arguments_rs 20.2 µs 16.7 µs +20.91%
test_none_py 14.4 µs 10.3 µs +39.16%
test_none_rs 13.4 µs 9.7 µs +38.36%
test_positional_only_py 13.9 µs 10.3 µs +34.6%
test_positional_only_rs 14.4 µs 10.7 µs +34.45%
test_simple_args_kwargs_py 20.5 µs 17.2 µs +19.27%
... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing davidhewitt:void-return-ffi (6c136d0) with main (c92117c)

Open in CodSpeed

@davidhewitt davidhewitt added this pull request to the merge queue May 13, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 13, 2026
@davidhewitt davidhewitt added this pull request to the merge queue May 14, 2026
Merged via the queue into PyO3:main with commit d818aef May 14, 2026
48 checks passed
@davidhewitt davidhewitt deleted the void-return-ffi branch May 14, 2026 07:38
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.

2 participants