diff options
| author | Kim F. Storm | 2003-01-12 00:40:09 +0000 |
|---|---|---|
| committer | Kim F. Storm | 2003-01-12 00:40:09 +0000 |
| commit | 035261dcccb2f8e1b88ec9074d2f714d993ba24c (patch) | |
| tree | 721b94102e515a5722dbb6d6a0321fa7c3d4e648 /src/alloc.c | |
| parent | 2c10f029175edea49c2de3547dc1a6473cd428f9 (diff) | |
| download | emacs-035261dcccb2f8e1b88ec9074d2f714d993ba24c.tar.gz emacs-035261dcccb2f8e1b88ec9074d2f714d993ba24c.zip | |
(pure_alloc): Corrected last change; now align the
pointer and adjust the size rather than aligning the size and
adjusting the pointer. Use a goto to handle overflow exception.
Diffstat (limited to 'src/alloc.c')
| -rw-r--r-- | src/alloc.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/alloc.c b/src/alloc.c index 47885c67534..f19c2328899 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -3833,39 +3833,42 @@ pure_alloc (size, type) | |||
| 3833 | { | 3833 | { |
| 3834 | size_t nbytes; | 3834 | size_t nbytes; |
| 3835 | POINTER_TYPE *result; | 3835 | POINTER_TYPE *result; |
| 3836 | char *beg = purebeg; | 3836 | char *beg; |
| 3837 | |||
| 3838 | again: | ||
| 3839 | beg = purebeg; | ||
| 3840 | result = (POINTER_TYPE *) (beg + pure_bytes_used); | ||
| 3841 | nbytes = ALIGN (size, sizeof (EMACS_INT)); | ||
| 3837 | 3842 | ||
| 3838 | /* Give Lisp_Floats an extra alignment. */ | 3843 | /* Give Lisp_Floats an extra alignment. */ |
| 3839 | if (type == Lisp_Float) | 3844 | if (type == Lisp_Float) |
| 3840 | { | 3845 | { |
| 3846 | POINTER_TYPE *orig = result; | ||
| 3841 | size_t alignment; | 3847 | size_t alignment; |
| 3842 | #if defined __GNUC__ && __GNUC__ >= 2 | 3848 | #if defined __GNUC__ && __GNUC__ >= 2 |
| 3843 | alignment = __alignof (struct Lisp_Float); | 3849 | alignment = __alignof (struct Lisp_Float); |
| 3844 | #else | 3850 | #else |
| 3845 | alignment = sizeof (struct Lisp_Float); | 3851 | alignment = sizeof (struct Lisp_Float); |
| 3846 | #endif | 3852 | #endif |
| 3847 | /* Make sure beg + pure_bytes_used is correctly aligned for a | 3853 | /* Make sure result is correctly aligned for a |
| 3848 | Lisp_Float, which might need stricter alignment than | 3854 | Lisp_Float, which might need stricter alignment than |
| 3849 | EMACS_INT. */ | 3855 | EMACS_INT. */ |
| 3850 | pure_bytes_used | 3856 | result = (POINTER_TYPE *)ALIGN((EMACS_UINT)result, alignment); |
| 3851 | = (ALIGN ((EMACS_UINT) (beg + pure_bytes_used), alignment) | 3857 | nbytes += (char *)result - (char *)orig; |
| 3852 | - (EMACS_UINT) beg); | ||
| 3853 | } | 3858 | } |
| 3854 | 3859 | ||
| 3855 | nbytes = ALIGN (size, sizeof (EMACS_INT)); | ||
| 3856 | |||
| 3857 | if (pure_bytes_used + nbytes > pure_size) | 3860 | if (pure_bytes_used + nbytes > pure_size) |
| 3858 | { | 3861 | { |
| 3859 | /* Don't allocate a large amount here, | 3862 | /* Don't allocate a large amount here, |
| 3860 | because it might get mmap'd and then its address | 3863 | because it might get mmap'd and then its address |
| 3861 | might not be usable. */ | 3864 | might not be usable. */ |
| 3862 | beg = purebeg = (char *) xmalloc (10000); | 3865 | purebeg = (char *) xmalloc (10000); |
| 3863 | pure_size = 10000; | 3866 | pure_size = 10000; |
| 3864 | pure_bytes_used_before_overflow += pure_bytes_used; | 3867 | pure_bytes_used_before_overflow += pure_bytes_used; |
| 3865 | pure_bytes_used = 0; | 3868 | pure_bytes_used = 0; |
| 3869 | goto again; | ||
| 3866 | } | 3870 | } |
| 3867 | 3871 | ||
| 3868 | result = (POINTER_TYPE *) (beg + pure_bytes_used); | ||
| 3869 | pure_bytes_used += nbytes; | 3872 | pure_bytes_used += nbytes; |
| 3870 | return result; | 3873 | return result; |
| 3871 | } | 3874 | } |