[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH mig] Use char* for inlined arrays of char in user headers
From: |
Samuel Thibault |
Subject: |
Re: [PATCH mig] Use char* for inlined arrays of char in user headers |
Date: |
Fri, 29 Dec 2023 17:40:14 +0100 |
User-agent: |
NeoMutt/20170609 (1.8.3) |
Applied, thanks!
Flavio Cruz, le ven. 29 déc. 2023 11:08:14 -0500, a ecrit:
> 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.
> ---
> utils.c | 30 ++++++++++++++++++++++++------
> 1 file 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
> --
> 2.39.2
>
>
--
Samuel
---
Pour une évaluation indépendante, transparente et rigoureuse !
Je soutiens la Commission d'Évaluation de l'Inria.