afb-export: Emit a warning on bad 'afb_require_api' call 53/16753/1 6.90.0 guppy/6.90.0 guppy_6.90.0
authorJosé Bollo <jose.bollo@iot.bzh>
Tue, 18 Sep 2018 09:03:23 +0000 (11:03 +0200)
committerJose Bollo <jose.bollo@iot.bzh>
Mon, 24 Sep 2018 08:05:00 +0000 (10:05 +0200)
The call to 'afb_require_api' in a preinit was forbiden
before binding v3 refactoring. Since v3 it is made possible
by deferring the requirement to the initialisation step.
But this may lead to bad behaviour if someone use the
call to test whether an api exists or not. This commit
introduce a message that could warn a developper raising
that issue.

Change-Id: Icc14c3887d70f73d87da0e664bb0e5e961867b4a
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
src/afb-export.c

index e679b76..fdd4573 100644 (file)
@@ -352,6 +352,11 @@ static int require_api_cb(struct afb_api_x3 *closure, const char *name, int init
        int rc, rc2;
        char *iter, *end, save;
 
+       /* emit a warning about unexpected require in preinit */
+       if (export->state == Api_State_Pre_Init)
+               WARNING("[API %s] requiring apis in pre-init may lead to unexpected result (requires%s: %s)",
+                       export->api.apiname, initialized ? " initialized" : "", name);
+
        /* scan the names in a local copy */
        rc = 0;
        iter = strdupa(name);