#1 2026-08-30 18:49:17

larand54
Member
Registered: 2018-12-25
Posts: 138

Assertion error in mormot.core.datetime

I get this error when I run the testprogram and even this short program gets the same error:

program SizeCheck;
{$APPTYPE CONSOLE}
uses
  Windows,
  mormot.core.os,
  mormot.core.datetime;
begin
  Writeln('SizeOf(TRWLightLock)  = ', SizeOf(TRWLightLock));
  Writeln('SizeOf(Windows.TSystemTime) = ', SizeOf(Windows.TSystemTime));
  Writeln('SizeOf(mormot.core.os.TSystemTime) = ', SizeOf(mormot.core.os.TSystemTime));
  Readln;
end.

Project SizeCheck.exe raised exception class EAssertionFailed with message 'Assertion failure (e:\devlib\mormot2\src\core\mormot.core.datetime.pas, line 4561)'.

Tested with both Delphi 12.2 and Delphi13.
The code that breakes is:

  assert(SizeOf(GlobalTime) = 128);

and sits in the initializeUnit procedure.
If I check what "SizeOf(GlobalTime)" reports I get: 120.

I also made a program that just took the declaration of "GlobalTime" from mormot.core.datetime and checked the size and I got 128.
Where are the size changed?

Last edited by larand54 (Yesterday 07:52:11)


Delphi-11, WIN10 and Win11

Offline

#2 2026-08-30 22:22:05

Prometeus
Member
Registered: 2020-11-20
Posts: 63

Re: Assertion error in mormot.core.datetime

It worked ok here, on Delphi 13.1, and the latest mORMot 2: 4, 16, 16 were the results

Last edited by Prometeus (2026-08-30 22:26:16)

Offline

#3 Yesterday 06:58:10

larand54
Member
Registered: 2018-12-25
Posts: 138

Re: Assertion error in mormot.core.datetime

I also tested a program that not use mormot which worked and produced the following result:

USERECORDWITHMETHODS is NOT defined
SizeOf(TRWLightLockTest) = 4  (förväntat: 4)
SizeOf(Windows.TSystemTime) = 16  (förväntat: 16)

The program looks like this:

program IsolatedSizeTest;
{$APPTYPE CONSOLE}
uses
  Windows;

type
  {$ifdef USERECORDWITHMETHODS}
  TRWLightLockTest = record
  {$else}
  TRWLightLockTest = object
  {$endif}
  private
    Flags: cardinal;
  public
    procedure Init;
  end;

procedure TRWLightLockTest.Init;
begin
  Flags := 0;
end;

begin
  {$ifdef USERECORDWITHMETHODS}
  Writeln('USERECORDWITHMETHODS is DEFINED');
  {$else}
  Writeln('USERECORDWITHMETHODS is NOT defined');
  {$endif}
  Writeln('SizeOf(TRWLightLockTest) = ', SizeOf(TRWLightLockTest), '  (förväntat: 4)');
  Writeln('SizeOf(Windows.TSystemTime) = ', SizeOf(Windows.TSystemTime), '  (förväntat: 16)');
  Readln;
end.

Last edited by larand54 (Yesterday 06:58:55)


Delphi-11, WIN10 and Win11

Offline

#4 Yesterday 09:21:39

flydev
Member
From: France
Registered: 2020-11-27
Posts: 196
Website

Re: Assertion error in mormot.core.datetime

on delphi 12.3 and win11, your first SizeCheck program returns and no exception triggered.

SizeOf(TRWLightLock)  = 4
SizeOf(Windows.TSystemTime) = 16
SizeOf(mormot.core.os.TSystemTime) = 16

Offline

#5 Yesterday 09:39:38

larand54
Member
Registered: 2018-12-25
Posts: 138

Re: Assertion error in mormot.core.datetime

I hardcoded a part of the "GlobalTime" declaration and the the error dissappear:

var
  // GlobalTime[LocalTime] thread-safe cache, each one taking one L1 cache line
  GlobalTime: array[boolean] of packed record
    safe: TRWLightLock;
    clock: cardinal;  // avoid slower API call with 16ms loss of precision
    time: TSystemTime;
//    _pad: array[1 .. 64 - SizeOf(TLightLock) - SizeOf(TSystemTime) - 4] of byte;
    _pad: array[1 .. 64 - 4 - 16 - 4] of Byte;
  end;

Delphi-11, WIN10 and Win11

Offline

#6 Yesterday 11:59:43

larand54
Member
Registered: 2018-12-25
Posts: 138

Re: Assertion error in mormot.core.datetime

Ooh! Now I see whats wrong or at least whats cause it is. GlobalTime has safe declared as TRWLightLock, wich size is 4, but the calculation of _pad size uses TLightLock wich size is 8.
Therefore the size of GlobalTime will be 120 and not 128 as the assertion use.
Whats wrong, TRWLightLock or TLightLock I don't know but at least it should be one of them . No matter which one you choose, just they are the same.

So... this should be a bug or ?


Delphi-11, WIN10 and Win11

Offline

#7 Yesterday 12:07:45

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,589
Website

Re: Assertion error in mormot.core.datetime

I don't understand. I guess I did fix it with https://github.com/synopse/mORMot2/commit/68c567e395f
Currently

  GlobalTime: array[boolean] of packed record
    safe: TRWLightLock;
    clock: cardinal;  // avoid slower API call with 16ms loss of precision
    time: TSystemTime;
    _pad: array[1 .. 64 - SizeOf(TRWLightLock) - SizeOf(TSystemTime) - 4] of byte;
  end;

seems correct to me?

Offline

#8 Yesterday 13:59:57

larand54
Member
Registered: 2018-12-25
Posts: 138

Re: Assertion error in mormot.core.datetime

Yes, you did. I pulled the latest some minutes later after my discovery and found that the correction was already done.
I try to run the mormot2Test program but I'm getting error again but I don't think it's mormot who cause it.
In mormot.net.ldap i Get this: [dcc64 Error] Project1.dpr(6): E2008 Incompatible types
at:

type
  /// define only one part of a Distinguished Name content e.g. for DNToCN()
  TNormalizeDN = set of (dnCN, dnOU, dnDC);
const
  /// define all parts of a Distinguished Name content
  DN_ALL = [low(TNormalizeDN) .. high(TNormalizeDN)];

I tested a short program and got the same error.

program LowHighSetTest;
{$APPTYPE CONSOLE}
type
  TTestSet = set of (aX, aY, aZ);
const
  ALL_TEST: TTestSet = [low(TTestSet) .. high(TTestSet)];
begin
  Writeln('Compiled OK, count = ', Ord(high(TTestSet)) - Ord(low(TTestSet)) + 1);
  Readln;
end.

Any idea?


Delphi-11, WIN10 and Win11

Offline

#9 Yesterday 14:56:27

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,589
Website

Re: Assertion error in mormot.core.datetime

Ah... FPC had no problem with this syntax.
Delphi can't understand it.

Please try with
https://github.com/synopse/mORMot2/commit/63b43ba0a

Offline

#10 Yesterday 16:33:36

larand54
Member
Registered: 2018-12-25
Posts: 138

Re: Assertion error in mormot.core.datetime

Worked with 64 bit but not with 32bit.

First chance exception at $7665A2B4. Exception class EHttpMultiPart with message 'THttpMultiPartDecoderStream.Read: malformed or truncated multipart content'. Process mormot2tests.exe (29744)

function THttpMultiPartDecoderStream.Read(var Buffer; Count: Longint): Longint;
begin
  result := fOwner.PartRead(Buffer, Count);
  if result > 0 then
  begin
    inc(fPosition, result);
    inc(fSize, result); // Size = content length seen so far
  end
  else if fOwner.fState = mpdsError then
    // never mistake a truncated section for a complete one
    EHttpMultiPart.RaiseUtf8(
      '%.Read: malformed or truncated multipart content', [self]);
end;

Not my day today sad


Delphi-11, WIN10 and Win11

Offline

#11 Yesterday 17:09:37

larand54
Member
Registered: 2018-12-25
Posts: 138

Re: Assertion error in mormot.core.datetime

Well the test run without error just that it stopped at all thrown exception. I must have some settings wrong or..?


Delphi-11, WIN10 and Win11

Offline

Board footer

Powered by FluxBB