Subject Grave problem with UDFs and DATEs
Author Lele Gaifax
Hi all,

I have a tiny library of UDFs I wrote years ago, and it's still
working ok. I was even surprised when I discovered that the very same
binary dll was compatible with IB5, IB6 and FB1.

But a few days ago, needing two more UDFs, I discovered that I'm not
anymore able to produce a working dll! No matter how I compile the
thing, the subset of functions related to DATEs fails miserably and
cause the server to crash!! This is what I find in the interbase.log
file:

PACI (Server) Wed Feb 06 11:41:46 2002
^Y An exception occurred that does
not have a description. Exception number EEDFADE.
This exception will cause the InterBase server
to terminate abnormally.

PACI (Client) Wed Feb 06 11:41:46 2002
C:\Programmi\FireBird\bin\ibserver.exe: terminated abnormally (-1)

All the other UDFs not related to DATE seems working as before!!

Given that I have two versions of the library, one in Delphi under
Windows, the other in C under GNU/Linux, and that the latter is still
working ok (no surprise there :-), I thought it was a matter of
IBIntf&IBHeader&C., so I downloaded a recent version of the IBX
library, and used those. But that wasn't the reason. So I tried
several different ways of achieving the same result, with different
declarations and using other APIs...

All the functions in question are very very simple, similar to the
following:

DECLARE EXTERNAL FUNCTION DATEDOW
DATE
RETURNS SMALLINT BY VALUE
ENTRY_POINT "wsudf_DateDOW" MODULE_NAME "WinsipexUDFs.dll"

and

function wsudf_DateDOW (D: PISC_QUAD): Short;
var
t: TCTimeStructure;

begin
if (D=nil) then
Result := 7
else begin
isc_decode_date (D, @t);
Result := t.tm_wday;
end;
end;

However I call ANY isc_decode_{date|time|timestamp}, changing of
course the type of the D argument and the UDF declaration, a simple

SELECT DateDOW('TODAY') FROM RDB$DATABASE

gives me a very strange number (7826, iirc) and the server crashes.

I instrumented the function with several debug statements (WriteLNs on
an external file of the parameters, there's not that much to debug;-),
and the problem seems only triggered by the call to the isc_xxx
function.

I extracted and translated in Pascal the isc_decode_timestamp()
(actually, the ndate() function on which that relays), basically
inlining the call, and everything worked as expected (although I did
not get the algorithm right, but the intent was to prove that the
declaration of the UDF was ok, and that it was receiving reasonable
arguments)

As said, I tried using both DATEs and TIMESTAMPs in the declaration,
but with the same results.

So, I reverted to the old binary dll, that still works, and seems I
won't be able to recompile it again...

PLEASE, if you have any hint on what is going on here, prevent my
madness! I hope this is the right list, maybe I should have
crossposted to ib-devel...

thank you in advance,
bye, lele.
--
nickname: Lele Gaifax | Quando vivro' di quello che ho pensato ieri
real: Emanuele Gaifas | comincero' ad aver paura di chi mi copia.
email: lele@... | -- Fortunato Depero, 1929.