fix unicode regexp-range problems, merge root-managing code for gc2 collectors
svn: r2254
This commit is contained in:
parent
4b75389bb2
commit
dc45ce794e
|
@ -488,79 +488,7 @@ void GC_register_traversers(Type_Tag tag, Size_Proc size, Mark_Proc mark, Fixup_
|
|||
/* root table */
|
||||
/******************************************************************************/
|
||||
|
||||
#define PTR_ALIGNMENT 4
|
||||
#define PTR_TO_INT(x) ((unsigned long)x)
|
||||
#define INT_TO_PTR(x) ((void *)x)
|
||||
|
||||
static long roots_count;
|
||||
static long roots_size;
|
||||
static unsigned long *roots;
|
||||
static int nothing_new = 0;
|
||||
|
||||
static int compare_roots(const void *a, const void *b)
|
||||
{
|
||||
if (*(unsigned long *)a < *(unsigned long *)b)
|
||||
return -1;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void sort_and_merge_roots()
|
||||
{
|
||||
int i, offset, top;
|
||||
|
||||
if (nothing_new)
|
||||
return;
|
||||
|
||||
if (roots_count < 4)
|
||||
return;
|
||||
|
||||
my_qsort(roots, roots_count >> 1, 2 * sizeof(unsigned long), compare_roots);
|
||||
offset = 0;
|
||||
top = roots_count;
|
||||
for (i = 2; i < top; i += 2) {
|
||||
if ((roots[i - 2 - offset] <= roots[i])
|
||||
&& ((roots[i - 1 - offset] + (PTR_ALIGNMENT - 1)) >= roots[i])) {
|
||||
/* merge: */
|
||||
if (roots[i + 1] > roots[i - 1 - offset])
|
||||
roots[i - 1 - offset] = roots[i + 1];
|
||||
offset += 2;
|
||||
roots_count -= 2;
|
||||
} else if (roots[i] == roots[i + 1]) {
|
||||
/* Remove empty range: */
|
||||
offset += 2;
|
||||
roots_count -= 2;
|
||||
} else if (offset) {
|
||||
/* compact: */
|
||||
roots[i - offset] = roots[i];
|
||||
roots[i + 1 - offset] = roots[i + 1];
|
||||
}
|
||||
}
|
||||
|
||||
nothing_new = 1;
|
||||
}
|
||||
|
||||
void GC_add_roots(void *start, void *end)
|
||||
{
|
||||
if (roots_count >= roots_size) {
|
||||
unsigned long *naya;
|
||||
|
||||
roots_size = roots_size ? 2 * roots_size : 500;
|
||||
naya = (unsigned long *)malloc(sizeof(unsigned long) * (roots_size + 1));
|
||||
|
||||
memcpy((void *)naya, (void *)roots,
|
||||
sizeof(unsigned long) * roots_count);
|
||||
|
||||
if (roots)
|
||||
free(roots);
|
||||
|
||||
roots = naya;
|
||||
}
|
||||
|
||||
roots[roots_count++] = PTR_TO_INT(start);
|
||||
roots[roots_count++] = PTR_TO_INT(end) - PTR_ALIGNMENT;
|
||||
nothing_new = 0;
|
||||
}
|
||||
#include "roots.inc"
|
||||
|
||||
void GC_register_thread(void *p, void *c)
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
#if defined(sun) || defined(__sun) || defined(__sun__)
|
||||
/* Sun's qsort() is broken. */
|
||||
/* Long ago, I became convinced that Sun's qsort() was broken.
|
||||
Probably it isn't any more, but I'm still more comfortable
|
||||
avoiding it. */
|
||||
|
||||
#define MAXSTACK 100
|
||||
|
||||
|
|
|
@ -726,70 +726,9 @@ void GC_fixup_variable_stack(void **var_stack, long delta, void *limit)
|
|||
|
||||
/*****************************************************************************/
|
||||
/* Routines for root sets */
|
||||
/* */
|
||||
/* This code is lifted in its entirety from compact.c */
|
||||
/*****************************************************************************/
|
||||
|
||||
static unsigned long roots_count = 0;
|
||||
static unsigned long roots_size = 0;
|
||||
static unsigned long *roots = NULL;;
|
||||
static int nothing_new = 0;
|
||||
|
||||
static int compare_roots(const void *a, const void *b)
|
||||
{
|
||||
if(*(unsigned long*)a < *(unsigned long*)b)
|
||||
return -1;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void sort_and_merge_roots()
|
||||
{
|
||||
int i, offset, top;
|
||||
|
||||
if(nothing_new || (roots_count < 4))
|
||||
return;
|
||||
|
||||
my_qsort(roots, roots_count >> 1, 2 * sizeof(unsigned long), compare_roots);
|
||||
offset = 0; top = roots_count;
|
||||
for(i = 2; i < top; i += 2) {
|
||||
if((roots[i - 2 - offset] <= roots[i])
|
||||
&& ((roots[i - 1 - offset] + (WORD_SIZE - 1)) >= roots[i])) {
|
||||
/* merge: */
|
||||
if(roots[i + 1] > roots[i - 1 - offset])
|
||||
roots[i - 1 - offset] = roots[i + 1];
|
||||
offset += 2; roots_count -= 2;
|
||||
} else if(roots[i] == roots[i + 1]) {
|
||||
/* Remove empty range: */
|
||||
offset += 2;
|
||||
roots_count -= 2;
|
||||
} else if(offset) {
|
||||
/* compact: */
|
||||
roots[i - offset] = roots[i];
|
||||
roots[i + 1 - offset] = roots[i + 1];
|
||||
}
|
||||
}
|
||||
nothing_new = 1;
|
||||
}
|
||||
|
||||
void GC_add_roots(void *start, void *end)
|
||||
{
|
||||
if(roots_count >= roots_size) {
|
||||
unsigned long *naya;
|
||||
|
||||
roots_size = roots_size ? 2 * roots_size : 500;
|
||||
naya = (unsigned long*)malloc(sizeof(unsigned long) * (roots_size + 1));
|
||||
if(!naya) GCERR((GCOUTF, "Couldn't allocate space for root pointers!\n"));
|
||||
memcpy((void*)naya, (void*)roots, sizeof(unsigned long) * roots_count);
|
||||
|
||||
if(roots) free(roots);
|
||||
roots = naya;
|
||||
}
|
||||
|
||||
roots[roots_count++] = (unsigned long)start;
|
||||
roots[roots_count++] = (unsigned long)end - WORD_SIZE;
|
||||
nothing_new = 0;
|
||||
}
|
||||
#include "roots.inc"
|
||||
|
||||
#define traverse_roots(gcMUCK) { \
|
||||
unsigned long j; \
|
||||
|
|
73
src/mzscheme/gc2/roots.inc
Normal file
73
src/mzscheme/gc2/roots.inc
Normal file
|
@ -0,0 +1,73 @@
|
|||
|
||||
#define ROOTS_PTR_ALIGNMENT WORD_SIZE
|
||||
#define ROOTS_PTR_TO_INT(x) ((unsigned long)x)
|
||||
|
||||
static long roots_count;
|
||||
static long roots_size;
|
||||
static unsigned long *roots;
|
||||
static int nothing_new = 0;
|
||||
|
||||
static int compare_roots(const void *a, const void *b)
|
||||
{
|
||||
if (*(unsigned long *)a < *(unsigned long *)b)
|
||||
return -1;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void sort_and_merge_roots()
|
||||
{
|
||||
int i, offset, top;
|
||||
|
||||
if (nothing_new)
|
||||
return;
|
||||
|
||||
if (roots_count < 4)
|
||||
return;
|
||||
|
||||
my_qsort(roots, roots_count >> 1, 2 * sizeof(unsigned long), compare_roots);
|
||||
offset = 0;
|
||||
top = roots_count;
|
||||
for (i = 2; i < top; i += 2) {
|
||||
if ((roots[i - 2 - offset] <= roots[i])
|
||||
&& ((roots[i - 1 - offset] + (ROOTS_PTR_ALIGNMENT - 1)) >= roots[i])) {
|
||||
/* merge: */
|
||||
if (roots[i + 1] > roots[i - 1 - offset])
|
||||
roots[i - 1 - offset] = roots[i + 1];
|
||||
offset += 2;
|
||||
roots_count -= 2;
|
||||
} else if (roots[i] == roots[i + 1]) {
|
||||
/* Remove empty range: */
|
||||
offset += 2;
|
||||
roots_count -= 2;
|
||||
} else if (offset) {
|
||||
/* compact: */
|
||||
roots[i - offset] = roots[i];
|
||||
roots[i + 1 - offset] = roots[i + 1];
|
||||
}
|
||||
}
|
||||
|
||||
nothing_new = 1;
|
||||
}
|
||||
|
||||
void GC_add_roots(void *start, void *end)
|
||||
{
|
||||
if (roots_count >= roots_size) {
|
||||
unsigned long *naya;
|
||||
|
||||
roots_size = roots_size ? 2 * roots_size : 500;
|
||||
naya = (unsigned long *)malloc(sizeof(unsigned long) * (roots_size + 1));
|
||||
|
||||
memcpy((void *)naya, (void *)roots,
|
||||
sizeof(unsigned long) * roots_count);
|
||||
|
||||
if (roots)
|
||||
free(roots);
|
||||
|
||||
roots = naya;
|
||||
}
|
||||
|
||||
roots[roots_count++] = ROOTS_PTR_TO_INT(start);
|
||||
roots[roots_count++] = ROOTS_PTR_TO_INT(end) - ROOTS_PTR_ALIGNMENT;
|
||||
nothing_new = 0;
|
||||
}
|
|
@ -1930,7 +1930,12 @@ END_XFORM_SKIP;
|
|||
|
||||
static int compare_ranges(const void *a, const void *b)
|
||||
{
|
||||
if (*(unsigned int *)a < *(unsigned int *)b)
|
||||
unsigned long av, bv;
|
||||
av = *(unsigned long *)a;
|
||||
bv = *(unsigned long *)b;
|
||||
if (av == bv)
|
||||
return 0;
|
||||
else if (av < bv)
|
||||
return -1;
|
||||
else
|
||||
return 1;
|
||||
|
@ -2212,7 +2217,8 @@ static int translate(unsigned char *s, int len, char **result)
|
|||
/* Need to translate. */
|
||||
char *simple_on;
|
||||
Scheme_Object *ranges;
|
||||
unsigned int *us, *range_array;
|
||||
unsigned int *us;
|
||||
unsigned long *range_array;
|
||||
int ulen, on_count, range_len, rp, p;
|
||||
|
||||
ulen = scheme_utf8_decode(s, rs.i + 1, k, NULL, 0, -1, NULL, 0, 0);
|
||||
|
@ -2278,14 +2284,15 @@ static int translate(unsigned char *s, int len, char **result)
|
|||
|
||||
/* Turn the ranges list into an array */
|
||||
range_len = scheme_list_length(ranges);
|
||||
range_array = (unsigned int *)scheme_malloc_atomic(2 * range_len * sizeof(unsigned int));
|
||||
for (rp = 0; SCHEME_PAIRP(ranges); ranges = SCHEME_CDR(ranges), rp++) {
|
||||
long hi, lo;
|
||||
range_array = (unsigned long *)scheme_malloc_atomic(2 * range_len * sizeof(unsigned long));
|
||||
for (rp = 0; SCHEME_PAIRP(ranges); ranges = SCHEME_CDR(ranges), rp += 2) {
|
||||
unsigned long hi, lo;
|
||||
scheme_get_unsigned_int_val(SCHEME_CAAR(ranges), &lo);
|
||||
scheme_get_unsigned_int_val(SCHEME_CDR(SCHEME_CAR(ranges)), &hi);
|
||||
range_array[rp] = lo;
|
||||
range_array[rp+1] = hi;
|
||||
}
|
||||
range_len *= 2;
|
||||
/* Sort the ranges by the starting index. */
|
||||
my_qsort(range_array, range_len >> 1, 2 * sizeof(unsigned long), compare_ranges);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user