Hello, folks!
A snapshot of my current GPC source is now available via anonymous ftp on agnes.dida.physik.uni-essen.de, directory gnu-pascal/alpha. It is a diff against gpc-2.0.
Changes:
* Some cosmetical changes not worth to talk about. ;-)
* Patched the runtime library to allow conio operations and access to device files on the MSDOS platform.
* Fixed wrong --pedantic warning for `rewrite'.
* New command-line option `-dY' to dump the source to stderr. This is useful when trying to figure out *where* gpc crashed ...
* Fixed a really crazy bug concerning objects. (See below.)
* Handle assignment between sets of different sizes correctly. Beware: When assigning a large set to a smaller one, it is truncated without warning or runtime check. And there might still be errors in this part of the compiler.
The story about the "crazy" object-related bug follows. It's hard to believe, but it's true - just check it with gpc-2.0!
Program Test;
Type TestObj = object FooBar: array [ 0..27 ] of Char; end (* TestObj *);
Procedure Init ( x: Integer );
begin (* Init *) x:= 7; end (* Init *);
begin Init ( 3 ); end.
This program compiles, but it crashes at runtime. )-:
Change `FooBar' to be an `array [ 0..28 ]' of Char, and it works. Note that the object is just a type declaration and everything which is really executed has nothing to do with it.
I tried different upper bounds for `FooBar' from 0 to 100. The crash happens with 23..27.
The solution: There was an error with variable initializers.
:-)-:-(-:-)-:-(-:-)-:-(-:-)-:-(-:-)-:-(-:-)-:-(-:-)-:-(-:-)-:-(-:
To understand this, one must know about the internal structure of objects in contrast to that of records. While records have just their fields, objects have an additional invisible "vmt" field which contains a pointer to the "Virtual Method Table". This table contains (a) the size of the object and (b) the addresses of all virtual methods. `TestObj' above does not have virtual methods, but it has a size - which is 32 bytes if the upper bound of `FooBar' is 23..27 - thus it needs a VMT. This VMT is an initialized variable, and the initial value of 32 for the size of the object triggered the error. Voila!
It's fixed now.
As a side-effect, initializers for other structured variables are more stable now, too:
Var foo: record i: Integer; x: Real; end (* foo *) value ( 1; 3.1415 );
bar: array [ 1..3 ] of Char value ( 'b', 'a', r' );
Okay, so let's go on!
Good night, |-)
Peter
Dipl.-Phys. Peter Gerwinski, Essen, Germany, free physicist and programmer peter.gerwinski@uni-essen.de - http://home.pages.de/~peter.gerwinski/ [970201] maintainer GNU Pascal - http://home.pages.de/~gnu-pascal/ [970125]