Skip to content

Don't use #[no_mangle] when mocking foreign C functions#603

Open
asomers wants to merge 1 commit into
masterfrom
extern-C-2
Open

Don't use #[no_mangle] when mocking foreign C functions#603
asomers wants to merge 1 commit into
masterfrom
extern-C-2

Conversation

@asomers

@asomers asomers commented Aug 20, 2024

Copy link
Copy Markdown
Owner

Don't use #[no_mangle] when mocking foreign C functions

That causes the Rust function to have exactly the same name as the
original, so the linker can't link to both. That is, it prevents a
program from mocking a C function and still calling the original.

This change partially reverts #504. Now, users wishing to call mock
functions directly from C must add a one-line wrapper function with the
C ABI, as shown in the call-from-c.rs example.

Fixes #602

@asomers asomers changed the title Improve the automock_foreign_C test Don't use #[no_mangle] when mocking foreign C functions May 24, 2026
That causes the Rust function to have exactly the same name as the
original, so the linker can't link to both.  That is, it prevents a
program from mocking a C function and still calling the original.

This change partially reverts #504.  Now, users wishing to call mock
functions directly from C must add a one-line wrapper function with the
C ABI, as shown in the call-from-c.rs example.

Fixes #602
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.

External functions seem to be "overwritten" by mocks when exported

1 participant