I am having some trouble interfacing the 7.5 server built with MINGW
with tools generated using other compilers.

I suspect that the issue is one of default structure packing.  In the
old version we were using, we built PostgreSQL using Intel C++ or MS
VC++ and the same for the libpq and other interfaces.

Now that I have built the server and associated tools with Mingw and a
version of the interface system with MS VC++ and Intel C++, I have
problems using (for instance) libpq.

Some character strings returned early in the struct are fine, but the
numeric fields occurring later are garbled.

Now, this issue seems like it must have happened before, since the
server might be generated on some 64 bit platform and the interface
library on some other platform.

In particular, this function:

char *PQgetvalue(const PGresult *res, int tup_num, int field_num)
{
	if (!check_tuple_field_number(res, tup_num, field_num))
		return NULL;
	return res->tuples[tup_num][field_num].value;
}

Seems to return nonsense when I get to pointers to non-character data.

Any thoughts?

Mon, 5 Apr 2004 17:43:08 -0700
"Dann Corbit" <DCorbit@connx.com>
7.5 beta version

I don't think you can mix libs/binaries from different compilers.

---------------------------------------------------------------------------

Dann Corbit wrote:
> I am having some trouble interfacing the 7.5 server built with MINGW
> with tools generated using other compilers.
> 
> I suspect that the issue is one of default structure packing.  In the
> old version we were using, we built PostgreSQL using Intel C++ or MS
> VC++ and the same for the libpq and other interfaces.
> 
> Now that I have built the server and associated tools with Mingw and a
> version of the interface system with MS VC++ and Intel C++, I have
> problems using (for instance) libpq.
> 
> Some character strings returned early in the struct are fine, but the
> numeric fields occurring later are garbled.
> 
> Now, this issue seems like it must have happened before, since the
> server might be generated on some 64 bit platform and the interface
> library on some other platform.
> 
> In particular, this function:
> 
> char *PQgetvalue(const PGresult *res, int tup_num, int field_num)
> {
> 	if (!check_tuple_field_number(res, tup_num, field_num))
> 		return NULL;
> 	return res->tuples[tup_num][field_num].value;
> }
> 
> Seems to return nonsense when I get to pointers to non-character data.
> 
> Any thoughts?
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
> 
>                http://archives.postgresql.org
> 

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Mon, 5 Apr 2004 21:38:13 -0400 (EDT)
Bruce Momjian <pgman@candle.pha.pa.us>
Re: 7.5 beta version
On Mon, Apr 05, 2004 at 09:38:13PM -0400, Bruce Momjian wrote:
> 
> I don't think you can mix libs/binaries from different compilers.

As long as it's plain old C, and the compilers adhere to the platform's
ABI standards, why not?  Even if you compile the C code using a C++
compiler, as in this case, any C structs will be PODs and so should be
compiled according to the C layout rules.


Jeroen


Sun, 11 Apr 2004 16:28:14 +0200
"Jeroen T. Vermeulen" <jtv@xs4all.nl>
Re: 7.5 beta version
Jeroen T. Vermeulen wrote:
> On Mon, Apr 05, 2004 at 09:38:13PM -0400, Bruce Momjian wrote:
> > 
> > I don't think you can mix libs/binaries from different compilers.
> 
> As long as it's plain old C, and the compilers adhere to the platform's
> ABI standards, why not?  Even if you compile the C code using a C++
> compiler, as in this case, any C structs will be PODs and so should be
> compiled according to the C layout rules.

I was not sure if Win32 had standard alignment for C.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Sun, 11 Apr 2004 22:21:30 -0400 (EDT)
Bruce Momjian <pgman@candle.pha.pa.us>
Re: 7.5 beta version
On Sun, Apr 11, 2004 at 10:21:30PM -0400, Bruce Momjian wrote:
 
> I was not sure if Win32 had standard alignment for C.

Good point.  There's standards, and then there's Windows.  It's possible
that separate "tight-packing" and "regular" pragmas are used there, just
for structs that are expected to be used across linkage boundaries.


Jeroen


Mon, 12 Apr 2004 11:26:16 +0200
"Jeroen T. Vermeulen" <jtv@xs4all.nl>
Re: 7.5 beta version
"Jeroen T. Vermeulen" <jtv@xs4all.nl> writes:
> On Sun, Apr 11, 2004 at 10:21:30PM -0400, Bruce Momjian wrote:
>> I was not sure if Win32 had standard alignment for C.

> Good point.  There's standards, and then there's Windows.  It's possible
> that separate "tight-packing" and "regular" pragmas are used there, just
> for structs that are expected to be used across linkage boundaries.

"#pragma pack" is one of the worst, most dangerous inventions in the
history of software development :-(.  However, I don't think we should
be at any great risk from it, since we don't use it in our own code.
The case that's really hazardous is where you have separately compiled
libraries interfacing through nontrivial struct declarations...  I still
have the scars from making libjpeg do things that way...

			regards, tom lane

Mon, 12 Apr 2004 08:35:16 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: 7.5 beta version 