Skip to content

Conversation

iliakan
Copy link

@iliakan iliakan commented Feb 5, 2023

The natural thing for wasm is to call functions from JS directly or using cwrap, but I failed to do so.

In short, this fails:

let repoPointer = Module._malloc(8);

// int git_repository_init(git_repository **out, const char *path, unsigned int is_bare);
let git_repository_init = Module.cwrap('git_repository_init', 'number', ['number','string','number']); 

let r1 = git_repository_init(repoPointer, "/working", 0); // -1 (failed)

I tracked the problem inside libgit2.

The root of the issue is here: https://github.com/libgit2/libgit2/blob/main/src/util/str.c#L86

This grealloc call (which appears to use the stdalloc realloc) doesn't work, new_ptr becomes 0.
May it be connected with some memory issues? Or did I screw up somewhere? ;)

This PR contains a few changes I made to use git_repository_init.
Not intended for merging. Once I figure out the problem, I'll be able to submit a better variant.

@iliakan iliakan mentioned this pull request Feb 5, 2023
@iliakan iliakan changed the title Tried to add direct calls example, but init fails [DRAFT] Tried to add direct calls example, but init fails Feb 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant