Mercurial > emacs
comparison src/alloc.c @ 35183:cc2a06489f0d
(CHECK_STRING_BYTES) [GC_CHECK_STRING_BYTES]: New macro.
(check_sblock, string_bytes) [GC_CHECK_STRING_BYTES]: New functions.
(check_string_bytes) [GC_CHECK_STRING_BYTES]: Add parameter ALL_P.
(allocate_string) [GC_CHECK_STRING_BYTES]: Always check strings in
the current sblock.
(mark_object) [GC_CHECK_STRING_BYTES]: Use CHECK_STRING_BYTES.
(gc_sweep) [GC_CHECK_STRING_BYTES]: Call check_string_bytes
after sweeping strings, and at the end.
(GC_CHECK_STRING_BYTES): Moved to lisp.h.
| author | Gerd Moellmann <gerd@gnu.org> |
|---|---|
| date | Tue, 09 Jan 2001 20:10:50 +0000 |
| parents | a9b677239421 |
| children | b9366f467430 |
comparison
equal
deleted
inserted
replaced
| 35182:fcdd43bc1c33 | 35183:cc2a06489f0d |
|---|---|
| 23 #include <stdio.h> | 23 #include <stdio.h> |
| 24 | 24 |
| 25 /* Note that this declares bzero on OSF/1. How dumb. */ | 25 /* Note that this declares bzero on OSF/1. How dumb. */ |
| 26 | 26 |
| 27 #include <signal.h> | 27 #include <signal.h> |
| 28 | |
| 29 /* Define this temporarily to hunt a bug. If defined, the size of | |
| 30 strings is redundantly recorded in sdata structures so that it can | |
| 31 be compared to the sizes recorded in Lisp strings. */ | |
| 32 | |
| 33 #define GC_CHECK_STRING_BYTES 1 | |
| 34 | 28 |
| 35 /* GC_MALLOC_CHECK defined means perform validity checks of malloc'd | 29 /* GC_MALLOC_CHECK defined means perform validity checks of malloc'd |
| 36 memory. Can do this only if using gmalloc.c. */ | 30 memory. Can do this only if using gmalloc.c. */ |
| 37 | 31 |
| 38 #if defined SYSTEM_MALLOC || defined DOUG_LEA_MALLOC | 32 #if defined SYSTEM_MALLOC || defined DOUG_LEA_MALLOC |
| 1199 } | 1193 } |
| 1200 | 1194 |
| 1201 | 1195 |
| 1202 #ifdef GC_CHECK_STRING_BYTES | 1196 #ifdef GC_CHECK_STRING_BYTES |
| 1203 | 1197 |
| 1204 /* Check validity of all live Lisp strings' string_bytes member. | |
| 1205 Used for hunting a bug. */ | |
| 1206 | |
| 1207 static int check_string_bytes_count; | 1198 static int check_string_bytes_count; |
| 1208 | 1199 |
| 1200 void check_string_bytes P_ ((int)); | |
| 1201 void check_sblock P_ ((struct sblock *)); | |
| 1202 | |
| 1203 #define CHECK_STRING_BYTES(S) STRING_BYTES (S) | |
| 1204 | |
| 1205 | |
| 1206 /* Like GC_STRING_BYTES, but with debugging check. */ | |
| 1207 | |
| 1208 int | |
| 1209 string_bytes (s) | |
| 1210 struct Lisp_String *s; | |
| 1211 { | |
| 1212 int nbytes = (s->size_byte < 0 ? s->size : s->size_byte) & ~MARKBIT; | |
| 1213 if (!PURE_POINTER_P (s) | |
| 1214 && s->data | |
| 1215 && nbytes != SDATA_NBYTES (SDATA_OF_STRING (s))) | |
| 1216 abort (); | |
| 1217 return nbytes; | |
| 1218 } | |
| 1219 | |
| 1220 /* Check validity Lisp strings' string_bytes member in B. */ | |
| 1221 | |
| 1209 void | 1222 void |
| 1210 check_string_bytes () | 1223 check_sblock (b) |
| 1211 { | 1224 struct sblock *b; |
| 1212 struct sblock *b; | 1225 { |
| 1213 | 1226 struct sdata *from, *end, *from_end; |
| 1214 for (b = large_sblocks; b; b = b->next) | |
| 1215 { | |
| 1216 struct Lisp_String *s = b->first_data.string; | |
| 1217 if (s && GC_STRING_BYTES (s) != SDATA_NBYTES (SDATA_OF_STRING (s))) | |
| 1218 abort (); | |
| 1219 } | |
| 1220 | 1227 |
| 1221 for (b = oldest_sblock; b; b = b->next) | 1228 end = b->next_free; |
| 1222 { | |
| 1223 struct sdata *from, *end, *from_end; | |
| 1224 | 1229 |
| 1225 end = b->next_free; | 1230 for (from = &b->first_data; from < end; from = from_end) |
| 1231 { | |
| 1232 /* Compute the next FROM here because copying below may | |
| 1233 overwrite data we need to compute it. */ | |
| 1234 int nbytes; | |
| 1226 | 1235 |
| 1227 for (from = &b->first_data; from < end; from = from_end) | 1236 /* Check that the string size recorded in the string is the |
| 1237 same as the one recorded in the sdata structure. */ | |
| 1238 if (from->string) | |
| 1239 CHECK_STRING_BYTES (from->string); | |
| 1240 | |
| 1241 if (from->string) | |
| 1242 nbytes = GC_STRING_BYTES (from->string); | |
| 1243 else | |
| 1244 nbytes = SDATA_NBYTES (from); | |
| 1245 | |
| 1246 nbytes = SDATA_SIZE (nbytes); | |
| 1247 from_end = (struct sdata *) ((char *) from + nbytes); | |
| 1248 } | |
| 1249 } | |
| 1250 | |
| 1251 | |
| 1252 /* Check validity of Lisp strings' string_bytes member. ALL_P | |
| 1253 non-zero means check all strings, otherwise check only most | |
| 1254 recently allocated strings. Used for hunting a bug. */ | |
| 1255 | |
| 1256 void | |
| 1257 check_string_bytes (all_p) | |
| 1258 int all_p; | |
| 1259 { | |
| 1260 if (all_p) | |
| 1261 { | |
| 1262 struct sblock *b; | |
| 1263 | |
| 1264 for (b = large_sblocks; b; b = b->next) | |
| 1228 { | 1265 { |
| 1229 /* Compute the next FROM here because copying below may | 1266 struct Lisp_String *s = b->first_data.string; |
| 1230 overwrite data we need to compute it. */ | 1267 if (s) |
| 1231 int nbytes; | 1268 CHECK_STRING_BYTES (s); |
| 1232 | |
| 1233 /* Check that the string size recorded in the string is the | |
| 1234 same as the one recorded in the sdata structure. */ | |
| 1235 if (from->string | |
| 1236 && GC_STRING_BYTES (from->string) != SDATA_NBYTES (from)) | |
| 1237 abort (); | |
| 1238 | |
| 1239 if (from->string) | |
| 1240 nbytes = GC_STRING_BYTES (from->string); | |
| 1241 else | |
| 1242 nbytes = SDATA_NBYTES (from); | |
| 1243 | |
| 1244 nbytes = SDATA_SIZE (nbytes); | |
| 1245 from_end = (struct sdata *) ((char *) from + nbytes); | |
| 1246 } | 1269 } |
| 1247 } | 1270 |
| 1271 for (b = oldest_sblock; b; b = b->next) | |
| 1272 check_sblock (b); | |
| 1273 } | |
| 1274 else | |
| 1275 check_sblock (current_sblock); | |
| 1248 } | 1276 } |
| 1249 | 1277 |
| 1250 #endif /* GC_CHECK_STRING_BYTES */ | 1278 #endif /* GC_CHECK_STRING_BYTES */ |
| 1251 | 1279 |
| 1252 | 1280 |
| 1292 ++total_strings; | 1320 ++total_strings; |
| 1293 ++strings_consed; | 1321 ++strings_consed; |
| 1294 consing_since_gc += sizeof *s; | 1322 consing_since_gc += sizeof *s; |
| 1295 | 1323 |
| 1296 #ifdef GC_CHECK_STRING_BYTES | 1324 #ifdef GC_CHECK_STRING_BYTES |
| 1297 if (!noninteractive && ++check_string_bytes_count == 50) | 1325 if (!noninteractive) |
| 1298 { | 1326 { |
| 1299 check_string_bytes_count = 0; | 1327 if (++check_string_bytes_count == 200) |
| 1300 check_string_bytes (); | 1328 { |
| 1301 } | 1329 check_string_bytes_count = 0; |
| 1302 #endif | 1330 check_string_bytes (1); |
| 1331 } | |
| 1332 else | |
| 1333 check_string_bytes (0); | |
| 1334 } | |
| 1335 #endif /* GC_CHECK_STRING_BYTES */ | |
| 1303 | 1336 |
| 1304 return s; | 1337 return s; |
| 1305 } | 1338 } |
| 1306 | 1339 |
| 1307 | 1340 |
| 4109 register struct Lisp_String *ptr = XSTRING (obj); | 4142 register struct Lisp_String *ptr = XSTRING (obj); |
| 4110 CHECK_ALLOCATED_AND_LIVE (live_string_p); | 4143 CHECK_ALLOCATED_AND_LIVE (live_string_p); |
| 4111 MARK_INTERVAL_TREE (ptr->intervals); | 4144 MARK_INTERVAL_TREE (ptr->intervals); |
| 4112 MARK_STRING (ptr); | 4145 MARK_STRING (ptr); |
| 4113 #ifdef GC_CHECK_STRING_BYTES | 4146 #ifdef GC_CHECK_STRING_BYTES |
| 4114 { | 4147 /* Check that the string size recorded in the string is the |
| 4115 /* Check that the string size recorded in the string is the | 4148 same as the one recorded in the sdata structure. */ |
| 4116 same as the one recorded in the sdata structure. */ | 4149 CHECK_STRING_BYTES (ptr); |
| 4117 struct sdata *p = SDATA_OF_STRING (ptr); | |
| 4118 if (GC_STRING_BYTES (ptr) != SDATA_NBYTES (p)) | |
| 4119 abort (); | |
| 4120 } | |
| 4121 #endif /* GC_CHECK_STRING_BYTES */ | 4150 #endif /* GC_CHECK_STRING_BYTES */ |
| 4122 } | 4151 } |
| 4123 break; | 4152 break; |
| 4124 | 4153 |
| 4125 case Lisp_Vectorlike: | 4154 case Lisp_Vectorlike: |
| 4606 /* Remove or mark entries in weak hash tables. | 4635 /* Remove or mark entries in weak hash tables. |
| 4607 This must be done before any object is unmarked. */ | 4636 This must be done before any object is unmarked. */ |
| 4608 sweep_weak_hash_tables (); | 4637 sweep_weak_hash_tables (); |
| 4609 | 4638 |
| 4610 sweep_strings (); | 4639 sweep_strings (); |
| 4640 #ifdef GC_CHECK_STRING_BYTES | |
| 4641 if (!noninteractive) | |
| 4642 check_string_bytes (1); | |
| 4643 #endif | |
| 4611 | 4644 |
| 4612 /* Put all unmarked conses on free list */ | 4645 /* Put all unmarked conses on free list */ |
| 4613 { | 4646 { |
| 4614 register struct cons_block *cblk; | 4647 register struct cons_block *cblk; |
| 4615 struct cons_block **cprev = &cons_block; | 4648 struct cons_block **cprev = &cons_block; |
| 4958 else | 4991 else |
| 4959 total_vector_size += vector->size; | 4992 total_vector_size += vector->size; |
| 4960 prev = vector, vector = vector->next; | 4993 prev = vector, vector = vector->next; |
| 4961 } | 4994 } |
| 4962 } | 4995 } |
| 4996 | |
| 4997 #ifdef GC_CHECK_STRING_BYTES | |
| 4998 if (!noninteractive) | |
| 4999 check_string_bytes (1); | |
| 5000 #endif | |
| 4963 } | 5001 } |
| 4964 | 5002 |
| 4965 | 5003 |
| 4966 | 5004 |
| 4967 | 5005 |
