Re: [PATCH] libtracefs: Prefer using const pointer arguments

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

 



On Mon, 22 Mar 2021 16:29:12 +0200
"Yordan Karadzhov (VMware)" <y.karadz@xxxxxxxxx> wrote:

> All functions should receive const pointer arguments, except in the
> cases when the argument object itself needs to be modified.
> 
> Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@xxxxxxxxx>
> ---
>  include/tracefs.h      | 15 ++++++++-------
>  src/tracefs-instance.c | 17 +++++++++--------
>  2 files changed, 17 insertions(+), 15 deletions(-)
> 
> diff --git a/include/tracefs.h b/include/tracefs.h
> index f3eec62..e54f791 100644
> --- a/include/tracefs.h
> +++ b/include/tracefs.h
> @@ -25,12 +25,13 @@ struct tracefs_instance *tracefs_instance_create(const char *name);
>  struct tracefs_instance *tracefs_instance_alloc(const char *tracing_dir,
>  						const char *name);
>  int tracefs_instance_destroy(struct tracefs_instance *instance);
> -bool tracefs_instance_is_new(struct tracefs_instance *instance);
> -const char *tracefs_instance_get_name(struct tracefs_instance *instance);
> -const char *tracefs_instance_get_trace_dir(struct tracefs_instance *instance);
> +bool tracefs_instance_is_new(const struct tracefs_instance *instance);
> +const char *tracefs_instance_get_name(const struct tracefs_instance *instance);
> +const char *tracefs_instance_get_trace_dir(const struct tracefs_instance *instance);
>  char *
> -tracefs_instance_get_file(struct tracefs_instance *instance, const char *file);
> -char *tracefs_instance_get_dir(struct tracefs_instance *instance);
> +tracefs_instance_get_file(const struct tracefs_instance *instance,
> +			  const char *file);
> +char *tracefs_instance_get_dir(const struct tracefs_instance *instance);
>  int tracefs_instance_file_write(struct tracefs_instance *instance,
>  				const char *file, const char *str);
>  char *tracefs_instance_file_read(struct tracefs_instance *instance,
> @@ -42,8 +43,8 @@ int tracefs_instance_file_open(struct tracefs_instance *instance,
>  int tracefs_instances_walk(int (*callback)(const char *, void *), void *context);
>  
>  bool tracefs_instance_exists(const char *name);
> -bool tracefs_file_exists(struct tracefs_instance *instance, char *name);
> -bool tracefs_dir_exists(struct tracefs_instance *instance, char *name);
> +bool tracefs_file_exists(struct tracefs_instance *instance, const char *name);
> +bool tracefs_dir_exists(struct tracefs_instance *instance, const char *name);
>  
>  int tracefs_trace_is_on(struct tracefs_instance *instance);
>  int tracefs_trace_on(struct tracefs_instance *instance);
> 

My fear about doing the above is that when dealing with complex structures
like tracefs_instance, which is opaque (private) to the caller that it now
prevents us from ever modifying the instance in one of those APIs. It may
not modify it now, but that does not mean it wont be modified in the
future. We could add ref counters, or something else.

What's the reason to make them constant? The caller does not have access to
the internals of what those are pointing to. It's just an abstract object.
Why would they care if its const or not?

-- Steve



[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux