pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Sam Stephens <tangent@inspire.net.nz>
To: pgsql-interfaces@postgresql.org
Subject: C text to string issue
Date: Mon, 16 Aug 2004 22:22:00 +1200
Message-ID: <41213388.2171.2E01748@localhost> (raw)

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




view thread (2+ messages)  latest in thread

Message-ID: <41213388.2171.2E01748@localhost>
Permalink:  ../41213388.2171.2E01748@localhost/
Also on:    postgresql.org/message-id/41213388.2171.2E01748@localhost

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: tangent@inspire.net.nz
  Subject: Re: C text to string issue
  In-Reply-To: <41213388.2171.2E01748@localhost>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox