aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
authorDmitry Antipov2012-07-30 08:02:39 +0400
committerDmitry Antipov2012-07-30 08:02:39 +0400
commite499d0eebc7d8c12b42b2aa5392ce747ca3619ea (patch)
treeaaedb6d85d477502989012658beda610adcdcc9a /src/alloc.c
parentd2bd74ff3e3f88027c4a7de0dcdb7dfb3e12716e (diff)
downloademacs-e499d0eebc7d8c12b42b2aa5392ce747ca3619ea.tar.gz
emacs-e499d0eebc7d8c12b42b2aa5392ce747ca3619ea.zip
Cleanup string bytes checking.
* alloc.c (GC_STRING_BYTES, CHECK_STRING_BYTES): Remove. Convert all users to STRING_BYTES or string_bytes if GC_CHECK_STRING_BYTES. (check_string_bytes): Define to empty if not GC_CHECK_STRING_BYTES. (check_sblock, compact_small_strings): Simplify.
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c65
1 files changed, 21 insertions, 44 deletions
diff --git a/src/alloc.c b/src/alloc.c
index f6f656fffa3..cb375f5432d 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -150,12 +150,6 @@ static pthread_mutex_t alloc_mutex;
150#define VECTOR_UNMARK(V) ((V)->header.size &= ~ARRAY_MARK_FLAG) 150#define VECTOR_UNMARK(V) ((V)->header.size &= ~ARRAY_MARK_FLAG)
151#define VECTOR_MARKED_P(V) (((V)->header.size & ARRAY_MARK_FLAG) != 0) 151#define VECTOR_MARKED_P(V) (((V)->header.size & ARRAY_MARK_FLAG) != 0)
152 152
153/* Value is the number of bytes of S, a pointer to a struct Lisp_String.
154 Be careful during GC, because S->size contains the mark bit for
155 strings. */
156
157#define GC_STRING_BYTES(S) (STRING_BYTES (S))
158
159/* Default value of gc_cons_threshold (see below). */ 153/* Default value of gc_cons_threshold (see below). */
160 154
161#define GC_DEFAULT_THRESHOLD (100000 * sizeof (Lisp_Object)) 155#define GC_DEFAULT_THRESHOLD (100000 * sizeof (Lisp_Object))
@@ -1802,10 +1796,8 @@ init_strings (void)
1802 1796
1803static int check_string_bytes_count; 1797static int check_string_bytes_count;
1804 1798
1805#define CHECK_STRING_BYTES(S) STRING_BYTES (S) 1799/* Like STRING_BYTES, but with debugging check. Can be
1806 1800 called during GC, so pay attention to the mark bit. */
1807
1808/* Like GC_STRING_BYTES, but with debugging check. */
1809 1801
1810ptrdiff_t 1802ptrdiff_t
1811string_bytes (struct Lisp_String *s) 1803string_bytes (struct Lisp_String *s)
@@ -1837,15 +1829,8 @@ check_sblock (struct sblock *b)
1837 1829
1838 /* Check that the string size recorded in the string is the 1830 /* Check that the string size recorded in the string is the
1839 same as the one recorded in the sdata structure. */ 1831 same as the one recorded in the sdata structure. */
1840 if (from->string) 1832 nbytes = SDATA_SIZE (from->string ? string_bytes (from->string)
1841 CHECK_STRING_BYTES (from->string); 1833 : SDATA_NBYTES (from));
1842
1843 if (from->string)
1844 nbytes = GC_STRING_BYTES (from->string);
1845 else
1846 nbytes = SDATA_NBYTES (from);
1847
1848 nbytes = SDATA_SIZE (nbytes);
1849 from_end = (struct sdata *) ((char *) from + nbytes + GC_STRING_EXTRA); 1834 from_end = (struct sdata *) ((char *) from + nbytes + GC_STRING_EXTRA);
1850 } 1835 }
1851} 1836}
@@ -1866,7 +1851,7 @@ check_string_bytes (int all_p)
1866 { 1851 {
1867 struct Lisp_String *s = b->first_data.string; 1852 struct Lisp_String *s = b->first_data.string;
1868 if (s) 1853 if (s)
1869 CHECK_STRING_BYTES (s); 1854 string_bytes (s);
1870 } 1855 }
1871 1856
1872 for (b = oldest_sblock; b; b = b->next) 1857 for (b = oldest_sblock; b; b = b->next)
@@ -1876,6 +1861,10 @@ check_string_bytes (int all_p)
1876 check_sblock (current_sblock); 1861 check_sblock (current_sblock);
1877} 1862}
1878 1863
1864#else /* not GC_CHECK_STRING_BYTES */
1865
1866#define check_string_bytes(all) ((void) 0)
1867
1879#endif /* GC_CHECK_STRING_BYTES */ 1868#endif /* GC_CHECK_STRING_BYTES */
1880 1869
1881#ifdef GC_CHECK_STRING_FREE_LIST 1870#ifdef GC_CHECK_STRING_FREE_LIST
@@ -1987,7 +1976,7 @@ allocate_string_data (struct Lisp_String *s,
1987 if (s->data) 1976 if (s->data)
1988 { 1977 {
1989 old_data = SDATA_OF_STRING (s); 1978 old_data = SDATA_OF_STRING (s);
1990 old_nbytes = GC_STRING_BYTES (s); 1979 old_nbytes = STRING_BYTES (s);
1991 } 1980 }
1992 else 1981 else
1993 old_data = NULL; 1982 old_data = NULL;
@@ -2121,10 +2110,10 @@ sweep_strings (void)
2121 how large that is. Reset the sdata's string 2110 how large that is. Reset the sdata's string
2122 back-pointer so that we know it's free. */ 2111 back-pointer so that we know it's free. */
2123#ifdef GC_CHECK_STRING_BYTES 2112#ifdef GC_CHECK_STRING_BYTES
2124 if (GC_STRING_BYTES (s) != SDATA_NBYTES (data)) 2113 if (string_bytes (s) != SDATA_NBYTES (data))
2125 abort (); 2114 abort ();
2126#else 2115#else
2127 data->u.nbytes = GC_STRING_BYTES (s); 2116 data->u.nbytes = STRING_BYTES (s);
2128#endif 2117#endif
2129 data->string = NULL; 2118 data->string = NULL;
2130 2119
@@ -2227,22 +2216,17 @@ compact_small_strings (void)
2227 /* Compute the next FROM here because copying below may 2216 /* Compute the next FROM here because copying below may
2228 overwrite data we need to compute it. */ 2217 overwrite data we need to compute it. */
2229 ptrdiff_t nbytes; 2218 ptrdiff_t nbytes;
2219 struct Lisp_String *s = from->string;
2230 2220
2231#ifdef GC_CHECK_STRING_BYTES 2221#ifdef GC_CHECK_STRING_BYTES
2232 /* Check that the string size recorded in the string is the 2222 /* Check that the string size recorded in the string is the
2233 same as the one recorded in the sdata structure. */ 2223 same as the one recorded in the sdata structure. */
2234 if (from->string 2224 if (s && string_bytes (s) != SDATA_NBYTES (from))
2235 && GC_STRING_BYTES (from->string) != SDATA_NBYTES (from))
2236 abort (); 2225 abort ();
2237#endif /* GC_CHECK_STRING_BYTES */ 2226#endif /* GC_CHECK_STRING_BYTES */
2238 2227
2239 if (from->string) 2228 nbytes = s ? STRING_BYTES (s) : SDATA_NBYTES (from);
2240 nbytes = GC_STRING_BYTES (from->string); 2229 eassert (nbytes <= LARGE_STRING_BYTES);
2241 else
2242 nbytes = SDATA_NBYTES (from);
2243
2244 if (nbytes > LARGE_STRING_BYTES)
2245 abort ();
2246 2230
2247 nbytes = SDATA_SIZE (nbytes); 2231 nbytes = SDATA_SIZE (nbytes);
2248 from_end = (struct sdata *) ((char *) from + nbytes + GC_STRING_EXTRA); 2232 from_end = (struct sdata *) ((char *) from + nbytes + GC_STRING_EXTRA);
@@ -2254,8 +2238,8 @@ compact_small_strings (void)
2254 abort (); 2238 abort ();
2255#endif 2239#endif
2256 2240
2257 /* FROM->string non-null means it's alive. Copy its data. */ 2241 /* Non-NULL S means it's alive. Copy its data. */
2258 if (from->string) 2242 if (s)
2259 { 2243 {
2260 /* If TB is full, proceed with the next sblock. */ 2244 /* If TB is full, proceed with the next sblock. */
2261 to_end = (struct sdata *) ((char *) to + nbytes + GC_STRING_EXTRA); 2245 to_end = (struct sdata *) ((char *) to + nbytes + GC_STRING_EXTRA);
@@ -5955,7 +5939,7 @@ mark_object (Lisp_Object arg)
5955#ifdef GC_CHECK_STRING_BYTES 5939#ifdef GC_CHECK_STRING_BYTES
5956 /* Check that the string size recorded in the string is the 5940 /* Check that the string size recorded in the string is the
5957 same as the one recorded in the sdata structure. */ 5941 same as the one recorded in the sdata structure. */
5958 CHECK_STRING_BYTES (ptr); 5942 string_bytes (ptr);
5959#endif /* GC_CHECK_STRING_BYTES */ 5943#endif /* GC_CHECK_STRING_BYTES */
5960 } 5944 }
5961 break; 5945 break;
@@ -6294,10 +6278,7 @@ gc_sweep (void)
6294 sweep_weak_hash_tables (); 6278 sweep_weak_hash_tables ();
6295 6279
6296 sweep_strings (); 6280 sweep_strings ();
6297#ifdef GC_CHECK_STRING_BYTES 6281 check_string_bytes (!noninteractive);
6298 if (!noninteractive)
6299 check_string_bytes (1);
6300#endif
6301 6282
6302 /* Put all unmarked conses on free list */ 6283 /* Put all unmarked conses on free list */
6303 { 6284 {
@@ -6617,11 +6598,7 @@ gc_sweep (void)
6617 } 6598 }
6618 6599
6619 sweep_vectors (); 6600 sweep_vectors ();
6620 6601 check_string_bytes (!noninteractive);
6621#ifdef GC_CHECK_STRING_BYTES
6622 if (!noninteractive)
6623 check_string_bytes (1);
6624#endif
6625} 6602}
6626 6603
6627 6604