diff options
Diffstat (limited to 'src/alloc.c')
| -rw-r--r-- | src/alloc.c | 87 |
1 files changed, 44 insertions, 43 deletions
diff --git a/src/alloc.c b/src/alloc.c index 7598386ebca..62b6e449831 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -636,10 +636,12 @@ overrun_check_malloc (size) | |||
| 636 | val = (unsigned char *) malloc (size + overhead); | 636 | val = (unsigned char *) malloc (size + overhead); |
| 637 | if (val && check_depth == 1) | 637 | if (val && check_depth == 1) |
| 638 | { | 638 | { |
| 639 | bcopy (xmalloc_overrun_check_header, val, XMALLOC_OVERRUN_CHECK_SIZE - 4); | 639 | memcpy (val, xmalloc_overrun_check_header, |
| 640 | XMALLOC_OVERRUN_CHECK_SIZE - 4); | ||
| 640 | val += XMALLOC_OVERRUN_CHECK_SIZE; | 641 | val += XMALLOC_OVERRUN_CHECK_SIZE; |
| 641 | XMALLOC_PUT_SIZE(val, size); | 642 | XMALLOC_PUT_SIZE(val, size); |
| 642 | bcopy (xmalloc_overrun_check_trailer, val + size, XMALLOC_OVERRUN_CHECK_SIZE); | 643 | memcpy (val + size, xmalloc_overrun_check_trailer, |
| 644 | XMALLOC_OVERRUN_CHECK_SIZE); | ||
| 643 | } | 645 | } |
| 644 | --check_depth; | 646 | --check_depth; |
| 645 | return (POINTER_TYPE *)val; | 647 | return (POINTER_TYPE *)val; |
| @@ -659,28 +661,29 @@ overrun_check_realloc (block, size) | |||
| 659 | 661 | ||
| 660 | if (val | 662 | if (val |
| 661 | && check_depth == 1 | 663 | && check_depth == 1 |
| 662 | && bcmp (xmalloc_overrun_check_header, | 664 | && memcmp (xmalloc_overrun_check_header, |
| 663 | val - XMALLOC_OVERRUN_CHECK_SIZE, | 665 | val - XMALLOC_OVERRUN_CHECK_SIZE, |
| 664 | XMALLOC_OVERRUN_CHECK_SIZE - 4) == 0) | 666 | XMALLOC_OVERRUN_CHECK_SIZE - 4) == 0) |
| 665 | { | 667 | { |
| 666 | size_t osize = XMALLOC_GET_SIZE (val); | 668 | size_t osize = XMALLOC_GET_SIZE (val); |
| 667 | if (bcmp (xmalloc_overrun_check_trailer, | 669 | if (memcmp (xmalloc_overrun_check_trailer, val + osize, |
| 668 | val + osize, | 670 | XMALLOC_OVERRUN_CHECK_SIZE)) |
| 669 | XMALLOC_OVERRUN_CHECK_SIZE)) | ||
| 670 | abort (); | 671 | abort (); |
| 671 | bzero (val + osize, XMALLOC_OVERRUN_CHECK_SIZE); | 672 | memset (val + osize, 0, XMALLOC_OVERRUN_CHECK_SIZE); |
| 672 | val -= XMALLOC_OVERRUN_CHECK_SIZE; | 673 | val -= XMALLOC_OVERRUN_CHECK_SIZE; |
| 673 | bzero (val, XMALLOC_OVERRUN_CHECK_SIZE); | 674 | memset (val, 0, XMALLOC_OVERRUN_CHECK_SIZE); |
| 674 | } | 675 | } |
| 675 | 676 | ||
| 676 | val = (unsigned char *) realloc ((POINTER_TYPE *)val, size + overhead); | 677 | val = (unsigned char *) realloc ((POINTER_TYPE *)val, size + overhead); |
| 677 | 678 | ||
| 678 | if (val && check_depth == 1) | 679 | if (val && check_depth == 1) |
| 679 | { | 680 | { |
| 680 | bcopy (xmalloc_overrun_check_header, val, XMALLOC_OVERRUN_CHECK_SIZE - 4); | 681 | memcpy (val, xmalloc_overrun_check_header, |
| 682 | XMALLOC_OVERRUN_CHECK_SIZE - 4); | ||
| 681 | val += XMALLOC_OVERRUN_CHECK_SIZE; | 683 | val += XMALLOC_OVERRUN_CHECK_SIZE; |
| 682 | XMALLOC_PUT_SIZE(val, size); | 684 | XMALLOC_PUT_SIZE(val, size); |
| 683 | bcopy (xmalloc_overrun_check_trailer, val + size, XMALLOC_OVERRUN_CHECK_SIZE); | 685 | memcpy (val + size, xmalloc_overrun_check_trailer, |
| 686 | XMALLOC_OVERRUN_CHECK_SIZE); | ||
| 684 | } | 687 | } |
| 685 | --check_depth; | 688 | --check_depth; |
| 686 | return (POINTER_TYPE *)val; | 689 | return (POINTER_TYPE *)val; |
| @@ -697,22 +700,21 @@ overrun_check_free (block) | |||
| 697 | ++check_depth; | 700 | ++check_depth; |
| 698 | if (val | 701 | if (val |
| 699 | && check_depth == 1 | 702 | && check_depth == 1 |
| 700 | && bcmp (xmalloc_overrun_check_header, | 703 | && memcmp (xmalloc_overrun_check_header, |
| 701 | val - XMALLOC_OVERRUN_CHECK_SIZE, | 704 | val - XMALLOC_OVERRUN_CHECK_SIZE, |
| 702 | XMALLOC_OVERRUN_CHECK_SIZE - 4) == 0) | 705 | XMALLOC_OVERRUN_CHECK_SIZE - 4) == 0) |
| 703 | { | 706 | { |
| 704 | size_t osize = XMALLOC_GET_SIZE (val); | 707 | size_t osize = XMALLOC_GET_SIZE (val); |
| 705 | if (bcmp (xmalloc_overrun_check_trailer, | 708 | if (memcmp (xmalloc_overrun_check_trailer, val + osize, |
| 706 | val + osize, | 709 | XMALLOC_OVERRUN_CHECK_SIZE)) |
| 707 | XMALLOC_OVERRUN_CHECK_SIZE)) | ||
| 708 | abort (); | 710 | abort (); |
| 709 | #ifdef XMALLOC_CLEAR_FREE_MEMORY | 711 | #ifdef XMALLOC_CLEAR_FREE_MEMORY |
| 710 | val -= XMALLOC_OVERRUN_CHECK_SIZE; | 712 | val -= XMALLOC_OVERRUN_CHECK_SIZE; |
| 711 | memset (val, 0xff, osize + XMALLOC_OVERRUN_CHECK_SIZE*2); | 713 | memset (val, 0xff, osize + XMALLOC_OVERRUN_CHECK_SIZE*2); |
| 712 | #else | 714 | #else |
| 713 | bzero (val + osize, XMALLOC_OVERRUN_CHECK_SIZE); | 715 | memset (val + osize, 0, XMALLOC_OVERRUN_CHECK_SIZE); |
| 714 | val -= XMALLOC_OVERRUN_CHECK_SIZE; | 716 | val -= XMALLOC_OVERRUN_CHECK_SIZE; |
| 715 | bzero (val, XMALLOC_OVERRUN_CHECK_SIZE); | 717 | memset (val, 0, XMALLOC_OVERRUN_CHECK_SIZE); |
| 716 | #endif | 718 | #endif |
| 717 | } | 719 | } |
| 718 | 720 | ||
| @@ -799,7 +801,7 @@ xstrdup (const char *s) | |||
| 799 | { | 801 | { |
| 800 | size_t len = strlen (s) + 1; | 802 | size_t len = strlen (s) + 1; |
| 801 | char *p = (char *) xmalloc (len); | 803 | char *p = (char *) xmalloc (len); |
| 802 | bcopy (s, p, len); | 804 | memcpy (p, s, len); |
| 803 | return p; | 805 | return p; |
| 804 | } | 806 | } |
| 805 | 807 | ||
| @@ -1873,7 +1875,7 @@ allocate_string (void) | |||
| 1873 | int i; | 1875 | int i; |
| 1874 | 1876 | ||
| 1875 | b = (struct string_block *) lisp_malloc (sizeof *b, MEM_TYPE_STRING); | 1877 | b = (struct string_block *) lisp_malloc (sizeof *b, MEM_TYPE_STRING); |
| 1876 | bzero (b, sizeof *b); | 1878 | memset (b, 0, sizeof *b); |
| 1877 | b->next = string_blocks; | 1879 | b->next = string_blocks; |
| 1878 | string_blocks = b; | 1880 | string_blocks = b; |
| 1879 | ++n_string_blocks; | 1881 | ++n_string_blocks; |
| @@ -1897,7 +1899,7 @@ allocate_string (void) | |||
| 1897 | MALLOC_UNBLOCK_INPUT; | 1899 | MALLOC_UNBLOCK_INPUT; |
| 1898 | 1900 | ||
| 1899 | /* Probably not strictly necessary, but play it safe. */ | 1901 | /* Probably not strictly necessary, but play it safe. */ |
| 1900 | bzero (s, sizeof *s); | 1902 | memset (s, 0, sizeof *s); |
| 1901 | 1903 | ||
| 1902 | --total_free_strings; | 1904 | --total_free_strings; |
| 1903 | ++total_strings; | 1905 | ++total_strings; |
| @@ -2005,8 +2007,7 @@ allocate_string_data (struct Lisp_String *s, int nchars, int nbytes) | |||
| 2005 | s->size_byte = nbytes; | 2007 | s->size_byte = nbytes; |
| 2006 | s->data[nbytes] = '\0'; | 2008 | s->data[nbytes] = '\0'; |
| 2007 | #ifdef GC_CHECK_STRING_OVERRUN | 2009 | #ifdef GC_CHECK_STRING_OVERRUN |
| 2008 | bcopy (string_overrun_cookie, (char *) data + needed, | 2010 | memcpy (data + needed, string_overrun_cookie, GC_STRING_OVERRUN_COOKIE_SIZE); |
| 2009 | GC_STRING_OVERRUN_COOKIE_SIZE); | ||
| 2010 | #endif | 2011 | #endif |
| 2011 | 2012 | ||
| 2012 | /* If S had already data assigned, mark that as free by setting its | 2013 | /* If S had already data assigned, mark that as free by setting its |
| @@ -2197,9 +2198,9 @@ compact_small_strings (void) | |||
| 2197 | from_end = (struct sdata *) ((char *) from + nbytes + GC_STRING_EXTRA); | 2198 | from_end = (struct sdata *) ((char *) from + nbytes + GC_STRING_EXTRA); |
| 2198 | 2199 | ||
| 2199 | #ifdef GC_CHECK_STRING_OVERRUN | 2200 | #ifdef GC_CHECK_STRING_OVERRUN |
| 2200 | if (bcmp (string_overrun_cookie, | 2201 | if (memcmp (string_overrun_cookie, |
| 2201 | ((char *) from_end) - GC_STRING_OVERRUN_COOKIE_SIZE, | 2202 | (char *) from_end - GC_STRING_OVERRUN_COOKIE_SIZE, |
| 2202 | GC_STRING_OVERRUN_COOKIE_SIZE)) | 2203 | GC_STRING_OVERRUN_COOKIE_SIZE)) |
| 2203 | abort (); | 2204 | abort (); |
| 2204 | #endif | 2205 | #endif |
| 2205 | 2206 | ||
| @@ -2221,7 +2222,7 @@ compact_small_strings (void) | |||
| 2221 | if (from != to) | 2222 | if (from != to) |
| 2222 | { | 2223 | { |
| 2223 | xassert (tb != b || to <= from); | 2224 | xassert (tb != b || to <= from); |
| 2224 | safe_bcopy ((char *) from, (char *) to, nbytes + GC_STRING_EXTRA); | 2225 | memmove (to, from, nbytes + GC_STRING_EXTRA); |
| 2225 | to->string->data = SDATA_DATA (to); | 2226 | to->string->data = SDATA_DATA (to); |
| 2226 | } | 2227 | } |
| 2227 | 2228 | ||
| @@ -2280,7 +2281,7 @@ INIT must be an integer that represents a character. */) | |||
| 2280 | end = p + nbytes; | 2281 | end = p + nbytes; |
| 2281 | while (p != end) | 2282 | while (p != end) |
| 2282 | { | 2283 | { |
| 2283 | bcopy (str, p, len); | 2284 | memcpy (p, str, len); |
| 2284 | p += len; | 2285 | p += len; |
| 2285 | } | 2286 | } |
| 2286 | } | 2287 | } |
| @@ -2362,7 +2363,7 @@ make_unibyte_string (const char *contents, int length) | |||
| 2362 | { | 2363 | { |
| 2363 | register Lisp_Object val; | 2364 | register Lisp_Object val; |
| 2364 | val = make_uninit_string (length); | 2365 | val = make_uninit_string (length); |
| 2365 | bcopy (contents, SDATA (val), length); | 2366 | memcpy (SDATA (val), contents, length); |
| 2366 | STRING_SET_UNIBYTE (val); | 2367 | STRING_SET_UNIBYTE (val); |
| 2367 | return val; | 2368 | return val; |
| 2368 | } | 2369 | } |
| @@ -2376,7 +2377,7 @@ make_multibyte_string (const char *contents, int nchars, int nbytes) | |||
| 2376 | { | 2377 | { |
| 2377 | register Lisp_Object val; | 2378 | register Lisp_Object val; |
| 2378 | val = make_uninit_multibyte_string (nchars, nbytes); | 2379 | val = make_uninit_multibyte_string (nchars, nbytes); |
| 2379 | bcopy (contents, SDATA (val), nbytes); | 2380 | memcpy (SDATA (val), contents, nbytes); |
| 2380 | return val; | 2381 | return val; |
| 2381 | } | 2382 | } |
| 2382 | 2383 | ||
| @@ -2389,7 +2390,7 @@ make_string_from_bytes (const char *contents, int nchars, int nbytes) | |||
| 2389 | { | 2390 | { |
| 2390 | register Lisp_Object val; | 2391 | register Lisp_Object val; |
| 2391 | val = make_uninit_multibyte_string (nchars, nbytes); | 2392 | val = make_uninit_multibyte_string (nchars, nbytes); |
| 2392 | bcopy (contents, SDATA (val), nbytes); | 2393 | memcpy (SDATA (val), contents, nbytes); |
| 2393 | if (SBYTES (val) == SCHARS (val)) | 2394 | if (SBYTES (val) == SCHARS (val)) |
| 2394 | STRING_SET_UNIBYTE (val); | 2395 | STRING_SET_UNIBYTE (val); |
| 2395 | return val; | 2396 | return val; |
| @@ -2414,7 +2415,7 @@ make_specified_string (const char *contents, int nchars, int nbytes, int multiby | |||
| 2414 | nchars = nbytes; | 2415 | nchars = nbytes; |
| 2415 | } | 2416 | } |
| 2416 | val = make_uninit_multibyte_string (nchars, nbytes); | 2417 | val = make_uninit_multibyte_string (nchars, nbytes); |
| 2417 | bcopy (contents, SDATA (val), nbytes); | 2418 | memcpy (SDATA (val), contents, nbytes); |
| 2418 | if (!multibyte) | 2419 | if (!multibyte) |
| 2419 | STRING_SET_UNIBYTE (val); | 2420 | STRING_SET_UNIBYTE (val); |
| 2420 | return val; | 2421 | return val; |
| @@ -2587,7 +2588,7 @@ make_float (double float_value) | |||
| 2587 | new = (struct float_block *) lisp_align_malloc (sizeof *new, | 2588 | new = (struct float_block *) lisp_align_malloc (sizeof *new, |
| 2588 | MEM_TYPE_FLOAT); | 2589 | MEM_TYPE_FLOAT); |
| 2589 | new->next = float_block; | 2590 | new->next = float_block; |
| 2590 | bzero ((char *) new->gcmarkbits, sizeof new->gcmarkbits); | 2591 | memset (new->gcmarkbits, 0, sizeof new->gcmarkbits); |
| 2591 | float_block = new; | 2592 | float_block = new; |
| 2592 | float_block_index = 0; | 2593 | float_block_index = 0; |
| 2593 | n_float_blocks++; | 2594 | n_float_blocks++; |
| @@ -2709,7 +2710,7 @@ DEFUN ("cons", Fcons, Scons, 2, 2, 0, | |||
| 2709 | register struct cons_block *new; | 2710 | register struct cons_block *new; |
| 2710 | new = (struct cons_block *) lisp_align_malloc (sizeof *new, | 2711 | new = (struct cons_block *) lisp_align_malloc (sizeof *new, |
| 2711 | MEM_TYPE_CONS); | 2712 | MEM_TYPE_CONS); |
| 2712 | bzero ((char *) new->gcmarkbits, sizeof new->gcmarkbits); | 2713 | memset (new->gcmarkbits, 0, sizeof new->gcmarkbits); |
| 2713 | new->next = cons_block; | 2714 | new->next = cons_block; |
| 2714 | cons_block = new; | 2715 | cons_block = new; |
| 2715 | cons_block_index = 0; | 2716 | cons_block_index = 0; |
| @@ -2950,8 +2951,8 @@ allocate_terminal (void) | |||
| 2950 | struct terminal *t = ALLOCATE_PSEUDOVECTOR (struct terminal, | 2951 | struct terminal *t = ALLOCATE_PSEUDOVECTOR (struct terminal, |
| 2951 | next_terminal, PVEC_TERMINAL); | 2952 | next_terminal, PVEC_TERMINAL); |
| 2952 | /* Zero out the non-GC'd fields. FIXME: This should be made unnecessary. */ | 2953 | /* Zero out the non-GC'd fields. FIXME: This should be made unnecessary. */ |
| 2953 | bzero (&(t->next_terminal), | 2954 | memset (&t->next_terminal, 0, |
| 2954 | ((char*)(t+1)) - ((char*)&(t->next_terminal))); | 2955 | (char*) (t + 1) - (char*) &t->next_terminal); |
| 2955 | 2956 | ||
| 2956 | return t; | 2957 | return t; |
| 2957 | } | 2958 | } |
| @@ -2962,8 +2963,8 @@ allocate_frame (void) | |||
| 2962 | struct frame *f = ALLOCATE_PSEUDOVECTOR (struct frame, | 2963 | struct frame *f = ALLOCATE_PSEUDOVECTOR (struct frame, |
| 2963 | face_cache, PVEC_FRAME); | 2964 | face_cache, PVEC_FRAME); |
| 2964 | /* Zero out the non-GC'd fields. FIXME: This should be made unnecessary. */ | 2965 | /* Zero out the non-GC'd fields. FIXME: This should be made unnecessary. */ |
| 2965 | bzero (&(f->face_cache), | 2966 | memset (&f->face_cache, 0, |
| 2966 | ((char*)(f+1)) - ((char*)&(f->face_cache))); | 2967 | (char *) (f + 1) - (char *) &f->face_cache); |
| 2967 | return f; | 2968 | return f; |
| 2968 | } | 2969 | } |
| 2969 | 2970 | ||
| @@ -4713,7 +4714,7 @@ make_pure_string (const char *data, int nchars, int nbytes, int multibyte) | |||
| 4713 | if (s->data == NULL) | 4714 | if (s->data == NULL) |
| 4714 | { | 4715 | { |
| 4715 | s->data = (unsigned char *) pure_alloc (nbytes + 1, -1); | 4716 | s->data = (unsigned char *) pure_alloc (nbytes + 1, -1); |
| 4716 | bcopy (data, s->data, nbytes); | 4717 | memcpy (s->data, data, nbytes); |
| 4717 | s->data[nbytes] = '\0'; | 4718 | s->data[nbytes] = '\0'; |
| 4718 | } | 4719 | } |
| 4719 | s->size = nchars; | 4720 | s->size = nchars; |
| @@ -4980,9 +4981,9 @@ returns nil, because real GC can't be done. */) | |||
| 4980 | if (stack_copy) | 4981 | if (stack_copy) |
| 4981 | { | 4982 | { |
| 4982 | if ((EMACS_INT) (&stack_top_variable - stack_bottom) > 0) | 4983 | if ((EMACS_INT) (&stack_top_variable - stack_bottom) > 0) |
| 4983 | bcopy (stack_bottom, stack_copy, i); | 4984 | memcpy (stack_copy, stack_bottom, i); |
| 4984 | else | 4985 | else |
| 4985 | bcopy (&stack_top_variable, stack_copy, i); | 4986 | memcpy (stack_copy, &stack_top_variable, i); |
| 4986 | } | 4987 | } |
| 4987 | } | 4988 | } |
| 4988 | } | 4989 | } |