/* * GRacer * * Copyright (C) 1999 Takashi Matsuda * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #ifndef __GRACER_MEMORY_H__ #define __GRACER_MEMORY_H__ #ifdef __cplusplus extern "C" { #endif #if 0 } #endif #include #define gr_new(type,num) (type *) malloc (sizeof(type) * (num)) #define gr_new0(type,num) (type *) __malloc0 (sizeof(type) * (num)) #define gr_renew(ptr,type,num) (type *) realloc (ptr, sizeof(type) * (num)) void* __malloc0 (size_t size); typedef struct GrSList { struct GrSList *next; void *data; } GrSList; typedef struct GrDList { struct GrDList *prev, *next; void *data; } GrDList; typedef struct GrRef GrRef; typedef void (*GrRefFreeFunc) (GrRef *ref); struct GrRef { int count; GrRefFreeFunc free_func; }; GrSList* gr_slist_prepend (GrSList *top, void *data); GrSList* gr_slist_append (GrSList *top, void *data); GrSList* gr_slist_remove (GrSList *list); void gr_slist_free (GrSList *list); void gr_dlist_free (GrDList *list); #define gr_FOREACH(l,p) \ for (; (l) != NULL && ((p) = (l)->data, 1); (l) = (l)->next) void gr_ref_incr (GrRef *ref); void gr_ref_decr (GrRef *ref); #define gr_INCREF(x) gr_ref_incr ((GrRef *) (x)) #define gr_DECREF(x) gr_ref_decr ((GrRef *) (x)) #define gr_FREE_FUNC(x,f) \ (((GrRef *) (x))->free_func = ((GrRefFreeFunc) f)) #ifdef __cplusplus } #endif #endif /* __GRACER_MEMORY_H__ */