All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-trace-devel@vger.kernel.org
Subject: Re: [PATCH] libtracefs: Prefer using const pointer arguments
Date: Mon, 22 Mar 2021 18:59:42 +0200	[thread overview]
Message-ID: <64861357-e2ef-e2aa-239c-9b8a96a5bf9b@gmail.com> (raw)
In-Reply-To: <20210322114721.118c83ae@gandalf.local.home>



On 22.03.21 г. 17:47, Steven Rostedt wrote:
> On Mon, 22 Mar 2021 16:29:12 +0200
> "Yordan Karadzhov (VMware)" <y.karadz@gmail.com> 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@gmail.com>
>> ---
>>   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.
> 

Hi Steven,

I understand your preference to keep the flexibility of those API, 
however generally spiking those are "getter" functions and they are not 
supposed to modify the encapsulated object. If we allow the "getters" of 
the API to modify the encapsulated object (tracefs_instancein this case) 
this will be a bit of hacking stile of programing. At least for me, 
having a firm and intuitive design of the API is more valuable than the 
inconvenience that this reduced flexibility can potentially bring.

Thanks!
Yordan


> 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
> 

  reply	other threads:[~2021-03-22 17:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-22 14:29 [PATCH] libtracefs: Prefer using const pointer arguments Yordan Karadzhov (VMware)
2021-03-22 15:47 ` Steven Rostedt
2021-03-22 16:59   ` Yordan Karadzhov (VMware) [this message]
2021-03-22 22:29     ` Steven Rostedt
2021-03-23 12:58       ` Yordan Karadzhov (VMware)
2021-03-23 13:06         ` Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=64861357-e2ef-e2aa-239c-9b8a96a5bf9b@gmail.com \
    --to=y.karadz@gmail.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.