Skip to contentSkip to conversation

mem: more const qualifiers in malloc API

PATCH In review Thomas Monjalon 2 participants 3 messages Jul 26, 2013 2 messages not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mem: more const qualifiers in malloc API

Some functions don't modify their parameter which should be marked as const.

---
 lib/librte_malloc/malloc_elem.h |    6 +++---
 lib/librte_malloc/malloc_heap.c |    2 +-
 lib/librte_malloc/malloc_heap.h |    2 +-
 lib/librte_malloc/rte_malloc.c  |    4 ++--
 lib/librte_malloc/rte_malloc.h  |    2 +-
 5 files changed, 8 insertions(+), 8 deletions(-)
lib/librte_malloc/malloc_elem.h +3 -3
index 8a75e0c..fadf0a5 100644
@@ -62,7 +62,7 @@ static const unsigned MALLOC_ELEM_TRAILER_LEN = 0;
 
 /* dummy function - just check if pointer is non-null */
 static inline int
-malloc_elem_cookies_ok(struct malloc_elem *elem){ return elem != NULL; }
+malloc_elem_cookies_ok(const struct malloc_elem *elem){ return elem != NULL; }
 
 /* dummy function - no header if malloc_debug is not enabled */
 static inline void
@@ -100,7 +100,7 @@ set_trailer(struct malloc_elem *elem)
 
 /* check that the header and trailer cookies are set correctly */
 static inline int
-malloc_elem_cookies_ok(struct malloc_elem *elem)
+malloc_elem_cookies_ok(const struct malloc_elem *elem)
 {
 	return (elem != NULL &&
 			MALLOC_ELEM_HEADER(elem) == MALLOC_HEADER_COOKIE &&
@@ -117,7 +117,7 @@ static const unsigned MALLOC_ELEM_HEADER_LEN = sizeof(struct malloc_elem);
  * the actual malloc_elem header for that block.
  */
 static inline struct malloc_elem *
-malloc_elem_from_data(void *data)
+malloc_elem_from_data(const void *data)
 {
 	if (data == NULL)
 		return NULL;
lib/librte_malloc/malloc_heap.c +1 -1
index b6d83a4..54b6b0c 100644
@@ -201,7 +201,7 @@ malloc_heap_alloc(struct malloc_heap *heap,
  * Function to retrieve data for heap on given socket
  */
 int
-malloc_heap_get_stats(struct malloc_heap *heap,
+malloc_heap_get_stats(const struct malloc_heap *heap,
 		struct rte_malloc_socket_stats *socket_stats)
 {
 	if (!heap->initialised)
lib/librte_malloc/malloc_heap.h +1 -1
index e4a5063..e3eb906 100644
@@ -53,7 +53,7 @@ malloc_heap_alloc(struct malloc_heap *heap, const char *type,
 		size_t size, unsigned align);
 
 int
-malloc_heap_get_stats(struct malloc_heap *heap,
+malloc_heap_get_stats(const struct malloc_heap *heap,
 		struct rte_malloc_socket_stats *socket_stats);
 
 int
lib/librte_malloc/rte_malloc.c +2 -2
index 03db51f..e16ba9c 100644
@@ -169,9 +169,9 @@ rte_realloc(void *ptr, size_t size, unsigned align)
 }
 
 int
-rte_malloc_validate(void *ptr, size_t *size)
+rte_malloc_validate(const void *ptr, size_t *size)
 {
-	struct malloc_elem *elem = malloc_elem_from_data(ptr);
+	const struct malloc_elem *elem = malloc_elem_from_data(ptr);
 	if (!malloc_elem_cookies_ok(elem))
 		return -1;
 	if (size != NULL)
lib/librte_malloc/rte_malloc.h +1 -1
index 64ffaf0..acf2ae0 100644
@@ -273,7 +273,7 @@ rte_free(void *ptr);
  *   0 on success
  */
 int
-rte_malloc_validate(void *ptr, size_t *size);
+rte_malloc_validate(const void *ptr, size_t *size);
 
 /**
  * Get heap statistics for the specified heap.
Signature · 1 line
1.7.10.4
#2 lore raw
In reply to a message not in the archive
Quoted 10 lines · Thomas Monjalon

Some functions don't modify their parameter which should be marked as const.

---
 lib/librte_malloc/malloc_elem.h |    6 +++---
 lib/librte_malloc/malloc_heap.c |    2 +-
 lib/librte_malloc/malloc_heap.h |    2 +-
 lib/librte_malloc/rte_malloc.c  |    4 ++--
 lib/librte_malloc/rte_malloc.h  |    2 +-
 5 files changed, 8 insertions(+), 8 deletions(-)
Signature · 2 lines
Adrien Mazarguil
6WIND
#4 lore raw
In reply to a message not in the archive

26/07/2013 16:37, Adrien Mazarguil :

Quoted 7 lines · Thomas Monjalon
Quoted 6 lines

Some functions don't modify their parameter which should be marked as const.

---

Quoted 8 lines
Quoted 6 lines
 lib/librte_malloc/malloc_elem.h |    6 +++---
 lib/librte_malloc/malloc_heap.c |    2 +-
 lib/librte_malloc/malloc_heap.h |    2 +-
 lib/librte_malloc/rte_malloc.c  |    4 ++--
 lib/librte_malloc/rte_malloc.h  |    2 +-
 5 files changed, 8 insertions(+), 8 deletions(-)

pushed

Signature · 1 line
Thomas