1 /* 2 * GRacer 3 * 4 * Copyright (C) 1999 Takashi Matsuda <matsu@users.sourceforge.net> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of the 9 * License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 19 * USA 20 */ 21 22 #ifndef __GRACER_MEMORY_H__ 23 #define __GRACER_MEMORY_H__ 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 #if 0 29 } 30 #endif 31 32 #include <stdlib.h> 33 34 #define gr_new(type,num) (type *) malloc (sizeof(type) * (num)) 35 #define gr_new0(type,num) (type *) __malloc0 (sizeof(type) * (num)) 36 #define gr_renew(ptr,type,num) (type *) realloc (ptr, sizeof(type) * (num)) 37 38 void* __malloc0 (size_t size); 39 40 typedef struct GrSList { 41 struct GrSList *next; 42 void *data; 43 } GrSList; 44 45 typedef struct GrDList { 46 struct GrDList *prev, *next; 47 void *data; 48 } GrDList; 49 50 typedef struct GrRef GrRef; 51 typedef void (*GrRefFreeFunc) (GrRef *ref); 52 53 struct GrRef { 54 int count; 55 GrRefFreeFunc free_func; 56 }; 57 58 59 GrSList* gr_slist_prepend (GrSList *top, void *data); 60 GrSList* gr_slist_append (GrSList *top, void *data); 61 GrSList* gr_slist_remove (GrSList *list); 62 63 void gr_slist_free (GrSList *list); 64 void gr_dlist_free (GrDList *list); 65 66 #define gr_FOREACH(l,p) \ 67 for (; (l) != NULL && ((p) = (l)->data, 1); (l) = (l)->next) 68 69 void gr_ref_incr (GrRef *ref); 70 void gr_ref_decr (GrRef *ref); 71 72 #define gr_INCREF(x) gr_ref_incr ((GrRef *) (x)) 73 #define gr_DECREF(x) gr_ref_decr ((GrRef *) (x)) 74 #define gr_FREE_FUNC(x,f) \ 75 (((GrRef *) (x))->free_func = ((GrRefFreeFunc) f)) 76 77 #ifdef __cplusplus 78 } 79 #endif 80 81 #endif /* __GRACER_MEMORY_H__ */ 82