#1 2022-06-05 01:02:19

scamp
Member
Registered: 2022-06-05
Posts: 3

Problematic Types in mormot.core.base

I recently started using mormot.core.base in a bigger project of mine.

There are a couple of types declared in mormot.core.base which are problematic:

  unaligned = Double;

unaligned is a special Typecast in Freepascal that is used to give the compiler a hint for unaligned memory accesses. This is important because ARMv7 and older will issue a system trap if memory is access without that modifier, making your code extermely slow. Sadly FPC does not give it's internal Typecast preference if mormot.core.base is used, so any code that uses the "real" unaligned typecast no longer compiles. You should rename this to remove this clash.
https://www.freepascal.org/docs-html/ref/refse86.html

TByteArray / PByteArray and TWordArray / PWordArray are already declared in SysUtils. If you project has a unit that uses SysUtils and another that uses mormot.core.base, your code will not compile as the compiler sees the clashing type definitions as incompatible types. As mormot.core.base uses sysutils anyway, these duplicate declarations should be removed.

Cheers,

scamp

Offline

#2 2022-06-05 06:11:11

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Problematic Types in mormot.core.base

Please check the lines before and after:

  {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  /// unaligned() will be defined and useful only on FPC ARM/Aarch64 plaforms
  unaligned = Double;
  {$endif FPC_REQUIRES_PROPER_ALIGNMENT}

So this unaligned is defined only when alignment is not required. So for ARMv7, FPC_REQUIRES_PROPER_ALIGNMENT is defined, and regular unaligned() is compiled.

About TByteArray / PByteArray and TWordArray / PWordArray, the idea is to define mormot.core.base after sysutils in the uses clause.
And if you really need to access the sysutils version, then explicitly write sysutils.TByteArray. And to be honnest, they are very rarely used in normal code, because they are just pointers to an unrealistic huge array.

Offline

Board footer

Powered by FluxBB