Обсуждение: Fw: SEGFAULT ON EXTENDED FUNCTION
This probably means the server terminated abnormally
before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.
Hopefully someone can help with this;
I have an extension library which basically adds some common financial functions from gnumeric. This has worked just fine for a couple of years on a 32 bit machine running 8.1.0. and still does. I have recently built a new dual core 64 bit gentoo system with 8.1.0 installed.
The library in question compiles and links just fine. I install it in /usr/lib.
When I execute the create or replace function call that also succeeds however when I execute the command .. for example:
select * from eomonth('10/22/2006',0);
1. Is there anything special I should have done when building postgres ?
PG_CONFIG OUTPUT:
BINDIR = /usr/local/pgsql/bin
DOCDIR = /usr/local/pgsql/doc
INCLUDEDIR = /usr/local/pgsql/include
PKGINCLUDEDIR = /usr/local/pgsql/include INCLUDEDIR-SERVER = /usr/local/pgsql/include/server LIBDIR = /usr/local/pgsql/lib PKGLIBDIR = /usr/local/pgsql/lib LOCALEDIR = MANDIR = /usr/local/pgsql/man SHAREDIR = /usr/local/pgsql/share SYSCONFDIR = /usr/local/pgsql/etc PGXS = /usr/local/pgsql/lib/pgxs/src/makefiles/pgxs.mk
CONFIGURE = '--enable-thread-safety' '--with-perl' '--with-pam' '--with-python' '--enable-depend' '--with-gnu-ld'
CC = gcc
CPPFLAGS = -D_GNU_SOURCE
CFLAGS = -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Winline -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing CFLAGS_SL = -fpic LDFLAGS = -Wl,-rpath,/usr/local/pgsql/lib LDFLAGS_SL = LIBS = -lpgport -lpam -lz -lreadline -lcrypt -lresolv -lnsl -ldl -lm -lbsd VERSION = PostgreSQL 8.1.4
which should return the end of month for argument one I get a seg fault:
********************************* FAULT MESSAGE IN LOG FILE ********************************
Nov 21 05:10:49 gideon postmaster[12461]: segfault at 0000000000000000 rip 00002b3af2c2f3b9 rsp 00007fffb8914398 error 4
CODE FOR EOMONTH:***************************** SNIPPIT ***************************************
PG_FUNCTION_INFO_V1(eomonth);
Datum
eomonth(PG_FUNCTION_ARGS)
{
text *date = PG_GETARG_TEXT_P(0);
int months = PG_GETARG_INT32(1);
GDate sDate;
int serialDate;
int tmp = months;
char mySDate[12];
char *pyear = NULL;
char *pmonth = NULL;
char *pday = NULL;
/* NOW FOR DATE VARS USED WITH parse_date */
char *pdate = NULL;
char pbuf[255];
struct tm tm;
text *myRDate = (text *) palloc(VARHDRSZ + 12);
VARATT_SIZEP(myRDate) = VARHDRSZ + 12;
g_date_clear(&sDate,1);
memset(pbuf,'\0',sizeof(pbuf)); /*initialize buffer */
memcpy(pbuf,VARDATA(date),VARSIZE(date)-VARHDRSZ); /* copy input string to buffer */
pdate = parse_date(pbuf,&tm); /*call parse date and see if we know about format*/
g_date_set_parse(&sDate,pdate);/* now set the GDate object sDate with pdate buf*/
if(g_date_valid(&sDate)) /* is the date we set valid */
{
/*
* now figure the eomonth calc
*/
if(months > 0)
{
g_date_add_months(&sDate,months);
}
if( months < 0)
{
g_date_subtract_months(&sDate,-months);
}
/*
* Now this is the real calculation
*/
g_date_set_day(&sDate,g_date_get_days_in_month(
g_date_get_month(&sDate),
g_date_get_year(&sDate)));
sprintf(VARDATA(myRDate),"%d/%d/%d",
g_date_get_month(&sDate),
g_date_get_day(&sDate),
g_date_get_year(&sDate));
/*
elog(NOTICE,"EOMONTH(%s)",VARDATA(myRDate));
*/
/*
serialDate = datetime_g_to_serial(&sDate);
PG_RETURN_INT32(serialDate);
*/
pfree(myRDate);
PG_RETURN_TEXT_P(myRDate);
}
else
{
elog(ERROR,"EOMONTH date invalid %s ",VARDATA(date));
}
}