Workaround of GC crash on Cygwin64

Patch from <http://www.j10n.org/files/w3m-cvs-1.1055-win64gc.patch>,
[w3m-dev:04469] on 2013-10-14.
This commit is contained in:
AIDA Shinra
2013-10-14 22:31:01 +09:00
committed by Tatsuya Kinoshita
parent dbd52ac2ca
commit ec81194f38
13 changed files with 447 additions and 181 deletions

105
indep.c
View File

@@ -707,6 +707,111 @@ shell_quote(char *str)
return str;
}
void *
xrealloc(void *ptr, size_t size)
{
void *newptr = realloc(ptr, size);
if (newptr == NULL) {
fprintf(stderr, "Out of memory\n");
exit(-1);
}
return newptr;
}
/* Define this as a separate function in case the free() has
* an incompatible prototype. */
void
xfree(void *ptr)
{
free(ptr);
}
void *
w3m_GC_realloc_atomic(void *ptr, size_t size)
{
return ptr ? GC_REALLOC(ptr, size) : GC_MALLOC_ATOMIC(size);
}
void
w3m_GC_free(void *ptr)
{
GC_FREE(ptr);
}
void
growbuf_init(struct growbuf *gb)
{
gb->ptr = NULL;
gb->length = 0;
gb->area_size = 0;
gb->realloc_proc = &w3m_GC_realloc_atomic;
gb->free_proc = &w3m_GC_free;
}
void
growbuf_init_without_GC(struct growbuf *gb)
{
gb->ptr = NULL;
gb->length = 0;
gb->area_size = 0;
gb->realloc_proc = &xrealloc;
gb->free_proc = &xfree;
}
void
growbuf_clear(struct growbuf *gb)
{
(*gb->free_proc) (gb->ptr);
gb->ptr = NULL;
gb->length = 0;
gb->area_size = 0;
}
Str
growbuf_to_Str(struct growbuf *gb)
{
Str s;
if (gb->free_proc == &w3m_GC_free) {
growbuf_reserve(gb, gb->length + 1);
gb->ptr[gb->length] = '\0';
s = New(struct _Str);
s->ptr = gb->ptr;
s->length = gb->length;
s->area_size = gb->area_size;
} else {
s = Strnew_charp_n(gb->ptr, gb->length);
(*gb->free_proc) (gb->ptr);
}
gb->ptr = NULL;
gb->length = 0;
gb->area_size = 0;
return s;
}
void
growbuf_reserve(struct growbuf *gb, int leastarea)
{
int newarea;
if (gb->area_size < leastarea) {
newarea = gb->area_size * 3 / 2;
if (newarea < leastarea)
newarea = leastarea;
newarea += 16;
gb->ptr = (*gb->realloc_proc) (gb->ptr, newarea);
gb->area_size = newarea;
}
}
void
growbuf_append(struct growbuf *gb, const char *src, int len)
{
growbuf_reserve(gb, gb->length + len);
memcpy(&gb->ptr[gb->length], src, len);
gb->length += len;
}
static char *
w3m_dir(const char *name, char *dft)
{