-
Notifications
You must be signed in to change notification settings - Fork 34
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
Define and use macros for exporting public functions for dll/dylib/so usages, enforce cdcel for public functions/callbacks #300
Define and use macros for exporting public functions for dll/dylib/so usages, enforce cdcel for public functions/callbacks #300
Conversation
… usages, enforce cdcel for public functions/callbacks
2b1e48a
to
4e77b0c
Compare
Default to RC_STATIC Replace BUILDING_RC with RC_IMPORT (which is for external code using rcheevos as a shared library) Check if GNUC version is high enough (>= 4) for the visibility attribute Add in rc_version/rc_version_string functions, so external code using rcheevos as a shared library can obtain the version (as they might not be able to use the macros).
include/rc_export.h
Outdated
* | ||
* #include <stdint.h> | ||
* | ||
* RC_CXX_GUARD_BEGIN |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still not sold on using #defines for this. Every library I've looked at just has the raw #ifndef __cplusplus extern "C" {
- https://github.com/madler/zlib/blob/643e17b7498d12ab8d15565662880579692f769d/zlib.h#L36-L38
- https://github.com/libsdl-org/SDL/blob/b937c54b665f134f241313eb45a4e0110807ae2c/include/SDL3/SDL_version.h#L34-L37
- https://github.com/openssl/openssl/blob/e4542332fa36eab6d6bbf33815bde433ade3b547/include/openssl/decoder.h#L25-L27
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some libraries do use a macro for this (well, mGBA is the only one I know on hand)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RetroArch apparently also does it (although they have more excuse since they do something slightly more complicated) https://github.com/libretro/RetroArch/blob/2980eb7e1296498305b9c047c82050ffd4d85778/libretro-common/include/retro_common_api.h#L41-L59
glib also does it
https://github.com/GNOME/glib/blob/e7eef648e187b117bb03937c30261a413fddd3e6/glib/gmacros.h#L900-L907
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RetroArch apparently also does it
And definitely not consistently.
$ grep -rnI "extern \"C\" {" * | grep -v deps | wc -l
462
$ grep -rnI RETRO_BEGIN_DECLS * | grep -v deps | wc -l
209
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The closest I can find to any sort of industry standard is this document for writing gnu libraries. It uses BEGIN_C_DECLS
and END_C_DECLS
, which do seem somewhat familiar, and googling for BEGIN_C_DECLS
returns plenty of hits.
Would you be willing to change the defines to RC_BEGIN_C_DECLS
and RC_END_C_DECLS
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be willing to do that. I mainly did CXX_GUARD as I only remember mGBA doing this and that's what it used (although in retrospect this is more an exception than the norm)
not touching md5.h (probably needs more fixes overall, like the typedefs should use fixed width types)
No description provided.