Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2007-09

FPU Configuration inside a library

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Adrian Veith

Hi,

i posted this already under a differnt subject, but didn't get a feedback.

A .dll written in fpc changes the configuration of the FPU (FPUCW). This might cause a strange behavior inside the loading program.

If the loading program allows division by zero (1.0 / 0.0), it will crash after the .dll written in freepascal is loaded. What is really bad with this is, that the crash occurs at total different place and time inside the loading program (very hard to find).

The initialization of fpc should only change the FPU configuration inside a program not inside a library.

IMHO same should be true with other settings like LOCALE settings.

Cheers,

Adrian.

Michael Van Canneyt
to Adrian Veith
Adrian Veith wrote 14 lines
Hi, i posted this already under a differnt subject, but didn't get a feedback. A .dll written in fpc changes the configuration of the FPU (FPUCW). This might cause a strange behavior inside the loading program. If the loading program allows division by zero (1.0 / 0.0), it will crash after the .dll written in freepascal is loaded. What is really bad with this is, that the crash occurs at total different place and time inside the loading program (very hard to find). The initialization of fpc should only change the FPU configuration inside a program not inside a library.

This is not so easy. The compiler has no way of knowing what code will be executed in the initialization sections of the units inside the library. The ABI also makes no demand. I've seen much Delphi code which explictly saves and restores the FPU control word around a call to LoadLibrary...

IMHO same should be true with other settings like LOCALE settings.

FPC does not change the locale settings. If the user does not change it, then neither does the library.

Michael.