1. Phix - bytes_to_int
- Posted by lesterb Jul 13, 2018
- 1222 views
Hi Pete,
I was trying to resurrect some stuff I wrote for Eu3 in 2012 and came across this anomaly. I made this little test program to demonstrate (the actual code is much larger).
--/* include machine.e --*/ integer test_out sequence test_in test_in = {22} test_out = bytes_to_int(test_in & repeat(0,4)) print(1, test_out) -- vim: ft=phix:
bytes_to_int behaves differently in Eu3 and Phix.
I note the doc description is also slightly different.
I also admit that my failing code is at best 'lazy' in extending the test_in sequence by at least 4 bytes.
In this case, the input to bytes_to_int is actually 5 bytes {22,0,0,0,0}.
The last (unnecessary) byte is ignored by Eu3 but causes an exception in Phix as follows...
--Result with Eu3.1 22 --Result with Phix (warning: lineno of -1 for era of #0060CF5F) fatal exception #80000003 at #0060CF5F Global & Local Variables
Changing the input to {22,0,0,0} makes it work in both.
I had a quick look at the code for bytes_to_int and it doesn't look like it should fail.
I don't know whether this can be classed as a bug or just a difference - I found it by writing sloppy code.
I shall go and fall on my coding pencil now.
Les
2. Re: Phix - bytes_to_int
- Posted by petelomax Jul 13, 2018
- 1204 views
The last (unnecessary) byte is ignored by Eu3 but causes an exception in Phix as follows...
--Result with Eu3.1 22 --Result with Phix (warning: lineno of -1 for era of #0060CF5F) fatal exception #80000003 at #0060CF5F
Thanks, the next release will instead issue
C:\Program Files (x86)\Phix\builtins\machine.e:213 in function bytes_to_int() peek size must be 1|2|4|8
and the manual (for bytes_to_int) has been clarified slightly:
This routine can be used for byte/word/dword/qword conversion, and is just a simple wrapper for peekNS(). An error occurs if s contains any non-atom elements, or the length is not one of 1, 2, 4, or 8 (unlike OpenEuphoria, which pads/trims it to length 4).
Pete