bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Initialize basic types once and print errors for duplicate d


From: Samuel Thibault
Subject: Re: [PATCH] Initialize basic types once and print errors for duplicate definitions
Date: Tue, 15 Nov 2022 02:45:19 +0100
User-agent: NeoMutt/20170609 (1.8.3)

Applied, thanks!

Flavio Cruz, le lun. 14 nov. 2022 00:40:07 -0500, a ecrit:
> For kernel server or user subsystems we would initialize basic types
> twice, once in main() and again for the subsystem declaration. Instead,
> initialize basic types when the subsystem is declared and then throw
> errors when types are defined multiple times.
> ---
>  migcom.c |  1 -
>  parser.y |  5 ++---
>  type.c   | 16 ++++++++++++++++
>  3 files changed, 18 insertions(+), 4 deletions(-)
> 
> diff --git a/migcom.c b/migcom.c
> index c07e84d..e61c79b 100644
> --- a/migcom.c
> +++ b/migcom.c
> @@ -213,7 +213,6 @@ main(int argc, char **argv)
>      set_program_name("mig");
>      parseArgs(argc, argv);
>      init_global();
> -    init_type();
>  
>      LookNormal();
>      (void) yyparse();
> diff --git a/parser.y b/parser.y
> index 104f604..23294bf 100644
> --- a/parser.y
> +++ b/parser.y
> @@ -212,6 +212,7 @@ Subsystem         :       SubsystemStart SubsystemMods
>              IsKernelUser ? ", KernelUser" : "",
>              IsKernelServer ? ", KernelServer" : "");
>      }
> +    init_type();
>  }
>                       ;
>  
> @@ -238,7 +239,6 @@ SubsystemMod              :       syKernelUser
>      IsKernelUser = TRUE;
>      port_size = vm_offset_size;
>      port_size_in_bits = vm_offset_size_in_bits;
> -    init_type();
>  }
>                       |       syKernelServer
>  {
> @@ -247,7 +247,6 @@ SubsystemMod              :       syKernelUser
>      IsKernelServer = TRUE;
>      port_size = vm_offset_size;
>      port_size_in_bits = vm_offset_size_in_bits;
> -    init_type();
>  }
>                       ;
>  
> @@ -351,7 +350,7 @@ TypeDecl          :       syType NamedTypeSpec
>      identifier_t name = $2->itName;
>  
>      if (itLookUp(name) != itNULL)
> -     warn("overriding previous definition of %s", name);
> +             error("overriding previous definition of %s", name);
>      itInsert(name, $2);
>  }
>                       ;
> diff --git a/type.c b/type.c
> index 66944d9..3846746 100644
> --- a/type.c
> +++ b/type.c
> @@ -57,6 +57,7 @@ ipc_type_t *itWaitTimeType; /* used for dummy WaitTime args 
> */
>  ipc_type_t *itMsgOptionType; /* used for dummy MsgOption args */
>  ipc_type_t *itShortType;        /* used for the short type */
>  ipc_type_t *itIntType;          /* used for the int type */
> +static boolean_t types_initialized = FALSE;
>  
>  static ipc_type_t *list = itNULL;
>  
> @@ -67,6 +68,13 @@ static ipc_type_t *list = itNULL;
>  ipc_type_t *
>  itLookUp(identifier_t name)
>  {
> +    if (!types_initialized)
> +    {
> +        error("Basic types not initialized when looking up type %s. Did you "
> +              "forget to define the subsystem?", name);
> +        return NULL;
> +    }
> +
>      ipc_type_t *it, **last;
>  
>      for (it = *(last = &list); it != itNULL; it = *(last = &it->itNext))
> @@ -875,6 +883,14 @@ itMakeDeallocType(void)
>  void
>  init_type(void)
>  {
> +    if (types_initialized)
> +    {
> +        error("Basic types were already initialized");
> +        exit(EXIT_FAILURE);
> +    }
> +    /* Mark initialization here since itInsert below will require it. */
> +    types_initialized = TRUE;
> +
>      itByteType = itAlloc();
>      itByteType->itName = "unsigned char";
>      itByteType->itInName = MACH_MSG_TYPE_BYTE;
> -- 
> 2.37.2
> 
> 

-- 
Samuel
---
Pour une évaluation indépendante, transparente et rigoureuse !
Je soutiens la Commission d'Évaluation de l'Inria.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]