Received: from localhost (uranus.hub.org [200.46.204.60]) by postgresql.org (Postfix) with ESMTP id 492119FA333 for ; Tue, 21 Nov 2006 11:49:38 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.60]) (amavisd-new, port 10024) with ESMTP id 60555-06 for ; Tue, 21 Nov 2006 11:49:35 -0400 (AST) X-Greylist: delayed 01:13:19.697544 by SQLgrey- Received: from jdoherty.net (cdm-208-180-124-109.gtwn.cox-internet.com [208.180.124.109]) by postgresql.org (Postfix) with SMTP id 5BBDA9FA2B9 for ; Tue, 21 Nov 2006 11:49:34 -0400 (AST) Received: (qmail 22522 invoked from network); 21 Nov 2006 11:49:32 -0000 Received: from unknown (HELO jmdbox) (192.168.1.200) by 192.168.1.202 with SMTP; 21 Nov 2006 11:49:32 -0000 Message-ID: <001301c70d63$19a0f210$c801a8c0@jmdbox> From: "Doherty EMAIL ACCOUNT" To: Subject: SEGFAULT ON EXTENDED FUNCTION Date: Tue, 21 Nov 2006 05:49:28 -0600 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0010_01C70D30.CEBEF1C0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2869 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2962 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.134 tagged_above=0 required=5 tests=BAYES_50, FORGED_RCVD_HELO, HTML_MESSAGE, SUBJ_ALL_CAPS X-Spam-Level: * X-Archive-Number: 200611/3 X-Sequence-Number: 6318 This is a multi-part message in MIME format. ------=_NextPart_000_0010_01C70D30.CEBEF1C0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable 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 =3D /usr/local/pgsql/bin DOCDIR =3D /usr/local/pgsql/doc INCLUDEDIR =3D /usr/local/pgsql/include PKGINCLUDEDIR =3D /usr/local/pgsql/include INCLUDEDIR-SERVER =3D = /usr/local/pgsql/include/server LIBDIR =3D /usr/local/pgsql/lib = PKGLIBDIR =3D /usr/local/pgsql/lib LOCALEDIR =3D MANDIR =3D = /usr/local/pgsql/man SHAREDIR =3D /usr/local/pgsql/share SYSCONFDIR =3D = /usr/local/pgsql/etc PGXS =3D = /usr/local/pgsql/lib/pgxs/src/makefiles/pgxs.mk CONFIGURE =3D '--enable-thread-safety' '--with-perl' '--with-pam' = '--with-python' '--enable-depend' '--with-gnu-ld' CC =3D gcc CPPFLAGS =3D -D_GNU_SOURCE CFLAGS =3D -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Winline = -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing = CFLAGS_SL =3D -fpic LDFLAGS =3D -Wl,-rpath,/usr/local/pgsql/lib = LDFLAGS_SL =3D LIBS =3D -lpgport -lpam -lz -lreadline -lcrypt -lresolv = -lnsl -ldl -lm -lbsd VERSION =3D 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 =3D PG_GETARG_TEXT_P(0); int months =3D PG_GETARG_INT32(1); GDate sDate; int serialDate; int tmp =3D months; char mySDate[12]; char *pyear =3D NULL; char *pmonth =3D NULL; char *pday =3D NULL; /* NOW FOR DATE VARS USED WITH parse_date */ char *pdate =3D NULL; char pbuf[255]; struct tm tm; text *myRDate =3D (text *) palloc(VARHDRSZ + 12); VARATT_SIZEP(myRDate) =3D 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 =3D 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 =3D 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)); } } ------=_NextPart_000_0010_01C70D30.CEBEF1C0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

Hopefully someone can help with this;

I have an extension library which basically adds some common = financial=20 functions from gnumeric. This has worked just fine for a couple of years = on a 32=20 bit machine running 8.1.0. and still does. I have recently built a new = dual core=20 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=20 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 =3D /usr/local/pgsql/bin

DOCDIR =3D /usr/local/pgsql/doc

INCLUDEDIR =3D /usr/local/pgsql/include

PKGINCLUDEDIR =3D /usr/local/pgsql/include INCLUDEDIR-SERVER =3D=20 /usr/local/pgsql/include/server LIBDIR =3D /usr/local/pgsql/lib = PKGLIBDIR =3D=20 /usr/local/pgsql/lib LOCALEDIR =3D MANDIR =3D /usr/local/pgsql/man = SHAREDIR =3D=20 /usr/local/pgsql/share SYSCONFDIR =3D /usr/local/pgsql/etc PGXS =3D=20 /usr/local/pgsql/lib/pgxs/src/makefiles/pgxs.mk

CONFIGURE =3D '--enable-thread-safety' '--with-perl' '--with-pam'=20 '--with-python' '--enable-depend' '--with-gnu-ld'

CC =3D gcc

CPPFLAGS =3D -D_GNU_SOURCE

CFLAGS =3D -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Winline=20 -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing = CFLAGS_SL =3D=20 -fpic LDFLAGS =3D -Wl,-rpath,/usr/local/pgsql/lib LDFLAGS_SL =3D LIBS = =3D -lpgport=20 -lpam -lz -lreadline -lcrypt -lresolv -lnsl -ldl -lm -lbsd VERSION =3D = PostgreSQL=20 8.1.4

 

which should return the end of month for argument one I get a seg = fault:

********************************* FAULT MESSAGE IN LOG FILE=20 ********************************

Nov 21 05:10:49 gideon postmaster[12461]: segfault at = 0000000000000000 rip=20 00002b3af2c2f3b9 rsp 00007fffb8914398 error 4

CODE FOR EOMONTH:***************************** SNIPPIT=20 ***************************************

PG_FUNCTION_INFO_V1(eomonth);

Datum

eomonth(PG_FUNCTION_ARGS)

{

text *date =3D PG_GETARG_TEXT_P(0);

int months =3D PG_GETARG_INT32(1);

GDate sDate;

int serialDate;

int tmp =3D months;

char mySDate[12];

char *pyear =3D NULL;

char *pmonth =3D NULL;

char *pday =3D NULL;

/* NOW FOR DATE VARS USED WITH parse_date */

char *pdate =3D NULL;

char pbuf[255];

struct tm tm;

text *myRDate =3D (text *) palloc(VARHDRSZ + 12);

VARATT_SIZEP(myRDate) =3D 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=20 buffer */

pdate =3D parse_date(pbuf,&tm); /*call parse date and see if we = know about=20 format*/

g_date_set_parse(&sDate,pdate);/* now set the GDate object sDate = with=20 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 =3D 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));

}

}

------=_NextPart_000_0010_01C70D30.CEBEF1C0--