2 * Window Maker miscelaneous function library
4 * Copyright (c) 1997 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.
22 #include "../src/config.h"
27 #include <sys/types.h>
47 defaultHandler(int bla
)
50 kill(getpid(), SIGABRT
);
56 static waborthandler
*aborthandler
= (waborthandler
*)defaultHandler
;
58 #define wAbort(a) (*aborthandler)(a)
62 wsetabort(waborthandler
*handler
)
64 waborthandler
*old
= aborthandler
;
66 aborthandler
= handler
;
73 static int Aborting
=0; /* if we're in the middle of an emergency exit */
76 static WMHashTable
*table
= NULL
;
79 void *wmalloc(size_t size
)
84 tmp
= GC_malloc(size
);
89 wwarning("malloc() failed. Retrying after 2s.");
92 tmp
= GC_malloc(size
);
98 fputs("Really Bad Error: recursive malloc() failure.", stderr
);
101 wfatal("virtual memory exhausted");
111 void *wrealloc(void *ptr
, size_t newsize
)
116 nptr
= wmalloc(newsize
);
119 nptr
= GC_realloc(ptr
, newsize
);
121 nptr
= realloc(ptr
, newsize
);
124 wwarning("realloc() failed. Retrying after 2s.");
127 nptr
= GC_realloc(ptr
, newsize
);
129 nptr
= realloc(ptr
, newsize
);
133 fputs("Really Bad Error: recursive realloc() failure.",
137 wfatal("virtual memory exhausted");
154 table
= WMCreateHashTable(WMIntHashCallbacks
);
157 refcount
= WMHashGet(table
, ptr
);
159 refcount
= wmalloc(sizeof(int));
161 WMHashInsert(table
, ptr
, refcount
);
163 printf("== %i (%p)\n", *refcount
, ptr
);
168 printf("+ %i (%p)\n", *refcount
, ptr
);
194 refcount
= WMHashGet(table
, ptr
);
196 wwarning("trying to release unexisting data %p", ptr
);
201 printf("RELEASING %p\n", ptr
);
203 WMHashRemove(table
, ptr
);
209 printf("- %i (%p)\n", *refcount
, ptr
);
221 return strcpy(wmalloc(strlen(str
)+1), str
);
226 wstrappend(char *dst
, char *src
)
235 str
= wmalloc(strlen(dst
)+strlen(src
)+1);