diff options
Diffstat (limited to 'src/charset.c')
| -rw-r--r-- | src/charset.c | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/src/charset.c b/src/charset.c index f1b4897ffe6..8d6a3982d14 100644 --- a/src/charset.c +++ b/src/charset.c | |||
| @@ -1162,10 +1162,10 @@ usage: (define-charset-internal ...) */) | |||
| 1162 | sizeof *charset_table); | 1162 | sizeof *charset_table); |
| 1163 | memcpy (new_table, charset_table, old_size * sizeof *new_table); | 1163 | memcpy (new_table, charset_table, old_size * sizeof *new_table); |
| 1164 | charset_table = new_table; | 1164 | charset_table = new_table; |
| 1165 | /* FIXME: Doesn't this leak memory? The old charset_table becomes | 1165 | /* FIXME: This leaks memory, as the old charset_table becomes |
| 1166 | unreachable. It could be that this is intentional, because the | 1166 | unreachable. If the old charset table is charset_table_init |
| 1167 | old charset table may be in a dumped emacs, and reallocating such | 1167 | then this leak is intentional; otherwise, it's unclear. |
| 1168 | a table may not work. If the memory leak is intentional, a | 1168 | If the latter memory leak is intentional, a |
| 1169 | comment should be added to explain this. If not, the old | 1169 | comment should be added to explain this. If not, the old |
| 1170 | charset_table should be freed, by passing it as the 1st argument | 1170 | charset_table should be freed, by passing it as the 1st argument |
| 1171 | to xpalloc and removing the memcpy. */ | 1171 | to xpalloc and removing the memcpy. */ |
| @@ -2327,22 +2327,21 @@ init_charset_once (void) | |||
| 2327 | 2327 | ||
| 2328 | #ifdef emacs | 2328 | #ifdef emacs |
| 2329 | 2329 | ||
| 2330 | /* Allocate an initial charset table that is large enough to handle | ||
| 2331 | Emacs while it is bootstrapping. As of September 2011, the size | ||
| 2332 | needs to be at least 166; make it a bit bigger to allow for future | ||
| 2333 | expansion. | ||
| 2334 | |||
| 2335 | Don't make the value so small that the table is reallocated during | ||
| 2336 | bootstrapping, as glibc malloc calls larger than just under 64 KiB | ||
| 2337 | during an initial bootstrap wreak havoc after dumping; see the | ||
| 2338 | M_MMAP_THRESHOLD value in alloc.c, plus there is a extra overhead | ||
| 2339 | internal to glibc malloc and perhaps to Emacs malloc debugging. */ | ||
| 2340 | static struct charset charset_table_init[180]; | ||
| 2341 | |||
| 2330 | void | 2342 | void |
| 2331 | syms_of_charset (void) | 2343 | syms_of_charset (void) |
| 2332 | { | 2344 | { |
| 2333 | /* Allocate an initial charset table that is just under 64 KiB in size. | ||
| 2334 | This should be large enough so that the charset table need not be | ||
| 2335 | reallocated during an initial bootstrap. Allocating anything larger than | ||
| 2336 | 64 KiB in an initial run may not work, because glibc malloc might use | ||
| 2337 | mmap for larger allocations, and these don't work well across dumped | ||
| 2338 | systems. */ | ||
| 2339 | enum { | ||
| 2340 | glibc_malloc_overhead = 3 * sizeof (size_t) - 1, | ||
| 2341 | initial_malloc_max = | ||
| 2342 | (1 << 16) - 1 - glibc_malloc_overhead - XMALLOC_OVERRUN_CHECK_OVERHEAD, | ||
| 2343 | charset_table_size_init = initial_malloc_max / sizeof (struct charset) | ||
| 2344 | }; | ||
| 2345 | |||
| 2346 | DEFSYM (Qcharsetp, "charsetp"); | 2345 | DEFSYM (Qcharsetp, "charsetp"); |
| 2347 | 2346 | ||
| 2348 | DEFSYM (Qascii, "ascii"); | 2347 | DEFSYM (Qascii, "ascii"); |
| @@ -2375,9 +2374,8 @@ syms_of_charset (void) | |||
| 2375 | Vcharset_hash_table = Fmake_hash_table (2, args); | 2374 | Vcharset_hash_table = Fmake_hash_table (2, args); |
| 2376 | } | 2375 | } |
| 2377 | 2376 | ||
| 2378 | charset_table = (struct charset *) xmalloc (sizeof (struct charset) | 2377 | charset_table = charset_table_init; |
| 2379 | * charset_table_size_init); | 2378 | charset_table_size = sizeof charset_table_init / sizeof *charset_table_init; |
| 2380 | charset_table_size = charset_table_size_init; | ||
| 2381 | charset_table_used = 0; | 2379 | charset_table_used = 0; |
| 2382 | 2380 | ||
| 2383 | defsubr (&Scharsetp); | 2381 | defsubr (&Scharsetp); |