2 * Window Maker miscelaneous function library
4 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
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.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <sys/types.h>
46 defaultHandler(int bla
)
49 kill(getpid(), SIGABRT
);
55 static waborthandler
*aborthandler
= (waborthandler
*)defaultHandler
;
57 #define wAbort(a) (*aborthandler)(a)
61 wsetabort(waborthandler
*handler
)
63 waborthandler
*old
= aborthandler
;
65 aborthandler
= handler
;
72 static int Aborting
=0; /* if we're in the middle of an emergency exit */
75 static WMHashTable
*table
= NULL
;
86 tmp
= GC_malloc(size
);
91 wwarning("malloc() failed. Retrying after 2s.");
94 tmp
= GC_malloc(size
);
100 fputs("Really Bad Error: recursive malloc() failure.", stderr
);
103 wfatal("virtual memory exhausted");
114 wmalloc0(size_t size
)
116 void *ptr
= wmalloc(size
);
120 memset(ptr
, 0, size
);
127 wrealloc(void *ptr
, size_t newsize
)
132 nptr
= wmalloc(newsize
);
133 } else if (newsize
==0) {
138 nptr
= GC_realloc(ptr
, newsize
);
140 nptr
= realloc(ptr
, newsize
);
143 wwarning("realloc() failed. Retrying after 2s.");
146 nptr
= GC_realloc(ptr
, newsize
);
148 nptr
= realloc(ptr
, newsize
);
152 fputs("Really Bad Error: recursive realloc() failure.",
156 wfatal("virtual memory exhausted");
173 table
= WMCreateHashTable(WMIntHashCallbacks
);
176 refcount
= WMHashGet(table
, ptr
);
178 refcount
= wmalloc(sizeof(int));
180 WMHashInsert(table
, ptr
, refcount
);
182 printf("== %i (%p)\n", *refcount
, ptr
);
187 printf("+ %i (%p)\n", *refcount
, ptr
);
213 refcount
= WMHashGet(table
, ptr
);
215 wwarning("trying to release unexisting data %p", ptr
);
220 printf("RELEASING %p\n", ptr
);
222 WMHashRemove(table
, ptr
);
228 printf("- %i (%p)\n", *refcount
, ptr
);