Merge branch 'master' of git://yap.git.sourceforge.net/gitroot/yap/yap-6.3

This commit is contained in:
Ricardo Rocha 2011-06-21 15:21:46 +01:00
commit 0929dc4fc0
7 changed files with 62 additions and 44 deletions

View File

@ -284,6 +284,7 @@ Yap_MkBlobStringTerm(const char *s, size_t len)
MP_INT *dst = (MP_INT *)(H+2);
blob_string_t *sp;
size_t siz;
char *dest;
sz = strlen(s);
if (len > 0 && sz > len) sz = len;
@ -292,17 +293,16 @@ Yap_MkBlobStringTerm(const char *s, size_t len)
}
H[0] = (CELL)FunctorBigInt;
H[1] = BLOB_STRING;
siz = (sizeof(size_t)+len+sizeof(CELL))/sizeof(CELL);
siz = ALIGN_YAPTYPE((len+1+sizeof(blob_string_t)),CELL);
dst->_mp_size = 0L;
dst->_mp_alloc = siz;
dst->_mp_alloc = siz/sizeof(mp_limb_t);
sp = (blob_string_t *)(dst+1);
H = (CELL *)sp;
sp->len = sz;
strncpy((char *)(sp+1), s, sz+1);
H += siz;
H[0] = EndSpecials;
H++;
dest = (char *)(sp+1);
strncpy(dest, s, sz);
dest[sz] = '\0';
H += (siz + 2*sizeof(CELL)+sizeof(MP_INT)+sizeof(Functor))/sizeof(CELL);
H[-1] = EndSpecials;
return AbsAppl(ret);
}
@ -313,56 +313,49 @@ Yap_MkBlobWideStringTerm(const wchar_t *s, size_t len)
CELL *ret = H;
size_t sz;
MP_INT *dst = (MP_INT *)(H+2);
blob_string_t *sp;
blob_string_t *sp = (blob_string_t *)(dst+1);
size_t siz, i = 0;
H[0] = (CELL)FunctorBigInt;
dst->_mp_size = 0L;
sz = wcslen(s);
if (len > 0 && sz > len) sz = len;
if (len > 0 && sz > len) {
sz = len;
}
if ((len/sizeof(CELL)) > (ASP-ret)-1024) {
return TermNil;
}
while (i < sz) {
if (s[i++] >= 255) break;
}
if (i == sz) {
/* we have a standard ascii string */
char *target;
size_t i = 0;
if (len/sizeof(CELL) > (ASP-ret)-1024) {
return TermNil;
}
H[0] = (CELL)FunctorBigInt;
H[1] = BLOB_STRING;
siz = (sizeof(size_t)+len+sizeof(CELL))/sizeof(CELL);
dst->_mp_size = 0L;
dst->_mp_alloc = siz;
sp = (blob_string_t *)(dst+1);
H = (CELL *)sp;
siz = ALIGN_YAPTYPE((sz+1+sizeof(blob_string_t)),CELL);
dst->_mp_alloc = siz/sizeof(mp_limb_t);
sp->len = sz;
target = (char *)(sp+1);
while (i < sz+1) {
for (i = 0 ; i < sz; i++) {
target[i] = s[i];
i++;
}
H += siz;
H[0] = EndSpecials;
H++;
return AbsAppl(ret);
}
if (len/sizeof(CELL) > (ASP-ret)-1024) {
return TermNil;
}
H[0] = (CELL)FunctorBigInt;
H[1] = BLOB_WIDE_STRING;
target[sz] = '\0';
H += (siz+2*sizeof(CELL)+sizeof(MP_INT)+sizeof(Functor))/sizeof(CELL);
} else {
wchar_t * target;
siz = (sizeof(size_t)+(len+2)*sizeof(wchar_t))/sizeof(CELL);
dst->_mp_size = 0L;
dst->_mp_alloc = siz;
sp = (blob_string_t *)(dst+1);
H = (CELL *)sp;
sp->len = sz;
wcsncpy((wchar_t *)(sp+1), s, sz+1);
H += siz;
H[0] = EndSpecials;
H++;
H[1] = BLOB_WIDE_STRING;
siz = ALIGN_YAPTYPE((sz+1)*sizeof(wchar_t)+sizeof(blob_string_t),CELL);
dst->_mp_alloc = siz/sizeof(mp_limb_t);
sp->len = sz;
target = (wchar_t *)(sp+1);
wcsncpy(target, s, sz);
target[sz] = '\0';
H += (siz + 2*sizeof(CELL)+sizeof(MP_INT)+sizeof(Functor))/sizeof(CELL);
}
H[-1] = EndSpecials;
return AbsAppl(ret);
}

View File

@ -691,7 +691,7 @@ c_arg(Int argno, Term t, unsigned int arity, unsigned int level, compiler_struct
CELL l1 = ++cglobs->labelno;
CELL *src = RepAppl(t);
PInstr *ocpc = cglobs->cint.cpc, *OCodeStart = cglobs->cint.CodeStart;
Int sz = 2*sizeof(CELL)+
Int sz = 2*sizeof(CELL)+sizeof(Functor)+
sizeof(MP_INT)+
((((MP_INT *)(RepAppl(t)+2))->_mp_alloc)*sizeof(mp_limb_t));
CELL *dest;

View File

@ -1323,6 +1323,11 @@ mark_variable(CELL_PTR current USES_REGS)
LOCAL_total_marked += 2+sz;
PUSH_POINTER(next PASS_REGS);
sz++;
#if DEBUG
if (next[sz] != EndSpecials) {
fprintf(stderr,"[ Error: could not find EndSpecials at blob %p type %lx ]\n", next, next[1]);
}
#endif
MARK(next+sz);
PUSH_POINTER(next+sz PASS_REGS);
}

View File

@ -633,6 +633,8 @@ static Int
} else {
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable, LOCAL_Comments);
if (store_comments && !Yap_unify(LOCAL_Comments, ARG7))
return FALSE;
return Yap_unify_constant(ARG2, MkAtomTerm (AtomEof))
&& Yap_unify_constant(ARG4, TermNil);
}

View File

@ -813,6 +813,7 @@ close_comment( USES_REGS1 ) {
LOCAL_CommentsBuff[LOCAL_CommentsBuffPos] = '\0';
*LOCAL_CommentsNextChar = Yap_MkBlobWideStringTerm(LOCAL_CommentsBuff, LOCAL_CommentsBuffPos);
free(LOCAL_CommentsBuff);
LOCAL_CommentsBuff = NULL;
LOCAL_CommentsBuffLim = 0;
}
@ -1372,5 +1373,8 @@ Yap_clean_tokenizer(TokEntry *tokstart, VarEntry *vartable, VarEntry *anonvartab
}
LOCAL_Comments = TermNil;
LOCAL_CommentsNextChar = LOCAL_CommentsTail = NULL;
free(LOCAL_CommentsBuff);
LOCAL_CommentsBuff = NULL;
LOCAL_CommentsBuffLim = 0;
}

View File

@ -210,6 +210,20 @@ writebig(Term t, int p, int depth, int rinfixarg, struct write_globs *wglb, stru
return;
}
#endif
if (pt[0] == BLOB_STRING) {
wrputc('"',wglb->writewch);
wrputs(Yap_BlobStringOfTerm(t),wglb->writewch);
wrputc('"',wglb->writewch);
return;
} else if (pt[0] == BLOB_STRING) {
wchar_t *s = Yap_BlobWideStringOfTerm(t);
wrputc('"', wglb->writewch);
while (*s) {
wrputc(*s++, wglb->writewch);
}
wrputc('"',wglb->writewch);
return;
}
wrputs("0",wglb->writewch);
}

View File

@ -397,7 +397,7 @@ IsLargeIntTerm (Term t)
#endif
typedef struct string_struct {
size_t len;
UInt len;
} blob_string_t;
Term STD_PROTO (Yap_MkBlobStringTerm, (const char *, size_t len));