Skip site navigation (1) Skip section navigation (2)

Re: C Function

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: feblec <carvalho(at)ig(dot)com(dot)br>
Cc: <pgsql-interfaces(at)postgresql(dot)org>
Subject: Re: C Function
Date: 2001-07-17 16:28:37
Message-ID: Pine.LNX.4.30.0107171826320.678-100000@peter.localdomain (view raw or flat)
Thread:
Lists: pgsql-interfaces
feblec writes:

> #include <pgsql/postgres.h>
> #include <string.h>
>
> unsigned char *fernando(unsigned char *texto)
> {
> 	char *resultp = palloc(strlen(texto)+5);

texto will not be null-terminated.  Read the examples in the documentation
again, e.g.,

http://www.de.postgresql.org/users-lounge/docs/7.0/postgres/xfunc19022.htm

> 	resultp = texto;
> 	strcat(resultp," mais");
> 	return resultp;
> }
>
> gcc -shared fernando.c -o fernando.so
>
> CREATE FUNCTION fernando (bpchar) RETURNS bpchar
>   AS '/u/src/tef/fernando.so' LANGUAGE 'c';
> CREATE
> SELECT fernando ('Teste');
> ERROR:  Memory exhausted in AllocSetAlloc(287341377)

-- 
Peter Eisentraut   peter_e(at)gmx(dot)net   http://funkturm.homeip.net/~peter


In response to

pgsql-interfaces by date

Next:From: Peter EisentrautDate: 2001-07-17 16:30:08
Subject: Re: Clob - Issue
Previous:From: Peter EisentrautDate: 2001-07-17 16:18:55
Subject: Re: Issues with using 7.1 frontend, 7.0 backend?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group