[lttng-dev] [BABELTRACE PATCH] Fix : coherency in const parameters

Mathieu Desnoyers mathieu.desnoyers at efficios.com
Tue Feb 21 10:44:04 EST 2012


* Julien Desfossez (julien.desfossez at efficios.com) wrote:
> This patchs adds the const attribute to the field access functions
> (get_int64 and others) in order to keep the coherency with the get_field
> and get_field_list function which return a const pointer.

merged, thanks!

Mathieu

> 
> fixes #84
> 
> Signed-off-by: Julien Desfossez <julien.desfossez at efficios.com>
> ---
>  formats/ctf/events.c            |   10 +++++-----
>  include/babeltrace/ctf/events.h |   10 +++++-----
>  include/babeltrace/types.h      |    8 ++++----
>  types/array.c                   |    2 +-
>  types/integer.c                 |    4 ++--
>  types/string.c                  |    2 +-
>  6 files changed, 18 insertions(+), 18 deletions(-)
> 
> diff --git a/formats/ctf/events.c b/formats/ctf/events.c
> index 8ecb7c4..22623aa 100644
> --- a/formats/ctf/events.c
> +++ b/formats/ctf/events.c
> @@ -224,7 +224,7 @@ const char *bt_ctf_field_name(const struct definition *def)
>  	return NULL;
>  }
>  
> -enum ctf_type_id bt_ctf_field_type(struct definition *def)
> +enum ctf_type_id bt_ctf_field_type(const struct definition *def)
>  {
>  	if (def)
>  		return def->declaration->id;
> @@ -339,7 +339,7 @@ int bt_ctf_field_get_error(void)
>  	return ret;
>  }
>  
> -uint64_t bt_ctf_get_uint64(struct definition *field)
> +uint64_t bt_ctf_get_uint64(const struct definition *field)
>  {
>  	unsigned int ret = 0;
>  
> @@ -351,7 +351,7 @@ uint64_t bt_ctf_get_uint64(struct definition *field)
>  	return ret;
>  }
>  
> -int64_t bt_ctf_get_int64(struct definition *field)
> +int64_t bt_ctf_get_int64(const struct definition *field)
>  {
>  	int ret = 0;
>  
> @@ -364,7 +364,7 @@ int64_t bt_ctf_get_int64(struct definition *field)
>  
>  }
>  
> -char *bt_ctf_get_char_array(struct definition *field)
> +char *bt_ctf_get_char_array(const struct definition *field)
>  {
>  	char *ret = NULL;
>  
> @@ -376,7 +376,7 @@ char *bt_ctf_get_char_array(struct definition *field)
>  	return ret;
>  }
>  
> -char *bt_ctf_get_string(struct definition *field)
> +char *bt_ctf_get_string(const struct definition *field)
>  {
>  	char *ret = NULL;
>  
> diff --git a/include/babeltrace/ctf/events.h b/include/babeltrace/ctf/events.h
> index 61e3f6a..c08314f 100644
> --- a/include/babeltrace/ctf/events.h
> +++ b/include/babeltrace/ctf/events.h
> @@ -160,7 +160,7 @@ const char *bt_ctf_field_name(const struct definition *def);
>  /*
>   * bt_ctf_field_type: returns the type of a field or -1 if unknown
>   */
> -enum ctf_type_id bt_ctf_field_type(struct definition *def);
> +enum ctf_type_id bt_ctf_field_type(const struct definition *def);
>  
>  /*
>   * Field access functions
> @@ -172,10 +172,10 @@ enum ctf_type_id bt_ctf_field_type(struct definition *def);
>   * returned is undefined. To check if an error occured, use the
>   * bt_ctf_field_error() function after accessing a field.
>   */
> -uint64_t bt_ctf_get_uint64(struct definition *field);
> -int64_t bt_ctf_get_int64(struct definition *field);
> -char *bt_ctf_get_char_array(struct definition *field);
> -char *bt_ctf_get_string(struct definition *field);
> +uint64_t bt_ctf_get_uint64(const struct definition *field);
> +int64_t bt_ctf_get_int64(const struct definition *field);
> +char *bt_ctf_get_char_array(const struct definition *field);
> +char *bt_ctf_get_string(const struct definition *field);
>  
>  /*
>   * bt_ctf_field_error: returns the last error code encountered while
> diff --git a/include/babeltrace/types.h b/include/babeltrace/types.h
> index 0cedb33..ad2b42d 100644
> --- a/include/babeltrace/types.h
> +++ b/include/babeltrace/types.h
> @@ -373,8 +373,8 @@ struct declaration_integer *integer_declaration_new(size_t len, int byte_order,
>  				  int signedness, size_t alignment,
>  				  int base, enum ctf_string_encoding encoding,
>  				  struct ctf_clock *clock);
> -uint64_t get_unsigned_int(struct definition *field);
> -int64_t get_signed_int(struct definition *field);
> +uint64_t get_unsigned_int(const struct definition *field);
> +int64_t get_signed_int(const struct definition *field);
>  
>  /*
>   * mantissa_len is the length of the number of bytes represented by the mantissa
> @@ -421,7 +421,7 @@ struct declaration_enum *
>  
>  struct declaration_string *
>  	string_declaration_new(enum ctf_string_encoding encoding);
> -char *get_string(struct definition *field);
> +char *get_string(const struct definition *field);
>  
>  struct declaration_struct *
>  	struct_declaration_new(struct declaration_scope *parent_scope,
> @@ -486,7 +486,7 @@ struct declaration_array *
>  uint64_t array_len(struct definition_array *array);
>  struct definition *array_index(struct definition_array *array, uint64_t i);
>  int array_rw(struct stream_pos *pos, struct definition *definition);
> -GString *get_char_array(struct definition *field);
> +GString *get_char_array(const struct definition *field);
>  
>  /*
>   * int_declaration and elem_declaration passed as parameter now belong
> diff --git a/types/array.c b/types/array.c
> index f2c10ad..dbdcb4b 100644
> --- a/types/array.c
> +++ b/types/array.c
> @@ -207,7 +207,7 @@ struct definition *array_index(struct definition_array *array, uint64_t i)
>  	return g_ptr_array_index(array->elems, i);
>  }
>  
> -GString *get_char_array(struct definition *field)
> +GString *get_char_array(const struct definition *field)
>  {
>  	struct definition_array *array_definition;
>  	struct declaration_array *array_declaration;
> diff --git a/types/integer.c b/types/integer.c
> index 59a6c1b..6e12430 100644
> --- a/types/integer.c
> +++ b/types/integer.c
> @@ -107,7 +107,7 @@ void _integer_definition_free(struct definition *definition)
>  	g_free(integer);
>  }
>  
> -uint64_t get_unsigned_int(struct definition *field)
> +uint64_t get_unsigned_int(const struct definition *field)
>  {
>  	struct definition_integer *integer_definition;
>  	const struct declaration_integer *integer_declaration;
> @@ -122,7 +122,7 @@ uint64_t get_unsigned_int(struct definition *field)
>  	return (uint64_t)integer_definition->value._signed;
>  }
>  
> -int64_t get_signed_int(struct definition *field)
> +int64_t get_signed_int(const struct definition *field)
>  {
>  	struct definition_integer *integer_definition;
>  	const struct declaration_integer *integer_declaration;
> diff --git a/types/string.c b/types/string.c
> index 0fdd81e..dadcd08 100644
> --- a/types/string.c
> +++ b/types/string.c
> @@ -101,7 +101,7 @@ void _string_definition_free(struct definition *definition)
>  	g_free(string);
>  }
>  
> -char *get_string(struct definition *field)
> +char *get_string(const struct definition *field)
>  {
>  	struct definition_string *string_definition =
>  		container_of(field, struct definition_string, p);
> -- 
> 1.7.9
> 

-- 
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com



More information about the lttng-dev mailing list