Re: Access violation from palloc, Visual Studio 2005, C-language function

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Kevin Flanagan" <kevin-f(at)linkprior(dot)com>
Cc: "'PostgreSQL-development'" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Access violation from palloc, Visual Studio 2005, C-language function
Date: 2010-03-10 00:26:57
Message-ID: 1885.1268180817@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

"Kevin Flanagan" <kevin-f(at)linkprior(dot)com> writes:
> Environment: Windows Vista, PostgreSQL 8.4 (1-click installer), Visual
> Studio 2005 sp1.

> I have a bare-bones DLL built as per the above, compiling the 'add_one' and
> 'copytext' samples found at
> http://www.postgresql.org/docs/8.4/interactive/xfunc-c.html (version 1
> calling convention), compiled as 'C'. I can use 'add_one' just fine from
> within SQL, but if I use 'copytext', an access violation occurs as soon as
> palloc() is called.

> Could anyone suggest what the problem might be?

Hard to tell without seeing the actual code and a stack trace, but I'd
bet that you haven't fully resolved the build process problems you
mentioned earlier. I'm thinking this may be a symptom of linkage
failure, since palloc is probably the first place in the above-described
sequence where your DLL is going to call back into the core backend.

Another possibility is that you mistranscribed the example somehow.
Maybe you forgot the PG_FUNCTION_INFO_V1(copytext) macro?

> Failing that, are there any other (creative?) ways to return strings from a
> C-language function without using palloc?

If you can't make those examples work, you have fundamental problems you
need to fix, not find a "creative workaround".

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Takahiro Itagaki 2010-03-10 02:09:40 Re: lock mode for ControlFileLock which pg_start_backup uses
Previous Message Kevin Flanagan 2010-03-10 00:11:57 Access violation from palloc, Visual Studio 2005, C-language function