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

Minor cleanup #30

Open
bansan85 opened this issue Jul 13, 2021 · 2 comments
Open

Minor cleanup #30

bansan85 opened this issue Jul 13, 2021 · 2 comments

Comments

@bansan85
Copy link
Contributor

After reading some part of the library, I noticed some minor change with ABI break.

  1. unverified_safe_because is template<size_t N> but N is never used.

Another declaration could be:

inline auto unverified_safe_because(const char *reason)

  1. const -> static constexpr

The library is explicitly c++17. There is lots of const int CompileErrorCode = 42; that could be replaced by static constexpr int CompileErrorCode = 42;

  1. in #define helper_create_converted_field, isFrozen is unused

So new declaration could be:

#define helper_create_converted_field(fieldType, fieldName)

  1. Finally a question: the library is explicitly not thread-safe.

So why there is a std::mutex callback_lock, RLBOX_SHARED_LOCK, RLBOX_ACQUIRE_SHARED_GUARD and RLBOX_ACQUIRE_UNIQUE_GUARD? Is this a try to make a thread-safe library?

Thanks,

PS: If you're fine with these changes, I can implement them.

@deian
Copy link
Member

deian commented Nov 17, 2021

These sound good to me (thanks @bansan85 !)

@shravanrn
Copy link
Collaborator

shravanrn commented Nov 17, 2021

unverified_safe_because is template<size_t N> but N is never used.

This is by design. This pattern forces all callers to only pass local strings (character arrays that have not decayed into pointers). If a caller passes in a string whose source is unknown to this API that is a code-smell and likely a mistake. So i would leave this as is.

const -> constexpr

Makes sense, a PR for this would be great! 👍
Many of these don't need to be static though. As a general rule, I think we want to stay away from static unless we explicitly need it. The compiler is going to optimize all of this out either way :)

in #define helper_create_converted_field, isFrozen is unused

This is for backward compatibility with a feature that was removed, which we may be re-introduced in the future.
Unfortunately removing this field now will break ABI with existing uses. If you can remove this in a way that does not break the ABI (by adding an overload that discards the extra params), awesome! If not, i think we won't be able to easily make this change.

Finally a question: the library is explicitly not thread-safe.

In general RLBox can be thread-safe. The early prototypes in fact included support for multiple threads. It is in the roadmap to make the library fully thread-safe in the future (about 3/4th of the work for this is already done which are the parts you are seeing).

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

3 participants