@@ -812,7 +812,7 @@ static char *simple_key_value_paired_stringtify
812812 */
813813static inline int switch_from_incomplete_obj_str_data
814814(struct incomplete_property_str * restrict dst , enum cjlib_json_datatypes type ,
815- cjlib_json_object * entry , bool init )
815+ cjlib_json_object * entry )
816816{
817817 struct cjlib_json_data * examine_entry_data = CJLIB_DICT_NODE_DATA (entry );
818818 * dst = (struct incomplete_property_str ) {
@@ -826,12 +826,8 @@ static inline int switch_from_incomplete_obj_str_data
826826
827827 cjlib_queue_init (dst -> i_pending_data_q );
828828
829- if (init ) {
830- if (CJLIB_OBJECT == type ) dst -> i_data .object = entry ;
831- } else {
832- if (CJLIB_OBJECT == type ) dst -> i_data .object = examine_entry_data -> c_value .c_obj ;
833- else dst -> i_data .array = examine_entry_data -> c_value .c_arr ;
834- }
829+ if (CJLIB_OBJECT == type ) dst -> i_data .object = entry ;
830+ else dst -> i_data .array = examine_entry_data -> c_value .c_arr ;
835831
836832 return 0 ;
837833}
@@ -899,9 +895,9 @@ const char *cjlib_json_object_stringtify(const cjlib_json_object *src)
899895 incomplete_property_str_init (& curr_incomp );
900896 cjlib_stack_init (& incomplete_st );
901897
902- if (-1 == switch_from_incomplete_obj_str_data (& curr_incomp , CJLIB_OBJECT , (cjlib_json_object * ) src , true )) return NULL ;
898+ if (-1 == switch_from_incomplete_obj_str_data (& curr_incomp , CJLIB_OBJECT , (cjlib_json_object * ) src )) return NULL ;
903899
904- if (-1 == cjlib_dict_postorder (curr_incomp .i_pending_data_q , curr_incomp .i_data .object )) return NULL ;
900+ if (-1 == cjlib_dict_preorder (curr_incomp .i_pending_data_q , curr_incomp .i_data .object )) return NULL ;
905901
906902 // Put a dummy entry in the stack to start the process.
907903 if (-1 == cjlib_stack_push ((void * ) & curr_incomp , sizeof (struct incomplete_property_str ),
@@ -944,25 +940,10 @@ const char *cjlib_json_object_stringtify(const cjlib_json_object *src)
944940 cjlib_stack_push (& curr_incomp , sizeof (struct incomplete_property_str ),
945941 & incomplete_st );
946942
947- /**
948- * (gdb) print(*examine_entry_data)
949- $23 = {c_value = {c_str = 0x40a640 "\200\231@", c_num = 2.0932889485015272e-317, c_boolean = 64, c_obj = 0x40a640,
950- c_null = 0x40a640, c_arr = 0x40a640}, c_datatype = CJLIB_OBJECT}
951-
952- (gdb) print(*examine_entry_data.c_value.c_obj)
953- $24 = {avl_data = 0x409980, avl_key = 0x4098c0 "request", avl_left = 0x409dd0, avl_right = 0x409c90}
954- (gdb) n
955- cjlib_stack_push(&curr_incomp, sizeof(struct incomplete_property_str),
956- (gdb) n
957- <----- HERE IS THE BUG ----- > TODO - When switching from array, DO NOT pass the examine entry.
958- if (-1 == switch_from_incomplete_obj_str_data(&curr_incomp, CJLIB_OBJECT, examine_entry, false)) return NULL;
959- (gdb)
960- if (-1 == cjlib_dict_postorder(curr_incomp.i_pending_data_q, curr_incomp.i_data.object)) return NULL;
961- */
962-
963- if (-1 == switch_from_incomplete_obj_str_data (& curr_incomp , CJLIB_OBJECT , examine_entry , false)) return NULL ;
943+ if (CJLIB_ARRAY == curr_incomp .i_type ) examine_entry = examine_entry_data -> c_value .c_obj ;
944+ if (-1 == switch_from_incomplete_obj_str_data (& curr_incomp , CJLIB_OBJECT , examine_entry )) return NULL ;
964945
965- if (-1 == cjlib_dict_postorder (curr_incomp .i_pending_data_q , curr_incomp .i_data .object )) return NULL ;
946+ if (-1 == cjlib_dict_preorder (curr_incomp .i_pending_data_q , curr_incomp .i_data .object )) return NULL ;
966947 break ;
967948 case CJLIB_ARRAY :
968949 cjlib_stack_push (& curr_incomp , sizeof (struct incomplete_property_str ), & incomplete_st );
@@ -999,6 +980,7 @@ const char *cjlib_json_object_stringtify(const cjlib_json_object *src)
999980 }
1000981
1001982 free (curr_incomp .i_key );
983+
1002984 // Return the now completed JSON.
1003985 return curr_incomp .i_state ;
1004986}
0 commit comments