more text allocation
This commit is contained in:
parent
afd24bb8db
commit
73f05f2ed2
@ -1355,7 +1355,9 @@ X_API void YAP_FreeSpaceFromYap(void *ptr) { Yap_FreeCodeSpace(ptr); }
|
||||
*/ X_API char *
|
||||
YAP_StringToBuffer(Term t, char *buf, unsigned int bufsize) {
|
||||
CACHE_REGS
|
||||
seq_tv_t inp, out;
|
||||
BACKUP_MACHINE_REGS();
|
||||
seq_tv_t inp, out;
|
||||
int l = push_text_stack();
|
||||
inp.val.t = t;
|
||||
inp.type = YAP_STRING_ATOMS_CODES | YAP_STRING_STRING | YAP_STRING_ATOM |
|
||||
YAP_STRING_TRUNC | YAP_STRING_MALLOC;
|
||||
@ -1363,9 +1365,18 @@ YAP_StringToBuffer(Term t, char *buf, unsigned int bufsize) {
|
||||
out.type = YAP_STRING_CHARS;
|
||||
out.val.c = buf;
|
||||
out.enc = ENC_ISO_UTF8;
|
||||
if (!Yap_CVT_Text(&inp, &out PASS_REGS))
|
||||
return NULL;
|
||||
return out.val.c;
|
||||
if (!Yap_CVT_Text(&inp, &out PASS_REGS)) {
|
||||
pop_text_stack(l);
|
||||
RECOVER_MACHINE_REGS();
|
||||
return NULL;
|
||||
} else {
|
||||
RECOVER_MACHINE_REGS();
|
||||
if (buf == out.val.c) {
|
||||
return buf;
|
||||
} else {
|
||||
return pop_output_text_stack(l, out.val.c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* copy a string to a buffer */
|
||||
@ -2220,17 +2231,26 @@ X_API char *YAP_WriteBuffer(Term t, char *buf, size_t sze, int flags) {
|
||||
seq_tv_t inp, out;
|
||||
|
||||
BACKUP_MACHINE_REGS();
|
||||
int l = push_text_stack();
|
||||
inp.val.t = t;
|
||||
inp.type = YAP_STRING_TERM|YAP_STRING_DATUM;
|
||||
out.type = YAP_STRING_CHARS;
|
||||
out.val.c = buf;
|
||||
out.max = sze - 1;
|
||||
out.enc = LOCAL_encoding;
|
||||
if (!Yap_CVT_Text(&inp, &out PASS_REGS))
|
||||
return NULL;
|
||||
if (!Yap_CVT_Text(&inp, &out PASS_REGS)) {
|
||||
RECOVER_MACHINE_REGS();
|
||||
return out.val.c;
|
||||
}
|
||||
pop_text_stack(l);
|
||||
return NULL;
|
||||
} else {
|
||||
RECOVER_MACHINE_REGS();
|
||||
if (buf == out.val.c) {
|
||||
return buf;
|
||||
} else {
|
||||
return pop_output_text_stack(l, out.val.c);
|
||||
}
|
||||
}}
|
||||
|
||||
|
||||
/// write a a term to n user-provided buffer: make sure not tp
|
||||
/// overflow the buffer even if the text is much larger.
|
||||
|
4
C/text.c
4
C/text.c
@ -84,7 +84,7 @@ void *pop_output_text_stack__(int i, void *export) {
|
||||
while (p) {
|
||||
struct mblock *np = p->next;
|
||||
if (p + 1 == export) {
|
||||
size_t sz = p->sz;
|
||||
size_t sz = p->sz-sizeof(struct mblock) ;
|
||||
memcpy(p, p + 1, sz);
|
||||
export = p;
|
||||
} else {
|
||||
@ -641,7 +641,7 @@ void *write_buffer(unsigned char *s0, seq_tv_t *out USES_REGS) {
|
||||
size_t leng = strlen((char *)s0);
|
||||
size_t min = 0, max = leng;
|
||||
if (out->enc == ENC_ISO_UTF8) {
|
||||
if (true || out->val.uc == NULL) { // this should always be the case
|
||||
if ( out->val.uc == NULL) { // this should always be the case
|
||||
out->val.uc = BaseMalloc(leng + 1);
|
||||
strcpy(out->val.c, (char *)s0);
|
||||
} else if (out->val.uc != s0) {
|
||||
|
Reference in New Issue
Block a user