comparison man/internals/internals.texi @ 448:3078fd1074e8 r21-2-39

Import from CVS: tag r21-2-39
author cvs
date Mon, 13 Aug 2007 11:38:25 +0200
parents 1ccc32a20af4
children 3d3049ae1304
comparison
equal deleted inserted replaced
447:4fc5f13f3bd3 448:3078fd1074e8
1719 C++ compilers are more nit-picking, and a number of coding errors have 1719 C++ compilers are more nit-picking, and a number of coding errors have
1720 been found by compiling with C++. The ability to use both C and C++ 1720 been found by compiling with C++. The ability to use both C and C++
1721 tools means that a greater variety of development tools are available to 1721 tools means that a greater variety of development tools are available to
1722 the developer. 1722 the developer.
1723 1723
1724 Almost every module contains a @code{syms_of_*()} function and a
1725 @code{vars_of_*()} function. The former declares any Lisp primitives
1726 you have defined and defines any symbols you will be using. The latter
1727 declares any global Lisp variables you have added and initializes global
1728 C variables in the module. For each such function, declare it in
1729 @file{symsinit.h} and make sure it's called in the appropriate place in
1730 @file{emacs.c}. @strong{Important}: There are stringent requirements on
1731 exactly what can go into these functions. See the comment in
1732 @file{emacs.c}. The reason for this is to avoid obscure unwanted
1733 interactions during initialization. If you don't follow these rules,
1734 you'll be sorry! If you want to do anything that isn't allowed, create
1735 a @code{complex_vars_of_*()} function for it. Doing this is tricky,
1736 though: You have to make sure your function is called at the right time
1737 so that all the initialization dependencies work out.
1738
1739 Every module includes @file{<config.h>} (angle brackets so that 1724 Every module includes @file{<config.h>} (angle brackets so that
1740 @samp{--srcdir} works correctly; @file{config.h} may or may not be in 1725 @samp{--srcdir} works correctly; @file{config.h} may or may not be in
1741 the same directory as the C sources) and @file{lisp.h}. @file{config.h} 1726 the same directory as the C sources) and @file{lisp.h}. @file{config.h}
1742 must always be included before any other header files (including 1727 must always be included before any other header files (including
1743 system header files) to ensure that certain tricks played by various 1728 system header files) to ensure that certain tricks played by various
1750 have this rule, imagine what happens when you do a build in the source 1735 have this rule, imagine what happens when you do a build in the source
1751 directory using @samp{./configure} and another build in another 1736 directory using @samp{./configure} and another build in another
1752 directory using @samp{../work/configure}. There will be two different 1737 directory using @samp{../work/configure}. There will be two different
1753 @file{config.h} files. Which one will be used if you @samp{#include 1738 @file{config.h} files. Which one will be used if you @samp{#include
1754 "config.h"}? 1739 "config.h"}?
1740
1741 Almost every module contains a @code{syms_of_*()} function and a
1742 @code{vars_of_*()} function. The former declares any Lisp primitives
1743 you have defined and defines any symbols you will be using. The latter
1744 declares any global Lisp variables you have added and initializes global
1745 C variables in the module. @strong{Important}: There are stringent
1746 requirements on exactly what can go into these functions. See the
1747 comment in @file{emacs.c}. The reason for this is to avoid obscure
1748 unwanted interactions during initialization. If you don't follow these
1749 rules, you'll be sorry! If you want to do anything that isn't allowed,
1750 create a @code{complex_vars_of_*()} function for it. Doing this is
1751 tricky, though: you have to make sure your function is called at the
1752 right time so that all the initialization dependencies work out.
1753
1754 Declare each function of these kinds in @file{symsinit.h}. Make sure
1755 it's called in the appropriate place in @file{emacs.c}. You never need
1756 to include @file{symsinit.h} directly, because it is included by
1757 @file{lisp.h}.
1755 1758
1756 @strong{All global and static variables that are to be modifiable must 1759 @strong{All global and static variables that are to be modifiable must
1757 be declared uninitialized.} This means that you may not use the 1760 be declared uninitialized.} This means that you may not use the
1758 ``declare with initializer'' form for these variables, such as @code{int 1761 ``declare with initializer'' form for these variables, such as @code{int
1759 some_variable = 0;}. The reason for this has to do with some kludges 1762 some_variable = 0;}. The reason for this has to do with some kludges
5863 differences though: 5866 differences though:
5864 5867
5865 @enumerate 5868 @enumerate
5866 @item 5869 @item
5867 We do not use the mark bit (which does not exist for C structures 5870 We do not use the mark bit (which does not exist for C structures
5868 anyway), we use a big hash table instead. 5871 anyway); we use a big hash table instead.
5869 5872
5870 @item 5873 @item
5871 We do not use the mark function of lrecords but instead rely on the 5874 We do not use the mark function of lrecords but instead rely on the
5872 external descriptions. This happens essentially because we need to 5875 external descriptions. This happens essentially because we need to
5873 follow pointers to C structures and opaque data in addition to 5876 follow pointers to C structures and opaque data in addition to
5880 5883
5881 The hash table doubles as a map object to pdump_entry_list_elmt (i.e. 5884 The hash table doubles as a map object to pdump_entry_list_elmt (i.e.
5882 allows us to look up a pdump_entry_list_elmt with the object it points 5885 allows us to look up a pdump_entry_list_elmt with the object it points
5883 to). Entries are added with @code{pdump_add_entry()} and looked up with 5886 to). Entries are added with @code{pdump_add_entry()} and looked up with
5884 @code{pdump_get_entry()}. There is no need for entry removal. The hash 5887 @code{pdump_get_entry()}. There is no need for entry removal. The hash
5885 value is computed quite basically from the object pointer by 5888 value is computed quite simply from the object pointer by
5886 @code{pdump_make_hash()}. 5889 @code{pdump_make_hash()}.
5887 5890
5888 The roots for the marking are: 5891 The roots for the marking are:
5889 5892
5890 @enumerate 5893 @enumerate
5891 @item 5894 @item
5892 the @code{staticpro}'ed variables (there is a special @code{staticpro_nodump()} 5895 the @code{staticpro}'ed variables (there is a special @code{staticpro_nodump()}
5893 call for protected variables we do not want to dump). 5896 call for protected variables we do not want to dump).
5894 5897
5895 @item 5898 @item
5896 the @code{pdump_wire}'d variables (@code{staticpro} is equivalent to 5899 the @code{pdump_wire}'d variables (@code{staticpro()} is equivalent to
5897 @code{staticpro_nodump()} + @code{pdump_wire()}). 5900 @code{staticpro_nodump()} + @code{pdump_wire()}).
5898 5901
5899 @item 5902 @item
5900 the @code{dumpstruct}'ed variables, which points to C structures. 5903 the @code{dumpstruct}'ed variables, which points to C structures.
5901 @end enumerate 5904 @end enumerate
5923 @item 5926 @item
5924 real world alignment requirements are powers of two. 5927 real world alignment requirements are powers of two.
5925 5928
5926 @item 5929 @item
5927 the C compiler is required to adjust the size of a struct so that you 5930 the C compiler is required to adjust the size of a struct so that you
5928 can have an array of them next to each other. This means you can have a 5931 can have an array of them next to each other. This means you can have an
5929 upper bound of the alignment requirements of a given structure by 5932 upper bound of the alignment requirements of a given structure by
5930 looking at which power of two its size is a multiple. 5933 looking at which power of two its size is a multiple.
5931 5934
5932 @item 5935 @item
5933 the non-variant part of variable size lrecords has an alignment 5936 the non-variant part of variable size lrecords has an alignment
5941 first. This ensures the best packing. 5944 first. This ensures the best packing.
5942 5945
5943 The maximum alignment requirement we take into account is 2^8. 5946 The maximum alignment requirement we take into account is 2^8.
5944 5947
5945 @code{pdump_allocate_offset()} only has to do a linear allocation, 5948 @code{pdump_allocate_offset()} only has to do a linear allocation,
5946 starting at offset 256 (this leaves room for the header and keep the 5949 starting at offset 256 (this leaves room for the header and keeps the
5947 alignments happy). 5950 alignments happy).
5948 5951
5949 @node The header, Data dumping, Address allocation, Dumping phase 5952 @node The header, Data dumping, Address allocation, Dumping phase
5950 @subsection The header 5953 @subsection The header
5951 5954
5952 The next step creates the file and writes a header with a signature and 5955 The next step creates the file and writes a header with a signature and
5953 some random informations in it (number of staticpro, number of assigned 5956 some random information in it (number of staticpro, number of assigned
5954 lrecord types, etc...). The reloc_address field, which indicates at 5957 lrecord types, etc...). The reloc_address field, which indicates at
5955 which address the file should be loaded if we want to avoid post-reload 5958 which address the file should be loaded if we want to avoid post-reload
5956 relocation, is set to 0. It then seeks to offset 256 (base offset for 5959 relocation, is set to 0. It then seeks to offset 256 (base offset for
5957 the objects). 5960 the objects).
5958 5961
5983 the lrecord_implementation_table array 5986 the lrecord_implementation_table array
5984 @item 5987 @item
5985 a vector of all the offsets to the objects in the file that include a 5988 a vector of all the offsets to the objects in the file that include a
5986 description (for faster relocation at reload time) 5989 description (for faster relocation at reload time)
5987 @item 5990 @item
5988 the pdump_wired and pdump_wired_list arrays 5991 the pdump_wire and pdump_wire_list arrays
5989 @end enumerate 5992 @end enumerate
5990 5993
5991 For each of the arrays we write both the pointer to the variables and 5994 For each of the arrays we write both the pointer to the variables and
5992 the relocated offset of the object they point to. Since these variables 5995 the relocated offset of the object they point to. Since these variables
5993 are global, the pointers are still valid when restarting the program and 5996 are global, the pointers are still valid when restarting the program and
5994 are used to regenerate the global pointers. 5997 are used to regenerate the global pointers.
5995 5998
5996 The @code{pdump_wired_list} array is a special case. The variables it 5999 The @code{pdump_wire_list} array is a special case. The variables it
5997 points to are the head of weak linked lists of lisp objects of the same 6000 points to are the head of weak linked lists of lisp objects of the same
5998 type. Not all objects of this list are dumped so the relocated pointer 6001 type. Not all objects of this list are dumped so the relocated pointer
5999 we associate with them points to the first dumped object of the list, or 6002 we associate with them points to the first dumped object of the list, or
6000 Qnil if none is available. This is also the reason why they are not 6003 Qnil if none is available. This is also the reason why they are not
6001 used as roots for the purpose of object enumeration. 6004 used as roots for the purpose of object enumeration.