From 9cfe6e97a0688bd6321e4a42603e0a6ed0cb3815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Van=20Canneyt?= Date: Thu, 5 Jan 2023 10:10:10 +0100 Subject: [PATCH] * add uachar loading for unicode rtl --- compiler/pmodules.pas | 26 ++++++++++++++++++++++---- rtl/inc/uachar.pp | 28 ++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 rtl/inc/uachar.pp diff --git a/compiler/pmodules.pas b/compiler/pmodules.pas index bbd394de32..e5f58a82dc 100644 --- a/compiler/pmodules.pas +++ b/compiler/pmodules.pas @@ -36,7 +36,7 @@ implementation globtype,systems,tokens, cutils,cfileutl,cclasses,comphook, globals,verbose,fmodule,finput,fppu,globstat,fpcp,fpkg, - symconst,symbase,symtype,symdef,symsym,symtable,symcreat, + symconst,symbase,symtype,symdef,symsym,symtable,defutil,symcreat, wpoinfo, aasmtai,aasmdata,aasmbase,aasmcpu, cgbase,ngenutil, @@ -316,6 +316,12 @@ implementation prevent crashes when accessing .owner } generrorsym.owner:=systemunit; generrordef.owner:=systemunit; + // Implicitly enable unicode strings in unicode RTL in modes objfpc/delphi. + { TODO: Check if we should also do this for mode macpas } + if not (cs_compilesystem in current_settings.moduleswitches) then + if ([m_objfpc,m_delphi] * current_settings.modeswitches)<>[] then + if is_systemunit_unicode then + Include(current_settings.modeswitches,m_default_unicodestring) end; @@ -382,9 +388,21 @@ implementation if m_blocks in current_settings.modeswitches then AddUnit('blockrtl'); - { default char=widechar? } - if m_default_unicodestring in current_settings.modeswitches then - AddUnit('uuchar'); + { Determine char size. } + + // Ansi RTL ? + if not is_systemunit_unicode then + begin + if m_default_unicodestring in current_settings.modeswitches then + AddUnit('uuchar'); // redefines char as widechar + end + else + begin + // Unicode RTL + if not (m_default_ansistring in current_settings.modeswitches) then + if not (current_module.modulename^<>'UACHAR') then + AddUnit('uachar'); // redefines char as ansichar + end; { Objective-C support unit? } if (m_objectivec1 in current_settings.modeswitches) then diff --git a/rtl/inc/uachar.pp b/rtl/inc/uachar.pp new file mode 100644 index 0000000000..8446dfe551 --- /dev/null +++ b/rtl/inc/uachar.pp @@ -0,0 +1,28 @@ +{ + This file is part of the Free Pascal Run time library. + Copyright (c) 2011 by the Free Pascal development team + + This unit redefines the Char type from widechar into ansichar + + See the file COPYING.FPC, included in this distribution, + For details about the copyright. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + **********************************************************************} + +unit uachar; + +{$h-} + +interface + + type + Char = AnsiChar; + PChar = PAnsiChar; + +implementation + +end.