#1 2026-10-17 19:01:10

idigger
Member
Registered: 2022-11-05
Posts: 37

There is a problem with the variant in the latest version of Mormot2

The code is as follows

program test;
{$mode delphi}{$H+}
{$I mormot.defines.inc}
uses
  {$I mormot.uses.inc}
  Windows,
  mormot.core.base,
  mormot.core.variants;
var
  s: UTF8String;
  V: Variant;
begin
  s := '{"code":200,"msg":"ok"}';
  V := _Json(RawUtf8(s));
  WriteLn(V.code, V.msg);
end.

After compiling with the following command, the program crashed when running. (mormot2.lpk has been rebuilt.)

# c:\fpcbuild\fpc\bin\i386-win32\fpc -FiD:\Borland\mORMot2\src -FuD:\Borland\mORMot2\packages\lazarus\lib\i386-win32 test.lpr
Free Pascal Compiler version 3.3.1 [2026/10/16] for i386
Copyright (c) 1993-2026 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling test.lpr
Linking test.exe
1352 lines compiled, 0.2 sec, 570096 bytes code, 22244 bytes data

# test
An unhandled exception occurred at $0042E7CC:
EVariantTypeCastError: Could not convert variant of type (Null) into type (AnsiString)
  $0042E7CC
  $00427F1B
  $0042C703
  $0040CE6D

However, after compiling with the following command, the program ran correctly.

# c:\fpcbuild\fpc\bin\i386-win32\fpc -FiD:\Borland\mORMot2\src -FuD:\Borland\mORMot2\src\core test.lpr
Free Pascal Compiler version 3.3.1 [2026/10/16] for i386
Copyright (c) 1993-2026 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling test.lpr
Linking test.exe
1354 lines compiled, 0.2 sec, 661616 bytes code, 22244 bytes data

# test
200ok

The versions of FPC and Lazarus are as follows:
Lazarus 5.99 (rev main_5_99-117-g2130d7edc2) FPC 3.3.1 [2026/10/16] i386-win32-win32/win64

I remember that the programs compiled from previous versions of FPC did not have the aforementioned problems.

This issue caused my project to fail at runtime after being compiled with a newer version of FPC/Lazarus.

Last edited by idigger (2026-10-17 19:15:57)

Offline

#2 2026-10-17 21:03:49

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

Re: There is a problem with the variant in the latest version of Mormot2

It is not clear if it is a mormot issue or a fpc issue....

Offline

#3 2026-10-18 05:32:23

idigger
Member
Registered: 2022-11-05
Posts: 37

Re: There is a problem with the variant in the latest version of Mormot2

ab wrote:

It is not clear if it is a mormot issue or a fpc issue....

Confirmed that  it is a mORMot issue.

After repeatedly switching between different mormot versions for testing, it was ultimately determined that the issue was caused by commit 835079437d00d5d03e95464221b28df96d9b2dd6(* core: optimized TSynInvokeableVariantType.DispInvoke() 2026-07-06 15:58:25).

Last edited by idigger (2026-10-18 14:52:52)

Offline

#4 2026-10-19 02:48:09

lfyey121
Member
From: china
Registered: 2022-08-25
Posts: 92

Re: There is a problem with the variant in the latest version of Mormot2

mormot2.lpk compiler options level need change to -O1

Offline

#5 2026-10-19 11:57:27

idigger
Member
Registered: 2022-11-05
Posts: 37

Re: There is a problem with the variant in the latest version of Mormot2

Compiling `mormot2.lpk` with `-O1` does indeed help. However, versions prior to commit `835079437d00d5d03e95464221b28df96d9b2dd6` could be compiled using the default `-O3` setting without any runtime errors; therefore, the issue is likely introduced by commit `83507943`.

Offline

Board footer

Powered by FluxBB