Forum > General

Multiple floating point traps when using external DLL

(1/3) > >>

y.ivanov:
I'm trying to "merge" an existing MSVC project with Lazarus by converting it to a DLL and then calling some of its entry points from the Lazarus App. Everything is OK until some FP operation used (in this case the _ftol2_pentium4() ) and the exception  0xC00002B5: Multiple floating point traps raises.

I've searched in GitLab issues, found a couple of issues with FP and DLLs:
https://gitlab.com/freepascal.org/fpc/source/-/issues/16801
https://gitlab.com/freepascal.org/fpc/source/-/issues/16263, but those are >10yrs old.

Is there some recipe how to accomplish such kind of a merger? Is it possible?
Should I start preparing myself to divide in separate processes and use IPC for that? 

Suggestions welcome
Thanks in advance!

Thaddy:
If it is msvc (that does not play nice with floats since IONS!, it is not IEEE compliant) and is 32 bits windows you simply -partially - disable floating point exceptions through Set8087CW if you access a msvc compiled dll.
I have an example, but not at hand.
See this discussion:
https://forum.lazarus.freepascal.org/index.php/topic,46014.msg326495.html#msg326495
BTW, since 3.2.0 you may want to use winapi instead of stdcall. That will also cover 64 bit issues, including other platforms than windows.

If you are not compiling for 32 bit i386 Windows, I need a small example.
If you are, I will post that example.

PascalDragon:

--- Quote from: y.ivanov on January 25, 2022, 05:42:55 pm ---I'm trying to "merge" an existing MSVC project with Lazarus by converting it to a DLL and then calling some of its entry points from the Lazarus App. Everything is OK until some FP operation used (in this case the _ftol2_pentium4() ) and the exception  0xC00002B5: Multiple floating point traps raises.
--- End quote ---

C code doesn't usually expect the floating point exceptions that FPC enables. Use SetExceptionMask to disable the corresponding exceptions (especially overflow and underflow).


--- Quote from: Thaddy on January 25, 2022, 06:07:57 pm ---If it is msvc (that does not play nice with floats since IONS!, it is not IEEE compliant) and is 32 bits windows you simply -partially - disable floating point exceptions through Set8087CW if you access a msvc compiled dll.
I have an example, but not at hand.
See this discussion:
https://forum.lazarus.freepascal.org/index.php/topic,46014.msg326495.html#msg326495

--- End quote ---

Set8087CW only sets the control word for the x87 FPU, but in case of x86_64 Windows only SSE is used, thus the corresponding SSE exceptions wouldn't be disabled. And on ARM64 it doesn't exist at all. So the correct solution is SetExceptionMask (which handles both the x87 and SSE) and not Set8087CW directly.

AlexTP:
I just stored this answer to https://wiki.freepascal.org/SetExceptionMask .

Thaddy:
That is correct, in so far that afaik there is an option to enable 8087() in x86_32-win64.
That sounds funny, is hidden, but Florian did that. I forgot the option. Intel/AMD only.

Navigation

[0] Message Index

[#] Next page

Go to full version