[fpc-devel] Gaps in a non-contiguous enum
I was able to fix issue https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/39832 about TEnumPropertyEditor in Lazarus IdeIntf. Explanation: function GetEnumName() in FPC's rtl/objpas/typinfo.pp returns the enum's unit name for one gap in a non-contiguous enum, and an empty string for the other gaps. IMO returning the unit name can be considered a bug in FPC code. Fortunately TPropertyEditor has a method GetPropTypeUnitName(), made by Mattias I guess, which I could use to filter out the unit name. An enum element cannot have the same name as the unit which makes this a robust solution. This is the fixed property editor method: procedure TEnumPropertyEditor.GetValues(Proc: TGetStrProc); var I: Integer; EnumType: PTypeInfo; s, EnumUnitName: String; begin EnumType := GetPropType; EnumUnitName := GetPropTypeUnitName; with GetTypeData(EnumType)^ do for I := MinValue to MaxValue do begin s := GetEnumName(EnumType, I); // An empty string and the enum's unit name happen in gaps // of a non-contiguous enum. Why the unit name? A bug in FPC code? if (s <> '') and (s <> EnumUnitName) then Proc(s); end; end; Property editors deal with RTTI. I started to think about how such enum elements are iterated in a normal user code which doesn't need RTTI. I came up with this, using the Fruit example enum from the bug report: program enumconsole; type //TFruit = (fApple, fOrange, fBanana, fGrapes, fPear); TFruitMore = (fmApple=0, fmOrange=2, fmBanana=4, fmGrapes, fmPear); const CFruitMoreSet = [fmApple, fmOrange, fmBanana, fmGrapes, fmPear]; var e: TFruitMore; begin for e := Low(TFruitMore) to High(TFruitMore) do if e in CFruitMoreSet then WriteLn(Ord(e), ': ', e); end. It seems there is no easy way, or at least I didn't find any. The code requires a constant set with all enum elements included. Feels like a hack. Leaving out the test "if e in CFruitMoreSet then" leads to a run time error. If there is a better way to iterate, please tell me. Regards, Juha ___ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Re: [fpc-devel] Gaps in a non-contiguous enum
On 11/08/2022 13:38, Juha Manninen via fpc-devel wrote: // An empty string and the enum's unit name happen in gaps // of a non-contiguous enum. Why the unit name? A bug in FPC code? with GetTypeData(EnumType)^ do for I := MinValue to MaxValue do begin s := GetEnumName(EnumType, I); Because you are not supposed to use MaxValue Instead use GetEnumNameCount for I := MinValue to MinValue + GetEnumNameCount(...) - 1 do begin The unit name is returned because the TypeDate stores the unitname after the continuous list of element names. And once you are out of index ... ___ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Re: [fpc-devel] Cross-compiling Linux x86_64 -> Win32
09.08.2022 03:49, Maxim Ganetsky via fpc-devel пишет: Hello. I am trying to set up cross-compilation from Linux x86_64 to Win32 and have the following problems: Case 1. Using FPC 3.2.0. I installed the following: fpc-3.2.0-x86_64-linux.tar fpc-3.2.0.i386-linux.tar fpc-3.2.0-i386-win32.cross.x86_64-linux.tar Installation process finished successfully without warnings. Case 2. Using FPC 3.2.2. I don't see i386-win32.cross.x86_64-linux for FPC 3.2.2. What is the recommended way to cross-compile with it? Forget it, omitting installing fpc-3.2.0.i386-linux.tar and building cross-compiler from source fixed the issue. -- Best regards, Maxim Ganetsky mailto:gan...@narod.ru ___ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Re: [fpc-devel] Gaps in a non-contiguous enum
On 11/08/2022 18:11, Juha Manninen via fpc-devel wrote: The MaxValue is used in many places for enum and set properties while GetEnumNameCount() is not used anywhere. There are other similar bugs. At least these 2 in propedits.pp look fishy: - procedure TSetPropertyEditor.GetProperties CompType of a set is an enum, so yes => GetEnumNameCount - subfunction IsPropInSet under function IsInteresting seems the same OK, it was not a bug in FPC code. Sorry. fpc code is still "unexpected". It takes into account the MinValue type TMyEnum = (a=5, b=7); GetEnumName(pt, 5) // a GetEnumName(pt, 6) // b // should be 7 if it is just the nth name, then it should start at 0 (or if needs be at 1).___ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Re: [fpc-devel] Gaps in a non-contiguous enum
On Thu, Aug 11, 2022 at 4:44 PM Martin Frb via fpc-devel < fpc-devel@lists.freepascal.org> wrote: > Because you are not supposed to use MaxValue > Instead use GetEnumNameCount > > for I := MinValue to MinValue + GetEnumNameCount(...) - 1 do begin > > The unit name is returned because the TypeDate stores the unitname after > the continuous list of element names. And once you are out of index ... Damn, you are right. I fixed it better. The MaxValue is used in many places for enum and set properties while GetEnumNameCount() is not used anywhere. There are other similar bugs. At least these 2 in propedits.pp look fishy: - procedure TSetPropertyEditor.GetProperties - subfunction IsPropInSet under function IsInteresting OK, it was not a bug in FPC code. Sorry. Regards, Juha ___ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel