Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--intern/guardedalloc/MEM_guardedalloc.h25
-rw-r--r--intern/guardedalloc/intern/mallocn.c4
-rw-r--r--source/blender/blenlib/BLI_memarena.h39
-rw-r--r--source/blender/blenlib/BLI_mempool.h62
4 files changed, 98 insertions, 32 deletions
diff --git a/intern/guardedalloc/MEM_guardedalloc.h b/intern/guardedalloc/MEM_guardedalloc.h
index 7fcfba5afec..dfb3fe69474 100644
--- a/intern/guardedalloc/MEM_guardedalloc.h
+++ b/intern/guardedalloc/MEM_guardedalloc.h
@@ -60,8 +60,8 @@
#ifndef __MEM_GUARDEDALLOC_H__
#define __MEM_GUARDEDALLOC_H__
-#include <stdio.h> /* needed for FILE* */
-#include "MEM_sys_types.h" /* needed for uintptr_t */
+#include <stdio.h> /* needed for FILE* */
+#include "MEM_sys_types.h" /* needed for uintptr_t */
#ifdef __cplusplus
extern "C" {
@@ -70,7 +70,7 @@ extern "C" {
/** Returns the length of the allocated memory segment pointed at
* by vmemh. If the pointer was not previously allocated by this
* module, the result is undefined.*/
- size_t MEM_allocN_len(void *vmemh)
+ size_t MEM_allocN_len(const void *vmemh)
#ifdef __GNUC__
__attribute__((warn_unused_result))
#endif
@@ -111,10 +111,10 @@ extern "C" {
* Allocate a block of memory of size len, with tag name str. The
* memory is cleared. The name must be static, because only a
* pointer to it is stored ! */
- void *MEM_callocN(size_t len, const char * str)
+ void *MEM_callocN(size_t len, const char *str)
#ifdef __GNUC__
__attribute__((warn_unused_result))
- __attribute__((nonnull))
+ __attribute__((nonnull(2)))
__attribute__((alloc_size(1)))
#endif
;
@@ -122,10 +122,10 @@ extern "C" {
/** Allocate a block of memory of size len, with tag name str. The
* name must be a static, because only a pointer to it is stored !
* */
- void *MEM_mallocN(size_t len, const char * str)
+ void *MEM_mallocN(size_t len, const char *str)
#ifdef __GNUC__
__attribute__((warn_unused_result))
- __attribute__((nonnull))
+ __attribute__((nonnull(2)))
__attribute__((alloc_size(1)))
#endif
;
@@ -133,10 +133,10 @@ extern "C" {
/** Same as callocN, clears memory and uses mmap (disk cached) if supported.
* Can be free'd with MEM_freeN as usual.
* */
- void *MEM_mapallocN(size_t len, const char * str)
+ void *MEM_mapallocN(size_t len, const char *str)
#ifdef __GNUC__
__attribute__((warn_unused_result))
- __attribute__((nonnull))
+ __attribute__((nonnull(2)))
__attribute__((alloc_size(1)))
#endif
;
@@ -213,11 +213,10 @@ public: \
MEM_freeN(mem); \
} \
-#endif
-
+#endif /* __cplusplus */
#ifdef __cplusplus
}
-#endif
+#endif /* __cplusplus */
-#endif
+#endif /* __MEM_GUARDEDALLOC_H__ */
diff --git a/intern/guardedalloc/intern/mallocn.c b/intern/guardedalloc/intern/mallocn.c
index 9ba8c0f3d58..7eda5a3ab5e 100644
--- a/intern/guardedalloc/intern/mallocn.c
+++ b/intern/guardedalloc/intern/mallocn.c
@@ -222,10 +222,10 @@ void MEM_set_memory_debug(void)
malloc_debug_memset = 1;
}
-size_t MEM_allocN_len(void *vmemh)
+size_t MEM_allocN_len(const void *vmemh)
{
if (vmemh) {
- MemHead *memh = vmemh;
+ const MemHead *memh = vmemh;
memh--;
return memh->len;
diff --git a/source/blender/blenlib/BLI_memarena.h b/source/blender/blenlib/BLI_memarena.h
index abba03ece9d..2a2dd31b26f 100644
--- a/source/blender/blenlib/BLI_memarena.h
+++ b/source/blender/blenlib/BLI_memarena.h
@@ -50,16 +50,43 @@ extern "C" {
struct MemArena;
typedef struct MemArena MemArena;
+struct MemArena *BLI_memarena_new(const int bufsize, const char *name)
+#ifdef __GNUC__
+__attribute__((warn_unused_result))
+__attribute__((nonnull(2)))
+#endif
+;
-struct MemArena *BLI_memarena_new(int bufsize, const char *name);
-void BLI_memarena_free(struct MemArena *ma);
+void BLI_memarena_free(struct MemArena *ma)
+#ifdef __GNUC__
+__attribute__((nonnull(1)))
+#endif
+;
-void BLI_memarena_use_malloc(struct MemArena *ma);
-void BLI_memarena_use_calloc(struct MemArena *ma);
+void BLI_memarena_use_malloc(struct MemArena *ma)
+#ifdef __GNUC__
+__attribute__((nonnull(1)))
+#endif
+;
+void BLI_memarena_use_calloc(struct MemArena *ma)
+#ifdef __GNUC__
+__attribute__((nonnull(1)))
+#endif
+;
-void BLI_memarena_use_align(struct MemArena *ma, int align);
+void BLI_memarena_use_align(struct MemArena *ma, const int align)
+#ifdef __GNUC__
+__attribute__((nonnull(1)))
+#endif
+;
-void *BLI_memarena_alloc(struct MemArena *ma, int size);
+void *BLI_memarena_alloc(struct MemArena *ma, int size)
+#ifdef __GNUC__
+__attribute__((warn_unused_result))
+__attribute__((nonnull(1)))
+__attribute__((alloc_size(2)))
+#endif
+;
#ifdef __cplusplus
}
diff --git a/source/blender/blenlib/BLI_mempool.h b/source/blender/blenlib/BLI_mempool.h
index 9d7c7d496c8..c773cfbe680 100644
--- a/source/blender/blenlib/BLI_mempool.h
+++ b/source/blender/blenlib/BLI_mempool.h
@@ -48,16 +48,47 @@ typedef struct BLI_mempool BLI_mempool;
* first four bytes of the elements never contain the character string
* 'free'. use with care.*/
-BLI_mempool *BLI_mempool_create(int esize, int totelem, int pchunk, int flag);
-void *BLI_mempool_alloc(BLI_mempool *pool);
-void *BLI_mempool_calloc(BLI_mempool *pool);
-void BLI_mempool_free(BLI_mempool *pool, void *addr);
-void BLI_mempool_destroy(BLI_mempool *pool);
-int BLI_mempool_count(BLI_mempool *pool);
-void *BLI_mempool_findelem(BLI_mempool *pool, int index);
+BLI_mempool *BLI_mempool_create(int esize, int totelem, int pchunk, int flag)
+#ifdef __GNUC__
+__attribute__((warn_unused_result))
+#endif
+;
+void *BLI_mempool_alloc(BLI_mempool *pool)
+#ifdef __GNUC__
+__attribute__((warn_unused_result))
+__attribute__((nonnull(1)))
+#endif
+;
+void *BLI_mempool_calloc(BLI_mempool *pool)
+#ifdef __GNUC__
+__attribute__((warn_unused_result))
+__attribute__((nonnull(1)))
+#endif
+;
+void BLI_mempool_free(BLI_mempool *pool, void *addr)
+#ifdef __GNUC__
+__attribute__((nonnull(1, 2)))
+#endif
+;
+void BLI_mempool_destroy(BLI_mempool *pool)
+#ifdef __GNUC__
+__attribute__((nonnull(1)))
+#endif
+;
+int BLI_mempool_count(BLI_mempool *pool)
+#ifdef __GNUC__
+__attribute__((nonnull(1)))
+#endif
+;
+void *BLI_mempool_findelem(BLI_mempool *pool, int index)
+#ifdef __GNUC__
+__attribute__((warn_unused_result))
+__attribute__((nonnull(1)))
+#endif
+;
/** iteration stuff. note: this may easy to produce bugs with **/
-/*private structure*/
+/* private structure */
typedef struct BLI_mempool_iter {
BLI_mempool *pool;
struct BLI_mempool_chunk *curchunk;
@@ -70,11 +101,20 @@ enum {
BLI_MEMPOOL_ALLOW_ITER = (1 << 1)
};
-void BLI_mempool_iternew(BLI_mempool *pool, BLI_mempool_iter *iter);
-void *BLI_mempool_iterstep(BLI_mempool_iter *iter);
+void BLI_mempool_iternew(BLI_mempool *pool, BLI_mempool_iter *iter)
+#ifdef __GNUC__
+__attribute__((nonnull(1, 2)))
+#endif
+;
+void *BLI_mempool_iterstep(BLI_mempool_iter *iter)
+#ifdef __GNUC__
+__attribute__((warn_unused_result))
+__attribute__((nonnull(1)))
+#endif
+;
#ifdef __cplusplus
}
#endif
-#endif
+#endif /* __BLI_MEMPOOL_H__ */