X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 233415E46D2 for ; Mon, 16 Aug 2004 07:17:55 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 19765-03 for ; Mon, 16 Aug 2004 10:17:50 +0000 (GMT) Received: from mail.inspire.net.nz (mail1.inspire.net.nz [203.114.128.8]) by svr1.postgresql.org (Postfix) with ESMTP id 553DB5E3F15 for ; Mon, 16 Aug 2004 07:17:48 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.inspire.net.nz (Postfix) with ESMTP id B8B441A567D for ; Mon, 16 Aug 2004 22:17:49 +1200 (NZST) Received: from mail.inspire.net.nz ([127.0.0.1]) by localhost (mail1 [127.0.0.1:10024]) (amavisd-new) with ESMTP id 12960-10 for ; Mon, 16 Aug 2004 22:17:49 +1200 (NZST) Received: from q-6i3rfq8xmian0 (203-114-159-190-dsl.inspire.net.nz [203.114.159.190]) by mail.inspire.net.nz (Postfix) with ESMTP id B72EF1A4F7D for ; Mon, 16 Aug 2004 22:17:48 +1200 (NZST) From: "Sam Stephens" To: pgsql-interfaces@postgresql.org Date: Mon, 16 Aug 2004 22:22:00 +1200 MIME-Version: 1.0 Subject: C text to string issue Message-ID: <41213388.2171.2E01748@localhost> X-mailer: Pegasus Mail for Windows (v4.12a) Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Content-description: Mail message body X-Virus-Scanned: by amavisd-new X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200408/22 X-Sequence-Number: 5070 Hiya, I'm trying to write a function that takes a text argument as input, and converts it to a C string to then use for file I/O. However it crashes my postgres when it gets to the memcpy line (e.g. you get the Test A notice and the Test B notice, but not the Test C notice) The odd thing is my code is now based on genfile.c and I cannot see what I'm doing differently/wrong. http://cvs.pgadmin.org/cgi-bin/viewcvs.cgi/pgadmin-tools/support/genfile.c?rev=HEAD I compile using the commands gcc -c qpsolve.c -I/usr/src/postgresql-7.4.2/src/include gcc -shared -o qpsolve.so qpsolve.o cp qpsolve.so /usr/local/pgsql/lib -f My command to create the function is CREATE OR REPLACE FUNCTION F_QPSOLVE(text) RETURNS text AS 'qpsolve.so' LANGUAGE 'C' WITH (isStrict); This is my source code, qpsolve.c **** #include "postgres.h" #include "fmgr.h" /* Routine to write session variables */ PG_FUNCTION_INFO_V1(f_qpsolve); text * f_qpsolve(text *arg) { char *filename; int len=VARSIZE(arg)-VARHDRSZ; elog(NOTICE, "test A"); filename = palloc(len+1); elog(NOTICE, "test B"); memcpy(filename,VARDATA(arg), len); elog(NOTICE, "test C"); filename[len]=0; elog(NOTICE, filename); return 0; } **** Your help solving this would be much appreciated. All the best, Sam