/* * 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 */ #include #include #include "gr_memory.h" static GrSList *free_list; void gr_slist_free (GrSList *list) { GrSList *next; if (!list) return; next = free_list; free_list = list; while (list->next != NULL) { list = list->next; } list->next = next; } GrSList* gr_slist_prepend (GrSList *top, void *data) { GrSList *tmp; if (free_list) { tmp = free_list; free_list = free_list->next; } else { tmp = gr_new (GrSList, 1); } tmp->next = top; tmp->data = data; return tmp; } GrSList* gr_slist_append (GrSList *top, void *data) { GrSList *tmp, *bottom; if (free_list) { tmp = free_list; free_list = free_list->next; } else { tmp = gr_new (GrSList, 1); } tmp->data = data; tmp->next = NULL; if (!top) { return tmp; } else { bottom = top; while (bottom->next) { bottom = bottom->next; } bottom->next = tmp; return top; } } GrSList* gr_slist_remove (GrSList *list) { GrSList *tmp; if (!list) return NULL; tmp = list->next; list->next = free_list; free_list = list; return tmp; } void *__malloc0 (size_t size) { void *ptr = malloc (size); if (ptr) { memset (ptr, 0, size); } return ptr; } void gr_ref_incr (GrRef *ref) { ref->count ++; } void gr_ref_decr (GrRef *ref) { ref->count --; if (ref->count < 0) { if (ref->free_func) { (ref->free_func) (ref); } else { free (ref); } } }