summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server.c5
-rw-r--r--utils.c33
-rw-r--r--utils.h2
3 files changed, 36 insertions, 4 deletions
diff --git a/server.c b/server.c
index 6d089c1..1dd10c8 100644
--- a/server.c
+++ b/server.c
@@ -268,8 +268,9 @@ WriteLocalPtrDecl(FILE *file, const argument_t *arg)
static void
WriteServerArgDecl(FILE *file, const argument_t *arg)
{
- fprintf(file, "%s %s%s",
- arg->argType->itTransType,
+ const char *qualif = ServerVarQualifier(arg);
+ fprintf(file, "%s%s %s%s",
+ qualif, arg->argType->itTransType,
arg->argByReferenceServer ? "*" : "",
arg->argVarName);
}
diff --git a/utils.c b/utils.c
index 5111e73..48c4420 100644
--- a/utils.c
+++ b/utils.c
@@ -182,13 +182,42 @@ WriteUserVarDecl(FILE *file, const argument_t *arg)
fprintf(file, "\t%s%s %s%s", qualif, arg->argType->itUserType, ref, arg->argVarName);
}
+/* Returns whether parameter should be qualified with const because we will only
+ receive the pointed data, not modify it. */
+static boolean_t
+ServerVarConst(const argument_t *arg)
+{
+ return (arg->argKind & (akbSend|akbReturn)) == akbSend
+ && !arg->argType->itStruct;
+}
+
+const char *
+ServerVarQualifier(const argument_t *arg)
+{
+ if (!ServerVarConst(arg))
+ return "";
+
+ if (arg->argType->itIndefinite ||
+ arg->argType->itInName == MACH_MSG_TYPE_STRING_C ||
+ !strcmp(arg->argType->itTransType, "string_t"))
+ /* This is a pointer, so we have to use the const_foo type to
+ make const qualify the data, not the pointer.
+
+ Or this is a string_t, which should use const_string_t to avoid
+ forcing the caller to respect the definite string size */
+ return "const_";
+ else
+ return "const ";
+}
+
void
WriteServerVarDecl(FILE *file, const argument_t *arg)
{
+ const char *qualif = ServerVarQualifier(arg);
const char *ref = arg->argByReferenceServer ? "*" : "";
- fprintf(file, "\t%s %s%s",
- arg->argType->itTransType, ref, arg->argVarName);
+ fprintf(file, "\t%s%s %s%s",
+ qualif, arg->argType->itTransType, ref, arg->argVarName);
}
void
diff --git a/utils.h b/utils.h
index 3a4c832..0524f0c 100644
--- a/utils.h
+++ b/utils.h
@@ -54,6 +54,8 @@ extern const char *ReturnTypeStr(const routine_t *rt);
extern const char *FetchUserType(const ipc_type_t *it);
extern const char *FetchServerType(const ipc_type_t *it);
+extern const char *ServerVarQualifier(const argument_t *arg);
+
extern void WriteFieldDeclPrim(FILE *file, const argument_t *arg,
const char *(*tfunc)(const ipc_type_t *it));