comparison src/alloc.c @ 49159:bc82a79251b5

(pure_alloc): Rewritten and simplified.
author Kim F. Storm <storm@cua.dk>
date Sun, 12 Jan 2003 15:36:40 +0000
parents c9d5d9f8e071
children 2cbb0b823e83
comparison
equal deleted inserted replaced
49158:c9d5d9f8e071 49159:bc82a79251b5
3829 static POINTER_TYPE * 3829 static POINTER_TYPE *
3830 pure_alloc (size, type) 3830 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 3845 }
3854 Lisp_Float, which might need stricter alignment than 3846
3855 EMACS_INT. */ 3847 again:
3856 result = (POINTER_TYPE *)ALIGN((EMACS_UINT)result, alignment); 3848 result = (POINTER_TYPE *) ALIGN ((EMACS_UINT)purebeg + pure_bytes_used, alignment);
3857 nbytes += (char *)result - (char *)orig; 3849 pure_bytes_used = ((char *)result - (char *)purebeg) + size;
3858 } 3850
3859 3851 if (pure_bytes_used <= pure_size)
3860 if (pure_bytes_used + nbytes > pure_size) 3852 return result;
3861 { 3853
3862 /* Don't allocate a large amount here, 3854 /* Don't allocate a large amount here,
3863 because it might get mmap'd and then its address 3855 because it might get mmap'd and then its address
3864 might not be usable. */ 3856 might not be usable. */
3865 purebeg = (char *) xmalloc (10000); 3857 purebeg = (char *) xmalloc (10000);
3866 pure_size = 10000; 3858 pure_size = 10000;
3867 pure_bytes_used_before_overflow += pure_bytes_used; 3859 pure_bytes_used_before_overflow += pure_bytes_used - size;
3868 pure_bytes_used = 0; 3860 pure_bytes_used = 0;
3869 goto again; 3861 goto again;
3870 }
3871
3872 pure_bytes_used += nbytes;
3873 return result;
3874 } 3862 }
3875 3863
3876 3864
3877 /* Print a warning if PURESIZE is too small. */ 3865 /* Print a warning if PURESIZE is too small. */
3878 3866