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

Create a platform abstraction layer #122

Open
chille opened this issue Feb 7, 2019 · 3 comments
Open

Create a platform abstraction layer #122

chille opened this issue Feb 7, 2019 · 3 comments

Comments

@chille
Copy link
Contributor

chille commented Feb 7, 2019

Some parts of the EEL core relies on functions only available on certain operating system. This means there is #ifdef _WIN32_, #ifdef __MACOSX__, etc in the code. A better solution would be to keep the code clean from those #ifdef's and instead use an abstraction layer.

I suggest we add a subdirectoy called ./src/platform. This directory should have the files win32.c, macosx.c and linux.c (or similar). A define in CMakeLists.txt tells the compiler which one it should compile and link to.

Modules like eelium should link to the global platform file above, for generic stuff. And if needed provide their own platform directory.

The abstraction layer should also wrap memory allocations and other things that might be useful to change when running on an embedded and/or realtime system.

I don't think printing text should be a part of this abstraction layer. See #123.

@chille
Copy link
Contributor Author

chille commented Feb 7, 2019

I figured out the core is already nicely separated via e_platform.h, but it could probably be improved by splitting it into separate files. The benefit would be that git status wouldn't be bloated if the files are changed locally, and git pull wouldn't require a merge if the files are changed in the repository.

This is what I'm thining about:

  • Split e_platform.h into one file for each platform an place them in a new directory called "platform".
  • Move all the timer stuff in e_builtin.c to the platform file.
  • EEL_ARCH, EEL_SOEXT and EEL_DIRSEP could be hardcoded in each platform file. The only thing left in EEL_platform.h.cmake will be EEL_PLATFORM_INLINE, which I can't figure out where it comes from. Except from that it could be a static file.
  • All occurances of calloc(), malloc() realloc() and free() should be wrapped and moved to the platform file.
  • Move default_malloc|realloc|free in e_vm.c to platform files
  • Replace all vm->malloc() with eel_malloc() for consistency

I have not yet looked into the modules, everything else (executive, eeltest, includes and compiler) should be fine.

@chille
Copy link
Contributor Author

chille commented Feb 7, 2019

I think abort() should also be wrapped.

(No need to wrap exit() as it's just a hack and not supposed to be reached due to the longjmp())

@olofson
Copy link
Owner

olofson commented Feb 8, 2019

Sounds reasonable!

As for EEL_PLATFORM_INLINE, I think that's something that was lost in translation when moving from Autotools to CMake. It's supposed to take care of compilers that don't have the 'inline' keyword.

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