Forum > Beginners
Crash in Assign()
Thaddy:
Well it must be related to the string literal if fpc_ansistr_to_widechararray () is called. The literal itself should be an array type of ansichar, which is not a PChar..
I suggest you explicitly declare it as PAnsiChar. What does gettypekind return? Assign() on its own does very little until rewrite or reset is called. It merely assigns, but not use, a file name 'test' to be used later.
Find out what the string literal type is and change the code explicitly using either PAnsiChar or PWideChar. You may also have a look at if the calling convention is correct:
the code probably stems from 32 bit era. What happens if you remove the cdecl? I can test AARCH64, but not Apple hardware.
And where is the export modifier?
Steve Baxter:
Thanks for the comments.
1. This is on Mac, so no console or anything should be needed
2. It's not possible for the client to call the wrong architecture (and it still crashes with a single architecture)
3. The PChar isn't involved - I'm calling Assign() with a literal
@Thaddy - what is the export modifier? This is code we have inherited, nobody on our team knows much at all about Pascal!
This is such an obvious crash that there must be something else going on. Is there some initialisation that needs to happen?
Thaddy:
Assign() to a file does basically nothing until rewrite or reset is called. It just associates the handle with a recognizable file name.
From your code it seems, like Benny suspects too, that the string literal 'test' causes your issue. And that string literal should resolve to array of ansichar. Which is not a PChar. Pay attention to the string details when porting to a unicode 64 bit system.
Steve Baxter:
So I think this is an initialisation problem. It looks like `widestringmanager` isn't initialised, this is used in `fpc_ansistr_to_widechararray()`:
https://github.com/fpc/FPCSource/blob/main/rtl/inc/ustrings.inc#L828
It looks like this is supposed to be initialised automatically here:
https://github.com/fpc/FPCSource/blob/b1f0c504cc58d9441af5dd81229d54c84e74b162/rtl/objpas/fpwidestring.pp#L889
Possibly as this is a static library the runtime isn't getting initialised automatically. Does anyone know how to make that work?
PascalDragon:
--- Quote from: Steve Baxter on July 09, 2024, 08:32:29 pm ---Possibly as this is a static library the runtime isn't getting initialised automatically. Does anyone know how to make that work?
--- End quote ---
That is correct. FPC code is not designed to be usable as a static library. If you want to go this route you need to make sure that you call FPC_INITIALIZEUNITS (it's exported with that uppercase symbol name from the System unit (and thus its object file)).
Navigation
[0] Message Index
[#] Next page
[*] Previous page