|
// Prevent double‑free of the source items |
|
let src_items = ManuallyDrop::new(items); |
|
|
|
#[allow(unsafe_code)] |
|
unsafe { |
|
// Reconstruct pointers |
|
let dest_base = buffer_addr as *mut MaybeUninit<T>; |
|
let dest_uninit = dest_base.add(start_idx); |
|
|
|
// Cast MaybeUninit<T> -> T (Layout compatible) |
|
let dest_ptr = dest_uninit as *mut T; |
|
let src_ptr = src_items.as_ptr(); |
|
|
|
// Efficient copy |
|
std::ptr::copy_nonoverlapping(src_ptr, dest_ptr, count); |
|
} |
|
Ok(()) |
This leaks memory, quickly. Also, definitely not zero-copy. Sidenote: The previous unsafe block was terse, easier to verify, and just as correct: https://github.com/RetypeOS/parcode/pull/1/files#diff-267c9f4da66412a9f439ac08d224356fe24265b5e1cebb6c44c2d55b96414513R393-R400 Just please tell your LLM about pointer::expose_provenance / with_exposed_provenance as alternatives to as usize.
Some aspects of this are neat, there's an idea where to take the project and what is necessary to make a usable API. I'd have more comments but I don't see myself spending more time reading code and writing issue comments than an LLM query takes to write. Siempre es necesario entender el código fuente, especialmente el que no escribiste.
parcode/src/reader.rs
Lines 902 to 918 in 1cdc49d
This leaks memory, quickly. Also, definitely not zero-copy. Sidenote: The previous
unsafeblock was terse, easier to verify, and just as correct: https://github.com/RetypeOS/parcode/pull/1/files#diff-267c9f4da66412a9f439ac08d224356fe24265b5e1cebb6c44c2d55b96414513R393-R400 Just please tell your LLM aboutpointer::expose_provenance/with_exposed_provenanceas alternatives toas usize.Some aspects of this are neat, there's an idea where to take the project and what is necessary to make a usable API. I'd have more comments but I don't see myself spending more time reading code and writing issue comments than an LLM query takes to write. Siempre es necesario entender el código fuente, especialmente el que no escribiste.