Hello, Is it possible to make the set datatype to occupy only one byte? Now by default the compiler allocates 4 bytes.We even tried packing it,but it's still the same. Have a Great Day! Kind Regards, Karthic and Hari
P.S: As specified in one of your mails in the mailing list for a similar problem, we even tried builiding the compiler by changing the P/rts/sets.pas(Tsetelement = byte) and also in P/util.c(set_word_size and set_alignment = 8).Still we are unsuccessful.
Hello, Is it possible to make the set datatype to occupy only one byte? Now by default the compiler allocates 4 bytes.We even tried packing it,but it's still the same.
After reading this message, I tried to experiment with set types a little bit. It turned out that the compiler segfaults on "set of Void" (this is a nonsense type, but anyway...)
[pas]% gpc -v ; uname -a Reading specs from /usr/local/lib/gcc-lib/i586-pc-linux-gnu/2.95.2/specs gpc version 20020308, based on 2.95.2 19991024 (release) Linux localhost.localdomain 2.4.2-2 #1 Sun Apr 8 19:37:14 EDT 2001 i586 unknown [pas]% cat voidset.pas program VoidSet (Output);
type T = set of Void; (* WRONG *)
begin WriteLn ('failed') end. [pas]% gpc voidset.pas voidset.pas:4: ordinal type expected gpc: Internal compiler error: program gpc1 got fatal signal 11 (Segmentation fault) [pas]% gdb /usr/local/lib/gcc-lib/i586-pc-linux-gnu/2.95.2/gpc1 core GNU gdb 5.0rh-5 Red Hat Linux 7.1 Copyright 2001 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-redhat-linux"... Core was generated by `/usr/local/lib/gcc-lib/i586-pc-linux-gnu/2.95.2/gpc1 /tmp/ccSEiSIV.i -quiet -du'. Program terminated with signal 11, Segmentation fault. Reading symbols from /lib/libc.so.6...done. Loaded symbols for /lib/libc.so.6 Reading symbols from /lib/ld-linux.so.2...done. Loaded symbols for /lib/ld-linux.so.2 #0 0x0816d399 in layout_type (type=0x8274028) at ../../../gcc-2.95.2/gcc/p/../stor-layout.c:1053 1053 ../../../gcc-2.95.2/gcc/p/../stor-layout.c: No such file or directory. in ../../../gcc-2.95.2/gcc/p/../stor-layout.c (gdb) bt #0 0x0816d399 in layout_type (type=0x8274028) at ../../../gcc-2.95.2/gcc/p/../stor-layout.c:1053 #1 0x081b2159 in build_set_type (members=0x8274014) at ../../../gcc-2.95.2/gcc/p/types.c:579 #2 0x081a358f in yyparse () at parse.y:2043 #3 0x0816fae1 in compile_file (name=0xbffffb84 "/tmp/ccSEiSIV.i") at ../../../gcc-2.95.2/gcc/p/../toplev.c:3265 #4 0x08172dca in main (argc=8, argv=0xbffffa1c) at ../../../gcc-2.95.2/gcc/p/../toplev.c:5440 #5 0x40041e5e in __libc_start_main (main=0x8171e14 <main>, argc=8, ubp_av=0xbffffa1c, init=0x80490f8 <_init>, fini=0x81ba7a0 <_fini>, rtld_fini=0x4000d3c4 <_dl_fini>, stack_end=0xbffffa0c) at ../sysdeps/generic/libc-start.c:129
GPC accepts "array of Void" (and even static variables of that type; should it?), but it crashes on "packed array of Void". More importantly, it crashes the same way on the following ISO 7185 code:
[pas]% cat recordend1.pas program Foo (Output);
type T = packed array [1 .. 42] of record end;
begin WriteLn ('OK') end. [pas]% gpc recordend1.pas recordend1.pas:4: Internal compiler error in `float_signal', at toplev.c:2418 Please submit a full bug report. See URL:http://www.gnu.org/software/gcc/faq.html#bugreport for instructions.
A similar file-type generates a run-time error:
[pas]% cat recordend2.pas program Foo (Output);
type EmptyType = record end;
var F: file of EmptyType;
begin rewrite (F); { F^ := EmptyType[]; } put (F); reset (F); get (F); writeln ('OK') end. [pas]% gpc recordend2.pas [pas]% ./a.out ./a.out: internal error: `InitFDR' has not been called for file (error #913 at 8049c05)
Emil Jerabek
Emil Jerabek wrote:
After reading this message, I tried to experiment with set types a little bit. It turned out that the compiler segfaults on "set of Void" (this is a nonsense type, but anyway...)
GPC accepts "array of Void" (and even static variables of that type; should it?), but it crashes on "packed array of Void". More importantly, it crashes the same way on the following ISO 7185 code:
[...]
A similar file-type generates a run-time error:
Thanks for the reports. All fixed now (emil{12,13[a-c],14,15}.pas).
Frank
Emil Jerabek wrote:
After reading this message, I tried to experiment with set types a little bit. It turned out that the compiler segfaults on "set of Void" (this is a nonsense type, but anyway...)
GPC accepts "array of Void" (and even static variables of that type; should it?), but it crashes on "packed array of Void". More importantly, it crashes the same way on the following ISO 7185 code:
[...]
A similar file-type generates a run-time error:
Thanks for the reports. All fixed now (emil{12,13[a-c],14,15}.pas).
Frank
Sorry, should think twice before submitting a bugreport. The story with "file of record end" is more complicated then I wrote.
The test below should pass for any type (which is permissible as a file component-type, of course). It indeed works with, say, "file of Integer", but with the empty record type it fails:
[pas]% gpc -v Reading specs from /usr/local/lib/gcc-lib/i586-pc-linux-gnu/2.95.2/specs gpc version 20020318, based on 2.95.2 19991024 (release) [pas]% gpc recordend3.pas [pas]% ./a.out failed 1: (end) ... EOF = False zsh: floating point exception (core dumped) ./a.out
Apparently, the RTS doesn't track the length and current position of file variables, and tries to compute them from the byte-size of the file when needed. This is wrong for "file of record end" and similar beasts, because
(i) it makes EOF always return False (in Inspection mode, at least)
(ii) most direct access functions raise a "division by zero" signal
Here's the code of recordend3.pas:
----------- program FileTest (Output); {$macros}
const MaxLen = 100; Len = 42; TestPos = 13;
type EmptyType = record end;
var F: file of EmptyType; G: file [1 .. MaxLen] of EmptyType; I: Integer; OK: Boolean value True;
{$define Fail(Pass, Pos, Func, Result) begin WriteLn ('failed ', Pass, ': ', Pos : 5, ' ... ', Func, ' = ', Result); OK := False end }
begin Rewrite (F); for I := 1 to Len do begin if not EOF (F) then Fail (0, I, 'EOF', False); Put (F) end;
Reset (F); for I := 1 to Len do begin if EOF (F) then Fail (1, I, 'EOF', True); Get (F) end; if not EOF (F) then Fail (1, '(end)', 'EOF', False);
Rewrite (G); for I := 1 to Len do begin if not EOF (G) then Fail (2, I, 'EOF', False); if Position (G) <> I then Fail (2, I, 'Position', Position (G)); Put (G); if LastPosition (G) <> I then Fail (2, I, 'LastPosition', LastPosition (G)) end;
Reset (G); for I := 1 to Len do begin if EOF (G) then Fail (3, I, 'EOF', True); if Position (G) <> I then Fail (3, I, 'Position', Position (G)); Get (G) end; if not EOF (G) then Fail (3, '(end)', 'EOF', False);
if Empty (G) then Fail (3, '(end)', 'Empty', True);
SeekUpdate (G, TestPos); Update (G); if EOF (G) then Fail (4, TestPos, 'EOF', True); if Position (G) <> TestPos then Fail (4, TestPos, 'Position', Position (G)); if LastPosition (G) <> Len then Fail (4, TestPos, 'LastPosition', LastPosition (G));
if OK then WriteLn ('OK') end. ----------------------
Emil Jerabek
Emil Jerabek wrote:
Sorry, should think twice before submitting a bugreport. The story with "file of record end" is more complicated then I wrote.
The test below should pass for any type (which is permissible as a file component-type, of course). It indeed works with, say, "file of Integer", but with the empty record type it fails:
[pas]% gpc -v Reading specs from /usr/local/lib/gcc-lib/i586-pc-linux-gnu/2.95.2/specs gpc version 20020318, based on 2.95.2 19991024 (release) [pas]% gpc recordend3.pas [pas]% ./a.out failed 1: (end) ... EOF = False zsh: floating point exception (core dumped) ./a.out
Apparently, the RTS doesn't track the length and current position of file variables, and tries to compute them from the byte-size of the file when needed. This is wrong for "file of record end" and similar beasts, because
(i) it makes EOF always return False (in Inspection mode, at least)
(ii) most direct access functions raise a "division by zero" signal
That's true. Since you agreed that this is "completely pointless" in practice, and it's not trivial to fix, I'll assign it a rather low priority (emil16.pas).
However, maybe it would make the code somewhat cleaner in general to track the current position, so I'll think about it.
Though one question remains: What *should* the size of a file of emptyrec actually be? If the external file is empty, it's undefined (0/0), otherwise it's infinite (n/0, n>0). Has the standard got anything to say about it? Otherwise, what would be most reasonable? Perhaps MaxInt?
(All other Pascal compilers I have handy, i.e. BP and an older version of FPC, choke on it as well, so there doesn't seem to be any precedence.)
Frank
Frank wrote:
Emil Jerabek wrote:
Sorry, should think twice before submitting a bugreport. The story with "file of record end" is more complicated then I wrote.
The test below should pass for any type (which is permissible as a file component-type, of course). It indeed works with, say, "file of Integer", but with the empty record type it fails:
[pas]% gpc -v Reading specs from /usr/local/lib/gcc-lib/i586-pc-linux-gnu/2.95.2/specs gpc version 20020318, based on 2.95.2 19991024 (release) [pas]% gpc recordend3.pas [pas]% ./a.out failed 1: (end) ... EOF = False zsh: floating point exception (core dumped) ./a.out
Apparently, the RTS doesn't track the length and current position of file variables, and tries to compute them from the byte-size of the file when needed. This is wrong for "file of record end" and similar beasts, because
(i) it makes EOF always return False (in Inspection mode, at least)
(ii) most direct access functions raise a "division by zero" signal
That's true. Since you agreed that this is "completely pointless" in practice, and it's not trivial to fix, I'll assign it a rather low priority (emil16.pas).
However, maybe it would make the code somewhat cleaner in general to track the current position, so I'll think about it.
Though one question remains: What *should* the size of a file of emptyrec actually be? If the external file is empty, it's undefined (0/0), otherwise it's infinite (n/0, n>0). Has the standard got anything to say about it? Otherwise, what would be most reasonable? Perhaps MaxInt?
Short answer: the standard doesn't say anything about the correspondence between external objects and their internal representation.
The semantics of _internal_ files is simple: the size is initially undefined, `rewrite' makes it 0, and each `put' (performed at the end of the file) increments it by 1.
Basic behavior of _external_ files is the same, except that any property of the file (incl size) may be set to whatever value the compiler likes after a successful `bind', and any operation on a bound file may lead to an error or to some action on the external entity to which it is bound (again, the compiler is free to choose any action it wants).
Hence, from the standpoint of the standard, it doesn't matter which size is assigned to files of emptyrec, provided it is consistent with the behavior of other operations on the file (i.e., if the size is 0, the file should behave as empty; if it is 234, it should be possible to do 234 `read's from the file, after which `eof' should be true, etc).
Also, the RTS could simply refuse to `bind' such files, this would bypass the size question entirely.
Maybe the most simple solution is to pad each emptyrec in a file by 8 bits :-)
Emil
(All other Pascal compilers I have handy, i.e. BP and an older version of FPC, choke on it as well, so there doesn't seem to be any precedence.)
Frank
-- Frank Heckenbach, frank@g-n-u.de, http://fjf.gnu.de/, 7977168E GPC To-Do list, latest features, fixed bugs: http://agnes.dida.physik.uni-essen.de/~gnu-pascal/todo.html
Emil Jerabek wrote:
Though one question remains: What *should* the size of a file of emptyrec actually be? If the external file is empty, it's undefined (0/0), otherwise it's infinite (n/0, n>0). Has the standard got anything to say about it? Otherwise, what would be most reasonable? Perhaps MaxInt?
Short answer: the standard doesn't say anything about the correspondence between external objects and their internal representation.
Oh yeah, right. ;-)
The semantics of _internal_ files is simple: the size is initially undefined, `rewrite' makes it 0, and each `put' (performed at the end of the file) increments it by 1.
Basic behavior of _external_ files is the same, except that any property of the file (incl size) may be set to whatever value the compiler likes after a successful `bind', and any operation on a bound file may lead to an error or to some action on the external entity to which it is bound (again, the compiler is free to choose any action it wants).
Hence, from the standpoint of the standard, it doesn't matter which size is assigned to files of emptyrec, provided it is consistent with the behavior of other operations on the file (i.e., if the size is 0, the file should behave as empty; if it is 234, it should be possible to do 234 `read's from the file, after which `eof' should be true, etc).
Also, the RTS could simply refuse to `bind' such files, this would bypass the size question entirely.
For external files. For internal ones, we'd still have to keep track of the size.
Maybe the most simple solution is to pad each emptyrec in a file by 8 bits :-)
Good idea! I prefer this, especially because it's very easy to do. :-)
So this problem is fixed now (emil16.pas).
Frank