aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
authorGerd Moellmann2000-10-17 15:38:30 +0000
committerGerd Moellmann2000-10-17 15:38:30 +0000
commit361b097f3a15060733f417eb6cbabf63b121bec9 (patch)
tree2f534a4b26a9be37701e7f4dff000b0e91933c7b /src/alloc.c
parent54918e2b47ffcb64fcce348a977a45e33d7a9760 (diff)
downloademacs-361b097f3a15060733f417eb6cbabf63b121bec9.tar.gz
emacs-361b097f3a15060733f417eb6cbabf63b121bec9.zip
(mark_object) [GC_CHECK_STRING_BYTES]: Check validity of
string's size_byte. (check_string_bytes) [GC_CHECK_STRING_BYTES]: New function. (check_string_bytes_count) [GC_CHECK_STRING_BYTES]: New variable. (allocate_string) [GC_CHECK_STRING_BYTES]: Call it for every 10th string allocated.
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 85b9d42f1a3..47e75f50a8e 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -1021,6 +1021,57 @@ init_strings ()
1021} 1021}
1022 1022
1023 1023
1024#ifdef GC_CHECK_STRING_BYTES
1025
1026/* Check validity of all live Lisp strings' string_bytes member.
1027 Used for hunting a bug. */
1028
1029static int check_string_bytes_count;
1030
1031void
1032check_string_bytes ()
1033{
1034 struct sblock *b;
1035
1036 for (b = large_sblocks; b; b = b->next)
1037 {
1038 struct Lisp_String *s = b->first_data.string;
1039 if (s && GC_STRING_BYTES (s) != SDATA_NBYTES (SDATA_OF_STRING (s)))
1040 abort ();
1041 }
1042
1043 for (b = oldest_sblock; b; b = b->next)
1044 {
1045 struct sdata *from, *end, *from_end;
1046
1047 end = b->next_free;
1048
1049 for (from = &b->first_data; from < end; from = from_end)
1050 {
1051 /* Compute the next FROM here because copying below may
1052 overwrite data we need to compute it. */
1053 int nbytes;
1054
1055 /* Check that the string size recorded in the string is the
1056 same as the one recorded in the sdata structure. */
1057 if (from->string
1058 && GC_STRING_BYTES (from->string) != SDATA_NBYTES (from))
1059 abort ();
1060
1061 if (from->string)
1062 nbytes = GC_STRING_BYTES (from->string);
1063 else
1064 nbytes = SDATA_NBYTES (from);
1065
1066 nbytes = SDATA_SIZE (nbytes);
1067 from_end = (struct sdata *) ((char *) from + nbytes);
1068 }
1069 }
1070}
1071
1072#endif /* GC_CHECK_STRING_BYTES */
1073
1074
1024/* Return a new Lisp_String. */ 1075/* Return a new Lisp_String. */
1025 1076
1026static struct Lisp_String * 1077static struct Lisp_String *
@@ -1064,6 +1115,14 @@ allocate_string ()
1064 ++strings_consed; 1115 ++strings_consed;
1065 consing_since_gc += sizeof *s; 1116 consing_since_gc += sizeof *s;
1066 1117
1118#ifdef GC_CHECK_STRING_BYTES
1119 if (++check_string_bytes_count == 10)
1120 {
1121 check_string_bytes_count = 0;
1122 check_string_bytes ();
1123 }
1124#endif
1125
1067 return s; 1126 return s;
1068} 1127}
1069 1128
@@ -3928,6 +3987,15 @@ mark_object (argptr)
3928 CHECK_ALLOCATED_AND_LIVE (live_string_p); 3987 CHECK_ALLOCATED_AND_LIVE (live_string_p);
3929 MARK_INTERVAL_TREE (ptr->intervals); 3988 MARK_INTERVAL_TREE (ptr->intervals);
3930 MARK_STRING (ptr); 3989 MARK_STRING (ptr);
3990#ifdef GC_CHECK_STRING_BYTES
3991 {
3992 /* Check that the string size recorded in the string is the
3993 same as the one recorded in the sdata structure. */
3994 struct sdata *p = SDATA_OF_STRING (ptr);
3995 if (GC_STRING_BYTES (ptr) != SDATA_NBYTES (p))
3996 abort ();
3997 }
3998#endif /* GC_CHECK_STRING_BYTES */
3931 } 3999 }
3932 break; 4000 break;
3933 4001