Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: RS2007/Indy10.6.2.0 (5359) - ZLib - Improper use of typedef 'z_stream'


This question is answered. Helpful answers available: 0. Correct answers available: 1.


Permlink Replies: 5 - Last Post: Jul 6, 2016 4:19 PM Last Post By: Remy Lebeau (Te...
Ted Lyngmo

Posts: 117
Registered: 10/3/06
RS2007/Indy10.6.2.0 (5359) - ZLib - Improper use of typedef 'z_stream'  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 5, 2016 1:10 PM
Hi!

I just noticed that zlib is part of Indy so I decided to drop the very old zlib download I've used so far and try using the one in Indy.

I placed a TIdCompressorZLib component on the form an wrote a small test program:
struct TOpenStreamBase {
	TStream *stream;
	TOpenStreamBase( TFileStream *opened ) : stream( opened ) {}
	virtual ~TOpenStreamBase() { delete stream; }
};
struct TFSIn : public TOpenStreamBase {
	TFSIn( AnsiString file ) : TOpenStreamBase( new TFileStream( file, fmOpenRead | fmShareDenyWrite ) ) {}
};
struct TFSOut : public TOpenStreamBase {
	TFSOut( AnsiString file ) : TOpenStreamBase( new TFileStream( file, fmCreate | fmShareDenyWrite ) ) {}
};
 
void __fastcall TForm1::btnExecClick(TObject *Sender) {
	try {
		TFSIn in( edtIn->Text );
		TFSOut out( edtOut->Text );
 
		Zlib->CompressStream(
			in.stream,
			out.stream,
			edtLevel->Text.ToIntDef(9),
			edtBits->Text.ToIntDef(31),
			8,
			0
		);
	} catch ( const Exception &ex ) {
		memo->Lines->Add( ex.Message );
	}
}

Compiling gives me these errors:
[BCC32 Error] IdZLibHeaders.hpp(78): E2108 Improper use of typedef 'z_stream'
[BCC32 Error] IdZLibHeaders.hpp(82): E2108 Improper use of typedef 'z_stream'
[BCC32 Error] IdZLibHeaders.hpp(123): E2108 Improper use of typedef 'gz_header'
[BCC32 Error] IdZLibHeaders.hpp(127): E2108 Improper use of typedef 'gz_header'

It seems to be complaining about these:
#if alignof(z_stream) < 1
...
#if alignof(gz_header) < 1

alignof() seems to be a C++11 addition.

I found http://www.programforge.com/8951625819/ ("bcb6 install the latest indy10.5.5 problems") giving me no solution: modify the header file related definitions. :-)
I didn't notice any problems when compiling and installing Indy. I don't know why I get this problem now or what to do about it. I'd prefer if I didn't have to modify the Indy headers since that will make this problem reappear when I upgrade Indy next time.

Ideas?

Br,
Ted
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: RS2007/Indy10.6.2.0 (5359) - ZLib - Improper use of typedef 'z_stream'
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 5, 2016 4:43 PM   in response to: Ted Lyngmo in response to: Ted Lyngmo
Ted wrote:

I just noticed that zlib is part of Indy so I decided to drop the very
old zlib download I've used so far and try using the one in Indy.

Delphi/C++Builder has had its own copy of ZLib for awhile now, in the System.ZLib
unit, which Indy has not been updated to use yet. I would not suggest using
Indy's ZLib standalone, it is primarily meant for zlib compression in TIdHTTP
specifically (and in the future, TIdHTTPServer).

It seems to be complaining about these:

#if alignof(z_stream) < 1
...
#if alignof(gz_header) < 1


alignof() seems to be a C++11 addition.

alignof() was added to C++Builder in CB2009 (in addition to other C++0x features
before C++11 was finalized):

http://docwiki.embarcadero.com/RADStudio/2010/en/C%2B%2B0x_Features_(C%2B%2BBuilder_2009)_Index

http://docwiki.embarcadero.com/RADStudio/2010/en/Alignof_Operator_(C%2B%2B0x)

http://docwiki.embarcadero.com/RADStudio/en/Alignof

Here is a page that shows how to implement alignof() manually:

http://www.wambold.com/Martin/writings/alignof.html

If that works, I can look into incorporating it into IdZLibHeaders.hpp.

I didn't notice any problems when compiling and installing Indy.

Indy is written in Delphi, not C++, and the IDE does not use .hpp files generated
for Delphi components.

I don't know why I get this problem now

Because alignof() is not available in CB2007.

or what to do about it. I'd prefer if I didn't have to modify the
Indy headers since that will make this problem reappear when
I upgrade Indy next time.

Unless the changes are incorporated into IdZLibHeaders.pas itself, which
has {$HPPEMIT} statements used when generating IdZLibHeaders.hpp, including
the alignof() statements.

--
Remy Lebeau (TeamB)
Ted Lyngmo

Posts: 117
Registered: 10/3/06
Re: RS2007/Indy10.6.2.0 (5359) - ZLib - Improper use of typedef 'z_stream'  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 6, 2016 12:17 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Ted wrote:

I just noticed that zlib is part of Indy so I decided to drop the very
old zlib download I've used so far and try using the one in Indy.

Delphi/C++Builder has had its own copy of ZLib for awhile now, in the System.ZLib
unit, which Indy has not been updated to use yet. I would not suggest using
Indy's ZLib standalone, it is primarily meant for zlib compression in TIdHTTP
specifically (and in the future, TIdHTTPServer).

I see. I'm mainly maintaining an old BCB4 project in which I've used a ZLib I downloaded in 2005. I've also used RS2007 to create a C++ DLL containing all the Indy stuff needed to keep the old BCB4 project alive (TLS 1.2 support etc) and was now thinking of adding support to use Indys Zlib to that DLL - to get any updates of ZLib that might be brought into Indy for free so to say. :-)

I found the ZLib included in RS2007 now. It says zlib_Version 1.0.4 and the version I currently use is 1.2.3 - so if using Indy's TIdCompressorZLib isn't recommended, I'm probably better off keeping my own ZLib copy up-to-date and to make some wrapper classes for it to avoid regression.

It seems to be complaining about these:

#if alignof(z_stream) < 1

alignof() was added to C++Builder in CB2009 (in addition to other C++0x features
before C++11 was finalized):
[...]
Here is a page that shows how to implement alignof() manually:

http://www.wambold.com/Martin/writings/alignof.html

If that works, I can look into incorporating it into IdZLibHeaders.hpp.

Oh, that'd be great. I downloaded that alignof implementation and perhaps it's possible to make something that works in a conditional compiler directive out of it.

I added my own definition of alignof and test thereof in my form's header file like this:
#define alignof(x) 0
#include "IdCompressorZLib.hpp"
#include "IdZLibCompressorBase.hpp"
#include <IdBaseComponent.hpp>
#if alignof(z_stream) < 1
#pragma message ("Hello world")
#endif


The compilation was then ok and I got the "Hello world" message, but I didn't get the warning message from within IdZLibHeaders.hpp I was expecting.
Compressing a file with this program and then uncompressing it with gunzip worked fine.

Indy is written in Delphi, not C++, and the IDE does not use .hpp files generated
for Delphi components.

Ah...

... what to do about it. I'd prefer if I didn't have to modify the
Indy headers since that will make this problem reappear when
I upgrade Indy next time.

Unless the changes are incorporated into IdZLibHeaders.pas itself, which
has {$HPPEMIT} statements used when generating IdZLibHeaders.hpp, including
the alignof() statements.

That sounds nice. I'll try to do something out of the alignof implementation you sent - or what about this? :-)

(*$HPPEMIT '#if __BORLANDC__ > 0x0593'*)
(*$HPPEMIT '#if alignof(z_stream) > 1'*)
...

I guess the directives to print out the "Pascal/C++ alignment mismatch" and "Pascal/C++ size mismatch" warnings were added for a reason but I wonder if isn't possible to make sure that the Pascal/C++ alignments and sizes always match (where it really matters) to get rid of the reason for these checks altogether? If these checks are important it seems a little risky to just send a warning via a pragma message that by default isn't shown in the (RS2007) IDE.

Br,
Ted
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: RS2007/Indy10.6.2.0 (5359) - ZLib - Improper use of typedef'z_stream'
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 6, 2016 1:21 PM   in response to: Ted Lyngmo in response to: Ted Lyngmo
Ted wrote:

I found the ZLib included in RS2007 now. It says zlib_Version
1.0.4 and the version I currently use is 1.2.3

http://www.base2ti.com has a Delphi wrapper unit for 1.2.8 (the current version
on http://www.zlib.net). I think Indy is still using 1.2.5.

I wonder if isn't possible to make sure that the Pascal/C++ alignments
and sizes always match (where it really matters) to get rid of the
reason for these checks altogether?

The checks are used because the actual definitions of z_stream and gz_stream
are not defined by Indy in C++, only in Pascal. The C++ definitions are
in zlib.h instead. And since z_stream and gz_stream are just plain structures
with no API functions to access their data members, Indy checks to make sure
the sizes and alignments match so passing a structure from C++ code into
Indy's Pascal code (and vice versa) will not cause problems when accessing
those data members directly.

--
Remy Lebeau (TeamB)
Ted Lyngmo

Posts: 117
Registered: 10/3/06
Re: RS2007/Indy10.6.2.0 (5359) - ZLib - Improper use of typedef'z_stream'  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 6, 2016 3:05 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Ted wrote:

I found the ZLib included in RS2007 now. It says zlib_Version
1.0.4 and the version I currently use is 1.2.3

http://www.base2ti.com has a Delphi wrapper unit for 1.2.8 (the current version
on http://www.zlib.net). I think Indy is still using 1.2.5.

Nice! That's definitely worth looking in to too. I think I'll make the classes as platform independent as I can but that wrapper may give me some ideas.

I wonder if isn't possible to make sure that the Pascal/C++ alignments
and sizes always match (where it really matters) to get rid of the
reason for these checks altogether?

The checks are used because the actual definitions of z_stream and gz_stream
are not defined by Indy in C++, only in Pascal. The C++ definitions are
in zlib.h instead. And since z_stream and gz_stream are just plain structures
with no API functions to access their data members, Indy checks to make sure
the sizes and alignments match so passing a structure from C++ code into
Indy's Pascal code (and vice versa) will not cause problems when accessing
those data members directly.

Ok, so it's an indirect verification of that the (hand written?) Pascal definitions matches the those in zlib.h too then I guess? Could the checks be moved into the compilation phase of the Pascal code and fail compiling if there's a mismatch?

Br,
Ted
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: RS2007/Indy10.6.2.0 (5359) - ZLib - Improper use oftypedef'z_stream'  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 6, 2016 4:19 PM   in response to: Ted Lyngmo in response to: Ted Lyngmo
Ted wrote:

Ok, so it's an indirect verification of that the (hand written?)
Pascal definitions matches the those in zlib.h too then I guess?

Something like that.

Could the checks be moved into the compilation phase of the
Pascal code and fail compiling if there's a mismatch?

No, because Pascal has no concept of C/C++ and cannot use C/C++ header files.
That is why things that are declared in C/C++ have to be redeclared in Pascal,
and why directives like {$NODECLARE} and {$EXTERNALSYM} exist in Delphi when
generating C/C++ .hpp files from Pascal code to avoid creating duplicates
on the C/C++ side.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02