Mercurial > hg > xemacs-beta
comparison src/dumper.c @ 647:b39c14581166
[xemacs-hg @ 2001-08-13 04:45:47 by ben]
removal of unsigned, size_t, etc.
author | ben |
---|---|
date | Mon, 13 Aug 2001 04:46:48 +0000 |
parents | 8d7292eb4a18 |
children | fdefd0186b75 |
comparison
equal
deleted
inserted
replaced
646:00c54252fe4f | 647:b39c14581166 |
---|---|
43 #endif | 43 #endif |
44 | 44 |
45 typedef struct | 45 typedef struct |
46 { | 46 { |
47 const void *varaddress; | 47 const void *varaddress; |
48 size_t size; | 48 Memory_Count size; |
49 } pdump_opaque; | 49 } pdump_opaque; |
50 | 50 |
51 typedef struct | 51 typedef struct |
52 { | 52 { |
53 Dynarr_declare (pdump_opaque); | 53 Dynarr_declare (pdump_opaque); |
82 static Lisp_Object_ptr_dynarr *pdump_weak_object_chains; | 82 static Lisp_Object_ptr_dynarr *pdump_weak_object_chains; |
83 | 83 |
84 /* Mark SIZE bytes at non-heap address VARADDRESS for dumping as is, | 84 /* Mark SIZE bytes at non-heap address VARADDRESS for dumping as is, |
85 without any bit-twiddling. */ | 85 without any bit-twiddling. */ |
86 void | 86 void |
87 dump_add_opaque (const void *varaddress, size_t size) | 87 dump_add_opaque (const void *varaddress, Memory_Count size) |
88 { | 88 { |
89 pdump_opaque info; | 89 pdump_opaque info; |
90 info.varaddress = varaddress; | 90 info.varaddress = varaddress; |
91 info.size = size; | 91 info.size = size; |
92 if (pdump_opaques == NULL) | 92 if (pdump_opaques == NULL) |
127 Dynarr_add (pdump_weak_object_chains, varaddress); | 127 Dynarr_add (pdump_weak_object_chains, varaddress); |
128 } | 128 } |
129 | 129 |
130 | 130 |
131 inline static void | 131 inline static void |
132 pdump_align_stream (FILE *stream, size_t alignment) | 132 pdump_align_stream (FILE *stream, Memory_Count alignment) |
133 { | 133 { |
134 long offset = ftell (stream); | 134 long offset = ftell (stream); |
135 long adjustment = ALIGN_SIZE (offset, alignment) - offset; | 135 long adjustment = ALIGN_SIZE (offset, alignment) - offset; |
136 if (adjustment) | 136 if (adjustment) |
137 fseek (stream, adjustment, SEEK_CUR); | 137 fseek (stream, adjustment, SEEK_CUR); |
213 int nb_opaques; | 213 int nb_opaques; |
214 } pdump_header; | 214 } pdump_header; |
215 | 215 |
216 char *pdump_start; | 216 char *pdump_start; |
217 char *pdump_end; | 217 char *pdump_end; |
218 static size_t pdump_length; | 218 static Memory_Count pdump_length; |
219 | 219 |
220 #ifdef WIN32_NATIVE | 220 #ifdef WIN32_NATIVE |
221 /* Handle for the dump file */ | 221 /* Handle for the dump file */ |
222 static HANDLE pdump_hFile = INVALID_HANDLE_VALUE; | 222 static HANDLE pdump_hFile = INVALID_HANDLE_VALUE; |
223 /* Handle for the file mapping object for the dump file */ | 223 /* Handle for the file mapping object for the dump file */ |
232 16, 1, 2, 1, 4, 1, 2, 1, 8, 1, 2, 1, 4, 1, 2, 1, | 232 16, 1, 2, 1, 4, 1, 2, 1, 8, 1, 2, 1, 4, 1, 2, 1, |
233 32, 1, 2, 1, 4, 1, 2, 1, 8, 1, 2, 1, 4, 1, 2, 1, | 233 32, 1, 2, 1, 4, 1, 2, 1, 8, 1, 2, 1, 4, 1, 2, 1, |
234 16, 1, 2, 1, 4, 1, 2, 1, 8, 1, 2, 1, 4, 1, 2, 1 | 234 16, 1, 2, 1, 4, 1, 2, 1, 8, 1, 2, 1, 4, 1, 2, 1 |
235 }; | 235 }; |
236 | 236 |
237 static inline unsigned int | 237 static inline int |
238 pdump_size_to_align (size_t size) | 238 pdump_size_to_align (Memory_Count size) |
239 { | 239 { |
240 return pdump_align_table[size % countof (pdump_align_table)]; | 240 return pdump_align_table[size % countof (pdump_align_table)]; |
241 } | 241 } |
242 | 242 |
243 typedef struct pdump_entry_list_elt | 243 typedef struct pdump_entry_list_elt |
244 { | 244 { |
245 struct pdump_entry_list_elt *next; | 245 struct pdump_entry_list_elt *next; |
246 const void *obj; | 246 const void *obj; |
247 size_t size; | 247 Memory_Count size; |
248 int count; | 248 int count; |
249 EMACS_INT save_offset; | 249 EMACS_INT save_offset; |
250 } pdump_entry_list_elt; | 250 } pdump_entry_list_elt; |
251 | 251 |
252 typedef struct | 252 typedef struct |
274 static pdump_struct_list pdump_struct_table; | 274 static pdump_struct_list pdump_struct_table; |
275 | 275 |
276 static int *pdump_alert_undump_object; | 276 static int *pdump_alert_undump_object; |
277 | 277 |
278 static unsigned long cur_offset; | 278 static unsigned long cur_offset; |
279 static size_t max_size; | 279 static Memory_Count max_size; |
280 static int pdump_fd; | 280 static int pdump_fd; |
281 static void *pdump_buf; | 281 static void *pdump_buf; |
282 static FILE *pdump_out; | 282 static FILE *pdump_out; |
283 | 283 |
284 #define PDUMP_HASHSIZE 200001 | 284 #define PDUMP_HASHSIZE 200001 |
311 } | 311 } |
312 return 0; | 312 return 0; |
313 } | 313 } |
314 | 314 |
315 static void | 315 static void |
316 pdump_add_entry (pdump_entry_list *list, const void *obj, size_t size, | 316 pdump_add_entry (pdump_entry_list *list, const void *obj, Memory_Count size, |
317 int count) | 317 int count) |
318 { | 318 { |
319 pdump_entry_list_elt *e; | 319 pdump_entry_list_elt *e; |
320 int pos = pdump_make_hash (obj); | 320 int pos = pdump_make_hash (obj); |
321 | 321 |
421 int delta = XD_INDIRECT_DELTA (code); | 421 int delta = XD_INDIRECT_DELTA (code); |
422 | 422 |
423 irdata = ((char *)idata) + idesc[line].offset; | 423 irdata = ((char *)idata) + idesc[line].offset; |
424 switch (idesc[line].type) | 424 switch (idesc[line].type) |
425 { | 425 { |
426 case XD_SIZE_T: | 426 case XD_MEMORY_COUNT: |
427 count = *(size_t *)irdata; | 427 count = *(Memory_Count *)irdata; |
428 break; | |
429 case XD_ELEMENT_COUNT: | |
430 count = *(Element_Count *)irdata; | |
431 break; | |
432 case XD_HASH_CODE: | |
433 count = *(Hash_Code *)irdata; | |
428 break; | 434 break; |
429 case XD_INT: | 435 case XD_INT: |
430 count = *(int *)irdata; | 436 count = *(int *)irdata; |
431 break; | 437 break; |
432 case XD_LONG: | 438 case XD_LONG: |
437 break; | 443 break; |
438 default: | 444 default: |
439 stderr_out ("Unsupported count type : %d (line = %d, code=%ld)\n", | 445 stderr_out ("Unsupported count type : %d (line = %d, code=%ld)\n", |
440 idesc[line].type, line, (long)code); | 446 idesc[line].type, line, (long)code); |
441 pdump_backtrace (); | 447 pdump_backtrace (); |
448 count = 0; /* warning suppression */ | |
442 abort (); | 449 abort (); |
443 } | 450 } |
444 count += delta; | 451 count += delta; |
445 return count; | 452 return count; |
446 } | 453 } |
462 { | 469 { |
463 case XD_SPECIFIER_END: | 470 case XD_SPECIFIER_END: |
464 pos = 0; | 471 pos = 0; |
465 desc = ((const Lisp_Specifier *)data)->methods->extra_description; | 472 desc = ((const Lisp_Specifier *)data)->methods->extra_description; |
466 goto restart; | 473 goto restart; |
467 case XD_SIZE_T: | 474 case XD_MEMORY_COUNT: |
475 case XD_ELEMENT_COUNT: | |
476 case XD_HASH_CODE: | |
468 case XD_INT: | 477 case XD_INT: |
469 case XD_LONG: | 478 case XD_LONG: |
470 case XD_BYTECOUNT: | 479 case XD_BYTECOUNT: |
471 case XD_INT_RESET: | 480 case XD_INT_RESET: |
472 case XD_LO_LINK: | 481 case XD_LO_LINK: |
623 | 632 |
624 static void | 633 static void |
625 pdump_dump_data (pdump_entry_list_elt *elt, | 634 pdump_dump_data (pdump_entry_list_elt *elt, |
626 const struct lrecord_description *desc) | 635 const struct lrecord_description *desc) |
627 { | 636 { |
628 size_t size = elt->size; | 637 Memory_Count size = elt->size; |
629 int count = elt->count; | 638 int count = elt->count; |
630 if (desc) | 639 if (desc) |
631 { | 640 { |
632 int pos, i; | 641 int pos, i; |
633 memcpy (pdump_buf, elt->obj, size*count); | 642 memcpy (pdump_buf, elt->obj, size*count); |
642 switch (desc[pos].type) | 651 switch (desc[pos].type) |
643 { | 652 { |
644 case XD_SPECIFIER_END: | 653 case XD_SPECIFIER_END: |
645 desc = ((const Lisp_Specifier *)(elt->obj))->methods->extra_description; | 654 desc = ((const Lisp_Specifier *)(elt->obj))->methods->extra_description; |
646 goto restart; | 655 goto restart; |
647 case XD_SIZE_T: | 656 case XD_MEMORY_COUNT: |
657 case XD_ELEMENT_COUNT: | |
658 case XD_HASH_CODE: | |
648 case XD_INT: | 659 case XD_INT: |
649 case XD_LONG: | 660 case XD_LONG: |
650 case XD_BYTECOUNT: | 661 case XD_BYTECOUNT: |
651 break; | 662 break; |
652 case XD_INT_RESET: | 663 case XD_INT_RESET: |
738 { | 749 { |
739 case XD_SPECIFIER_END: | 750 case XD_SPECIFIER_END: |
740 pos = 0; | 751 pos = 0; |
741 desc = ((const Lisp_Specifier *)data)->methods->extra_description; | 752 desc = ((const Lisp_Specifier *)data)->methods->extra_description; |
742 goto restart; | 753 goto restart; |
743 case XD_SIZE_T: | 754 case XD_MEMORY_COUNT: |
755 case XD_ELEMENT_COUNT: | |
756 case XD_HASH_CODE: | |
744 case XD_INT: | 757 case XD_INT: |
745 case XD_LONG: | 758 case XD_LONG: |
746 case XD_BYTECOUNT: | 759 case XD_BYTECOUNT: |
747 case XD_INT_RESET: | 760 case XD_INT_RESET: |
748 break; | 761 break; |
801 | 814 |
802 static void | 815 static void |
803 pdump_allocate_offset (pdump_entry_list_elt *elt, | 816 pdump_allocate_offset (pdump_entry_list_elt *elt, |
804 const struct lrecord_description *desc) | 817 const struct lrecord_description *desc) |
805 { | 818 { |
806 size_t size = elt->count * elt->size; | 819 Memory_Count size = elt->count * elt->size; |
807 elt->save_offset = cur_offset; | 820 elt->save_offset = cur_offset; |
808 if (size>max_size) | 821 if (size>max_size) |
809 max_size = size; | 822 max_size = size; |
810 cur_offset += size; | 823 cur_offset += size; |
811 } | 824 } |
842 | 855 |
843 static void | 856 static void |
844 pdump_dump_root_struct_ptrs (void) | 857 pdump_dump_root_struct_ptrs (void) |
845 { | 858 { |
846 int i; | 859 int i; |
847 size_t count = Dynarr_length (pdump_root_struct_ptrs); | 860 Element_Count count = Dynarr_length (pdump_root_struct_ptrs); |
848 pdump_static_pointer *data = alloca_array (pdump_static_pointer, count); | 861 pdump_static_pointer *data = alloca_array (pdump_static_pointer, count); |
849 for (i = 0; i < count; i++) | 862 for (i = 0; i < count; i++) |
850 { | 863 { |
851 data[i].address = (char **) Dynarr_atp (pdump_root_struct_ptrs, i)->ptraddress; | 864 data[i].address = (char **) Dynarr_atp (pdump_root_struct_ptrs, i)->ptraddress; |
852 data[i].value = (char *) pdump_get_entry (* data[i].address)->save_offset; | 865 data[i].value = (char *) pdump_get_entry (* data[i].address)->save_offset; |
918 } | 931 } |
919 | 932 |
920 static void | 933 static void |
921 pdump_dump_root_objects (void) | 934 pdump_dump_root_objects (void) |
922 { | 935 { |
923 size_t count = (Dynarr_length (pdump_root_objects) + | 936 Element_Count count = (Dynarr_length (pdump_root_objects) + |
924 Dynarr_length (pdump_weak_object_chains)); | 937 Dynarr_length (pdump_weak_object_chains)); |
925 size_t i; | 938 Element_Count i; |
926 | 939 |
927 PDUMP_WRITE_ALIGNED (size_t, count); | 940 PDUMP_WRITE_ALIGNED (Element_Count, count); |
928 PDUMP_ALIGN_OUTPUT (pdump_static_Lisp_Object); | 941 PDUMP_ALIGN_OUTPUT (pdump_static_Lisp_Object); |
929 | 942 |
930 for (i=0; i<Dynarr_length (pdump_root_objects); i++) | 943 for (i = 0; i < Dynarr_length (pdump_root_objects); i++) |
931 { | 944 { |
932 pdump_static_Lisp_Object obj; | 945 pdump_static_Lisp_Object obj; |
933 obj.address = Dynarr_at (pdump_root_objects, i); | 946 obj.address = Dynarr_at (pdump_root_objects, i); |
934 obj.value = * obj.address; | 947 obj.value = * obj.address; |
935 | 948 |
1140 if (!(--count)) | 1153 if (!(--count)) |
1141 break; | 1154 break; |
1142 } | 1155 } |
1143 | 1156 |
1144 /* Put the pdump_root_objects variables in place */ | 1157 /* Put the pdump_root_objects variables in place */ |
1145 i = PDUMP_READ_ALIGNED (p, size_t); | 1158 i = PDUMP_READ_ALIGNED (p, Element_Count); |
1146 p = (char *) ALIGN_PTR (p, ALIGNOF (pdump_static_Lisp_Object)); | 1159 p = (char *) ALIGN_PTR (p, ALIGNOF (pdump_static_Lisp_Object)); |
1147 while (i--) | 1160 while (i--) |
1148 { | 1161 { |
1149 pdump_static_Lisp_Object obj = PDUMP_READ (p, pdump_static_Lisp_Object); | 1162 pdump_static_Lisp_Object obj = PDUMP_READ (p, pdump_static_Lisp_Object); |
1150 | 1163 |
1256 if (pdump_start == NULL) | 1269 if (pdump_start == NULL) |
1257 return 0; | 1270 return 0; |
1258 | 1271 |
1259 pdump_free = pdump_resource_free; | 1272 pdump_free = pdump_resource_free; |
1260 pdump_length = SizeofResource (NULL, hRes); | 1273 pdump_length = SizeofResource (NULL, hRes); |
1261 if (pdump_length <= sizeof (pdump_header)) | 1274 if (pdump_length <= (Memory_Count) sizeof (pdump_header)) |
1262 { | 1275 { |
1263 pdump_start = 0; | 1276 pdump_start = 0; |
1264 return 0; | 1277 return 0; |
1265 } | 1278 } |
1266 | 1279 |
1289 int fd = open (path, O_RDONLY | OPEN_BINARY); | 1302 int fd = open (path, O_RDONLY | OPEN_BINARY); |
1290 if (fd<0) | 1303 if (fd<0) |
1291 return 0; | 1304 return 0; |
1292 | 1305 |
1293 pdump_length = lseek (fd, 0, SEEK_END); | 1306 pdump_length = lseek (fd, 0, SEEK_END); |
1294 if (pdump_length < sizeof (pdump_header)) | 1307 if (pdump_length < (Memory_Count) sizeof (pdump_header)) |
1295 { | 1308 { |
1296 close (fd); | 1309 close (fd); |
1297 return 0; | 1310 return 0; |
1298 } | 1311 } |
1299 | 1312 |