@@ -95,3 +95,84 @@ int add_structure_to_struct_db(struct_db_t *struct_db, struct_db_rec_t *struct_r
95
95
struct_db -> count ++ ;
96
96
return 0 ;
97
97
}
98
+
99
+ static struct_db_rec_t
100
+ * struct_db_look_up (struct_db_t * struct_db ,
101
+ char * struct_name ) {
102
+ struct_db_rec_t * head = struct_db -> head ;
103
+ if (!head ) return NULL ;
104
+ for (; head ; head = head -> next ) {
105
+ if (strncmp (head -> struct_name , struct_name , MAX_STRUCTURE_NAME_SIZE ) == 0 )
106
+ return head ;
107
+ }
108
+ return NULL ;
109
+ }
110
+
111
+ static object_db_rec_t
112
+ * object_db_look_up (object_db_t * object_db , void * ptr ) {
113
+ object_db_rec_t * head = object -> head ;
114
+ if (!head ) return NULL ;
115
+ for (; head ; head = head -> next ) {
116
+ if (head -> ptr == ptr )
117
+ return head ;
118
+ }
119
+ return NULL ;
120
+ }
121
+
122
+ /* To work with objects */
123
+ static void add_object_to_object_db (object_db_t * object_db ,
124
+ void * ptr ,
125
+ int units ,
126
+ struct_db_rec_t * struct_rec ,
127
+ mld_boolean_t is_root ) {
128
+ object_db_rec_t * obj_rec = object_db_look_up (object_db , ptr );
129
+ /* Don't add same object twice */
130
+ assert (!obj_rec );
131
+
132
+ obj_rec = calloc (1 , sizeof (object_db_rec_t ));
133
+
134
+ obj_rec -> next = NULL ;
135
+ obj_rec -> ptr = ptr ;
136
+ obj_rec -> units = units ;
137
+ obj_rec -> struct_rec = struct_rec ;
138
+ obj_rec -> is_visited = MLD_FALSE ;
139
+ obj_rec -> is_root = is_root ;
140
+
141
+ object_db_rec_t * head = object_db -> head ;
142
+
143
+ if (!head ) {
144
+ object_db -> head = obj_rec ;
145
+ object -> next = NULL ;
146
+ object_db -> count ++ ;
147
+ return ;
148
+ }
149
+ obj_rec -> next = head ;
150
+ object_db -> head = obj_rec ;
151
+ object_db -> count ++ ;
152
+ }
153
+
154
+ void * xcalloc (object_db_t * object_db , char * struct_name , int uints ) {
155
+ struct_db_rec_t * struct_rec = struct_db_look_up (object_db -> struct_db , struct_name );
156
+ assert (struct_rec );
157
+
158
+ void * ptr = calloc (uints , struct_rec -> ds_size );
159
+ add_object_to_object_db (object_db , ptr , uints , strutc_rec , MLD_FALSE );
160
+ return ptr ;
161
+ }
162
+
163
+ /* Print functions for object database */
164
+ void print_object_rec (object_db_rec_t * obj_rec , int i ) {
165
+ if (!obj_rec ) return ;
166
+ printf (ANSI_COLOR_MAGENTA "--------------------------|\n" ANSI_COLOR_RESET );
167
+ printf (ANSI_COLOR_YELLOW "%-3d ptr = %-10p | next = %-10p | units = %-4d | struct_name = %-10s | is_root = %s |\n" ANSI_COLOR_RESET , i , obj_rec -> ptr , obj_rec -> next , obj_rec -> units , obj_rec -> struct_rec -> struct_name , obj_rec -> is_root ? "TRUE" : "FALSE" );
168
+ printf (ANSI_COLOR_MAGENTA "--------------------------|\n" ANSI_COLOR_RESET );
169
+ }
170
+
171
+ void print_object_db (object_db_t * object_db ) {
172
+ object_db_rec_t * head = object_db -> head ;
173
+ unsigned int i = 0 ;
174
+ printf (ANSI_COLOR_CYAN "Printing OBJECT DATABASE\n" );
175
+ for (; head ; head -> next ) {
176
+ print_object_rec (head , i ++ );
177
+ }
178
+ }
0 commit comments