Mercurial > emacs
comparison src/alloc.c @ 83533:02e39decdc84
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
| author | Karoly Lorentey <lorentey@elte.hu> |
|---|---|
| date | Sat, 29 Jul 2006 09:59:12 +0000 |
| parents | 81f2d90dee68 fe7f8d2385f8 |
| children | 694bbb62a75d |
comparison
equal
deleted
inserted
replaced
| 83532:b19aaf4ab0ee | 83533:02e39decdc84 |
|---|---|
| 287 (((PNTR_COMPARISON_TYPE) (P) \ | 287 (((PNTR_COMPARISON_TYPE) (P) \ |
| 288 < (PNTR_COMPARISON_TYPE) ((char *) purebeg + pure_size)) \ | 288 < (PNTR_COMPARISON_TYPE) ((char *) purebeg + pure_size)) \ |
| 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 |
| 294 EMACS_INT pure_bytes_used; | 294 EMACS_INT pure_bytes_used; |
| 295 | |
| 296 /* Index in pure at which next pure Lisp object will be allocated.. */ | |
| 297 | |
| 298 static EMACS_INT pure_bytes_used_lisp; | |
| 299 | |
| 300 /* Number of bytes allocated for non-Lisp objects in pure storage. */ | |
| 301 | |
| 302 static EMACS_INT pure_bytes_used_non_lisp; | |
| 295 | 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 |
| 299 char *pending_malloc_warning; | 307 char *pending_malloc_warning; |
| 559 memory_full (); | 567 memory_full (); |
| 560 #endif | 568 #endif |
| 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 |
| 569 #ifdef XMALLOC_OVERRUN_CHECK | 576 #ifdef XMALLOC_OVERRUN_CHECK |
| 570 | 577 |
| 2777 while (tail) | 2784 while (tail) |
| 2778 tail = tail->u.chain; | 2785 tail = tail->u.chain; |
| 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 | |
| 2791 Lisp_Object | |
| 2792 list1 (arg1) | |
| 2793 Lisp_Object arg1; | |
| 2794 { | |
| 2795 return Fcons (arg1, Qnil); | |
| 2796 } | |
| 2783 | 2797 |
| 2784 Lisp_Object | 2798 Lisp_Object |
| 2785 list2 (arg1, arg2) | 2799 list2 (arg1, arg2) |
| 2786 Lisp_Object arg1, arg2; | 2800 Lisp_Object arg1, arg2; |
| 2787 { | 2801 { |
| 3493 bytes_used_when_full = BYTES_USED; | 3507 bytes_used_when_full = BYTES_USED; |
| 3494 #endif | 3508 #endif |
| 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), |
| 3503 and we have a fair amount free once again, | 3516 and we have a fair amount free once again, |
| 3504 try to set aside another reserve in case we run out once more. | 3517 try to set aside another reserve in case we run out once more. |
| 4687 Pure Storage Management | 4700 Pure Storage Management |
| 4688 ***********************************************************************/ | 4701 ***********************************************************************/ |
| 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 |
| 4697 static POINTER_TYPE * | 4707 static POINTER_TYPE * |
| 4698 pure_alloc (size, type) | 4708 pure_alloc (size, type) |
| 4699 size_t size; | 4709 size_t size; |
| 4700 int type; | 4710 int type; |
| 4715 #endif | 4725 #endif |
| 4716 } | 4726 } |
| 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; |
| 4725 | 4748 |
| 4726 /* Don't allocate a large amount here, | 4749 /* Don't allocate a large amount here, |
| 4728 might not be usable. */ | 4751 might not be usable. */ |
| 4729 purebeg = (char *) xmalloc (10000); | 4752 purebeg = (char *) xmalloc (10000); |
| 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 |
| 4736 | 4760 |
| 4737 /* Print a warning if PURESIZE is too small. */ | 4761 /* Print a warning if PURESIZE is too small. */ |
| 4740 check_pure_size () | 4764 check_pure_size () |
| 4741 { | 4765 { |
| 4742 if (pure_bytes_used_before_overflow) | 4766 if (pure_bytes_used_before_overflow) |
| 4743 message ("emacs:0:Pure Lisp storage overflow (approx. %d bytes needed)", | 4767 message ("emacs:0:Pure Lisp storage overflow (approx. %d bytes needed)", |
| 4744 (int) (pure_bytes_used + pure_bytes_used_before_overflow)); | 4768 (int) (pure_bytes_used + pure_bytes_used_before_overflow)); |
| 4769 } | |
| 4770 | |
| 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 | |
| 4776 static char * | |
| 4777 find_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; | |
| 4745 } | 4836 } |
| 4746 | 4837 |
| 4747 | 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 |
| 4761 { | 4852 { |
| 4762 Lisp_Object string; | 4853 Lisp_Object string; |
| 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; |
| 4774 } | 4869 } |
| 4775 | 4870 |
| 6223 { | 6318 { |
| 6224 /* Used to do Vpurify_flag = Qt here, but Qt isn't set up yet! */ | 6319 /* Used to do Vpurify_flag = Qt here, but Qt isn't set up yet! */ |
| 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. */ |
| 6231 free_ablock = NULL; | 6327 free_ablock = NULL; |
| 6232 | 6328 |
