From aa582396491eb9eb1c122f2f6e2b8e7c39e7edaf Mon Sep 17 00:00:00 2001 From: Bruno Deferrari Date: Sun, 27 Aug 2023 12:31:25 -0300 Subject: [PATCH 1/3] Fix argument types in expansion of bytecode-callable functions (fixes #52) --- src/macros.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index 4c0e9dd..ae56894 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1540,13 +1540,13 @@ macro_rules! expand_exported_byte_function { @return { $($rtyp:tt)* } } => { #[no_mangle] - pub extern "C" fn $byte_name(argv: &[$crate::RawOCaml], argn: isize) -> $crate::expand_exported_function_return!($($rtyp)*) { + pub extern "C" fn $byte_name(argv: *mut $crate::RawOCaml, argn: std::os::raw::c_int) -> $crate::expand_exported_function_return!($($rtyp)*) { let mut i = 0usize; $( - let $arg = argv[i]; + let $arg = unsafe { core::ptr::read(argv.add(i)) }; i += 1; )+ - debug_assert!(i == argn as usize); + debug_assert_eq!(i, argn as usize, "count of arguments read from argv matches argn"); $name($($arg),*) } }; From 7cb78bab66b540b9a0a28b9a48ec32725e0e3c3b Mon Sep 17 00:00:00 2001 From: Bruno Deferrari Date: Sun, 27 Aug 2023 12:46:44 -0300 Subject: [PATCH 2/3] Update CHANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f1f920..72283d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Expansion of bytecode-callable functions (PR #53, reported and debugged by @mt-caret in #52). + ## [0.9.1] - 2023-07-12 ### Fixed From 825695f079382d00b130ca83f4c6aaa61404465a Mon Sep 17 00:00:00 2001 From: Bruno Deferrari Date: Sun, 27 Aug 2023 12:53:46 -0300 Subject: [PATCH 3/3] In bytecode functions expansion, add clippy annotation to allow the unsafe pointer read --- src/macros.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/macros.rs b/src/macros.rs index ae56894..d0f0788 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1543,6 +1543,7 @@ macro_rules! expand_exported_byte_function { pub extern "C" fn $byte_name(argv: *mut $crate::RawOCaml, argn: std::os::raw::c_int) -> $crate::expand_exported_function_return!($($rtyp)*) { let mut i = 0usize; $( + #[allow(clippy::not_unsafe_ptr_arg_deref)] let $arg = unsafe { core::ptr::read(argv.add(i)) }; i += 1; )+