C Function

Поиск
Список
Период
Сортировка
Искать

C Function

От:
feblec <carvalho@ig.com.br>
Дата:

#include 
#include 

unsigned char *fernando(unsigned char *texto)
{char *resultp = palloc(strlen(texto)+5);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)


-- 

Fernando Edurado B. L. e Carvalho
Development/Consultant


Re: C Function

От:
Peter Eisentraut <peter_e@gmx.net>
Дата:
feblec writes:

> #include 
> #include 
>
> 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@gmx.net   http://funkturm.homeip.net/~peter


FAQ