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

C Plugins interface is not robust #861

Open
jchabod opened this issue Oct 27, 2022 · 1 comment
Open

C Plugins interface is not robust #861

jchabod opened this issue Oct 27, 2022 · 1 comment
Assignees

Comments

@jchabod
Copy link

jchabod commented Oct 27, 2022

There are coding caveats in plugin interfaces. Coding rules should be automatically checked to avoid issues.

For example:

  • classes (e.g. Datapoint) do not define their destructor as virtual. Thus it is impossible to define a sub-class because destructor will never be called, implying memory leaks (and inconsistent behavior)
  • (in south plugin) typedef void (*INGEST_CB)(void *, Reading); => Why is that passed by copy?. The documentation does not provide the actual definition of INGEST_CB (in https://fledge-iot.readthedocs.io/en/develop/plugin_developers_guide/03_south_C_plugins.html) This seems like a critical point because Readings copy imply a deep copy of Datapoints which may contain deep vectors of vectors of vectors ... Moreover there are a lot of useless copies of readings all during processing lifetime, thus leading to unefficient code execution

This is important to be able to derive clases, typically in scope of unit tests (For example I want to use a memory leak checker for datapoints in my unit tests:


class Datapoint_leak_chk : public Datapoint {
 public:
    Datapoint_leak_chk(const std::string& name, DatapointValue& value) :
        Datapoint(name, value) {
        instances.push_back(this);
        LOG_WARNING(" TEST TODO : created %p", this);
    }
    virtual ~Datapoint_leak_chk(void) {
        LOG_WARNING(" TEST TODO : deleted %p", this);
        std::vector<Datapoint_leak_chk*>::iterator it;
        it = std::find(instances.begin(), instances.end(), this);
        assert (it != instances.end());
        instances.erase(it);
    }
    static void resetNbInstances(void){
        for (Datapoint_leak_chk* p: instances) {delete p;}
        instances.clear();
    }
    static int getNbInstances(void){return instances.size();}
 private:
    static std::vector<Datapoint_leak_chk*> instances;
};
std::vector<Datapoint_leak_chk*> Datapoint_leak_chk::instances{};

  • some class members are not initialized (Reading).
@jchabod
Copy link
Author

jchabod commented Oct 27, 2022

This is even more blocking for classes which are intended to be derived like FledgeFilter

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