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

Just an idea: use the weakness property of functions #1

Closed
Lecrapouille opened this issue Aug 21, 2022 · 2 comments
Closed

Just an idea: use the weakness property of functions #1

Lecrapouille opened this issue Aug 21, 2022 · 2 comments

Comments

@Lecrapouille
Copy link

First, nice collection of repos :)

Here a simple message for giving an idea (with care, I may be wrong and probably not portable idea) but clib functions such as fopen, printf, read, write are weak functions, therefore you can define a function with their name to change their behavior without having to deal by "namespacing" them (fopen => eopen).

I used it on Linux for unit test for example: https://github.com/Lecrapouille/BacASable/tree/master/Cpp/UnitTests with some risk for example, like in my case not restoring the original function and calling code coverage tools that keep using the mocked function and ending by segfault.

@weigert
Copy link
Owner

weigert commented Sep 17, 2022

Thanks for the idea! I will have to take a look at this.

The reason why I use a compiler preprocessor directive (to re- #define eopen as fopen), is that it can be easily turned on and off during compile time with a flag. That means that you can use your local filesystem during development, which can change dynamically (without having to embed it first) and embed it quickly at deployment.

Additionally, it lets you use a local and an embedded filesystem simultaneously (in theory - although most use cases would probably use one or the other).

If I were to overwrite the functions with c-embed, then the local file system could not be used unless I removed the c-embed header entirely, which would be a code modification depending on whether you're developing or deploying; one of the main goals of this repo was to avoid this entirely.

@Lecrapouille
Copy link
Author

Yes I did not think about mixing local and embedded filesystem. I was only thinking about 100 % embedded filesystem.

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

No branches or pull requests

2 participants