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

Erroneous documentation for most plugin functions involving PLUGIN_HANDLE #1069

Open
FlorentP42 opened this issue May 15, 2023 · 1 comment
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@FlorentP42
Copy link
Contributor

Most of the documentation involving PLUGIN_HANDLE provides erroneous usage examples for the C++ implementation of a plugin.

The plugin_init() function is correct and returns a PLUGIN_HANDLE type (void*) containing a pointer to the main plugin class (in this example a DHT11*):
image

But then most of the other functions in the documentation take a PLUGIN_HANDLE* as parameter (void**) when it should in fact use a PLUGIN_HANDLE only. It is clearly visible that the input type is actually the same type as the one returned by plugin_init() when the input type is casted into DHT11* here:
image

All of the documentation involving this type needs to be reviewed: some functions may actually need PLUGIN_HANDLE* as an input, but most of them doesn't and must be fixed.

Sadly most of the existing plugins are based on those examples and do contain this erroneous implementation which is not raising any error because it is using the "jocker" void* type.

As an example in one of the plugins I reviewed this led to really messed up codes likes this one where you end up casting a PLUGIN_HANDLE into PLUGIN_HANDLE* which makes zero sense in term of pure C++:

TEST(HNZ, PluginInit) {
  ConfigCategory *config = new ConfigCategory("Test_Config", default_config);
  config->setItemsValueFromDefault();
  PLUGIN_HANDLE handle = nullptr;

  ASSERT_NO_THROW(handle = plugin_init(config));

  if (handle != nullptr) plugin_shutdown((PLUGIN_HANDLE *)handle);

  delete config;
}
@ashish-jabble ashish-jabble added the documentation Improvements or additions to documentation label May 16, 2023
@FlorentP42
Copy link
Contributor Author

Looks like part of this issue was already reported in #843, sorry for missing it.

mbourhis added a commit to mbourhis/fledge that referenced this issue Oct 13, 2023
Fix the issue fledge-iot#1069

In the 'plugin_developers_guide/03_south_C_plugins.html' documentation page,
the signature of some plugin functions involving PLUGIN_HANDLE is erroneous.

According to the definitions of the function pointers about the South
plugins ($FLEDGE_ROOT/C/services/south/include/south_plugin.h),
fix these signatures.

And use the appropriate C++ 'cast' operator,
more restrictive and accurate 'cast' operator than the C one,
for the 'PLUGIN_HANDLE' object.

Signed-off-by: Mikael Bourhis <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants