New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feature] #2161: generate FFI functions for data_model
#2164
[feature] #2161: generate FFI functions for data_model
#2164
Conversation
#[no_mangle] | ||
pub unsafe extern "C" fn dbg(ptr: *const u8, len: usize) { | ||
host::dbg(ptr, len) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the three functions above are just temporary placeholders. In the future smart contract will talk to host only through this module but there will be more meat in these functions. Namely, they'll convert opaque pointers received from the smart contract into scale encoded byte slice before passing them to the host for execution
9cfd519
to
8eff696
Compare
range: RangeFrom<usize>, | ||
) -> T { | ||
let bytes = Box::from_raw(core::slice::from_raw_parts_mut(ptr as *mut _, len as usize)); | ||
let bytes = Box::from_raw(core::slice::from_raw_parts_mut(ptr as *mut _, len)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is potentially UB, though I think it's not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I'd err on the side of caution, I think you're right in it not being intrinsically UB.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you really want to be pedantic, maybe add an assert
, that checks for conversion errors.
4aeef40
to
a749028
Compare
range: RangeFrom<usize>, | ||
) -> T { | ||
let bytes = Box::from_raw(core::slice::from_raw_parts_mut(ptr as *mut _, len as usize)); | ||
let bytes = Box::from_raw(core::slice::from_raw_parts_mut(ptr as *mut _, len)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I'd err on the side of caution, I think you're right in it not being intrinsically UB.
range: RangeFrom<usize>, | ||
) -> T { | ||
let bytes = Box::from_raw(core::slice::from_raw_parts_mut(ptr as *mut _, len as usize)); | ||
let bytes = Box::from_raw(core::slice::from_raw_parts_mut(ptr as *mut _, len)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you really want to be pedantic, maybe add an assert
, that checks for conversion errors.
|
||
## Usage | ||
|
||
Please follow the [WASM section of our tutorial](https://hyperledger.github.io/iroha-2-docs/guide/advanced/intro.html#wasm) for a detailed guide | ||
|
||
## How to build smart contract? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to be synchronised to the docs repo.
a749028
to
5150159
Compare
98c40fb
to
48a27a3
Compare
Codecov Report
@@ Coverage Diff @@
## iroha2-dev #2164 +/- ##
===============================================
+ Coverage 0 20.46% +20.46%
===============================================
Files 0 187 +187
Lines 0 26973 +26973
===============================================
+ Hits 0 5519 +5519
- Misses 0 21454 +21454
Continue to review full report at Codecov.
|
Signed-off-by: Marin Veršić <marin.versic101@gmail.com>
Signed-off-by: Marin Veršić <marin.versic101@gmail.com>
87f554a
to
6de64fe
Compare
Signed-off-by: Marin Veršić <marin.versic101@gmail.com>
Signed-off-by: Marin Veršić <marin.versic101@gmail.com>
Signed-off-by: Marin Veršić <marin.versic101@gmail.com>
6de64fe
to
125862b
Compare
Signed-off-by: Marin Veršić <marin.versic101@gmail.com>
125862b
to
f8d1fce
Compare
Signed-off-by: Marin Veršić marin.versic101@gmail.com
Description of the Change
You can find a description here: #1973
This PR introduces an
ffi
crate which holds a macroffi_bindgen
. This macro when attached to the impl block generates the equivalentffi
out of the methods listed in the impl block. The macro can also be attached to the structure definition where it integrates withgetset
to makeffi
fn equivalents of the getters/setters produced by thegetset
.Note:
FfiResult
return code. The idea is that the returned code can be used to query the errorLimitations:
Issue
Closes #2161
Benefits
Possible Drawbacks
Usage Examples or Tests [optional]
Alternate Designs [optional]
List out ffi functions manually. This is tedious and highly error prone because we're operating in the
unsafe
space