Sign in Join

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

Mailing lists / fpc-pascal / 2011-05

Minimal Sylpheed plugin in FreePascal

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

Anton Shepelev

Hello all,

I have tried to create a Windows plugin dll for the Sylpheed e-mail client in FreePascal but couldn't get past a strange side effect: the mere fact of the plugin being loaded makes GTK's window-showing functions crash the whole program.

This happens even with the smallest and emptiest plugin pos- sible, when it neither subscribes for any event nor calls any API functions. The minimal plugin only provides minimal implementations of the basic interface functions simply reporting the start of every function to the debug log, which is created when Sylpheed is invoked with the --debug option.

Then I tried coding the same plugin in C, using the Tiny C Compiler, and it worked pretty well, wherefrom I concluded that something must be wrong with FreePascal's DLL genera- tion, so I have come here for help.

Attached are the C and Pascal sources of the minimal plugin. A package with the same sources plus the binaries can be downloaded here:

http://uploadbox.com/files/6d08a0b625/

This is the original report of the problem on the Sylpheed mailing list:

http://www.sraoss.jp/pipermail/sylpheed/2011-May/004525.html

After I had encountered the problem I started to strip the plugin of its functionality and dependencies until I had the bare skeleton which still didn't work and which I have attached.

If you need any further information, please ask.

Thanks in advnace,
Anton

Jonas Maebe
to Anton Shepelev
Anton Shepelev wrote
I have tried to create a Windows plugin dll for the Sylpheed e-mail client in FreePascal but couldn't get past a strange side effect: the mere fact of the plugin being loaded makes GTK's window-showing functions crash the whole program.

One likely potential cause is the fact that released FPC versions enable all floating point exceptions. Since libc does not do that, many C programs and frameworks contain invalid floating point operations.

You can try adding the following to your dll:

uses
 math;

...

initialization
 SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide, exOverflow, exUnderflow, exPrecision])
end.

Of course, this means that you won't get such exceptions in Pascal code either anymore.

Anton Shepelev
to Jonas Maebe

Jonas Maebe:

One likely potential cause is the fact that released FPC versions enable all floating point exceptions. Since libc does not do that, many C programs and frameworks contain invalid floating point operations.

Wow! Many thanks. I thought that information would be use- less, but indeed, the crash is due to a floating-point exception. I have Visual Studio at work and it intercepted the error and said it was a floating point exception. And after it has been masked as you suggested my Pascal code works.

Do I understand correctly, that at load my library was dis- abling the exception mask for the whole program?

Is masking such exceptions a common practice in C? Will it be politically correct to ask the developer to fix the prob- lem?

Thank you again, Jonas
Anton

Jonas Maebe
to Anton Shepelev
Anton Shepelev wrote
Do I understand correctly, that at load my library was dis- abling the exception mask for the whole program?

The fpu exception mask is always global for an entire program. It is not possible to disable it only for the code in one single library.

Is masking such exceptions a common practice in C?

It's not C programmers that do it. It's the C library that does it in its startup code, or maybe even the operating system when creating a new process. But as a result, indeed almost no single C program takes invalid floating point operations into account (which is bad practice, because e.g. floating point operations involving NaNs can be extremely slow).

Will it be politically correct to ask the developer to fix the prob- lem?

You can try, but he probably won't care.

Jonas

Luiz Americo Pereira Camara
to Anton Shepelev: Jonas Maebe: Wow! Many thanks. I thought that information would be use- less, but …
Anton Shepelev wrote 10 lines
Jonas Maebe: > One likely potential cause is the fact that released FPC > versions enable all floating point exceptions. Since libc > does not do that, many C programs and frameworks contain > invalid floating point operations. Is masking such exceptions a common practice in C? Will it be politically correct to ask the developer to fix the prob- lem?

It's the default option for c compilers

Luiz