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

CR_LOAD called on first update, contrary to what the documentation states. Is this correct? #60

Closed
danielytics opened this issue Apr 14, 2021 · 2 comments

Comments

@danielytics
Copy link

Hi,

In the documentation for CR_LOAD, it says:

This does not happen when a plugin is loaded for the first time as there is no state to restore;

However, I'm observing that it gets called on initial call to cr_plugin_update. Is this the expected behaviour (and the documentation is wrong)?

My test code:

// main.cpp
#define CR_HOST
#include <cr.h>

int main (int argc, char* argv[])
{
    cr_plugin ctx;
    cr_plugin_open(ctx, "./test.so");
    cr_plugin_update(ctx);
    cr_plugin_close(ctx);
    return 0;
}
// test.cpp
#include <cr.h>
#include <iostream>

CR_EXPORT int cr_main(cr_plugin* ctx, cr_op operation)
{
    switch (operation) {
        case CR_STEP:
        {
            std::cout << "STEP\n";
            break;
        }
        case CR_CLOSE:
        {
            std::cout << "CLOSE\n";
            break;
        }
        case CR_LOAD:
        {
            std::cout << "LOAD\n";
            break;
        }
        case CR_UNLOAD:
        {
            std::cout << "UNLOAD\n";
            break;
        }
    }
    return 0;
}

Compiled with:

clang++ -fPIC -Icr -c test.cpp -o test.o
clang++ -shared test.o -o test.so
clang++ -Icr -c main.cpp -o main.o
clang++ -ldl main.o -o main

Running ./main gives the output:

LOAD
STEP
CLOSE
@fungos
Copy link
Owner

fungos commented Apr 16, 2021

Thanks for reporting that, I'll take a look once I have a bit of time. I suspect the behavior changed after a few fixes on the versioning flow and it is a bit hard to take a decision now without risking breaking any users. I will need to improve the tests and try to track down when this changed. But I would probably accept a PR to change the documentation to reflect this behavior in the meantime.

@danielytics
Copy link
Author

I'm not sure what to change the documentation to... But what I can do, later in the week or at the weekend, when I have a little time, is run git bisect to find the last commit where it doesn't call CR_LOAD on first step.

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