소스 검색

Add _STARPU_MALLOC_CAST macro to make list.h compatible with C++

Corentin Salingue 8 년 전
부모
커밋
b401b569ad
2개의 변경된 파일4개의 추가작업 그리고 2개의 파일을 삭제
  1. 2 2
      src/common/list.h
  2. 2 0
      src/common/utils.h

+ 2 - 2
src/common/list.h

@@ -156,7 +156,7 @@
     struct ENAME *_tail; /**< @internal tail of the list */ \
   }; \
   /** @internal */LIST_INLINE struct ENAME *ENAME##_new(void) \
-    { struct ENAME *e; _STARPU_MALLOC(e, sizeof(struct ENAME)); \
+    { struct ENAME *e; _STARPU_MALLOC_CAST(e, sizeof(struct ENAME), struct ENAME *); \
       e->_next = NULL; e->_prev = NULL; return e; } \
   /** @internal */LIST_INLINE void ENAME##_delete(struct ENAME *e) \
     { free(e); } \
@@ -185,7 +185,7 @@
   /** @internal */LIST_INLINE void ENAME##_list_init(struct ENAME##_list *l) \
     { l->_head=NULL; l->_tail=l->_head; } \
   /** @internal */LIST_INLINE struct ENAME##_list *ENAME##_list_new(void) \
-    { struct ENAME##_list *l; _STARPU_MALLOC(l, sizeof(struct ENAME##_list)); \
+    { struct ENAME##_list *l; _STARPU_MALLOC_CAST(l, sizeof(struct ENAME##_list), struct ENAME##_list *); \
       ENAME##_list_init(l); return l; } \
   /** @internal */LIST_INLINE int ENAME##_list_empty(const struct ENAME##_list *l) \
     { return (l->_head == NULL); } \

+ 2 - 0
src/common/utils.h

@@ -120,6 +120,8 @@
 #define _STARPU_CALLOC(ptr, nmemb, size) do { ptr = calloc(nmemb, size); STARPU_ASSERT_MSG(ptr != NULL, "Cannot allocate %ld bytes\n", (long) (nmemb*size)); } while (0)
 #define _STARPU_REALLOC(ptr, size) do { void *_new_ptr = realloc(ptr, size); STARPU_ASSERT_MSG(_new_ptr != NULL, "Cannot reallocate %ld bytes\n", (long) size); ptr = _new_ptr;} while (0)
 
+#define _STARPU_MALLOC_CAST(ptr, size, type) do { ptr = (type) malloc(size); STARPU_ASSERT_MSG(ptr != NULL, "Cannot allocate %ld bytes\n", (long) size); } while (0)
+
 #ifdef _MSC_VER
 #define _STARPU_IS_ZERO(a) (a == 0.0)
 #else