Subject | Re: UDF problem |
---|---|
Author | kittikira |
Post date | 2010-01-26T10:12:59Z |
I removed everything that could have nothing to do with my problem.
Here is the complete content of my source file, named rsudf.c.
#include <ibase.h>
#include <time.h>
#ifndef IB_START_YEAR
#define IB_START_YEAR 1900
#endif
ISC_DATE * first_day (int * , int * );
ISC_DATE * first_day (int * y, int * m)
{
ISC_DATE *bufdate = (ISC_DATE *) ib_util_malloc (sizeof(ISC_DATE));
struct tm tm1;
tm1.tm_sec = 0;
tm1.tm_min = 0;
tm1.tm_hour = 0;
tm1.tm_year = *y - IB_START_YEAR;
tm1.tm_mon = *m - 1;
tm1.tm_mday = 1;
isc_encode_sql_date(&tm1, bufdate);
return bufdate;
}
Here is the content of my shell script, I use to compile it. Maybe there is something wrong with it.
gcc -c -O -fpic rsudf.c
ld -G rsudf.o -lm -lc -o rsudf.so
when I run this script I get the warning
rsudf.c: In function `first_day':
rsudf.c:13: warning: cast to pointer from integer of different size
Do you see anything that is wrong?
I do have to get those UDFs working on Linux.
I still have some more, but the most of them are working. Some string conversions (int and float to str and back) are doing fine. For some I need a little adjustment (could not get thousends seperators into floats converted to strings so far), but that is not such a great problem. My biggest problem, as it seems, are those date functions I need.
If this problem is just a warning, I could life with it, but when I use the UDF Firebird quits the connection. So something must be wrong with memory handling, I think.
Maybe somthing is wrong with my libraries.
I compile on an Ubuntu 32 bit desktop. I am using the UDF on an 64 Bit Ubuntu server. Could this be the problem?
All other functions work fine, so I wonder why this should be the reason for the problem with the date function.
I use some example code to adapt it to my needs. Normaly that works for me, but this one drives me crazy.
I copied the code from rfunc librarie and adjusted it to get it compiled. I hope this is not against the LGPL.
The rfunc library contains nearly everything I need, but for easier use, I like to mix all I need up into one library file.
So I only pick up the functions I need and put them together into one file. Hopefully I do not violate against any licensing.
Another UDF that doesn't work well is a b_line_count for Blobs.
It counts all lines ending with a linefeed, but lines ending with eof are not counted.
I made a remark, where I think that should be done.
long b_line_count (BLOB b)
{
unsigned char *buf, *p;
unsigned short length, actual_length;
long curr_segment = 0L, linecount = 0L;
if (!b->blob_handle)
return 0L;
length = (unsigned short) (b->blob_max_segment + 1L);
buf = (unsigned char *) malloc (b->blob_max_segment + 1L);
while ((*b->blob_get_segment) (b->blob_handle, buf, length, &actual_length))
{
buf [actual_length] = 0;
p = buf;
while (*p)
{
if (*p++ =='\n')
linecount++;
}
if ((++curr_segment == b->blob_number_segments) && actual_length && (*--p != '\n'))
linecount++; /* I think here should be the increase for no LF at the end of the last line, but it doesn't work */
}
free (buf);
return linecount;
}
Here is the complete content of my source file, named rsudf.c.
#include <ibase.h>
#include <time.h>
#ifndef IB_START_YEAR
#define IB_START_YEAR 1900
#endif
ISC_DATE * first_day (int * , int * );
ISC_DATE * first_day (int * y, int * m)
{
ISC_DATE *bufdate = (ISC_DATE *) ib_util_malloc (sizeof(ISC_DATE));
struct tm tm1;
tm1.tm_sec = 0;
tm1.tm_min = 0;
tm1.tm_hour = 0;
tm1.tm_year = *y - IB_START_YEAR;
tm1.tm_mon = *m - 1;
tm1.tm_mday = 1;
isc_encode_sql_date(&tm1, bufdate);
return bufdate;
}
Here is the content of my shell script, I use to compile it. Maybe there is something wrong with it.
gcc -c -O -fpic rsudf.c
ld -G rsudf.o -lm -lc -o rsudf.so
when I run this script I get the warning
rsudf.c: In function `first_day':
rsudf.c:13: warning: cast to pointer from integer of different size
Do you see anything that is wrong?
I do have to get those UDFs working on Linux.
I still have some more, but the most of them are working. Some string conversions (int and float to str and back) are doing fine. For some I need a little adjustment (could not get thousends seperators into floats converted to strings so far), but that is not such a great problem. My biggest problem, as it seems, are those date functions I need.
If this problem is just a warning, I could life with it, but when I use the UDF Firebird quits the connection. So something must be wrong with memory handling, I think.
Maybe somthing is wrong with my libraries.
I compile on an Ubuntu 32 bit desktop. I am using the UDF on an 64 Bit Ubuntu server. Could this be the problem?
All other functions work fine, so I wonder why this should be the reason for the problem with the date function.
I use some example code to adapt it to my needs. Normaly that works for me, but this one drives me crazy.
I copied the code from rfunc librarie and adjusted it to get it compiled. I hope this is not against the LGPL.
The rfunc library contains nearly everything I need, but for easier use, I like to mix all I need up into one library file.
So I only pick up the functions I need and put them together into one file. Hopefully I do not violate against any licensing.
Another UDF that doesn't work well is a b_line_count for Blobs.
It counts all lines ending with a linefeed, but lines ending with eof are not counted.
I made a remark, where I think that should be done.
long b_line_count (BLOB b)
{
unsigned char *buf, *p;
unsigned short length, actual_length;
long curr_segment = 0L, linecount = 0L;
if (!b->blob_handle)
return 0L;
length = (unsigned short) (b->blob_max_segment + 1L);
buf = (unsigned char *) malloc (b->blob_max_segment + 1L);
while ((*b->blob_get_segment) (b->blob_handle, buf, length, &actual_length))
{
buf [actual_length] = 0;
p = buf;
while (*p)
{
if (*p++ =='\n')
linecount++;
}
if ((++curr_segment == b->blob_number_segments) && actual_length && (*--p != '\n'))
linecount++; /* I think here should be the increase for no LF at the end of the last line, but it doesn't work */
}
free (buf);
return linecount;
}
--- In firebird-support@yahoogroups.com, Dimitry Sibiryakov <sd@...> wrote:
>
> 25.01.2010 17:24, kittikira wrote:
> > I modyfied the function as follows:
> >
> > ISC_DATE * first_day (int * y, int * m)
> >
> > {
> > ISC_DATE *bufdate = (ISC_DATE *) ib_util_malloc (sizeof(ISC_DATE));
> > struct tm tm1;
> > tm1.tm_sec = 0;
> > tm1.tm_min = 0;
> > tm1.tm_hour = 0;
> > tm1.tm_year = *y - IB_START_YEAR;
> > tm1.tm_mon = *m - 1;
> > tm1.tm_mday = 1;
> > isc_encode_sql_date(&tm1, bufdate);
> > return bufdate;
> > }
> >
> > Still the same warning.
>
> I've just copy-pasted this code into file and gcc gave me no warning.
> Something must be wrong in pieces that you don't show.
>
> --
> SY, SD.
>