summaryrefslogtreecommitdiffstats
path: root/ctl-lib/ctl-plugin.c
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2019-07-01 17:05:10 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2019-07-05 07:25:09 +0000
commitc1acf36459ce3046b7fc46f26328ce408a2f49fb (patch)
tree548404bbc498ef3d37dab3dd3e6769c5f7d6220f /ctl-lib/ctl-plugin.c
parent0749697635678cbbe48bdf74e8be3e926e5b7d69 (diff)
ctl-plugin.c: Get rid of nested functionhalibut_7.99.3halibut/7.99.37.99.3
Nested C function is only valid in a non-standard extension of GCC. So this is not valid in C++ or any other compiler (i.e. Clang) Bug-AGL: SPEC-2113 Change-Id: If82395cad304e889ee8a97a39cf0c4f1dacbf1cd Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'ctl-lib/ctl-plugin.c')
-rw-r--r--ctl-lib/ctl-plugin.c46
1 files changed, 23 insertions, 23 deletions
diff --git a/ctl-lib/ctl-plugin.c b/ctl-lib/ctl-plugin.c
index 1732197..e60bd5e 100644
--- a/ctl-lib/ctl-plugin.c
+++ b/ctl-lib/ctl-plugin.c
@@ -85,6 +85,27 @@ static int DispatchOneL2c(void* luaState, char *funcname, Lua2cFunctionT callbac
#endif
}
+int Lua2cAddOne(afb_api_t apiHandle, CtlPluginT *ctlPlugin, void *dlHandle, luaL_Reg *l2cFunc, const char* l2cName, int index) {
+ if(ctlPlugin->ctlL2cFunc->l2cCount)
+ {index += ctlPlugin->ctlL2cFunc->l2cCount+1;}
+ char *funcName;
+ size_t p_length = 6 + strlen(l2cName);
+ funcName = malloc(p_length + 1);
+
+ strncpy(funcName, "lua2c_", p_length + 1);
+ strncat(funcName, l2cName, p_length - strlen (funcName) + 1);
+
+ Lua2cFunctionT l2cFunction = (Lua2cFunctionT) dlsym(dlHandle, funcName);
+ if (!l2cFunction) {
+ AFB_API_ERROR(apiHandle, "CTL-PLUGIN-LOADONE symbol'%s' missing err=%s", funcName, dlerror());
+ return 1;
+ }
+ l2cFunc[index].func = (void*) l2cFunction;
+ l2cFunc[index].name = strdup(l2cName);
+
+ return 0;
+}
+
static int PluginLoadCOne(afb_api_t apiHandle, const char *pluginpath, json_object *lua2csJ, const char *lua2c_prefix, void * handle, CtlPluginT *ctlPlugin)
{
void *dlHandle = dlopen(pluginpath, RTLD_NOW);
@@ -121,27 +142,6 @@ static int PluginLoadCOne(afb_api_t apiHandle, const char *pluginpath, json_obje
if (lua2csJ && lua2cInPlug) {
*lua2cInPlug = (Lua2cWrapperT)DispatchOneL2c;
- int Lua2cAddOne(luaL_Reg *l2cFunc, const char* l2cName, int index) {
- if(ctlPlugin->ctlL2cFunc->l2cCount)
- {index += ctlPlugin->ctlL2cFunc->l2cCount+1;}
- char *funcName;
- size_t p_length = 6 + strlen(l2cName);
- funcName = malloc(p_length + 1);
-
- strncpy(funcName, "lua2c_", p_length + 1);
- strncat(funcName, l2cName, p_length - strlen (funcName) + 1);
-
- Lua2cFunctionT l2cFunction = (Lua2cFunctionT) dlsym(dlHandle, funcName);
- if (!l2cFunction) {
- AFB_API_ERROR(apiHandle, "CTL-PLUGIN-LOADONE symbol'%s' missing err=%s", funcName, dlerror());
- return 1;
- }
- l2cFunc[index].func = (void*) l2cFunction;
- l2cFunc[index].name = strdup(l2cName);
-
- return 0;
- }
-
int count = 0, errCount = 0;
luaL_Reg *l2cFunc = NULL;
if(!ctlPlugin->ctlL2cFunc) {
@@ -159,13 +159,13 @@ static int PluginLoadCOne(afb_api_t apiHandle, const char *pluginpath, json_obje
for (count = 0; count < length; count++) {
int err;
const char *l2cName = json_object_get_string(json_object_array_get_idx(lua2csJ, count));
- err = Lua2cAddOne(l2cFunc, l2cName, count);
+ err = Lua2cAddOne(apiHandle, ctlPlugin, dlHandle, l2cFunc, l2cName, count);
if (err) errCount++;
}
} else {
l2cFunc = calloc(2 + ctlPlugin->ctlL2cFunc->l2cCount, sizeof (luaL_Reg));
const char *l2cName = json_object_get_string(lua2csJ);
- errCount = Lua2cAddOne(l2cFunc, l2cName, count);
+ errCount = Lua2cAddOne(apiHandle, ctlPlugin, dlHandle, l2cFunc, l2cName, count);
count++;
}
if (errCount) {