Issue Details (XML | Word | Printable)

Key: CORE-4088
Type: Bug Bug
Status: Open Open
Priority: Critical Critical
Assignee: Unassigned
Reporter: christophe derenne
Votes: 1
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Firebird Core

isc_encode_timestamp and isc_decode timestamp crach firebird superserver if used in UDF

Created: 23/Apr/13 08:23 AM   Updated: 12/Jun/13 09:16 AM
Component/s: UDF
Affects Version/s: 2.5.2
Fix Version/s: None

Environment: Fedora Core 18 64 bits, Firebird 2.5.2 super-server


 Description  « Hide
Using a personnal udf library that works since a long time ago, from firebird 1 to firebird 2.5 (classic server 32 bits only)
Trying to migrate to firebird superserver 64 bits.
Own source compiled without troubles in 64 bits mode, using gcc
linking OK (using ld) excepts necessity to make a symbolink link to fbudf.so in /var/lib64 otherwire, fbudf.so is not found found when executing (small bug in firebird installation ?)

But all functions that uses isc_encode_timestamp or isc_decode_timestamp makes firebird superserver crash.

Exemple :

ISC_TIMESTAMP * First_Day_Of(int *,int *);
ISC_TIMESTAMP * First_Day_Of(mm,aa)

     int *mm,*aa;
{
      ISC_TIMESTAMP *buffer = (ISC_TIMESTAMP*)ib_util_malloc(sizeof(ISC_TIMESTAMP));
      time_t t;
      typedef struct tm tm;
       struct tm{
       int tm_sec;int tm_min;int tm_hour;
       int tm_mday;int tm_mon;int tm_year;
       int tm_wday;int tm_yday;int tm_isdst;
               };
       tm *currtime = (tm*)ib_util_malloc(sizeof( tm));
       t = time(NULL);
       currtime = localtime(&t);
       currtime->tm_year = ( *aa + currtime->tm_year );
       currtime->tm_mon = ( *mm - 1 );
       currtime->tm_mday = 1;
       currtime->tm_sec = 0;
       currtime->tm_min = 0;
       currtime->tm_hour = 0;
       isc_encode_timestamp(currtime,buffer);
       return buffer;
}

This code code works on Firebird classique 32 bits, (Linux and windows) not on firebird superserver 64 bits.
Don't know about firebird-superserver 32 bits.


 All   Comments   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Dmitry Yemanov added a comment - 13/May/13 02:38 PM
Out of curiosity, why you declare struct tm yourself instead of using the standard one from time.h?
Why do you need a memory leak? I see currtime allocated dynamically and the new pointer is lost two lines below.
How is this UDF declared in the database?

christophe derenne added a comment - 12/Jun/13 09:15 AM - edited
Hi, sorry, i reply to you via email and it seems that you've not received my answer, so, i repeat it :

First thanks for your message : you're the first one who answsers me.

Before registering on firebird bu tracker, I've tried everything during 10 days.
replacing ib_malloc by malloc, using time.h instead of declaring my own tm structure etc....
If I ask the trackers, this is because I don't know what to do and I don't found any answser in google.

But You have to know that I've tried a very small udf that just do an is_encode_timestamp with the same issue.
This is strange because It works with firebird classic 32 bits for a long time, using on result sets with hundred of thousands rows and it works with a single test programme using this shared object

So, to answer your question this is how I've declared this functions in Firebird :

DECLARE EXTERNAL FUNCTION FIRST_DAY_OF
Integer, Integer
RETURNS Timestamp
ENTRY_POINT 'First_Day_Of'
MODULE_NAME 'udflib';

(of course my shared object's name is udflib.so)

Usage is : select First_Day_Of(1,-1) from rdb$database give you the first day of january of the last year (2012-01-01')
replace second parameter (-1) by 0 to change to the current year, by 1 to change to the next year and so on.
replace first parameter by 2..12 to change the month

Christophe