Rob and Makarius,
First, thanks Rob for providing the patch. I've pushed the fix. I think the reason it works is that it was printing a full 32 or 64-bit value when the value was negative but the scan that was reading it back in again was expecting only a single byte.


What is actually happening is an attempt to see whether a byte cell is a string or something else, such as an arbitrary precision number. There is no precise way of distinguishing the two and for almost all purposes it doesn't matter. The only reason the code here is trying to distinguish them is that strings have a length word that is in host byte order. If the exporting and importing machines have the same endianness the byte cell could just be exported and imported as byte data but it's possible that the interpreted version could be exported on a little-endian machine and run on a big-endian machine. This is such a rare situation that I would not want to reserve a bit in the header of a cell to get it completely correct. It just needs to be good enough to get the compiler running so it can compile in the basis library.

The comment was misleading so I've removed it.

Regards,
David

On 20/09/2016 16:53, Rob Arthan wrote:
Makarius,

On 20 Sep 2016, at 16:42, Makarius <makar...@sketis.net> wrote:

On 20/09/16 16:50, Rob Arthan wrote:

I think this patch fixes it:

diff --git a/libpolyml/pexport.cpp b/libpolyml/pexport.cpp
index b03b1da..a9ebd2e 100644
--- a/libpolyml/pexport.cpp
+++ b/libpolyml/pexport.cpp
@@ -158,7 +158,7 @@ void PExport::printObject(PolyObject *p)
            for (unsigned i = 0; i < ps->length; i++)
            {
                char ch = ps->chars[i];
-                fprintf(exportFile, "%02x", ch);
+                fprintf(exportFile, "%02x", ch & 0xff);
            }
        }
        else

It seems to work, but it is unclear to me why.

A few lines before there is the following text:

       /* See if the first word is a possible length.  The length
          cannot be one because single character strings are
          represented by the character. */
       /* This is not infallible but it seems to be good enough
          to detect the strings. */
       POLYUNSIGNED bytes = length * sizeof(PolyWord);
       if (length >= 2 && ...)

It looks like it requires further update.


I think length is the length of the PolyObject representing the string
while ps->length is the length of the string and will have been 1 in
the call that caused the problem. I suspect the comments
and possibly the test on length are redundant.

Regards,

Rob.
_______________________________________________
polyml mailing list
polyml@inf.ed.ac.uk
http://lists.inf.ed.ac.uk/mailman/listinfo/polyml

_______________________________________________
polyml mailing list
polyml@inf.ed.ac.uk
http://lists.inf.ed.ac.uk/mailman/listinfo/polyml

Reply via email to