1313#include < boost/http_proto/detail/config.hpp>
1414#include < boost/http_proto/service/zlib_service.hpp>
1515#include < zlib.h>
16+ #include < cstddef>
1617
1718namespace boost {
1819namespace http_proto {
@@ -33,10 +34,10 @@ struct stream_cast_impl
3334 zs_.next_out = st_.next_out ;
3435 zs_.avail_out = st_.avail_out ;
3536 zs_.total_out = st_.total_out ;
36- zs_.msg = st_. msg ;
37- zs_. state = st_.state ;
38- zs_.alloc = st_.zalloc ;
39- zs_.free = st_.zfree ;
37+ zs_.state = reinterpret_cast <
38+ internal_state*>( st_.state ) ;
39+ zs_.zalloc = st_.zalloc ;
40+ zs_.zfree = st_.zfree ;
4041 zs_.opaque = st_.opaque ;
4142 zs_.data_type = st_.data_type ;
4243 zs_.adler = st_.adler ;
@@ -53,18 +54,18 @@ struct stream_cast_impl
5354 st_.total_out = zs_.total_out ;
5455 st_.msg = zs_.msg ;
5556 st_.state = zs_.state ;
56- st_.alloc = zs_.zalloc ;
57- st_.free = zs_.zfree ;
57+ st_.zalloc = zs_.zalloc ;
58+ st_.zfree = zs_.zfree ;
5859 st_.opaque = zs_.opaque ;
5960 st_.data_type = zs_.data_type ;
6061 st_.adler = zs_.adler ;
6162 st_.reserved = zs_.reserved ;
6263 }
6364
64- z_stream_s&
65+ z_stream_s*
6566 get () noexcept
6667 {
67- return * pzs_;
68+ return pzs_;
6869 }
6970
7071private:
@@ -98,8 +99,42 @@ struct stream_cast_impl<false>
9899
99100// ------------------------------------------------
100101
102+ template <class T1 , class T2 >
103+ constexpr
104+ bool
105+ is_layout_identical ()
106+ {
107+ #define SAME_FIELD (T1, T2, M )( \
108+ (offsetof (T1 ,M)==offsetof (T2 ,M)) && \
109+ (std::is_same<T1 ::M,T2 ::M>::value) && \
110+ (sizeof (T1 ::M)==sizeof (T2 ::M)) )
111+ return
112+ sizeof (T1 ) == sizeof (T2 )
113+ #if 0
114+ SAME_FIELD(T1, T2, next_in)
115+ &&
116+ SAME_FIELD(T1, T2, avail_in) &&
117+ SAME_FIELD(T1, T2, total_in) &&
118+ SAME_FIELD(T1, T2, next_out) &&
119+ SAME_FIELD(T1, T2, avail_out) &&
120+ SAME_FIELD(T1, T2, total_out) &&
121+ SAME_FIELD(T1, T2, msg) &&
122+ SAME_FIELD(T1, T2, state) &&
123+ SAME_FIELD(T1, T2, zalloc) &&
124+ SAME_FIELD(T1, T2, zfree) &&
125+ SAME_FIELD(T1, T2, opaque) &&
126+ SAME_FIELD(T1, T2, data_type) &&
127+ SAME_FIELD(T1, T2, adler) &&
128+ SAME_FIELD(T1, T2, reserved)
129+ #endif
130+ ;
131+ }
132+
133+ // ------------------------------------------------
134+
101135// VFALCO A pinch of undefined behavior here
102- using stream_cast = stream_cast_impl<false >;
136+ using stream_cast = stream_cast_impl<
137+ is_layout_identical<stream_t , z_stream_s>()>;
103138
104139} // zlib
105140} // http_proto
0 commit comments