@@ -611,7 +611,7 @@ int h2_fake_peer_send_data_frame_with_padding_length(
611611 ASSERT_TRUE (msg -> message_data .len != 0 );
612612
613613 ASSERT_SUCCESS (testing_channel_push_read_message (peer -> testing_channel , msg ));
614- aws_input_stream_destroy (body_stream );
614+ aws_input_stream_release (body_stream );
615615 return AWS_OP_SUCCESS ;
616616}
617617
@@ -643,6 +643,8 @@ int h2_fake_peer_send_connection_preface_default_settings(struct h2_fake_peer *p
643643/******************************************************************************/
644644
645645struct aws_input_stream_tester {
646+ struct aws_input_stream base ;
647+ struct aws_allocator * allocator ;
646648 /* aws_input_stream_byte_cursor provides our actual functionality */
647649 struct aws_input_stream * cursor_stream ;
648650
@@ -655,12 +657,12 @@ static int s_aws_input_stream_tester_seek(
655657 int64_t offset ,
656658 enum aws_stream_seek_basis basis ) {
657659
658- struct aws_input_stream_tester * impl = stream -> impl ;
660+ struct aws_input_stream_tester * impl = AWS_CONTAINER_OF ( stream , struct aws_input_stream_tester , base ) ;
659661 return aws_input_stream_seek (impl -> cursor_stream , offset , basis );
660662}
661663
662664static int s_aws_input_stream_tester_read (struct aws_input_stream * stream , struct aws_byte_buf * dest ) {
663- struct aws_input_stream_tester * impl = stream -> impl ;
665+ struct aws_input_stream_tester * impl = AWS_CONTAINER_OF ( stream , struct aws_input_stream_tester , base ) ;
664666
665667 if (impl -> is_reading_broken ) {
666668 return aws_raise_error (AWS_IO_STREAM_READ_FAILED );
@@ -678,60 +680,49 @@ static int s_aws_input_stream_tester_read(struct aws_input_stream *stream, struc
678680}
679681
680682static int s_aws_input_stream_tester_get_status (struct aws_input_stream * stream , struct aws_stream_status * status ) {
681- struct aws_input_stream_tester * impl = stream -> impl ;
683+ struct aws_input_stream_tester * impl = AWS_CONTAINER_OF ( stream , struct aws_input_stream_tester , base ) ;
682684 return aws_input_stream_get_status (impl -> cursor_stream , status );
683685}
684686
685687static int s_aws_input_stream_tester_get_length (struct aws_input_stream * stream , int64_t * out_length ) {
686- struct aws_input_stream_tester * impl = stream -> impl ;
688+ struct aws_input_stream_tester * impl = AWS_CONTAINER_OF ( stream , struct aws_input_stream_tester , base ) ;
687689 return aws_input_stream_get_length (impl -> cursor_stream , out_length );
688690}
689691
690- static void s_aws_input_stream_tester_destroy (struct aws_input_stream * stream ) {
691- if (stream ) {
692- struct aws_input_stream_tester * impl = stream -> impl ;
693- aws_input_stream_destroy (impl -> cursor_stream );
694- aws_mem_release (stream -> allocator , stream );
695- }
692+ static void s_aws_input_stream_tester_destroy (struct aws_input_stream_tester * impl ) {
693+ aws_input_stream_release (impl -> cursor_stream );
694+ aws_mem_release (impl -> allocator , impl );
696695}
697696
698697static struct aws_input_stream_vtable s_aws_input_stream_tester_vtable = {
699698 .seek = s_aws_input_stream_tester_seek ,
700699 .read = s_aws_input_stream_tester_read ,
701700 .get_status = s_aws_input_stream_tester_get_status ,
702701 .get_length = s_aws_input_stream_tester_get_length ,
703- .destroy = s_aws_input_stream_tester_destroy ,
704702};
705703
706704struct aws_input_stream * aws_input_stream_new_tester (struct aws_allocator * alloc , struct aws_byte_cursor cursor ) {
707705
708- struct aws_input_stream * stream = NULL ;
709- struct aws_input_stream_tester * impl = NULL ;
710- aws_mem_acquire_many (
711- alloc , 2 , & stream , sizeof (struct aws_input_stream ), & impl , sizeof (struct aws_input_stream_tester ));
712- AWS_FATAL_ASSERT (stream );
713-
714- AWS_ZERO_STRUCT (* stream );
715- AWS_ZERO_STRUCT (* impl );
716-
717- stream -> allocator = alloc ;
718- stream -> impl = impl ;
719- stream -> vtable = & s_aws_input_stream_tester_vtable ;
706+ struct aws_input_stream_tester * impl = aws_mem_calloc (alloc , 1 , sizeof (struct aws_input_stream_tester ));
707+ AWS_FATAL_ASSERT (impl );
720708
721709 impl -> max_bytes_per_read = SIZE_MAX ;
722710
723711 impl -> cursor_stream = aws_input_stream_new_from_cursor (alloc , & cursor );
724712 AWS_FATAL_ASSERT (impl -> cursor_stream );
725-
726- return stream ;
713+ impl -> allocator = alloc ;
714+ impl -> base .vtable = & s_aws_input_stream_tester_vtable ;
715+ aws_ref_count_init (
716+ & impl -> base .ref_count , impl , (aws_simple_completion_callback * )s_aws_input_stream_tester_destroy );
717+ return & impl -> base ;
727718}
728719
729720void aws_input_stream_tester_set_max_bytes_per_read (struct aws_input_stream * input_stream , size_t max_bytes ) {
730- struct aws_input_stream_tester * impl = input_stream -> impl ;
721+ struct aws_input_stream_tester * impl = AWS_CONTAINER_OF ( input_stream , struct aws_input_stream_tester , base ) ;
731722 impl -> max_bytes_per_read = max_bytes ;
732723}
733724
734725void aws_input_stream_tester_set_reading_broken (struct aws_input_stream * input_stream , bool is_broken ) {
735- struct aws_input_stream_tester * impl = input_stream -> impl ;
726+ struct aws_input_stream_tester * impl = AWS_CONTAINER_OF ( input_stream , struct aws_input_stream_tester , base ) ;
736727 impl -> is_reading_broken = is_broken ;
737728}
0 commit comments