Mercurial > hg > xemacs-beta
comparison man/internals/internals.texi @ 404:2f8bb876ab1d r21-2-32
Import from CVS: tag r21-2-32
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:16:07 +0200 |
parents | a86b2b5e0111 |
children | 501cfd01ee6d |
comparison
equal
deleted
inserted
replaced
403:9f011ab08d48 | 404:2f8bb876ab1d |
---|---|
1624 a pointer to a structure, or an integer tag | 1624 a pointer to a structure, or an integer tag |
1625 @end example | 1625 @end example |
1626 | 1626 |
1627 A tag of 00 is used for all pointer object types, a tag of 10 is used | 1627 A tag of 00 is used for all pointer object types, a tag of 10 is used |
1628 for characters, and the other two tags 01 and 11 are joined together to | 1628 for characters, and the other two tags 01 and 11 are joined together to |
1629 form the integer object type. This representation gives us 31 bits | 1629 form the integer object type. This representation gives us 31 bit |
1630 integers, 30 bits characters and pointers are represented directly | 1630 integers and 30 bit characters, while pointers are represented directly |
1631 without any bit masking. This representation, though, assumes that | 1631 without any bit masking or shifting. This representation, though, |
1632 pointers to structs are always aligned to multiples of 4, so the lower 2 | 1632 assumes that pointers to structs are always aligned to multiples of 4, |
1633 bits are always zero. | 1633 so the lower 2 bits are always zero. |
1634 | 1634 |
1635 Lisp objects use the typedef @code{Lisp_Object}, but the actual C type | 1635 Lisp objects use the typedef @code{Lisp_Object}, but the actual C type |
1636 used for the Lisp object can vary. It can be either a simple type | 1636 used for the Lisp object can vary. It can be either a simple type |
1637 (@code{long} on the DEC Alpha, @code{int} on other machines) or a | 1637 (@code{long} on the DEC Alpha, @code{int} on other machines) or a |
1638 structure whose fields are bit fields that line up properly (actually, a | 1638 structure whose fields are bit fields that line up properly (actually, a |
1639 union of structures is used). Generally the simple integral type is | 1639 union of structures is used). Generally the simple integral type is |
1640 preferable because it ensures that the compiler will actually use a | 1640 preferable because it ensures that the compiler will actually use a |
1641 machine word to represent the object (some compilers will use more | 1641 machine word to represent the object (some compilers will use more |
1642 general and less efficient code for unions and structs even if they can | 1642 general and less efficient code for unions and structs even if they can |
1643 fit in a machine word). The union type, however, has the advantage of | 1643 fit in a machine word). The union type, however, has the advantage of |
1644 stricter type checking (if you accidentally pass an integer where a Lisp | 1644 stricter type checking. If you accidentally pass an integer where a Lisp |
1645 object is desired, you get a compile error), and it makes it easier to | 1645 object is desired, you get a compile error. The choice of which type |
1646 decode Lisp objects when debugging. The choice of which type to use is | 1646 to use is determined by the preprocessor constant @code{USE_UNION_TYPE} |
1647 determined by the preprocessor constant @code{USE_UNION_TYPE} which is | 1647 which is defined via the @code{--use-union-type} option to |
1648 defined via the @code{--use-union-type} option to @code{configure}. | 1648 @code{configure}. |
1649 | 1649 |
1650 Various macros are used to construct Lisp objects and extract the | 1650 Various macros are used to convert between Lisp_Objects and the |
1651 components. Macros of the form @code{XINT()}, @code{XCHAR()}, | 1651 corresponding C type. Macros of the form @code{XINT()}, @code{XCHAR()}, |
1652 @code{XSTRING()}, @code{XSYMBOL()}, etc. shift out the tag field if | 1652 @code{XSTRING()}, @code{XSYMBOL()}, do any required bit shifting and/or |
1653 needed cast it to the appropriate type. @code{XINT()} needs to be a bit | 1653 masking and cast it to the appropriate type. @code{XINT()} needs to be |
1654 tricky so that negative numbers are properly sign-extended. Since | 1654 a bit tricky so that negative numbers are properly sign-extended. Since |
1655 integers are stored left-shifted, if the right-shift operator does an | 1655 integers are stored left-shifted, if the right-shift operator does an |
1656 arithmetic shift (i.e. it leaves the most-significant bit as-is rather | 1656 arithmetic shift (i.e. it leaves the most-significant bit as-is rather |
1657 than shifting in a zero, so that it mimics a divide-by-two even for | 1657 than shifting in a zero, so that it mimics a divide-by-two even for |
1658 negative numbers) the shift to remove the tag bit is enough. This is | 1658 negative numbers) the shift to remove the tag bit is enough. This is |
1659 the case on all the systems we support. | 1659 the case on all the systems we support. |
1660 | 1660 |
1661 Note that when @code{ERROR_CHECK_TYPECHECK} is defined, the extractor | 1661 Note that when @code{ERROR_CHECK_TYPECHECK} is defined, the converter |
1662 macros become more complicated---they check the tag bits and/or the | 1662 macros become more complicated---they check the tag bits and/or the |
1663 type field in the first four bytes of a record type to ensure that the | 1663 type field in the first four bytes of a record type to ensure that the |
1664 object is really of the correct type. This is great for catching places | 1664 object is really of the correct type. This is great for catching places |
1665 where an incorrect type is being dereferenced---this typically results | 1665 where an incorrect type is being dereferenced---this typically results |
1666 in a pointer being dereferenced as the wrong type of structure, with | 1666 in a pointer being dereferenced as the wrong type of structure, with |
1667 unpredictable (and sometimes not easily traceable) results. | 1667 unpredictable (and sometimes not easily traceable) results. |
1668 | 1668 |
1669 There are similar @code{XSET@var{TYPE}()} macros that construct a Lisp | 1669 There are similar @code{XSET@var{TYPE}()} macros that construct a Lisp |
1670 object. These macros are of the form @code{XSET@var{TYPE} | 1670 object. These macros are of the form @code{XSET@var{TYPE} |
1671 (@var{lvalue}, @var{result})}, | 1671 (@var{lvalue}, @var{result})}, i.e. they have to be a statement rather |
1672 i.e. they have to be a statement rather than just used in an expression. | 1672 than just used in an expression. The reason for this is that standard C |
1673 The reason for this is that standard C doesn't let you ``construct'' a | 1673 doesn't let you ``construct'' a structure (but GCC does). Granted, this |
1674 structure (but GCC does). Granted, this sometimes isn't too convenient; | 1674 sometimes isn't too convenient; for the case of integers, at least, you |
1675 for the case of integers, at least, you can use the function | 1675 can use the function @code{make_int()}, which constructs and |
1676 @code{make_int()}, which constructs and @emph{returns} an integer | 1676 @emph{returns} an integer Lisp object. Note that the |
1677 Lisp object. Note that the @code{XSET@var{TYPE}()} macros are also | 1677 @code{XSET@var{TYPE}()} macros are also affected by |
1678 affected by @code{ERROR_CHECK_TYPECHECK} and make sure that the | 1678 @code{ERROR_CHECK_TYPECHECK} and make sure that the structure is of the |
1679 structure is of the right type in the case of record types, where the | 1679 right type in the case of record types, where the type is contained in |
1680 type is contained in the structure. | 1680 the structure. |
1681 | 1681 |
1682 The C programmer is responsible for @strong{guaranteeing} that a | 1682 The C programmer is responsible for @strong{guaranteeing} that a |
1683 Lisp_Object is is the correct type before using the @code{X@var{TYPE}} | 1683 Lisp_Object is the correct type before using the @code{X@var{TYPE}} |
1684 macros. This is especially important in the case of lists. Use | 1684 macros. This is especially important in the case of lists. Use |
1685 @code{XCAR} and @code{XCDR} if a Lisp_Object is certainly a cons cell, | 1685 @code{XCAR} and @code{XCDR} if a Lisp_Object is certainly a cons cell, |
1686 else use @code{Fcar()} and @code{Fcdr()}. Trust other C code, but not | 1686 else use @code{Fcar()} and @code{Fcdr()}. Trust other C code, but not |
1687 Lisp code. On the other hand, if XEmacs has an internal logic error, | 1687 Lisp code. On the other hand, if XEmacs has an internal logic error, |
1688 it's better to crash immediately, so sprinkle ``unreachable'' | 1688 it's better to crash immediately, so sprinkle @code{assert()}s and |
1689 @code{abort()}s liberally about the source code. | 1689 ``unreachable'' @code{abort()}s liberally about the source code. Where |
1690 performance is an issue, use @code{type_checking_assert}, | |
1691 @code{bufpos_checking_assert}, and @code{gc_checking_assert}, which do | |
1692 nothing unless the corresponding configure error checking flag was | |
1693 specified. | |
1690 | 1694 |
1691 @node Rules When Writing New C Code, A Summary of the Various XEmacs Modules, How Lisp Objects Are Represented in C, Top | 1695 @node Rules When Writing New C Code, A Summary of the Various XEmacs Modules, How Lisp Objects Are Represented in C, Top |
1692 @chapter Rules When Writing New C Code | 1696 @chapter Rules When Writing New C Code |
1693 | 1697 |
1694 The XEmacs C Code is extremely complex and intricate, and there are many | 1698 The XEmacs C Code is extremely complex and intricate, and there are many |
1738 must always be included before any other header files (including | 1742 must always be included before any other header files (including |
1739 system header files) to ensure that certain tricks played by various | 1743 system header files) to ensure that certain tricks played by various |
1740 @file{s/} and @file{m/} files work out correctly. | 1744 @file{s/} and @file{m/} files work out correctly. |
1741 | 1745 |
1742 When including header files, always use angle brackets, not double | 1746 When including header files, always use angle brackets, not double |
1743 quotes, except when the file to be included is in the same directory as | 1747 quotes, except when the file to be included is always in the same |
1744 the including file. If either file is a generated file, then that is | 1748 directory as the including file. If either file is a generated file, |
1745 not likely to be the case. In order to understand why we have this | 1749 then that is not likely to be the case. In order to understand why we |
1746 rule, imagine what happens when you do a build in the source directory | 1750 have this rule, imagine what happens when you do a build in the source |
1747 using @samp{./configure} and another build in another directory using | 1751 directory using @samp{./configure} and another build in another |
1748 @samp{../work/configure}. There will be two different @file{config.h} | 1752 directory using @samp{../work/configure}. There will be two different |
1749 files. Which one will be used if you @samp{#include "config.h"}? | 1753 @file{config.h} files. Which one will be used if you @samp{#include |
1754 "config.h"}? | |
1750 | 1755 |
1751 @strong{All global and static variables that are to be modifiable must | 1756 @strong{All global and static variables that are to be modifiable must |
1752 be declared uninitialized.} This means that you may not use the | 1757 be declared uninitialized.} This means that you may not use the |
1753 ``declare with initializer'' form for these variables, such as @code{int | 1758 ``declare with initializer'' form for these variables, such as @code{int |
1754 some_variable = 0;}. The reason for this has to do with some kludges | 1759 some_variable = 0;}. The reason for this has to do with some kludges |
1789 | 1794 |
1790 The C source code makes heavy use of C preprocessor macros. One popular | 1795 The C source code makes heavy use of C preprocessor macros. One popular |
1791 macro style is: | 1796 macro style is: |
1792 | 1797 |
1793 @example | 1798 @example |
1794 #define FOO(var, value) do @{ \ | 1799 #define FOO(var, value) do @{ \ |
1795 Lisp_Object FOO_value = (value); \ | 1800 Lisp_Object FOO_value = (value); \ |
1796 ... /* compute using FOO_value */ \ | 1801 ... /* compute using FOO_value */ \ |
1797 (var) = bar; \ | 1802 (var) = bar; \ |
1798 @} while (0) | 1803 @} while (0) |
1799 @end example | 1804 @end example |
2595 proceed writing new Mule-aware code. | 2600 proceed writing new Mule-aware code. |
2596 | 2601 |
2597 @node Techniques for XEmacs Developers, , Coding for Mule, Rules When Writing New C Code | 2602 @node Techniques for XEmacs Developers, , Coding for Mule, Rules When Writing New C Code |
2598 @section Techniques for XEmacs Developers | 2603 @section Techniques for XEmacs Developers |
2599 | 2604 |
2605 To make a purified XEmacs, do: @code{make puremacs}. | |
2600 To make a quantified XEmacs, do: @code{make quantmacs}. | 2606 To make a quantified XEmacs, do: @code{make quantmacs}. |
2601 | 2607 |
2602 You simply can't dump Quantified and Purified images. Run the image | 2608 You simply can't dump Quantified and Purified images (unless using the |
2603 like so: @code{quantmacs -batch -l loadup.el run-temacs @var{xemacs-args...}}. | 2609 portable dumper). Purify gets confused when xemacs frees memory in one |
2610 process that was allocated in a @emph{different} process on a different | |
2611 machine!. Run it like so: | |
2612 @example | |
2613 temacs -batch -l loadup.el run-temacs @var{xemacs-args...} | |
2614 @end example | |
2604 | 2615 |
2605 Before you go through the trouble, are you compiling with all | 2616 Before you go through the trouble, are you compiling with all |
2606 debugging and error-checking off? If not try that first. Be warned | 2617 debugging and error-checking off? If not, try that first. Be warned |
2607 that while Quantify is directly responsible for quite a few | 2618 that while Quantify is directly responsible for quite a few |
2608 optimizations which have been made to XEmacs, doing a run which | 2619 optimizations which have been made to XEmacs, doing a run which |
2609 generates results which can be acted upon is not necessarily a trivial | 2620 generates results which can be acted upon is not necessarily a trivial |
2610 task. | 2621 task. |
2611 | 2622 |
2640 | 2651 |
2641 Unfortunately, Emacs Lisp is slow, and is going to stay slow. Function | 2652 Unfortunately, Emacs Lisp is slow, and is going to stay slow. Function |
2642 calls in elisp are especially expensive. Iterating over a long list is | 2653 calls in elisp are especially expensive. Iterating over a long list is |
2643 going to be 30 times faster implemented in C than in Elisp. | 2654 going to be 30 times faster implemented in C than in Elisp. |
2644 | 2655 |
2656 Heavily used small code fragments need to be fast. The traditional way | |
2657 to implement such code fragments in C is with macros. But macros in C | |
2658 are known to be broken. | |
2659 | |
2660 Macro arguments that are repeatedly evaluated may suffer from repeated | |
2661 side effects or suboptimal performance. | |
2662 | |
2663 Variable names used in macros may collide with caller's variables, | |
2664 causing (at least) unwanted compiler warnings. | |
2665 | |
2666 In order to solve these problems, and maintain statement semantics, one | |
2667 should use the @code{do @{ ... @} while (0)} trick while trying to | |
2668 reference macro arguments exactly once using local variables. | |
2669 | |
2670 Let's take a look at this poor macro definition: | |
2671 | |
2672 @example | |
2673 #define MARK_OBJECT(obj) \ | |
2674 if (!marked_p (obj)) mark_object (obj), did_mark = 1 | |
2675 @end example | |
2676 | |
2677 This macro evaluates its argument twice, and also fails if used like this: | |
2678 @example | |
2679 if (flag) MARK_OBJECT (obj); else do_something(); | |
2680 @end example | |
2681 | |
2682 A much better definition is | |
2683 | |
2684 @example | |
2685 #define MARK_OBJECT(obj) do @{ \ | |
2686 Lisp_Object mo_obj = (obj); \ | |
2687 if (!marked_p (mo_obj)) \ | |
2688 @{ \ | |
2689 mark_object (mo_obj); \ | |
2690 did_mark = 1; \ | |
2691 @} \ | |
2692 @} while (0) | |
2693 @end example | |
2694 | |
2695 Notice the elimination of double evaluation by using the local variable | |
2696 with the obscure name. Writing safe and efficient macros requires great | |
2697 care. The one problem with macros that cannot be portably worked around | |
2698 is, since a C block has no value, a macro used as an expression rather | |
2699 than a statement cannot use the techniques just described to avoid | |
2700 multiple evaluation. | |
2701 | |
2702 In most cases where a macro has function semantics, an inline function | |
2703 is a better implementation technique. Modern compiler optimizers tend | |
2704 to inline functions even if they have no @code{inline} keyword, and | |
2705 configure magic ensures that the @code{inline} keyword can be safely | |
2706 used as an additional compiler hint. Inline functions used in a single | |
2707 .c files are easy. The function must already be defined to be | |
2708 @code{static}. Just add another @code{inline} keyword to the | |
2709 definition. | |
2710 | |
2711 @example | |
2712 inline static int | |
2713 heavily_used_small_function (int arg) | |
2714 @{ | |
2715 ... | |
2716 @} | |
2717 @end example | |
2718 | |
2719 Inline functions in header files are trickier, because we would like to | |
2720 make the following optimization if the function is @emph{not} inlined | |
2721 (for example, because we're compiling for debugging). We would like the | |
2722 function to be defined externally exactly once, and each calling | |
2723 translation unit would create an external reference to the function, | |
2724 instead of including a definition of the inline function in the object | |
2725 code of every translation unit that uses it. This optimization is | |
2726 currently only available for gcc. But you don't have to worry about the | |
2727 trickiness; just define your inline functions in header files using this | |
2728 pattern: | |
2729 | |
2730 @example | |
2731 INLINE_HEADER int | |
2732 i_used_to_be_a_crufty_macro_but_look_at_me_now (int arg); | |
2733 INLINE_HEADER int | |
2734 i_used_to_be_a_crufty_macro_but_look_at_me_now (int arg) | |
2735 @{ | |
2736 ... | |
2737 @} | |
2738 @end example | |
2739 | |
2740 The declaration right before the definition is to prevent warnings when | |
2741 compiling with @code{gcc -Wmissing-declarations}. I consider issuing | |
2742 this warning for inline functions a gcc bug, but the gcc maintainers disagree. | |
2743 | |
2744 Every header which contains inline functions, either directly by using | |
2745 @code{INLINE_HEADER} or indirectly by using @code{DECLARE_LRECORD} must | |
2746 be added to @file{inline.c}'s includes to make the optimization | |
2747 described above work. (Optimization note: if all INLINE_HEADER | |
2748 functions are in fact inlined in all translation units, then the linker | |
2749 can just discard @code{inline.o}, since it contains only unreferenced code). | |
2750 | |
2645 To get started debugging XEmacs, take a look at the @file{.gdbinit} and | 2751 To get started debugging XEmacs, take a look at the @file{.gdbinit} and |
2646 @file{.dbxrc} files in the @file{src} directory. | 2752 @file{.dbxrc} files in the @file{src} directory. See the section in the |
2647 @xref{Q2.1.15 - How to Debug an XEmacs problem with a debugger,,, | 2753 XEmacs FAQ on How to Debug an XEmacs problem with a debugger. |
2648 xemacs-faq, XEmacs FAQ}. | |
2649 | 2754 |
2650 After making source code changes, run @code{make check} to ensure that | 2755 After making source code changes, run @code{make check} to ensure that |
2651 you haven't introduced any regressions. If you're feeling ambitious, | 2756 you haven't introduced any regressions. If you want to make xemacs more |
2652 you can try to improve the test suite in @file{tests/automated}. | 2757 reliable, please improve the test suite in @file{tests/automated}. |
2758 | |
2759 Did you make sure you didn't introduce any new compiler warnings? | |
2760 | |
2761 Before submitting a patch, please try compiling at least once with | |
2762 | |
2763 @example | |
2764 configure --with-mule --with-union-type --error-checking=all | |
2765 @end example | |
2653 | 2766 |
2654 Here are things to know when you create a new source file: | 2767 Here are things to know when you create a new source file: |
2655 | 2768 |
2656 @itemize @bullet | 2769 @itemize @bullet |
2657 @item | 2770 @item |
2674 @item | 2787 @item |
2675 Header files should @emph{not} include @code{<config.h>} and | 2788 Header files should @emph{not} include @code{<config.h>} and |
2676 @code{"lisp.h"}. It is the responsibility of the @file{.c} files that | 2789 @code{"lisp.h"}. It is the responsibility of the @file{.c} files that |
2677 use it to do so. | 2790 use it to do so. |
2678 | 2791 |
2679 @item | |
2680 If the header uses @code{INLINE}, either directly or through | |
2681 @code{DECLARE_LRECORD}, then it must be added to @file{inline.c}'s | |
2682 includes. | |
2683 | |
2684 @item | |
2685 Try compiling at least once with | |
2686 | |
2687 @example | |
2688 gcc --with-mule --with-union-type --error-checking=all | |
2689 @end example | |
2690 | |
2691 @item | |
2692 Did I mention that you should run the test suite? | |
2693 @example | |
2694 make check | |
2695 @end example | |
2696 @end itemize | 2792 @end itemize |
2697 | 2793 |
2698 Here is a checklist of things to do when creating a new lisp object type | 2794 Here is a checklist of things to do when creating a new lisp object type |
2699 named @var{foo}: | 2795 named @var{foo}: |
2700 | 2796 |
2702 @item | 2798 @item |
2703 create @var{foo}.h | 2799 create @var{foo}.h |
2704 @item | 2800 @item |
2705 create @var{foo}.c | 2801 create @var{foo}.c |
2706 @item | 2802 @item |
2707 add definitions of syms_of_@var{foo}, etc. to @var{foo}.c | 2803 add definitions of @code{syms_of_@var{foo}}, etc. to @file{@var{foo}.c} |
2708 @item | 2804 @item |
2709 add declarations of syms_of_@var{foo}, etc. to symsinit.h | 2805 add declarations of @code{syms_of_@var{foo}}, etc. to @file{symsinit.h} |
2710 @item | 2806 @item |
2711 add calls to syms_of_@var{foo}, etc. to emacs.c(main_1) | 2807 add calls to @code{syms_of_@var{foo}}, etc. to @file{emacs.c} |
2712 @item | 2808 @item |
2713 add definitions of macros like CHECK_FOO and FOOP to @var{foo}.h | 2809 add definitions of macros like @code{CHECK_@var{FOO}} and |
2714 @item | 2810 @code{@var{FOO}P} to @file{@var{foo}.h} |
2715 add the new type index to enum lrecord_type | 2811 @item |
2716 @item | 2812 add the new type index to @code{enum lrecord_type} |
2717 add DEFINE_LRECORD_IMPLEMENTATION call to @var{foo}.c | 2813 @item |
2814 add a DEFINE_LRECORD_IMPLEMENTATION call to @file{@var{foo}.c} | |
2815 @item | |
2816 add an INIT_LRECORD_IMPLEMENTATION call to @code{syms_of_@var{foo}.c} | |
2718 @end enumerate | 2817 @end enumerate |
2719 | 2818 |
2720 @node A Summary of the Various XEmacs Modules, Allocation of Objects in XEmacs Lisp, Rules When Writing New C Code, Top | 2819 @node A Summary of the Various XEmacs Modules, Allocation of Objects in XEmacs Lisp, Rules When Writing New C Code, Top |
2721 @chapter A Summary of the Various XEmacs Modules | 2820 @chapter A Summary of the Various XEmacs Modules |
2722 | 2821 |
5164 | 5263 |
5165 [see @file{lrecord.h}] | 5264 [see @file{lrecord.h}] |
5166 | 5265 |
5167 All lrecords have at the beginning of their structure a @code{struct | 5266 All lrecords have at the beginning of their structure a @code{struct |
5168 lrecord_header}. This just contains a type number and some flags, | 5267 lrecord_header}. This just contains a type number and some flags, |
5169 including the mark bit. The type number, thru the | 5268 including the mark bit. All builtin type numbers are defined as |
5269 constants in @code{enum lrecord_type}, to allow the compiler to generate | |
5270 more efficient code for @code{@var{type}P}. The type number, thru the | |
5170 @code{lrecord_implementation_table}, gives access to a @code{struct | 5271 @code{lrecord_implementation_table}, gives access to a @code{struct |
5171 lrecord_implementation}, which is a structure containing method pointers | 5272 lrecord_implementation}, which is a structure containing method pointers |
5172 and such. There is one of these for each type, and it is a global, | 5273 and such. There is one of these for each type, and it is a global, |
5173 constant, statically-declared structure that is declared in the | 5274 constant, statically-declared structure that is declared in the |
5174 @code{DEFINE_LRECORD_IMPLEMENTATION()} macro. | 5275 @code{DEFINE_LRECORD_IMPLEMENTATION()} macro. |
5199 type. | 5300 type. |
5200 | 5301 |
5201 Whenever you create an lrecord, you need to call either | 5302 Whenever you create an lrecord, you need to call either |
5202 @code{DEFINE_LRECORD_IMPLEMENTATION()} or | 5303 @code{DEFINE_LRECORD_IMPLEMENTATION()} or |
5203 @code{DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION()}. This needs to be | 5304 @code{DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION()}. This needs to be |
5204 specified in a C file, at the top level. What this actually does is | 5305 specified in a @file{.c} file, at the top level. What this actually |
5205 define and initialize the implementation structure for the lrecord. (And | 5306 does is define and initialize the implementation structure for the |
5206 possibly declares a function @code{error_check_foo()} that implements | 5307 lrecord. (And possibly declares a function @code{error_check_foo()} that |
5207 the @code{XFOO()} macro when error-checking is enabled.) The arguments | 5308 implements the @code{XFOO()} macro when error-checking is enabled.) The |
5208 to the macros are the actual type name (this is used to construct the C | 5309 arguments to the macros are the actual type name (this is used to |
5209 variable name of the lrecord implementation structure and related | 5310 construct the C variable name of the lrecord implementation structure |
5210 structures using the @samp{##} macro concatenation operator), a string | 5311 and related structures using the @samp{##} macro concatenation |
5211 that names the type on the Lisp level (this may not be the same as the C | 5312 operator), a string that names the type on the Lisp level (this may not |
5212 type name; typically, the C type name has underscores, while the Lisp | 5313 be the same as the C type name; typically, the C type name has |
5213 string has dashes), various method pointers, and the name of the C | 5314 underscores, while the Lisp string has dashes), various method pointers, |
5214 structure that contains the object. The methods are used to encapsulate | 5315 and the name of the C structure that contains the object. The methods |
5215 type-specific information about the object, such as how to print it or | 5316 are used to encapsulate type-specific information about the object, such |
5216 mark it for garbage collection, so that it's easy to add new object | 5317 as how to print it or mark it for garbage collection, so that it's easy |
5217 types without having to add a specific case for each new type in a bunch | 5318 to add new object types without having to add a specific case for each |
5218 of different places. | 5319 new type in a bunch of different places. |
5219 | 5320 |
5220 The difference between @code{DEFINE_LRECORD_IMPLEMENTATION()} and | 5321 The difference between @code{DEFINE_LRECORD_IMPLEMENTATION()} and |
5221 @code{DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION()} is that the former is | 5322 @code{DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION()} is that the former is |
5222 used for fixed-size object types and the latter is for variable-size | 5323 used for fixed-size object types and the latter is for variable-size |
5223 object types. Most object types are fixed-size; some complex | 5324 object types. Most object types are fixed-size; some complex |
5227 (Currently this is only used for keeping allocation statistics.) | 5328 (Currently this is only used for keeping allocation statistics.) |
5228 | 5329 |
5229 For the purpose of keeping allocation statistics, the allocation | 5330 For the purpose of keeping allocation statistics, the allocation |
5230 engine keeps a list of all the different types that exist. Note that, | 5331 engine keeps a list of all the different types that exist. Note that, |
5231 since @code{DEFINE_LRECORD_IMPLEMENTATION()} is a macro that is | 5332 since @code{DEFINE_LRECORD_IMPLEMENTATION()} is a macro that is |
5232 specified at top-level, there is no way for it to add to the list of all | 5333 specified at top-level, there is no way for it to initialize the global |
5233 existing types. What happens instead is that each implementation | 5334 data structures containing type information, like |
5234 structure contains in it a dynamically assigned number that is | 5335 @code{lrecord_implementations_table}. For this reason a call to |
5235 particular to that type. (Or rather, it contains a pointer to another | 5336 @code{INIT_LRECORD_IMPLEMENTATION} must be added to the same source file |
5236 structure that contains this number. This evasiveness is done so that | 5337 containing @code{DEFINE_LRECORD_IMPLEMENTATION}, but instead of to the |
5237 the implementation structure can be declared const.) In the sweep stage | 5338 top level, to one of the init functions, typically |
5238 of garbage collection, each lrecord is examined to see if its | 5339 @code{syms_of_@var{foo}.c}. @code{INIT_LRECORD_IMPLEMENTATION} must be |
5239 implementation structure has its dynamically-assigned number set. If | 5340 called before an object of this type is used. |
5240 not, it must be a new type, and it is added to the list of known types | 5341 |
5241 and a new number assigned. The number is used to index into an array | 5342 The type number is also used to index into an array holding the number |
5242 holding the number of objects of each type and the total memory | 5343 of objects of each type and the total memory allocated for objects of |
5243 allocated for objects of that type. The statistics in this array are | 5344 that type. The statistics in this array are computed during the sweep |
5244 also computed during the sweep stage. These statistics are returned by | 5345 stage. These statistics are returned by the call to |
5245 the call to @code{garbage-collect} and are printed out at the end of the | 5346 @code{garbage-collect}. |
5246 loadup phase. | |
5247 | 5347 |
5248 Note that for every type defined with a @code{DEFINE_LRECORD_*()} | 5348 Note that for every type defined with a @code{DEFINE_LRECORD_*()} |
5249 macro, there needs to be a @code{DECLARE_LRECORD_IMPLEMENTATION()} | 5349 macro, there needs to be a @code{DECLARE_LRECORD_IMPLEMENTATION()} |
5250 somewhere in a @file{.h} file, and this @file{.h} file needs to be | 5350 somewhere in a @file{.h} file, and this @file{.h} file needs to be |
5251 included by @file{inline.c}. | 5351 included by @file{inline.c}. |
5447 XEmacs taps into them and issues a warning through the standard | 5547 XEmacs taps into them and issues a warning through the standard |
5448 warning system, when memory gets to 75%, 85%, and 95% full. | 5548 warning system, when memory gets to 75%, 85%, and 95% full. |
5449 (On some systems, the memory warnings are not functional.) | 5549 (On some systems, the memory warnings are not functional.) |
5450 | 5550 |
5451 Allocated memory that is going to be used to make a Lisp object | 5551 Allocated memory that is going to be used to make a Lisp object |
5452 is created using @code{allocate_lisp_storage()}. This calls @code{xmalloc()} | 5552 is created using @code{allocate_lisp_storage()}. This just calls |
5453 but also verifies that the pointer to the memory can fit into | 5553 @code{xmalloc()}. It used to verify that the pointer to the memory can |
5454 a Lisp word (remember that some bits are taken away for a type | 5554 fit into a Lisp word, before the current Lisp object representation was |
5455 tag and a mark bit). If not, an error is issued through @code{memory_full()}. | 5555 introduced. @code{allocate_lisp_storage()} is called by |
5456 @code{allocate_lisp_storage()} is called by @code{alloc_lcrecord()}, | 5556 @code{alloc_lcrecord()}, @code{ALLOCATE_FIXED_TYPE()}, and the vector |
5457 @code{ALLOCATE_FIXED_TYPE()}, and the vector and bit-vector creation | 5557 and bit-vector creation routines. These routines also call |
5458 routines. These routines also call @code{INCREMENT_CONS_COUNTER()} at the | 5558 @code{INCREMENT_CONS_COUNTER()} at the appropriate times; this keeps |
5459 appropriate times; this keeps statistics on how much memory is | 5559 statistics on how much memory is allocated, so that garbage-collection |
5460 allocated, so that garbage-collection can be invoked when the | 5560 can be invoked when the threshold is reached. |
5461 threshold is reached. | |
5462 | 5561 |
5463 @node Cons, Vector, Low-level allocation, Allocation of Objects in XEmacs Lisp | 5562 @node Cons, Vector, Low-level allocation, Allocation of Objects in XEmacs Lisp |
5464 @section Cons | 5563 @section Cons |
5465 | 5564 |
5466 Conses are allocated in standard frob blocks. The only thing to | 5565 Conses are allocated in standard frob blocks. The only thing to |
8796 @summarycontents | 8895 @summarycontents |
8797 @contents | 8896 @contents |
8798 @c That's all | 8897 @c That's all |
8799 | 8898 |
8800 @bye | 8899 @bye |
8801 |