diff --git a/C/text.c b/C/text.c index acc9d4e3f..dce99663f 100644 --- a/C/text.c +++ b/C/text.c @@ -370,7 +370,6 @@ unsigned char *Yap_readText(seq_tv_t *inp, size_t *lengp) { s = (char *)s0; else s = Malloc(0); - AUX_ERROR(inp->val.t, MaxTmp(PASS_REGS1), s, char); if (snprintf(s, MaxTmp(PASS_REGS1) - 1, Int_FORMAT, IntegerOfTerm(inp->val.t)) < 0) { AUX_ERROR(inp->val.t, 2 * MaxTmp(PASS_REGS1), s, char); diff --git a/C/write.c b/C/write.c index 9719142ca..04325ed0d 100644 --- a/C/write.c +++ b/C/write.c @@ -1275,7 +1275,8 @@ char *Yap_TermToString(Term t, size_t *lengthp, encoding_t enc, int flags) { CACHE_REGS int sno = Yap_open_buf_write_stream(enc, flags); const char *sf; - + DBTerm *e = LOCAL_BallTerm; + if (sno < 0) return NULL; LOCAL_c_output_stream = sno; @@ -1286,8 +1287,11 @@ char *Yap_TermToString(Term t, size_t *lengthp, encoding_t enc, int flags) { Yap_plwrite(t, GLOBAL_Stream + sno, 0, flags, GLOBAL_MaxPriority); sf = Yap_MemExportStreamPtr(sno); + size_t len = strlen(sf); + char *new = malloc( len + 1 ); + strcpy( new, sf ); Yap_CloseStream(sno); - if (Yap_HasException()) - return NULL; - return (char *)sf; + if (e) + LOCAL_BallTerm = e; + return new; } diff --git a/H/YapText.h b/H/YapText.h index 13d4145fb..7c8d2140f 100644 --- a/H/YapText.h +++ b/H/YapText.h @@ -806,6 +806,7 @@ static inline char *Yap_AtomToUTF8Text(Atom at, const char *s USES_REGS) { out.val.c0 = s; out.type |= YAP_STRING_WITH_BUFFER; } else { + out.type |= YAP_STRING_MALLOC; out.val.c = NULL; } if (!Yap_CVT_Text(&inp, &out PASS_REGS))