Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id CB96264FFB5 for ; Tue, 28 Oct 2008 16:34:46 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 68138-05 for ; Tue, 28 Oct 2008 16:34:44 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from fk-out-0910.google.com (fk-out-0910.google.com [209.85.128.189]) by postgresql.org (Postfix) with ESMTP id CC41C64FFA2 for ; Tue, 28 Oct 2008 16:34:43 -0300 (ADT) Received: by fk-out-0910.google.com with SMTP id e30so2903077fke.3 for ; Tue, 28 Oct 2008 12:34:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:mime-version:content-type:content-transfer-encoding :content-disposition; bh=3PupmRVJLnCt6GMEFjB9aBZLpoJ/c4dGVBRlCruHQ3M=; b=RdUiN86/iBMHSligoWs8nv9qCT7thBETKnMEqOaHAaIqD5JyWZn23a8/+uECO0VrBj 6QPQ9SgK2l0U+/U0GZUDcyxiwuiOUKp2xf8RenlQPGkBFrVJjGax1YGVmE2rDCX6TuUf EFLm8cZlY3KqeJLTd/+iiGLvh4So+MdNUkk0E= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type :content-transfer-encoding:content-disposition; b=i9El19T4ubVbzp4HQPf0bbMwl+LkE+f+z+3rWeXRFpdb7km8TSmAIaMWuPi/mwu9Hn nsrcfzXBNEp0efneAzpPAhegi3eepEjc+Mtud5GVCh7VpcYlMyM7+Ou5n8m5St/QYpkp 5Oks+M/ccyQ8B6CFKDQVggYKfdkLS4IKRSgpI= Received: by 10.187.189.7 with SMTP id r7mr726274fap.27.1225222481495; Tue, 28 Oct 2008 12:34:41 -0700 (PDT) Received: by 10.187.207.17 with HTTP; Tue, 28 Oct 2008 12:34:41 -0700 (PDT) Message-ID: <4dc28b160810281234g1292831awf4b8716d64f7f405@mail.gmail.com> Date: Tue, 28 Oct 2008 14:34:41 -0500 From: "Joe Halpin" To: pgsql-interfaces@postgresql.org Subject: Problem with trigger function in C MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200810/12 X-Sequence-Number: 6813 I'm new at this and I apologize if I got the wrong list, but I'm trying to write a trigger function in C which is linked in with libxqilla and is supposed to run an xquery against some xml we have stored in a column. I find that when the function is entered fcinfo is null, which causes a segfault. I copied the example trigger function from the documentation at http://www.postgresql.org/docs/8.3/static/trigger-example.html. I added some debug output to tell that fcinfo is null. I built the function by copying the makefile in the contrib directory for the xml2 demo and modifying it a bit. Here's what I wound up with: --- start --- MODULE_big = xqueryTrigger PG_CPPFLAGS = -I$(libpq_srcdir) OBJS = xqueryTrigger.o DATA = libxqueryTrigger.so SHLIB_LINK = -L/usr/local/lib -lxqilla -lxerces-c-3.0 -lcrypto -lssl ifdef USE_PGXS PG_CONFIG = pg_config PGXS := $(shell $(PG_CONFIG) --pgxs) include $(PGXS) else subdir = contrib/xml2 top_builddir = ../.. include $(top_builddir)/src/Makefile.global include $(top_srcdir)/contrib/contrib-global.mk endif --- stop --- Here's the trigger function (or at least as far as it gets) --- start --- #include "postgres.h" #include "executor/spi.h" /* this is what you need to work with SPI */ #include "commands/trigger.h" /* ... and triggers */ #include #ifdef PG_MODULE_MAGIC PG_MODULE_MAGIC; #endif typedef void*(*memFunc)(unsigned int sz); extern int runQuery(const char *qry, const char *xml, char **result, memFunc allocator); extern Datum xqueryTrigger(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(xqueryTrigger); void *memAllocator(unsigned int); Datum xquerytrigger(PG_FUNCTION_ARGS); void *memAllocator(unsigned int sz) { return palloc(sz); } Datum xquerytrigger(PG_FUNCTION_ARGS) { TriggerData *trigdata; TupleDesc tupdesc; HeapTuple rettuple; char *when; bool checknull; bool isnull; int ret, i; char *status; elog(INFO, "Entering xquerytrigger()"); elog(INFO, "getting TriggerData..."); elog(INFO, "fcinfo = %p", fcinfo); elog(INFO, "fcinfo->context = %p", fcinfo->context); trigdata = (TriggerData *) fcinfo->context; --- stop --- Any advice would be appreciated. Thanks Joe