Subject Re: [firebird-support] UDF - Windows vs Linux
Author Ivan Prenosil
> DECLARE EXTERNAL FUNCTION MOY
> RETURNS SMALLINT

I guess there should be
RETURNS SMALLINT BY VALUE


> /* tbuf below is declared oudside and works for other udfs Linux & Windows*/
> tbuf = localtime(&time_sec);

Does not look much threadsafe.


Why don't you just use standard functions instead of UDFs ?
e.g. EXTRACT(MONTH FROM CURRENT_DATE)

Ivan


----- Original Message -----
From: "taliyev" <taliyev@...>
To: <firebird-support@yahoogroups.com>
Sent: Thursday, May 25, 2006 5:18 PM
Subject: [firebird-support] UDF - Windows vs Linux


I have to port FB udf library from Windows to Linux. I have moved C
code of our udfs to our Linux box and it has compiled and linked
into library without any troubles. Here is where problem started. I
have to mention here that all functions work well on our Windows
server. Most of the functions work on Linux as well, but some of
them cause FB to abandon all connections and restart. Here are two
samples:

Declaration:

DECLARE EXTERNAL FUNCTION MOY
RETURNS SMALLINT
ENTRY_POINT 'fn_moy' MODULE_NAME 'CODASlib';

C code:

short EXPORT fn_moy()
{
long time_sec;
short r_short;
time (&time_sec);
/* tbuf below is declared oudside and works for other udfs Linux &
Windows*/
tbuf = localtime(&time_sec);
r_short = (short) (tbuf->tm_mon + 1);
return r_short;
}

Here is another one.

Declaration:

DECLARE EXTERNAL FUNCTION MAKEWEEKNUMID
INTEGER
RETURNS INTEGER BY VALUE
ENTRY_POINT 'fn_MakeWeekNumID' MODULE_NAME 'CODASlib';

C code:

int EXPORT fn_MakeWeekNumID(ARG(int*, yyyymmdd))
ARGLIST(int *yyyymmdd)
{
long bDate = (long) julian_date(2, 1, 2000);
int yyyy = *yyyymmdd / 10000;
int mm = (*yyyymmdd / 100) % 100;
int dd = *yyyymmdd % 100;
long ThisDate = (long) julian_date(dd, mm, yyyy);
if (ThisDate < bDate)
return (0);
return (int) ((ThisDate - bDate)/7 +1);
}

Once again this declaration and code work on Windows, but break FB
on Linux. What is wrong here? Where is my problem?

Thanks