summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlavio Cruz <flaviocruz@gmail.com>2023-12-29 11:08:14 -0500
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2023-12-29 17:40:06 +0100
commite5c3fa44fb75b23dc7100202e52f3d4366447851 (patch)
tree611d767cf316f684351ec2910acaa2e2afde5114
parent3b1fcb2b83bb26d43dc912884499345f561d0b6a (diff)
Use char* for inlined arrays of char in user headers
This changes how we declare RPC user prototypes for device_read_inband to use "char *data" rather than "io_buf_ptr_inband_t data". It is more standard to pass a pointer to represent arrays compared to "char [128]". This fixes a warning in console-client since GCC won't complain we are not passing an exact char [128]. Also updated code to use const_io_buf_ptr_inband_t for device_write_inband. This is a pointer to const data rather than a const pointer. Message-ID: <ZY7u7noOnHlyJi24@jupiter.tail36e24.ts.net>
-rw-r--r--utils.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/utils.c b/utils.c
index 0d69cb2..a6c895b 100644
--- a/utils.c
+++ b/utils.c
@@ -160,12 +160,19 @@ UserVarQualifier(const argument_t *arg)
if (!UserVarConst(arg))
return "";
- if (arg->argType->itIndefinite ||
- arg->argType->itInName == MACH_MSG_TYPE_STRING_C ||
- !strcmp(arg->argType->itUserType, "string_t"))
+ const ipc_type_t *it = arg->argType;
+
+ if (it->itIndefinite ||
+ it->itInName == MACH_MSG_TYPE_STRING_C ||
+ (it->itVarArray && !strcmp(it->itElement->itUserType, "char")) ||
+ !strcmp(it->itUserType, "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 pointer to a variable array. For now we only support arrays of char
+ but we can remove that condition if we define const typedefs for all types that
+ require it.
+
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_";
@@ -176,10 +183,21 @@ UserVarQualifier(const argument_t *arg)
void
WriteUserVarDecl(FILE *file, const argument_t *arg)
{
- const char *qualif = UserVarQualifier(arg);
- const char *ref = arg->argByReferenceUser ? "*" : "";
+ const ipc_type_t *it = arg->argType;
- fprintf(file, "\t%s%s %s%s", qualif, arg->argType->itUserType, ref, arg->argVarName);
+ if (it->itInLine && it->itVarArray && !it->itIndefinite &&
+ !UserVarConst(arg) &&
+ !strcmp(it->itElement->itUserType, "char"))
+ {
+ /* For variable arrays like "array[*:128] of char" we prefer to use "char *param"
+ * as the argument since it is more standard than using "char param[128]".
+ */
+ fprintf(file, "\tchar *%s /* max of %d elements */", arg->argVarName, it->itNumber);
+ } else {
+ const char *qualif = UserVarQualifier(arg);
+ const char *ref = arg->argByReferenceUser ? "*" : "";
+ fprintf(file, "\t%s%s %s%s", qualif, it->itUserType, ref, arg->argVarName);
+ }
}
/* Returns whether parameter should be qualified with const because we will only