source: trunk/src/emx/include/obstack.h@ 236

Last change on this file since 236 was 123, checked in by zap, 23 years ago

Started the work for re-designing the EMX C runtime library to not require
EMX.DLL. The new design is projected to be as follows:

  • all emx syscalls are replaced with the routines from the old sys.lib library which is now compilable in both a.out and OMF formats.
  • the sys.a library should be made replaceable and selectable by some gcc switch (e.g. -msyslib=emx would link with emx.a instead of sys.a which would give almost full backward compatibility with emx).
  • All C functions names were renamed to not contain the starting underscore (e.g. fopen and not _fopen). The underscored aliases will be added later with the c_alias library (which will be generated automatically from all public symbols of libc; any exported symbol that do not start with an underscore will be given an underscored alias unless such a symbol is already defined).

Also a lot of updates to the building system. It is now much faster (thanks
to Knut's suggestion of using ash's builtin echo).
Also re-wrote thunk1.asm and thunk2.asm to GAS format; this removes the need
for MASM and makes it possible to use 16-bit functions in a.out programs
without the need for EMX.DLL.
Also made a lot of small changes I don't remember now.

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 22.2 KB
Line 
1/* obstack.h - object stack macros
2 Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1996, 1997, 1998,
3 1999, 2000
4 Free Software Foundation, Inc.
5
6
7 NOTE: The canonical source of this file is maintained with the GNU C Library.
8 Bugs can be reported to [email protected].
9
10 This program is free software; you can redistribute it and/or modify it
11 under the terms of the GNU General Public License as published by the
12 Free Software Foundation; either version 2, or (at your option) any
13 later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
23 USA. */
24
25/* Summary:
26
27All the apparent functions defined here are macros. The idea
28is that you would use these pre-tested macros to solve a
29very specific set of problems, and they would run fast.
30Caution: no side-effects in arguments please!! They may be
31evaluated MANY times!!
32
33These macros operate a stack of objects. Each object starts life
34small, and may grow to maturity. (Consider building a word syllable
35by syllable.) An object can move while it is growing. Once it has
36been "finished" it never changes address again. So the "top of the
37stack" is typically an immature growing object, while the rest of the
38stack is of mature, fixed size and fixed address objects.
39
40These routines grab large chunks of memory, using a function you
41supply, called `obstack_chunk_alloc'. On occasion, they free chunks,
42by calling `obstack_chunk_free'. You must define them and declare
43them before using any obstack macros.
44
45Each independent stack is represented by a `struct obstack'.
46Each of the obstack macros expects a pointer to such a structure
47as the first argument.
48
49One motivation for this package is the problem of growing char strings
50in symbol tables. Unless you are "fascist pig with a read-only mind"
51--Gosper's immortal quote from HAKMEM item 154, out of context--you
52would not like to put any arbitrary upper limit on the length of your
53symbols.
54
55In practice this often means you will build many short symbols and a
56few long symbols. At the time you are reading a symbol you don't know
57how long it is. One traditional method is to read a symbol into a
58buffer, realloc()ating the buffer every time you try to read a symbol
59that is longer than the buffer. This is beaut, but you still will
60want to copy the symbol from the buffer to a more permanent
61symbol-table entry say about half the time.
62
63With obstacks, you can work differently. Use one obstack for all symbol
64names. As you read a symbol, grow the name in the obstack gradually.
65When the name is complete, finalize it. Then, if the symbol exists already,
66free the newly read name.
67
68The way we do this is to take a large chunk, allocating memory from
69low addresses. When you want to build a symbol in the chunk you just
70add chars above the current "high water mark" in the chunk. When you
71have finished adding chars, because you got to the end of the symbol,
72you know how long the chars are, and you can create a new object.
73Mostly the chars will not burst over the highest address of the chunk,
74because you would typically expect a chunk to be (say) 100 times as
75long as an average object.
76
77In case that isn't clear, when we have enough chars to make up
78the object, THEY ARE ALREADY CONTIGUOUS IN THE CHUNK (guaranteed)
79so we just point to it where it lies. No moving of chars is
80needed and this is the second win: potentially long strings need
81never be explicitly shuffled. Once an object is formed, it does not
82change its address during its lifetime.
83
84When the chars burst over a chunk boundary, we allocate a larger
85chunk, and then copy the partly formed object from the end of the old
86chunk to the beginning of the new larger chunk. We then carry on
87accreting characters to the end of the object as we normally would.
88
89A special macro is provided to add a single char at a time to a
90growing object. This allows the use of register variables, which
91break the ordinary 'growth' macro.
92
93Summary:
94 We allocate large chunks.
95 We carve out one object at a time from the current chunk.
96 Once carved, an object never moves.
97 We are free to append data of any size to the currently
98 growing object.
99 Exactly one object is growing in an obstack at any one time.
100 You can run one obstack per control block.
101 You may have as many control blocks as you dare.
102 Because of the way we do it, you can `unwind' an obstack
103 back to a previous state. (You may remove objects much
104 as you would with a stack.)
105*/
106
107
108/* Don't do the contents of this file more than once. */
109
110#ifndef _OBSTACK_H
111#define _OBSTACK_H 1
112
113#ifdef __cplusplus
114extern "C" {
115#endif
116
117
118/* We use subtraction of (char *) 0 instead of casting to int