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

Lua casting #17456

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions bgpd/bgp_routemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,7 @@ route_match_script(void *rule, const struct prefix *prefix, void *object)
return RMAP_NOMATCH;
}

long long *action = frrscript_get_result(fs, routematch_function,
"action", lua_tointegerp);
int *action = frrscript_get_result(fs, routematch_function, "action", lua_tointegerp);

int status = RMAP_NOMATCH;

Expand Down
19 changes: 10 additions & 9 deletions tests/lib/test_frrscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,16 @@ int main(int argc, char **argv)
long long *ansptr =
frrscript_get_result(fs, "fact", "ans", lua_tolonglongp);
assert(*ansptr == 120);
XFREE(MTYPE_SCRIPT_RES, ansptr);

/* check consecutive call + get_result without re-loading */
n = 4;
result = frrscript_call(fs, "fact", ("n", &n));
assert(result == 0);
ansptr = frrscript_get_result(fs, "fact", "ans", lua_tointegerp);
assert(*ansptr == 24);
int *ansptr_c = frrscript_get_result(fs, "fact", "ans", lua_tointegerp);

XFREE(MTYPE_SCRIPT_RES, ansptr);
assert(*ansptr_c == 24);
XFREE(MTYPE_SCRIPT_RES, ansptr_c);

/* Negative testing */

Expand All @@ -70,9 +71,9 @@ int main(int argc, char **argv)
assert(result == 1);

/* Get result from a function that was not loaded */
long long *llptr =
frrscript_get_result(fs, "does_not_exist", "c", lua_tointegerp);
assert(llptr == NULL);
int *intptr = frrscript_get_result(fs, "does_not_exist", "c", lua_tointegerp);

assert(intptr == NULL);

/* Function returns void */
result = frrscript_call(fs, "bad_return1");
Expand All @@ -85,9 +86,9 @@ int main(int argc, char **argv)
/* Get non-existent result from a function */
result = frrscript_call(fs, "bad_return3");
assert(result == 1);
long long *cllptr =
frrscript_get_result(fs, "bad_return3", "c", lua_tointegerp);
assert(cllptr == NULL);
intptr = frrscript_get_result(fs, "bad_return3", "c", lua_tointegerp);
assert(intptr == NULL);
XFREE(MTYPE_SCRIPT_RES, intptr);

/* Function throws exception */
result = frrscript_call(fs, "bad_return4");
Expand Down
Loading