Skip to content

C Interface - #28

Merged
JackTench merged 9 commits into
LibreSplit:mainfrom
JackTench:c-interface
Jun 15, 2026
Merged

C Interface#28
JackTench merged 9 commits into
LibreSplit:mainfrom
JackTench:c-interface

Conversation

@JackTench

Copy link
Copy Markdown
Member

Can now be built 2 ways:

wasm-pack build --scope libresplit --target web --release --features wasm
This builds a WASM library, for use on the web.
Output to the pkg folder.

cargo build --release
This builds a native library, for use with C.
Output to the target folder.

Example C usage:

#include <stdio.h>

char *converter_convert(const char *input);
void converter_free_string(char *ptr);

int main() {
    const char *lss = "<Run>...</Run>";

    char *json = converter_convert(lss);
    if (json == NULL) {
        return 1;
    }

    printf("%s\n", json);
    converter_free_string(json);

    return 0;
}

@Penaz91

Penaz91 commented Jun 9, 2026

Copy link
Copy Markdown
Member

I think this could use a bit more commenting, just to understand what each function expects and outputs (does it work on files directly, does it work on text streams?).

Also I see a lot of "unsafe" blocks, are those workarounds for the borrow checker or can things be handled safely, from a memory standpoint?

@JackTench

Copy link
Copy Markdown
Member Author

The unsafe blocks are required at some point for interfacing with C.

from_ptr always has to be in an unsafe block due to the boundary of what is happening in C or Rust. The rust code has no way to absolutely prove that the pointer points to a valid string in memory.

The intent is to keep the unsafe blocks isolated to just the C interface.
All parsing and conversion logic happens without unsafe blocks. As long as callers provide a valid null-terminated string, and free returned strings, this is memory safe.

Happy to explore other options, I just don't think it's entirely possible to remove them.

As for documentation, yeah I'll get that done.

@Penaz91 Penaz91 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the explanation, we can go forward with this and eventually if the need arises we can just make some edits.

@JackTench
JackTench requested review from Penaz91 and wins1ey June 11, 2026 20:30

@Penaz91 Penaz91 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nothing odd stands out to me. I think this can work for now.

@wins1ey wins1ey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@JackTench
JackTench merged commit 2ec5076 into LibreSplit:main Jun 15, 2026
1 check passed
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.

3 participants