From 74172cdd9a4b056d27ce2524e0aa0f3fcb2b0770 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 28 Jan 2018 16:35:16 +0100 Subject: Fix RPC build warnings Users of RPCs want to be able to pass pointers to const data, so add const qualifiers to RPCs as appropriate. * utils.c (UserVarConst, UserVarQualifier): New functions. (WriteUserVarDecl): Use UserVarQualifier to qualify function parameter. (WriteFieldDeclPrim): Use UserVarConst to qualify pointer to user variable. --- utils.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/utils.c b/utils.c index 265a123..4ddadc5 100644 --- a/utils.c +++ b/utils.c @@ -144,12 +144,36 @@ WriteNameDecl(FILE *file, const argument_t *arg) fprintf(file, "%s", arg->argVarName); } +/* Returns whether parameter should be qualified with const because we will only + send the pointed data, not receive it. */ +static boolean_t +UserVarConst(const argument_t *arg) +{ + return (arg->argKind & (akbSend|akbReturn)) == akbSend + && !arg->argType->itStruct; +} + +static const char * +UserVarQualifier(const argument_t *arg) +{ + if (!UserVarConst(arg)) + return ""; + + if (arg->argType->itIndefinite) + /* This is a pointer type, so we have to use the const_foo type to + make const qualify the data, not the pointer. */ + return "const_"; + else + return "const "; +} + void WriteUserVarDecl(FILE *file, const argument_t *arg) { + const char *qualif = UserVarQualifier(arg); const char *ref = arg->argByReferenceUser ? "*" : ""; - fprintf(file, "\t%s %s%s", arg->argType->itUserType, ref, arg->argVarName); + fprintf(file, "\t%s%s %s%s", qualif, arg->argType->itUserType, ref, arg->argVarName); } void @@ -244,7 +268,9 @@ WriteFieldDeclPrim(FILE *file, const argument_t *arg, (*tfunc)(btype), arg->argMsgField, it->itNumber/btype->itNumber); - fprintf(file, "\t\t\t%s *%s%s;\n", + fprintf(file, "\t\t\t%s%s *%s%s;\n", + tfunc == FetchUserType && UserVarConst(arg) + ? "const " : "", (*tfunc)(btype), arg->argMsgField, OOLPostfix); -- cgit v1.2.3