aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
authorKaroly Lorentey2006-07-29 09:59:12 +0000
committerKaroly Lorentey2006-07-29 09:59:12 +0000
commit251bc578cc636223d618d06cf2a2bb7d07db9cce (patch)
tree58e1c6b0a35bb4a77e6cb77876e4bc6a9d3f2ab2 /src/alloc.c
parent99715bbc447eb633e45ffa23b87284771ce3ac74 (diff)
parent0ed0527cb02180a50f6744086ce3a487740c73e4 (diff)
downloademacs-251bc578cc636223d618d06cf2a2bb7d07db9cce.tar.gz
emacs-251bc578cc636223d618d06cf2a2bb7d07db9cce.zip
Merged from emacs@sv.gnu.org
Patches applied: * emacs@sv.gnu.org/emacs--devo--0--patch-351 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-352 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-353 Merge from gnus--rel--5.10 * emacs@sv.gnu.org/emacs--devo--0--patch-354 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-355 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-356 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-357 Merge from gnus--rel--5.10 * emacs@sv.gnu.org/emacs--devo--0--patch-358 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-359 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-360 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-361 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-362 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-363 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-364 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-365 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-366 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-367 Merge from gnus--rel--5.10 * emacs@sv.gnu.org/emacs--devo--0--patch-368 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-369 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-370 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-115 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-116 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-117 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-118 Merge from emacs--devo--0 * emacs@sv.gnu.org/gnus--rel--5.10--patch-119 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-120 Update from CVS git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-573
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c126
1 files changed, 111 insertions, 15 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 8088540bb6b..e3609292749 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -289,10 +289,18 @@ static size_t pure_bytes_used_before_overflow;
289 && ((PNTR_COMPARISON_TYPE) (P) \ 289 && ((PNTR_COMPARISON_TYPE) (P) \
290 >= (PNTR_COMPARISON_TYPE) purebeg)) 290 >= (PNTR_COMPARISON_TYPE) purebeg))
291 291
292/* Index in pure at which next pure object will be allocated.. */ 292/* Total number of bytes allocated in pure storage. */
293 293
294EMACS_INT pure_bytes_used; 294EMACS_INT pure_bytes_used;
295 295
296/* Index in pure at which next pure Lisp object will be allocated.. */
297
298static EMACS_INT pure_bytes_used_lisp;
299
300/* Number of bytes allocated for non-Lisp objects in pure storage. */
301
302static EMACS_INT pure_bytes_used_non_lisp;
303
296/* If nonzero, this is a warning delivered by malloc and not yet 304/* If nonzero, this is a warning delivered by malloc and not yet
297 displayed. */ 305 displayed. */
298 306
@@ -561,8 +569,7 @@ buffer_memory_full ()
561 569
562 /* This used to call error, but if we've run out of memory, we could 570 /* This used to call error, but if we've run out of memory, we could
563 get infinite recursion trying to build the string. */ 571 get infinite recursion trying to build the string. */
564 while (1) 572 xsignal (Qnil, Vmemory_signal_data);
565 Fsignal (Qnil, Vmemory_signal_data);
566} 573}
567 574
568 575
@@ -2779,7 +2786,14 @@ check_cons_list ()
2779#endif 2786#endif
2780} 2787}
2781 2788
2782/* Make a list of 2, 3, 4 or 5 specified objects. */ 2789/* Make a list of 1, 2, 3, 4 or 5 specified objects. */
2790
2791Lisp_Object
2792list1 (arg1)
2793 Lisp_Object arg1;
2794{
2795 return Fcons (arg1, Qnil);
2796}
2783 2797
2784Lisp_Object 2798Lisp_Object
2785list2 (arg1, arg2) 2799list2 (arg1, arg2)
@@ -3495,8 +3509,7 @@ memory_full ()
3495 3509
3496 /* This used to call error, but if we've run out of memory, we could 3510 /* This used to call error, but if we've run out of memory, we could
3497 get infinite recursion trying to build the string. */ 3511 get infinite recursion trying to build the string. */
3498 while (1) 3512 xsignal (Qnil, Vmemory_signal_data);
3499 Fsignal (Qnil, Vmemory_signal_data);
3500} 3513}
3501 3514
3502/* If we released our reserve (due to running out of memory), 3515/* If we released our reserve (due to running out of memory),
@@ -4689,10 +4702,7 @@ valid_lisp_object_p (obj)
4689 4702
4690/* Allocate room for SIZE bytes from pure Lisp storage and return a 4703/* Allocate room for SIZE bytes from pure Lisp storage and return a
4691 pointer to it. TYPE is the Lisp type for which the memory is 4704 pointer to it. TYPE is the Lisp type for which the memory is
4692 allocated. TYPE < 0 means it's not used for a Lisp object. 4705 allocated. TYPE < 0 means it's not used for a Lisp object. */
4693
4694 If store_pure_type_info is set and TYPE is >= 0, the type of
4695 the allocated object is recorded in pure_types. */
4696 4706
4697static POINTER_TYPE * 4707static POINTER_TYPE *
4698pure_alloc (size, type) 4708pure_alloc (size, type)
@@ -4717,8 +4727,21 @@ pure_alloc (size, type)
4717#endif 4727#endif
4718 4728
4719 again: 4729 again:
4720 result = ALIGN (purebeg + pure_bytes_used, alignment); 4730 if (type >= 0)
4721 pure_bytes_used = ((char *)result - (char *)purebeg) + size; 4731 {
4732 /* Allocate space for a Lisp object from the beginning of the free
4733 space with taking account of alignment. */
4734 result = ALIGN (purebeg + pure_bytes_used_lisp, alignment);
4735 pure_bytes_used_lisp = ((char *)result - (char *)purebeg) + size;
4736 }
4737 else
4738 {
4739 /* Allocate space for a non-Lisp object from the end of the free
4740 space. */
4741 pure_bytes_used_non_lisp += size;
4742 result = purebeg + pure_size - pure_bytes_used_non_lisp;
4743 }
4744 pure_bytes_used = pure_bytes_used_lisp + pure_bytes_used_non_lisp;
4722 4745
4723 if (pure_bytes_used <= pure_size) 4746 if (pure_bytes_used <= pure_size)
4724 return result; 4747 return result;
@@ -4730,6 +4753,7 @@ pure_alloc (size, type)
4730 pure_size = 10000; 4753 pure_size = 10000;
4731 pure_bytes_used_before_overflow += pure_bytes_used - size; 4754 pure_bytes_used_before_overflow += pure_bytes_used - size;
4732 pure_bytes_used = 0; 4755 pure_bytes_used = 0;
4756 pure_bytes_used_lisp = pure_bytes_used_non_lisp = 0;
4733 goto again; 4757 goto again;
4734} 4758}
4735 4759
@@ -4745,6 +4769,73 @@ check_pure_size ()
4745} 4769}
4746 4770
4747 4771
4772/* Find the byte sequence {DATA[0], ..., DATA[NBYTES-1], '\0'} from
4773 the non-Lisp data pool of the pure storage, and return its start
4774 address. Return NULL if not found. */
4775
4776static char *
4777find_string_data_in_pure (data, nbytes)
4778 char *data;
4779 int nbytes;
4780{
4781 int i, skip, bm_skip[256], last_char_skip, infinity, start, start_max;
4782 unsigned char *p;
4783 char *non_lisp_beg;
4784
4785 if (pure_bytes_used_non_lisp < nbytes + 1)
4786 return NULL;
4787
4788 /* Set up the Boyer-Moore table. */
4789 skip = nbytes + 1;
4790 for (i = 0; i < 256; i++)
4791 bm_skip[i] = skip;
4792
4793 p = (unsigned char *) data;
4794 while (--skip > 0)
4795 bm_skip[*p++] = skip;
4796
4797 last_char_skip = bm_skip['\0'];
4798
4799 non_lisp_beg = purebeg + pure_size - pure_bytes_used_non_lisp;
4800 start_max = pure_bytes_used_non_lisp - (nbytes + 1);
4801
4802 /* See the comments in the function `boyer_moore' (search.c) for the
4803 use of `infinity'. */
4804 infinity = pure_bytes_used_non_lisp + 1;
4805 bm_skip['\0'] = infinity;
4806
4807 p = (unsigned char *) non_lisp_beg + nbytes;
4808 start = 0;
4809 do
4810 {
4811 /* Check the last character (== '\0'). */
4812 do
4813 {
4814 start += bm_skip[*(p + start)];
4815 }
4816 while (start <= start_max);
4817
4818 if (start < infinity)
4819 /* Couldn't find the last character. */
4820 return NULL;
4821
4822 /* No less than `infinity' means we could find the last
4823 character at `p[start - infinity]'. */
4824 start -= infinity;
4825
4826 /* Check the remaining characters. */
4827 if (memcmp (data, non_lisp_beg + start, nbytes) == 0)
4828 /* Found. */
4829 return non_lisp_beg + start;
4830
4831 start += last_char_skip;
4832 }
4833 while (start <= start_max);
4834
4835 return NULL;
4836}
4837
4838
4748/* Return a string allocated in pure space. DATA is a buffer holding 4839/* Return a string allocated in pure space. DATA is a buffer holding
4749 NCHARS characters, and NBYTES bytes of string data. MULTIBYTE 4840 NCHARS characters, and NBYTES bytes of string data. MULTIBYTE
4750 non-zero means make the result string multibyte. 4841 non-zero means make the result string multibyte.
@@ -4763,11 +4854,15 @@ make_pure_string (data, nchars, nbytes, multibyte)
4763 struct Lisp_String *s; 4854 struct Lisp_String *s;
4764 4855
4765 s = (struct Lisp_String *) pure_alloc (sizeof *s, Lisp_String); 4856 s = (struct Lisp_String *) pure_alloc (sizeof *s, Lisp_String);
4766 s->data = (unsigned char *) pure_alloc (nbytes + 1, -1); 4857 s->data = find_string_data_in_pure (data, nbytes);
4858 if (s->data == NULL)
4859 {
4860 s->data = (unsigned char *) pure_alloc (nbytes + 1, -1);
4861 bcopy (data, s->data, nbytes);
4862 s->data[nbytes] = '\0';
4863 }
4767 s->size = nchars; 4864 s->size = nchars;
4768 s->size_byte = multibyte ? nbytes : -1; 4865 s->size_byte = multibyte ? nbytes : -1;
4769 bcopy (data, s->data, nbytes);
4770 s->data[nbytes] = '\0';
4771 s->intervals = NULL_INTERVAL; 4866 s->intervals = NULL_INTERVAL;
4772 XSETSTRING (string, s); 4867 XSETSTRING (string, s);
4773 return string; 4868 return string;
@@ -6225,6 +6320,7 @@ init_alloc_once ()
6225 purebeg = PUREBEG; 6320 purebeg = PUREBEG;
6226 pure_size = PURESIZE; 6321 pure_size = PURESIZE;
6227 pure_bytes_used = 0; 6322 pure_bytes_used = 0;
6323 pure_bytes_used_lisp = pure_bytes_used_non_lisp = 0;
6228 pure_bytes_used_before_overflow = 0; 6324 pure_bytes_used_before_overflow = 0;
6229 6325
6230 /* Initialize the list of free aligned blocks. */ 6326 /* Initialize the list of free aligned blocks. */