diff options
| author | Kim F. Storm | 2003-01-12 15:40:23 +0000 |
|---|---|---|
| committer | Kim F. Storm | 2003-01-12 15:40:23 +0000 |
| commit | 441174202f21deff8366a8060b9e4eed4e7c29aa (patch) | |
| tree | b9231ed78c7ae5293b54b8eac91dfd74524a9dc2 /src | |
| parent | 035261dcccb2f8e1b88ec9074d2f714d993ba24c (diff) | |
| download | emacs-441174202f21deff8366a8060b9e4eed4e7c29aa.tar.gz emacs-441174202f21deff8366a8060b9e4eed4e7c29aa.zip | |
(pure_alloc): Rewritten and simplified.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 7 | ||||
| -rw-r--r-- | src/alloc.c | 44 |
2 files changed, 20 insertions, 31 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 77468a9d14c..ff63eb318a3 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,8 +1,9 @@ | |||
| 1 | 2003-01-12 Kim F. Storm <storm@cua.dk> | 1 | 2003-01-12 Kim F. Storm <storm@cua.dk> |
| 2 | 2 | ||
| 3 | * alloc.c (pure_alloc): Corrected last change; now align the | 3 | * alloc.c (pure_alloc): Fixed 2003-01-10 changed (caused spurious |
| 4 | pointer and adjust the size rather than aligning the size and | 4 | crashes). Code rewritten and simplified. Now directly aligns the |
| 5 | adjusting the pointer. Use a goto to handle overflow exception. | 5 | pointer and recalculates pure_bytes_used, rather than aligning the |
| 6 | size and adjusting the pointer. | ||
| 6 | 7 | ||
| 7 | 2003-01-11 Kim F. Storm <storm@cua.dk> | 8 | 2003-01-11 Kim F. Storm <storm@cua.dk> |
| 8 | 9 | ||
diff --git a/src/alloc.c b/src/alloc.c index f19c2328899..281288e69db 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -3831,46 +3831,34 @@ pure_alloc (size, type) | |||
| 3831 | size_t size; | 3831 | size_t size; |
| 3832 | int type; | 3832 | int type; |
| 3833 | { | 3833 | { |
| 3834 | size_t nbytes; | ||
| 3835 | POINTER_TYPE *result; | 3834 | POINTER_TYPE *result; |
| 3836 | char *beg; | 3835 | size_t alignment = sizeof (EMACS_INT); |
| 3837 | |||
| 3838 | again: | ||
| 3839 | beg = purebeg; | ||
| 3840 | result = (POINTER_TYPE *) (beg + pure_bytes_used); | ||
| 3841 | nbytes = ALIGN (size, sizeof (EMACS_INT)); | ||
| 3842 | 3836 | ||
| 3843 | /* Give Lisp_Floats an extra alignment. */ | 3837 | /* Give Lisp_Floats an extra alignment. */ |
| 3844 | if (type == Lisp_Float) | 3838 | if (type == Lisp_Float) |
| 3845 | { | 3839 | { |
| 3846 | POINTER_TYPE *orig = result; | ||
| 3847 | size_t alignment; | ||
| 3848 | #if defined __GNUC__ && __GNUC__ >= 2 | 3840 | #if defined __GNUC__ && __GNUC__ >= 2 |
| 3849 | alignment = __alignof (struct Lisp_Float); | 3841 | alignment = __alignof (struct Lisp_Float); |
| 3850 | #else | 3842 | #else |
| 3851 | alignment = sizeof (struct Lisp_Float); | 3843 | alignment = sizeof (struct Lisp_Float); |
| 3852 | #endif | 3844 | #endif |
| 3853 | /* Make sure result is correctly aligned for a | ||
| 3854 | Lisp_Float, which might need stricter alignment than | ||
| 3855 | EMACS_INT. */ | ||
| 3856 | result = (POINTER_TYPE *)ALIGN((EMACS_UINT)result, alignment); | ||
| 3857 | nbytes += (char *)result - (char *)orig; | ||
| 3858 | } | ||
| 3859 | |||
| 3860 | if (pure_bytes_used + nbytes > pure_size) | ||
| 3861 | { | ||
| 3862 | /* Don't allocate a large amount here, | ||
| 3863 | because it might get mmap'd and then its address | ||
| 3864 | might not be usable. */ | ||
| 3865 | purebeg = (char *) xmalloc (10000); | ||
| 3866 | pure_size = 10000; | ||
| 3867 | pure_bytes_used_before_overflow += pure_bytes_used; | ||
| 3868 | pure_bytes_used = 0; | ||
| 3869 | goto again; | ||
| 3870 | } | 3845 | } |
| 3871 | 3846 | ||
| 3872 | pure_bytes_used += nbytes; | 3847 | again: |
| 3873 | return result; | 3848 | result = (POINTER_TYPE *) ALIGN ((EMACS_UINT)purebeg + pure_bytes_used, alignment); |
| 3849 | pure_bytes_used = ((char *)result - (char *)purebeg) + size; | ||
| 3850 | |||
| 3851 | if (pure_bytes_used <= pure_size) | ||
| 3852 | return result; | ||
| 3853 | |||
| 3854 | /* Don't allocate a large amount here, | ||
| 3855 | because it might get mmap'd and then its address | ||
| 3856 | might not be usable. */ | ||
| 3857 | purebeg = (char *) xmalloc (10000); | ||
| 3858 | pure_size = 10000; | ||
| 3859 | pure_bytes_used_before_overflow += pure_bytes_used - size; | ||
| 3860 | pure_bytes_used = 0; | ||
| 3861 | goto again; | ||
| 3874 | } | 3862 | } |
| 3875 | 3863 | ||
| 3876 | 3864 | ||