-
Notifications
You must be signed in to change notification settings - Fork 4
Ensure symbol is associated with defined section #33
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
base: main
Are you sure you want to change the base?
Ensure symbol is associated with defined section #33
Conversation
…nd the section associated with the plugin
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #33 +/- ##
==========================================
+ Coverage 98.35% 98.39% +0.04%
==========================================
Files 2 2
Lines 182 187 +5
==========================================
+ Hits 179 184 +5
Misses 3 3
🚀 New features to boost your workflow:
|
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.
Its probably a good idea to add a unit test which confirms this works as expected and to ensure that it does not get broken in the future.
@@ -196,7 +216,7 @@ std::shared_ptr<PluginBase> PluginLoader::createInstance(const std::string& plug | |||
// Create an instance of the plugin | |||
for (const auto& lib : libraries) | |||
{ | |||
if (lib.has(plugin_name)) | |||
if (hasSymbol<PluginBase>(lib, plugin_name)) |
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.
Does line 50 also need to be updated to leverage this?
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.
If we make the call to hasSymbol
before calling createSharedInstance
, then no. I think we have that covered as far as this PR goes. As it stands now, trying to add hasSymbol
to createSharedInstance
is not possible because hasSymbol
tries to call PluginT::getSection
which is private and inaccessible to everything except the PluginLoader
class. So we would have to make createSharedInstance
a member of PluginLoader
, which I didn't think was worth the extra change. Let me know if you would rather do that
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.
We may just update the documentation to this function that it assumes that the symbol is a associated with the library and section.
I ran into a use-case where I have two plugin libraries with different section names that use the same symbol name(s) to denote plugins. The plugin loader currently loops over the identified plugin libraries (which are ordered arbitrarily) and only checks if the symbol exists in the library before returning the first plugin it finds, regardless of whether that symbol is belongs to the section associated with the plugin typedef. In my case, it found the incorrect library first and caused a segfault because it didn't load the correct plugin object.
The fix provided in this PR adds two functions for checking the validity of a symbol in a library (
hasSymbol
). When the plugin type has a section, this method checks that the requested symbol is in the list of symbols associated with the section. Otherwise, it just checks if the library contains that symbol (i.e., the current behavior).Note: the added method needs to be added to the class itself because it needs access to
getSection
which is generally a private method that is accessible to thePluginLoader
class (via thefriend class
declaration in the plugin type) but is not accessible to other functions