Tuesday, July 15, 2008

Re: [GENERAL] C-procedure crashed in Postgres 8.3.3 when using 'text' variable (WinXP)

Tom Lane wrote:
> el dorado <do_ra_do@mail.ru> writes:
>> 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.
>
> Was the Postgres server you're using built the same way? I seem to
> recall some incompatibilities between MinGW and MSVC builds.

I'd be surprised if there weren't some given how tricky it is to mix
different compilers on Windows, where that usually means mixing C
runtimes as well. On any platform it's best to stick to the same C
runtime for all libraries to be linked into the same process*.

That said, PostgreSQL does appear to use its own allocator for memory
passed across library boundaries, and if it doesn't pass any FILE
pointers across library boundaries either then that's the worst two
problems that arise with a C runtime mismatch taken care of. As far as I
know, anyway, and I've had the misfortune to have to dig into it a bit.

It seems like a good idea to use the same version of the same compiler
that your version of PostgreSQL was built with anyway. If nothing else,
I've only taken a cursory look at the code and have little knowledge
about it, so there could well be code paths/uses where memory is
malloc()'d in one DLL and freed()'d in another, etc. I'm sure there all
sorts of other possible wrinkles, and it'd just be easier to stick with
the same compiler. You can download Visual Studio 2005 Express Edition
for free from MS.

* Thankfully UNIXes tend to be sane enough to use the same C library
across all C compilers installed (and generally stick to one compiler
anyway), so most of us are able to avoid this exciting little complication.

--
Craig Ringer


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

No comments: