summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2018-01-28 16:35:16 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2018-01-28 16:35:16 +0100
commit74172cdd9a4b056d27ce2524e0aa0f3fcb2b0770 (patch)
tree5b724c4eb0be5c086cf8f9428c9d293cf49307f2
parent789a7e7299a580f295d1abd327bb4acf063fd9f0 (diff)
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.
-rw-r--r--utils.c30
1 files 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);