Mercurial > hg > xemacs-beta
comparison src/alloc.c @ 20:859a2309aef8 r19-15b93
Import from CVS: tag r19-15b93
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:50:05 +0200 |
parents | 0293115a14e9 |
children | 441bb1e64a06 |
comparison
equal
deleted
inserted
replaced
19:ac1f612d5250 | 20:859a2309aef8 |
---|---|
982 DECLARE_FIXED_TYPE_ALLOC (cons, struct Lisp_Cons); | 982 DECLARE_FIXED_TYPE_ALLOC (cons, struct Lisp_Cons); |
983 /* conses are used and freed so often that we set this really high */ | 983 /* conses are used and freed so often that we set this really high */ |
984 /* #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_cons 20000 */ | 984 /* #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_cons 20000 */ |
985 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_cons 2000 | 985 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_cons 2000 |
986 | 986 |
987 DEFUN ("cons", Fcons, Scons, 2, 2, 0 /* | 987 DEFUN ("cons", Fcons, 2, 2, 0, /* |
988 Create a new cons, give it CAR and CDR as components, and return it. | 988 Create a new cons, give it CAR and CDR as components, and return it. |
989 */ ) | 989 */ |
990 (car, cdr) | 990 (car, cdr)) |
991 Lisp_Object car, cdr; | |
992 { | 991 { |
993 /* This cannot GC. */ | 992 /* This cannot GC. */ |
994 Lisp_Object val = Qnil; | 993 Lisp_Object val = Qnil; |
995 struct Lisp_Cons *c; | 994 struct Lisp_Cons *c; |
996 | 995 |
1015 XCAR (val) = car; | 1014 XCAR (val) = car; |
1016 XCDR (val) = cdr; | 1015 XCDR (val) = cdr; |
1017 return val; | 1016 return val; |
1018 } | 1017 } |
1019 | 1018 |
1020 DEFUN ("list", Flist, Slist, 0, MANY, 0 /* | 1019 DEFUN ("list", Flist, 0, MANY, 0, /* |
1021 Return a newly created list with specified arguments as elements. | 1020 Return a newly created list with specified arguments as elements. |
1022 Any number of arguments, even zero arguments, are allowed. | 1021 Any number of arguments, even zero arguments, are allowed. |
1023 */ ) | 1022 */ |
1024 (nargs, args) | 1023 (int nargs, Lisp_Object *args)) |
1025 int nargs; | |
1026 Lisp_Object *args; | |
1027 { | 1024 { |
1028 Lisp_Object len, val, val_tail; | 1025 Lisp_Object len, val, val_tail; |
1029 | 1026 |
1030 len = make_int (nargs); | 1027 len = make_int (nargs); |
1031 val = Fmake_list (len, Qnil); | 1028 val = Fmake_list (len, Qnil); |
1087 { | 1084 { |
1088 /* This cannot GC. */ | 1085 /* This cannot GC. */ |
1089 return Fcons (obj0, list5 (obj1, obj2, obj3, obj4, obj5)); | 1086 return Fcons (obj0, list5 (obj1, obj2, obj3, obj4, obj5)); |
1090 } | 1087 } |
1091 | 1088 |
1092 DEFUN ("make-list", Fmake_list, Smake_list, 2, 2, 0 /* | 1089 DEFUN ("make-list", Fmake_list, 2, 2, 0, /* |
1093 Return a newly created list of length LENGTH, with each element being INIT. | 1090 Return a newly created list of length LENGTH, with each element being INIT. |
1094 */ ) | 1091 */ |
1095 (length, init) | 1092 (length, init)) |
1096 Lisp_Object length, init; | |
1097 { | 1093 { |
1098 Lisp_Object val; | 1094 Lisp_Object val; |
1099 int size; | 1095 int size; |
1100 | 1096 |
1101 CHECK_NATNUM (length); | 1097 CHECK_NATNUM (length); |
1193 vector_data(p)[elt] = init; | 1189 vector_data(p)[elt] = init; |
1194 | 1190 |
1195 return (vector); | 1191 return (vector); |
1196 } | 1192 } |
1197 | 1193 |
1198 DEFUN ("make-vector", Fmake_vector, Smake_vector, 2, 2, 0 /* | 1194 DEFUN ("make-vector", Fmake_vector, 2, 2, 0, /* |
1199 Return a newly created vector of length LENGTH, with each element being INIT. | 1195 Return a newly created vector of length LENGTH, with each element being INIT. |
1200 See also the function `vector'. | 1196 See also the function `vector'. |
1201 */ ) | 1197 */ |
1202 (length, init) | 1198 (length, init)) |
1203 Lisp_Object length, init; | |
1204 { | 1199 { |
1205 if (!INTP (length) || XINT (length) < 0) | 1200 if (!INTP (length) || XINT (length) < 0) |
1206 length = wrong_type_argument (Qnatnump, length); | 1201 length = wrong_type_argument (Qnatnump, length); |
1207 | 1202 |
1208 return (make_vector (XINT (length), init)); | 1203 return (make_vector (XINT (length), init)); |
1209 } | 1204 } |
1210 | 1205 |
1211 DEFUN ("vector", Fvector, Svector, 0, MANY, 0 /* | 1206 DEFUN ("vector", Fvector, 0, MANY, 0, /* |
1212 Return a newly created vector with specified arguments as elements. | 1207 Return a newly created vector with specified arguments as elements. |
1213 Any number of arguments, even zero arguments, are allowed. | 1208 Any number of arguments, even zero arguments, are allowed. |
1214 */ ) | 1209 */ |
1215 (nargs, args) | 1210 (int nargs, Lisp_Object *args)) |
1216 int nargs; | |
1217 Lisp_Object *args; | |
1218 { | 1211 { |
1219 Lisp_Object vector = Qnil; | 1212 Lisp_Object vector = Qnil; |
1220 int elt; | 1213 int elt; |
1221 struct Lisp_Vector *p; | 1214 struct Lisp_Vector *p; |
1222 | 1215 |
1401 set_bit_vector_bit (p, i, bytevec[i]); | 1394 set_bit_vector_bit (p, i, bytevec[i]); |
1402 | 1395 |
1403 return bit_vector; | 1396 return bit_vector; |
1404 } | 1397 } |
1405 | 1398 |
1406 DEFUN ("make-bit-vector", Fmake_bit_vector, Smake_bit_vector, 2, 2, 0 /* | 1399 DEFUN ("make-bit-vector", Fmake_bit_vector, 2, 2, 0, /* |
1407 Return a newly created bit vector of length LENGTH. | 1400 Return a newly created bit vector of length LENGTH. |
1408 Each element is set to INIT. See also the function `bit-vector'. | 1401 Each element is set to INIT. See also the function `bit-vector'. |
1409 */ ) | 1402 */ |
1410 (length, init) | 1403 (length, init)) |
1411 Lisp_Object length, init; | |
1412 { | 1404 { |
1413 if (!INTP (length) || XINT (length) < 0) | 1405 if (!INTP (length) || XINT (length) < 0) |
1414 length = wrong_type_argument (Qnatnump, length); | 1406 length = wrong_type_argument (Qnatnump, length); |
1415 | 1407 |
1416 return (make_bit_vector (XINT (length), init)); | 1408 return (make_bit_vector (XINT (length), init)); |
1417 } | 1409 } |
1418 | 1410 |
1419 DEFUN ("bit-vector", Fbit_vector, Sbit_vector, 0, MANY, 0 /* | 1411 DEFUN ("bit-vector", Fbit_vector, 0, MANY, 0, /* |
1420 Return a newly created bit vector with specified arguments as elements. | 1412 Return a newly created bit vector with specified arguments as elements. |
1421 Any number of arguments, even zero arguments, are allowed. | 1413 Any number of arguments, even zero arguments, are allowed. |
1422 */ ) | 1414 */ |
1423 (nargs, args) | 1415 (int nargs, Lisp_Object *args)) |
1424 int nargs; | |
1425 Lisp_Object *args; | |
1426 { | 1416 { |
1427 Lisp_Object bit_vector = Qnil; | 1417 Lisp_Object bit_vector = Qnil; |
1428 int elt; | 1418 int elt; |
1429 struct Lisp_Bit_Vector *p; | 1419 struct Lisp_Bit_Vector *p; |
1430 | 1420 |
1481 #endif | 1471 #endif |
1482 XSETCOMPILED_FUNCTION (new, b); | 1472 XSETCOMPILED_FUNCTION (new, b); |
1483 return (new); | 1473 return (new); |
1484 } | 1474 } |
1485 | 1475 |
1486 DEFUN ("make-byte-code", Fmake_byte_code, Smake_byte_code, 4, MANY, 0 /* | 1476 DEFUN ("make-byte-code", Fmake_byte_code, 4, MANY, 0, /* |
1487 Create a compiled-function object. | 1477 Create a compiled-function object. |
1488 Usage: (arglist instructions constants stack-size | 1478 Usage: (arglist instructions constants stack-size |
1489 &optional doc-string interactive-spec) | 1479 &optional doc-string interactive-spec) |
1490 Note that, unlike all other emacs-lisp functions, calling this with five | 1480 Note that, unlike all other emacs-lisp functions, calling this with five |
1491 arguments is NOT the same as calling it with six arguments, the last of | 1481 arguments is NOT the same as calling it with six arguments, the last of |
1492 which is nil. If the INTERACTIVE arg is specified as nil, then that means | 1482 which is nil. If the INTERACTIVE arg is specified as nil, then that means |
1493 that this function was defined with `(interactive)'. If the arg is not | 1483 that this function was defined with `(interactive)'. If the arg is not |
1494 specified, then that means the function is not interactive. | 1484 specified, then that means the function is not interactive. |
1495 This is terrible behavior which is retained for compatibility with old | 1485 This is terrible behavior which is retained for compatibility with old |
1496 `.elc' files which expected these semantics. | 1486 `.elc' files which expected these semantics. |
1497 */ ) | 1487 */ |
1498 (nargs, args) | 1488 (int nargs, Lisp_Object *args)) |
1499 int nargs; | |
1500 Lisp_Object *args; | |
1501 { | 1489 { |
1502 /* In a non-insane world this function would have this arglist... | 1490 /* In a non-insane world this function would have this arglist... |
1503 (arglist, instructions, constants, stack_size, doc_string, interactive) | 1491 (arglist, instructions, constants, stack_size, doc_string, interactive) |
1504 Lisp_Object arglist, instructions, constants, stack_size, doc_string, | 1492 Lisp_Object arglist, instructions, constants, stack_size, doc_string, |
1505 interactive; | 1493 interactive; |
1656 /**********************************************************************/ | 1644 /**********************************************************************/ |
1657 | 1645 |
1658 DECLARE_FIXED_TYPE_ALLOC (symbol, struct Lisp_Symbol); | 1646 DECLARE_FIXED_TYPE_ALLOC (symbol, struct Lisp_Symbol); |
1659 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_symbol 1000 | 1647 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_symbol 1000 |
1660 | 1648 |
1661 DEFUN ("make-symbol", Fmake_symbol, Smake_symbol, 1, 1, 0 /* | 1649 DEFUN ("make-symbol", Fmake_symbol, 1, 1, 0, /* |
1662 Return a newly allocated uninterned symbol whose name is NAME. | 1650 Return a newly allocated uninterned symbol whose name is NAME. |
1663 Its value and function definition are void, and its property list is nil. | 1651 Its value and function definition are void, and its property list is nil. |
1664 */ ) | 1652 */ |
1665 (str) | 1653 (str)) |
1666 Lisp_Object str; | |
1667 { | 1654 { |
1668 Lisp_Object val; | 1655 Lisp_Object val; |
1669 struct Lisp_Symbol *p; | 1656 struct Lisp_Symbol *p; |
1670 | 1657 |
1671 CHECK_STRING (str); | 1658 CHECK_STRING (str); |
1740 /**********************************************************************/ | 1727 /**********************************************************************/ |
1741 | 1728 |
1742 DECLARE_FIXED_TYPE_ALLOC (marker, struct Lisp_Marker); | 1729 DECLARE_FIXED_TYPE_ALLOC (marker, struct Lisp_Marker); |
1743 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_marker 1000 | 1730 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_marker 1000 |
1744 | 1731 |
1745 DEFUN ("make-marker", Fmake_marker, Smake_marker, 0, 0, 0 /* | 1732 DEFUN ("make-marker", Fmake_marker, 0, 0, 0, /* |
1746 Return a newly allocated marker which does not point at any place. | 1733 Return a newly allocated marker which does not point at any place. |
1747 */ ) | 1734 */ |
1748 () | 1735 ()) |
1749 { | 1736 { |
1750 Lisp_Object val; | 1737 Lisp_Object val; |
1751 struct Lisp_Marker *p; | 1738 struct Lisp_Marker *p; |
1752 | 1739 |
1753 ALLOCATE_FIXED_TYPE (marker, struct Lisp_Marker, p); | 1740 ALLOCATE_FIXED_TYPE (marker, struct Lisp_Marker, p); |
2068 #ifdef VERIFY_STRING_CHARS_INTEGRITY | 2055 #ifdef VERIFY_STRING_CHARS_INTEGRITY |
2069 verify_string_chars_integrity (); | 2056 verify_string_chars_integrity (); |
2070 #endif | 2057 #endif |
2071 } | 2058 } |
2072 | 2059 |
2073 DEFUN ("make-string", Fmake_string, Smake_string, 2, 2, 0 /* | 2060 DEFUN ("make-string", Fmake_string, 2, 2, 0, /* |
2074 Return a newly created string of length LENGTH, with each element being INIT. | 2061 Return a newly created string of length LENGTH, with each element being INIT. |
2075 LENGTH must be an integer and INIT must be a character. | 2062 LENGTH must be an integer and INIT must be a character. |
2076 */ ) | 2063 */ |
2077 (length, init) | 2064 (length, init)) |
2078 Lisp_Object length, init; | |
2079 { | 2065 { |
2080 Lisp_Object val; | 2066 Lisp_Object val; |
2081 | 2067 |
2082 CHECK_NATNUM (length); | 2068 CHECK_NATNUM (length); |
2083 CHECK_CHAR_COERCE_INT (init); | 2069 CHECK_CHAR_COERCE_INT (init); |
2518 } | 2504 } |
2519 #endif | 2505 #endif |
2520 | 2506 |
2521 | 2507 |
2522 | 2508 |
2523 DEFUN ("purecopy", Fpurecopy, Spurecopy, 1, 1, 0 /* | 2509 DEFUN ("purecopy", Fpurecopy, 1, 1, 0, /* |
2524 Make a copy of OBJECT in pure storage. | 2510 Make a copy of OBJECT in pure storage. |
2525 Recursively copies contents of vectors and cons cells. | 2511 Recursively copies contents of vectors and cons cells. |
2526 Does not copy symbols. | 2512 Does not copy symbols. |
2527 */ ) | 2513 */ |
2528 (obj) | 2514 (obj)) |
2529 Lisp_Object obj; | |
2530 { | 2515 { |
2531 int i; | 2516 int i; |
2532 if (!purify_flag) | 2517 if (!purify_flag) |
2533 return (obj); | 2518 return (obj); |
2534 | 2519 |
4110 struct type##_block *x = current_##type##_block; \ | 4095 struct type##_block *x = current_##type##_block; \ |
4111 while (x) { s += sizeof (*x) + MALLOC_OVERHEAD; x = x->prev; } \ | 4096 while (x) { s += sizeof (*x) + MALLOC_OVERHEAD; x = x->prev; } \ |
4112 (pl) = gc_plist_hack ((name), s, (pl)); \ | 4097 (pl) = gc_plist_hack ((name), s, (pl)); \ |
4113 } | 4098 } |
4114 | 4099 |
4115 DEFUN ("garbage-collect", Fgarbage_collect, Sgarbage_collect, 0, 0, "" /* | 4100 DEFUN ("garbage-collect", Fgarbage_collect, 0, 0, "", /* |
4116 Reclaim storage for Lisp objects no longer needed. | 4101 Reclaim storage for Lisp objects no longer needed. |
4117 Returns info on amount of space in use: | 4102 Returns info on amount of space in use: |
4118 ((USED-CONSES . FREE-CONSES) (USED-SYMS . FREE-SYMS) | 4103 ((USED-CONSES . FREE-CONSES) (USED-SYMS . FREE-SYMS) |
4119 (USED-MARKERS . FREE-MARKERS) USED-STRING-CHARS USED-VECTOR-SLOTS | 4104 (USED-MARKERS . FREE-MARKERS) USED-STRING-CHARS USED-VECTOR-SLOTS |
4120 PLIST) | 4105 PLIST) |
4121 where `PLIST' is a list of alternating keyword/value pairs providing | 4106 where `PLIST' is a list of alternating keyword/value pairs providing |
4122 more detailed information. | 4107 more detailed information. |
4123 Garbage collection happens automatically if you cons more than | 4108 Garbage collection happens automatically if you cons more than |
4124 `gc-cons-threshold' bytes of Lisp data since previous garbage collection. | 4109 `gc-cons-threshold' bytes of Lisp data since previous garbage collection. |
4125 */ ) | 4110 */ |
4126 () | 4111 ()) |
4127 { | 4112 { |
4128 Lisp_Object pl = Qnil; | 4113 Lisp_Object pl = Qnil; |
4129 Lisp_Object ret[6]; | 4114 Lisp_Object ret[6]; |
4130 int i; | 4115 int i; |
4131 | 4116 |
4228 ret[5] = pl; | 4213 ret[5] = pl; |
4229 return (Flist (6, ret)); | 4214 return (Flist (6, ret)); |
4230 } | 4215 } |
4231 #undef HACK_O_MATIC | 4216 #undef HACK_O_MATIC |
4232 | 4217 |
4233 DEFUN ("consing-since-gc", Fconsing_since_gc, Sconsing_since_gc, 0, 0, "" /* | 4218 DEFUN ("consing-since-gc", Fconsing_since_gc, 0, 0, "", /* |
4234 Return the number of bytes consed since the last garbage collection. | 4219 Return the number of bytes consed since the last garbage collection. |
4235 \"Consed\" is a misnomer in that this actually counts allocation | 4220 \"Consed\" is a misnomer in that this actually counts allocation |
4236 of all different kinds of objects, not just conses. | 4221 of all different kinds of objects, not just conses. |
4237 | 4222 |
4238 If this value exceeds `gc-cons-threshold', a garbage collection happens. | 4223 If this value exceeds `gc-cons-threshold', a garbage collection happens. |
4239 */ ) | 4224 */ |
4240 () | 4225 ()) |
4241 { | 4226 { |
4242 return (make_int (consing_since_gc)); | 4227 return (make_int (consing_since_gc)); |
4243 } | 4228 } |
4244 | 4229 |
4245 DEFUN ("memory-limit", Fmemory_limit, Smemory_limit, 0, 0, "" /* | 4230 DEFUN ("memory-limit", Fmemory_limit, 0, 0, "", /* |
4246 Return the address of the last byte Emacs has allocated, divided by 1024. | 4231 Return the address of the last byte Emacs has allocated, divided by 1024. |
4247 This may be helpful in debugging Emacs's memory usage. | 4232 This may be helpful in debugging Emacs's memory usage. |
4248 The value is divided by 1024 to make sure it will fit in a lisp integer. | 4233 The value is divided by 1024 to make sure it will fit in a lisp integer. |
4249 */ ) | 4234 */ |
4250 () | 4235 ()) |
4251 { | 4236 { |
4252 return (make_int ((EMACS_INT) sbrk (0) / 1024)); | 4237 return (make_int ((EMACS_INT) sbrk (0) / 1024)); |
4253 } | 4238 } |
4254 | 4239 |
4255 | 4240 |
4495 { | 4480 { |
4496 defsymbol (&Qpre_gc_hook, "pre-gc-hook"); | 4481 defsymbol (&Qpre_gc_hook, "pre-gc-hook"); |
4497 defsymbol (&Qpost_gc_hook, "post-gc-hook"); | 4482 defsymbol (&Qpost_gc_hook, "post-gc-hook"); |
4498 defsymbol (&Qgarbage_collecting, "garbage-collecting"); | 4483 defsymbol (&Qgarbage_collecting, "garbage-collecting"); |
4499 | 4484 |
4500 defsubr (&Scons); | 4485 DEFSUBR (Fcons); |
4501 defsubr (&Slist); | 4486 DEFSUBR (Flist); |
4502 defsubr (&Svector); | 4487 DEFSUBR (Fvector); |
4503 defsubr (&Sbit_vector); | 4488 DEFSUBR (Fbit_vector); |
4504 defsubr (&Smake_byte_code); | 4489 DEFSUBR (Fmake_byte_code); |
4505 defsubr (&Smake_list); | 4490 DEFSUBR (Fmake_list); |
4506 defsubr (&Smake_vector); | 4491 DEFSUBR (Fmake_vector); |
4507 defsubr (&Smake_bit_vector); | 4492 DEFSUBR (Fmake_bit_vector); |
4508 defsubr (&Smake_string); | 4493 DEFSUBR (Fmake_string); |
4509 defsubr (&Smake_symbol); | 4494 DEFSUBR (Fmake_symbol); |
4510 defsubr (&Smake_marker); | 4495 DEFSUBR (Fmake_marker); |
4511 defsubr (&Spurecopy); | 4496 DEFSUBR (Fpurecopy); |
4512 defsubr (&Sgarbage_collect); | 4497 DEFSUBR (Fgarbage_collect); |
4513 defsubr (&Smemory_limit); | 4498 DEFSUBR (Fmemory_limit); |
4514 defsubr (&Sconsing_since_gc); | 4499 DEFSUBR (Fconsing_since_gc); |
4515 } | 4500 } |
4516 | 4501 |
4517 void | 4502 void |
4518 vars_of_alloc (void) | 4503 vars_of_alloc (void) |
4519 { | 4504 { |