From 284ac492173f86eb7789c3e922b9bdab299317ee Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Fri, 2 Sep 2011 23:22:35 +0100 Subject: [PATCH] fix wide atom writing. --- packages/PLStream/pl-write.c | 15 +++++---------- packages/PLStream/pl-yap.h | 10 +++++++++- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/packages/PLStream/pl-write.c b/packages/PLStream/pl-write.c index 6042c8f87..230663ffb 100644 --- a/packages/PLStream/pl-write.c +++ b/packages/PLStream/pl-write.c @@ -567,6 +567,11 @@ writeAtom(atom_t a, write_options *options) return (*atomBlobType(atom)->write)(options->out, a, options->flags); if ( false(atomBlobType(atom), PL_BLOB_TEXT) ) return writeBlob(a, options); +#if __YAP_PROLOG__ + if (isWideAtom(atom)) { + return writeUCSAtom(options->out, a, options->flags); + } +#endif if ( true(options, PL_WRT_QUOTED) ) { switch( atomType(a, options->out) ) @@ -574,11 +579,6 @@ writeAtom(atom_t a, write_options *options) case AT_SYMBOL: case AT_SOLO: case AT_SPECIAL: -#if __YAP_PROLOG__ - if (isWideAtom(atom)) { - return PutWideToken(nameOfWideAtom(atom), options->out); - } -#endif return PutToken(nameOfAtom(atom), options->out); case AT_QUOTE: case AT_FULLSTOP: @@ -594,11 +594,6 @@ writeAtom(atom_t a, write_options *options) } } } else { -#if __YAP_PROLOG__ - if (isWideAtom(atom)) { - return PutWideTokenN(nameOfWideAtom(atom), atomLength(atom), options->out); - } -#endif return PutTokenN(nameOfAtom(atom), atomLength(atom), options->out); } } diff --git a/packages/PLStream/pl-yap.h b/packages/PLStream/pl-yap.h index 55f648967..f49693148 100644 --- a/packages/PLStream/pl-yap.h +++ b/packages/PLStream/pl-yap.h @@ -129,7 +129,15 @@ void PL_license(const char *license, const char *module); #define atomFromTerm(term) YAP_SWIAtomFromAtom(YAP_AtomOfTerm(term)) #define atomName(atom) ((char *)YAP_AtomName(atom)) #define nameOfAtom(atom) ((char *)YAP_AtomName(atom)) -#define atomLength(atom) YAP_AtomNameLength(atom) + +inline static size_t +atomLength(Atom atom) +{ + if (YAP_IsWideAtom(atom)) + return wcslen(atom->WStrOfAE)*sizeof(wchar_t); + return(strlen(atom->StrOfAE)); +} + #define atomBlobType(at) YAP_find_blob_type(at) #define argTermP(w,i) ((Word)((YAP_ArgsOfTerm(w)+(i)))) #define deRef(t) while (IsVarTerm(*(t)) && !IsUnboundVar(t)) { t = (CELL *)(*(t)); }