Skip to content

Commit c0f9fa1

Browse files
davidhewittmejrs
andauthored
[review]: majors
Co-authored-by: Bruno Kolenbrander <[email protected]>
1 parent 6c5a096 commit c0f9fa1

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

examples/sequential/src/id.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ unsafe extern "C" fn id_new(
2828
kwds: *mut PyObject,
2929
) -> *mut PyObject {
3030
if PyTuple_Size(args) != 0 || !kwds.is_null() {
31+
// We use pyo3-ffi's `c_str!` macro to create null-terminated literals because
32+
// Rust's string literals are not null-terminated
33+
// On Rust 1.77 or newer you can use `c"text"` instead.
3134
PyErr_SetString(PyExc_TypeError, c_str!("Id() takes no arguments").as_ptr());
3235
return ptr::null_mut();
3336
}

pyo3-macros-backend/src/method.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,8 @@ impl<'a> FnSpec<'a> {
474474

475475
pub fn null_terminated_python_name(&self, ctx: &Ctx) -> TokenStream {
476476
let Ctx { pyo3_path } = ctx;
477+
let span = self.python_name.span();
478+
let pyo3_path = pyo3_path.to_tokens_spanned(span);
477479
let name = self.python_name.to_string();
478480
quote_spanned!(self.python_name.span() => #pyo3_path::ffi::c_str!(#name))
479481
}

0 commit comments

Comments
 (0)