fix Bstring + fix current in gc_copy: string

This commit is contained in:
danyaberezun 2018-12-06 22:53:04 +03:00
parent b23e870890
commit 459fcfb1ab

View file

@ -159,7 +159,8 @@ extern void* Belem (void *p, int i) {
extern void* Bstring (void *p) { extern void* Bstring (void *p) {
int n = strlen (p); int n = strlen (p);
data *r = (data*) alloc (n + 1 + sizeof (int)); data *r = NULL;
r = (data*) alloc (n + 1 + sizeof (int));
r->tag = STRING_TAG | (n << 3); r->tag = STRING_TAG | (n << 3);
strncpy (r->contents, p, n + 1); strncpy (r->contents, p, n + 1);
@ -569,17 +570,21 @@ extern size_t * gc_copy (size_t *obj) {
d->tag = (int) copy; d->tag = (int) copy;
copy_elements (copy, obj, LEN(d->tag)); copy_elements (copy, obj, LEN(d->tag));
break; break;
case STRING_TAG: case STRING_TAG:
#ifdef DEBUG_PRINT #ifdef DEBUG_PRINT
printf ("gc_copy:string_tag \n"); printf ("gc_copy:string_tag; len = %d\n", LEN(d->tag) + 1);
current += (LEN(d->tag) + 1) * sizeof (int); fflush(stdout);
#endif #endif
// current += (LEN(d->tag) + 1) * sizeof (int);
current += LEN(d->tag) * sizeof(char) + sizeof (int);
*copy = d->tag; *copy = d->tag;
copy++; copy++;
d->tag = (int) copy; d->tag = (int) copy;
strcpy (&copy[1], (char*) obj); strcpy (&copy[1], (char*) obj);
break; break;
case SEXP_TAG :
case SEXP_TAG :
s = TO_SEXP(obj); s = TO_SEXP(obj);
#ifdef DEBUG_PRINT #ifdef DEBUG_PRINT
objj = s; objj = s;
@ -598,6 +603,7 @@ extern size_t * gc_copy (size_t *obj) {
d->tag = (int) copy; d->tag = (int) copy;
copy_elements (copy, obj, i); copy_elements (copy, obj, i);
break; break;
default: default:
#ifdef DEBUG_PRINT #ifdef DEBUG_PRINT
printf ("ERROR: gc_copy: weird tag: %x", TAG(d->tag)); printf ("ERROR: gc_copy: weird tag: %x", TAG(d->tag));
@ -607,7 +613,7 @@ extern size_t * gc_copy (size_t *obj) {
exit(5); exit(5);
} }
#ifdef DEBUG_PRINT #ifdef DEBUG_PRINT
printf("gc_copy: %x (%x) -> %x (%x)\n", obj, objj, copy, newobjj); printf("gc_copy: %x (%x) -> %x (%x); new-current = %x\n", obj, objj, copy, newobjj, current);
fflush(stdout); fflush(stdout);
#endif #endif
return copy; return copy;