C-procedure crashed in Postgres 8.3.3 when using 'text' variable (WinXP)

From: el dorado <do_ra_do(at)mail(dot)ru>
To: pgsql-general(at)postgresql(dot)org
Subject: C-procedure crashed in Postgres 8.3.3 when using 'text' variable (WinXP)
Date: 2008-07-15 08:33:15
Message-ID: E1KIfyF-000MRk-00.do_ra_do-mail-ru@f139.mail.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello!
I'd like to write C-function returning text for using in PG 8.3.3. (WinXP SP2)
For compilation I use MinGW-5.1.4 (gcc 3.4.5),MSYS-1.0.10.
The code looks like this (in reduced variant):

#include "postgres.h"
#include "fmgr.h"
#include "executor/executor.h"
#include "utils/timestamp.h"
#include "utils/builtins.h"
#include "utils/formatting.h"

#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif

#define PG_CSTR_GET_TEXT(cstrp) \
DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(cstrp)))

PG_FUNCTION_INFO_V1(SomeFunction);
Datum
SomeFunction(PG_FUNCTION_ARGS)
{
PG_RETURN_TEXT_P(PG_CSTR_GET_TEXT("my_string"));
}

Then I create stored procedure in PG:

CREATE OR REPLACE FUNCTION "service"."some_function" () RETURNS text AS
'$libdir/some_dll', 'SomeFunction'
LANGUAGE C STRICT;

-----------------------------------------------------
When I'm trying to use "service"."some_function" PG fails.

I tried to use the example from documentation:
PG_FUNCTION_INFO_V1(concat_text);

Datum
concat_text(PG_FUNCTION_ARGS)
{
text *arg1 = PG_GETARG_TEXT_P(0);
text *arg2 = PG_GETARG_TEXT_P(1);
int32 new_text_size = VARSIZE(arg1) + VARSIZE(arg2) - VARHDRSZ;
text *new_text = (text *) palloc(new_text_size);

SET_VARSIZE(new_text, new_text_size);
memcpy(VARDATA(new_text), VARDATA(arg1), VARSIZE(arg1) - VARHDRSZ);
memcpy(VARDATA(new_text) + (VARSIZE(arg1) - VARHDRSZ),
VARDATA(arg2), VARSIZE(arg2) - VARHDRSZ);
PG_RETURN_TEXT_P(new_text);
}

CREATE FUNCTION concat_text(text, text) RETURNS text
AS '$libdir/some_dll', 'concat_text'
LANGUAGE C STRICT;

And I got the same result.

When I'm trying to return integer, f.e., evetything is fine.
Also all this examples worked fine with PostgreSQL 8.2.

I saw some similar problems - but I didn't find the solution (
http://archives.postgresql.org/pgsql-general/2008-05/msg00060.php
http://archives.postgresql.org/pgsql-general/2008-05/msg00097.php

Have somebody any ideas how to resolve this problem?

Thanks in advance,
Marina

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Craig Ringer 2008-07-15 08:45:13 Re: 8.3.3 Complie issue
Previous Message Oleg Bartunov 2008-07-15 07:11:50 Re: Inconsistency with stemming/stop words in Tsearch2