Skip to content
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

Implement pre allocation context creation #125

Merged
merged 7 commits into from
Jul 5, 2019

Conversation

elichai
Copy link
Member

@elichai elichai commented Jul 4, 2019

Hi,
After talking with @apoelstra and after the great feedback and discussion on #116

I wrote this new API.

If it's too broad of a change I can try to split it into smaller PRs.

After this there shouldn't be any free/malloc/fprintf symbols in this library.
(which will help both wasm(#124) and full no-std embedded devices)

Edit: I missed a realloc(didn't even think of that one haha), rebased and pushed.

Fixes #114

Fixes #117

Fixes #124

src/context.rs Outdated
const DESCRIPTION: &'static str = "signing only";

fn deallocate(ptr: *mut [u8]) {
let _ = ptr;
Copy link
Member

Choose a reason for hiding this comment

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

I think it'd be clearer to write

fn deallocate(_: *mut [u8]) {
    // do nothing
}

I read let _ = ptr as "drop ptr" which is technically what's happening but it's a bit weird because dropping a pointer is a noop.

src/lib.rs Outdated
@@ -570,7 +570,7 @@ impl<C: Context> Secp256k1<C> {
}

/// Uses the ffi `secp256k1_context_preallocated_size` to check the memory size needed for a context
pub fn preallocate_size() -> usize {
pub(crate) fn preallocate_size_gen() -> usize {
Copy link
Member

Choose a reason for hiding this comment

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

I think we should still export this. It's needed to estimate the allocation size in generic contexts.

Copy link
Member Author

Choose a reason for hiding this comment

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

I mostly didn't want to confuse the user with too many functions, some generic and some not

@apoelstra
Copy link
Member

Confirmed that I can build and run a rust-wasm project with this.

ACK.

@elichai
Copy link
Member Author

elichai commented Jul 5, 2019

@apoelstra That's great :) Thanks!

@apoelstra apoelstra changed the title Implementing pre allocation context creation [newer] Implement pre allocation context creation Jul 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants