Skip to content

deprecate pyo3_ffi::c_str! - #6278

Open
chirizxc wants to merge 6 commits into
PyO3:mainfrom
chirizxc:pyo3_ffi_c_str!
Open

deprecate pyo3_ffi::c_str!#6278
chirizxc wants to merge 6 commits into
PyO3:mainfrom
chirizxc:pyo3_ffi_c_str!

Conversation

@chirizxc

@chirizxc chirizxc commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@mejrs

mejrs commented Jul 31, 2026

Copy link
Copy Markdown
Member

It is still quite useful as it accepts expressions, so I don't think we should get rid of it entirely. I wonder how much it is used like that outside pyo3.

@chirizxc

Copy link
Copy Markdown
Contributor Author

It is still quite useful as it accepts expressions, so I don't think we should get rid of it entirely. I wonder how much it is used like that outside pyo3.

A search on GitHub doesn't seem to return any repositories other than Pyo3 forks.

@LilyFirefly

Copy link
Copy Markdown
Contributor

There's a bunch more usages of c_str! that can be cleaned up (see failing tests). Even if we keep c_str! for expressions, I think it's useful to use C String literals where possible.

@codspeed-hq

codspeed-hq Bot commented Aug 1, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 10.24%

⚠️ 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

❌ 1 regressed benchmark
✅ 139 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation bench_fast 6.1 µs 6.8 µs -10.24%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing chirizxc:pyo3_ffi_c_str! (03f02f6) with main (92e47e1)

Open in CodSpeed

@LilyFirefly
LilyFirefly self-requested a review August 1, 2026 12:27

@LilyFirefly LilyFirefly left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

On reflection I also think we shouldn't deprecate c_str! for expressions - the old version is more readable in those cases. I do like the clean-up available when we can use C string literals (c"...").

Comment on lines -249 to +258
let py_foo = c_str!(include_str!(concat!(
let py_foo = CStr::from_bytes_with_nul(concat!(
env!("CARGO_MANIFEST_DIR"),
"/python_app/utils/foo.py"
)));
let py_app = c_str!(include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/python_app/app.py")));
"/python_app/utils/foo.py",
"\0"
).as_bytes()).unwrap();
let py_app = CStr::from_bytes_with_nul(concat!(
env!("CARGO_MANIFEST_DIR"),
"/python_app/app.py",
"\0"
).as_bytes()).unwrap();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think this is an improvement, so like @mejrs I think keeping cstr! for expressions would be better.

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.

3 participants