Mercurial > hg > xemacs-beta
annotate src/alloca.c @ 5353:38e24b8be4ea
Improve the lexical scoping in #'block, #'return-from.
lisp/ChangeLog addition:
2011-02-07 Aidan Kehoe <kehoea@parhasard.net>
* bytecomp.el:
* bytecomp.el (byte-compile-initial-macro-environment):
Shadow `block', `return-from' here, we implement them differently
when byte-compiling.
* bytecomp.el (byte-compile-active-blocks): New.
* bytecomp.el (byte-compile-block-1): New.
* bytecomp.el (byte-compile-return-from-1): New.
* bytecomp.el (return-from-1): New.
* bytecomp.el (block-1): New.
These are two aliases that exist to have their own associated
byte-compile functions, which functions implement `block' and
`return-from'.
* cl-extra.el (cl-macroexpand-all):
Fix a bug here when macros in the environment have been compiled.
* cl-macs.el (block):
* cl-macs.el (return):
* cl-macs.el (return-from):
Be more careful about lexical scope in these macros.
* cl.el:
* cl.el ('cl-block-wrapper): Removed.
* cl.el ('cl-block-throw): Removed.
These aren't needed in code generated by this XEmacs. They
shouldn't be needed in code generated by XEmacs 21.4, but if it
turns out the packages do need them, we can put them back.
2011-01-30 Mike Sperber <mike@xemacs.org>
* font-lock.el (font-lock-fontify-pending-extents): Don't fail if
`font-lock-mode' is unset, which can happen in the middle of
`revert-buffer'.
2011-01-23 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (delete):
* cl-macs.el (delq):
* cl-macs.el (remove):
* cl-macs.el (remq):
Don't use the compiler macro if these functions were given the
wrong number of arguments, as happens in lisp-tests.el.
* cl-seq.el (remove, remq): Removed.
I added these to subr.el, and forgot to remove them from here.
2011-01-22 Aidan Kehoe <kehoea@parhasard.net>
* bytecomp.el (byte-compile-setq, byte-compile-set):
Remove kludge allowing keywords' values to be set, all the code
that does that is gone.
* cl-compat.el (elt-satisfies-test-p):
* faces.el (set-face-parent):
* faces.el (face-doc-string):
* gtk-font-menu.el:
* gtk-font-menu.el (gtk-reset-device-font-menus):
* msw-font-menu.el:
* msw-font-menu.el (mswindows-reset-device-font-menus):
* package-get.el (package-get-installedp):
* select.el (select-convert-from-image-data):
* sound.el:
* sound.el (load-sound-file):
* x-font-menu.el (x-reset-device-font-menus-core):
Don't quote keywords, they're self-quoting, and the
win from backward-compatibility is sufficiently small now that the
style problem overrides it.
2011-01-22 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (block, return-from): Require that NAME be a symbol
in these macros, as always documented in the #'block docstring and
as required by Common Lisp.
* descr-text.el (unidata-initialize-unihan-database):
Correct the use of non-symbols in #'block and #'return-from in
this function.
2011-01-15 Aidan Kehoe <kehoea@parhasard.net>
* cl-extra.el (concatenate): Accept more complicated TYPEs in this
function, handing the sequences over to #'coerce if we don't
understand them here.
* cl-macs.el (inline): Don't proclaim #'concatenate as inline, its
compiler macro is more useful than doing that.
2011-01-11 Aidan Kehoe <kehoea@parhasard.net>
* subr.el (delete, delq, remove, remq): Move #'remove, #'remq
here, they don't belong in cl-seq.el; move #'delete, #'delq here
from fns.c, implement them in terms of #'delete*, allowing support
for sequences generally.
* update-elc.el (do-autoload-commands): Use #'delete*, not #'delq
here, now the latter's no longer dumped.
* cl-macs.el (delete, delq): Add compiler macros transforming
#'delete and #'delq to #'delete* calls.
2011-01-10 Aidan Kehoe <kehoea@parhasard.net>
* dialog.el (make-dialog-box): Correct a misplaced parenthesis
here, thank you Mats Lidell in 87zkr9gqrh.fsf@mail.contactor.se !
2011-01-02 Aidan Kehoe <kehoea@parhasard.net>
* dialog.el (make-dialog-box):
* list-mode.el (display-completion-list):
These functions used to use cl-parsing-keywords; change them to
use defun* instead, fixing the build. (Not sure what led to me
not including this change in d1b17a33450b!)
2011-01-02 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (define-star-compiler-macros):
Make sure the form has ITEM and LIST specified before attempting
to change to calls with explicit tests; necessary for some tests
in lisp-tests.el to compile correctly.
(stable-union, stable-intersection): Add compiler macros for these
functions, in the same way we do for most of the other functions
in cl-seq.el.
2011-01-01 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (dolist, dotimes, do-symbols, macrolet)
(symbol-macrolet):
Define these macros with defmacro* instead of parsing the argument
list by hand, for the sake of style and readability; use backquote
where appropriate, instead of calling #'list and and friends, for
the same reason.
2010-12-30 Aidan Kehoe <kehoea@parhasard.net>
* x-misc.el (device-x-display):
Provide this function, documented in the Lispref for years, but
not existing previously. Thank you Julian Bradfield, thank you
Jeff Mincy.
2010-12-30 Aidan Kehoe <kehoea@parhasard.net>
* cl-seq.el:
Move the heavy lifting from this file to C. Dump the
cl-parsing-keywords macro, but don't use defun* for the functions
we define that do take keywords, dynamic scope lossage makes that
not practical.
* subr.el (sort, fillarray): Move these aliases here.
(map-plist): #'nsublis is now built-in, but at this point #'eql
isn't necessarily available as a test; use #'eq.
* obsolete.el (cl-delete-duplicates): Make this available for old
compiler macros and old code.
(memql): Document that this is equivalent to #'member*, and worse.
* cl.el (adjoin, subst): Removed. These are in C.
2010-12-30 Aidan Kehoe <kehoea@parhasard.net>
* simple.el (assoc-ignore-case): Remove a duplicate definition of
this function (it's already in subr.el).
* iso8859-1.el (char-width):
On non-Mule, make this function equivalent to that produced by
(constantly 1), but preserve its docstring.
* subr.el (subst-char-in-string): Define this in terms of
#'substitute, #'nsubstitute.
(string-width): Define this using #'reduce and #'char-width.
(char-width): Give this a simpler definition, it makes far more
sense to check for mule at load time and redefine, as we do in
iso8859-1.el.
(store-substring): Implement this in terms of #'replace, now
#'replace is cheap.
2010-12-30 Aidan Kehoe <kehoea@parhasard.net>
* update-elc.el (lisp-files-needed-for-byte-compilation)
(lisp-files-needing-early-byte-compilation):
cl-macs belongs in the former, not the latter, it is as
fundamental as bytecomp.el.
2010-12-30 Aidan Kehoe <kehoea@parhasard.net>
* cl.el:
Provde the Common Lisp program-error, type-error as error
symbols. This doesn't nearly go far enough for anyone using the
Common Lisp errors.
2010-12-29 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (delete-duplicates):
If the form has an incorrect number of arguments, don't attempt a
compiler macroexpansion.
2010-12-29 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (cl-safe-expr-p):
Forms that start with the symbol lambda are also safe.
2010-12-29 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (= < > <= >=):
For these functions' compiler macros, the optimisation is safe
even if the first and the last arguments have side effects, since
they're only used the once.
2010-12-29 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (inline-side-effect-free-compiler-macros):
Unroll a loop here at macro-expansion time, so these compiler
macros are compiled. Use #'eql instead of #'eq in a couple of
places for better style.
2010-12-29 Aidan Kehoe <kehoea@parhasard.net>
* cl-extra.el (notany, notevery): Avoid some dynamic scope
stupidity with local variable names in these functions, when they
weren't prefixed with cl-; go into some more detail in the doc
strings.
2010-12-29 Aidan Kehoe <kehoea@parhasard.net>
* byte-optimize.el (side-effect-free-fns): #'remove, #'remq are
free of side-effects.
(side-effect-and-error-free-fns):
Drop dot, dot-marker from the list.
2010-11-17 Aidan Kehoe <kehoea@parhasard.net>
* cl-extra.el (coerce):
In the argument list, name the first argument OBJECT, not X; the
former name was always used in the doc string and is clearer.
Handle vector type specifications which include the length of the
target sequence, error if there's a mismatch.
* cl-macs.el (cl-make-type-test): Handle type specifications
starting with the symbol 'eql.
2010-11-14 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (eql): Don't remove the byte-compile property of this
symbol. That was necessary to override a bug in bytecomp.el where
#'eql was confused with #'eq, which bug we no longer have.
If neither expression is constant, don't attempt to handle the
expression in this compiler macro, leave it to byte-compile-eql,
which produces better code anyway.
* bytecomp.el (eq): #'eql is not the function associated with the
byte-eq byte code.
(byte-compile-eql): Add an explicit compile method for this
function, for cases where the cl-macs compiler macro hasn't
reduced it to #'eq or #'equal.
2010-10-25 Aidan Kehoe <kehoea@parhasard.net>
Add compiler macros and compilation sanity-checking for various
functions that take keywords.
* byte-optimize.el (side-effect-free-fns): #'symbol-value is
side-effect free and not error free.
* bytecomp.el (byte-compile-normal-call): Check keyword argument
lists for sanity; store information about the positions where
keyword arguments start using the new byte-compile-keyword-start
property.
* cl-macs.el (cl-const-expr-val): Take a new optional argument,
cl-not-constant, defaulting to nil, in this function; return it if
the expression is not constant.
(cl-non-fixnum-number-p): Make this into a separate function, we
want to pass it to #'every.
(eql): Use it.
(define-star-compiler-macros): Use the same code to generate the
member*, assoc* and rassoc* compiler macros; special-case some
code in #'add-to-list in subr.el.
(remove, remq): Add compiler macros for these two functions, in
preparation for #'remove being in C.
(define-foo-if-compiler-macros): Transform (remove-if-not ...) calls to
(remove ... :if-not) at compile time, which will be a real win
once the latter is in C.
(define-substitute-if-compiler-macros)
(define-subst-if-compiler-macros): Similarly for these functions.
(delete-duplicates): Change this compiler macro to use
#'plists-equal; if we don't have information about the type of
SEQUENCE at compile time, don't bother attempting to inline the
call, the function will be in C soon enough.
(equalp): Remove an old commented-out compiler macro for this, if
we want to see it it's in version control.
(subst-char-in-string): Transform this to a call to nsubstitute or
nsubstitute, if that is appropriate.
* cl.el (ldiff): Don't call setf here, this makes for a load-time
dependency problem in cl-macs.el
2010-06-14 Stephen J. Turnbull <stephen@xemacs.org>
* term/vt100.el:
Refer to XEmacs, not GNU Emacs, in permissions.
* term/bg-mouse.el:
* term/sup-mouse.el:
Put copyright notice in canonical "Copyright DATE AUTHOR" form.
Refer to XEmacs, not GNU Emacs, in permissions.
* site-load.el:
Add permission boilerplate.
* mule/canna-leim.el:
* alist.el:
Refer to XEmacs, not APEL/this program, in permissions.
* mule/canna-leim.el:
Remove my copyright, I've assigned it to the FSF.
2010-06-14 Stephen J. Turnbull <stephen@xemacs.org>
* gtk.el:
* gtk-widget-accessors.el:
* gtk-package.el:
* gtk-marshal.el:
* gtk-compose.el:
* gnome.el:
Add copyright notice based on internal evidence.
2010-06-14 Stephen J. Turnbull <stephen@xemacs.org>
* easymenu.el: Add reference to COPYING to permission notice.
* gutter.el:
* gutter-items.el:
* menubar-items.el:
Fix typo "Xmacs" in permissions notice.
2010-06-14 Stephen J. Turnbull <stephen@xemacs.org>
* auto-save.el:
* font.el:
* fontconfig.el:
* mule/kinsoku.el:
Add "part of XEmacs" text to permission notice.
2010-10-14 Aidan Kehoe <kehoea@parhasard.net>
* byte-optimize.el (side-effect-free-fns):
* cl-macs.el (remf, getf):
* cl-extra.el (tailp, cl-set-getf, cl-do-remf):
* cl.el (ldiff, endp):
Tighten up Common Lisp compatibility for #'ldiff, #'endp, #'tailp;
add circularity checking for the first two.
#'cl-set-getf and #'cl-do-remf were Lisp implementations of
#'plist-put and #'plist-remprop; change the names to aliases,
changes the macros that use them to using #'plist-put and
#'plist-remprop directly.
2010-10-12 Aidan Kehoe <kehoea@parhasard.net>
* abbrev.el (fundamental-mode-abbrev-table, global-abbrev-table):
Create both these abbrev tables using the usual
#'define-abbrev-table calls, rather than attempting to
special-case them.
* cl-extra.el: Force cl-macs to be loaded here, if cl-extra.el is
being loaded interpreted. Previously other, later files would
redundantly call (load "cl-macs") when interpreted, it's more
reasonable to do it here, once.
* cmdloop.el (read-quoted-char-radix): Use defcustom here, we
don't have any dump-order dependencies that would prevent that.
* custom.el (eval-when-compile): Don't load cl-macs when
interpreted or when byte-compiling, rely on cl-extra.el in the
former case and the appropriate entry in bytecomp-load-hook in the
latter. Get rid of custom-declare-variable-list, we have no
dump-time dependencies that would require it.
* faces.el (eval-when-compile): Don't load cl-macs when
interpreted or when byte-compiling.
* packages.el: Remove some inaccurate comments.
* post-gc.el (cleanup-simple-finalizers): Use #'delete-if-not
here, now the order of preloaded-file-list has been changed to
make it available.
* subr.el (custom-declare-variable-list): Remove. No need for it.
Also remove a stub define-abbrev-table from this file, given the
current order of preloaded-file-list there's no need for it.
2010-10-10 Aidan Kehoe <kehoea@parhasard.net>
* bytecomp.el (byte-compile-constp) Forms quoted with FUNCTION are
also constant.
(byte-compile-initial-macro-environment): In #'the, if FORM is
constant and does not match TYPE, warn at byte-compile time.
2010-10-10 Aidan Kehoe <kehoea@parhasard.net>
* backquote.el (bq-vector-contents, bq-list*): Remove; the former
is equivalent to (append VECTOR nil), the latter to (list* ...).
(bq-process-2): Use (append VECTOR nil) instead of using
#'bq-vector-contents to convert to a list.
(bq-process-1): Now we use list* instead of bq-list
* subr.el (list*): Moved from cl.el, since it is now required to
be available the first time a backquoted form is encountered.
* cl.el (list*): Move to subr.el.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* test-harness.el (Check-Message):
Add an omitted comma here, thank you the buildbot.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* hash-table.el (hash-table-key-list, hash-table-value-list)
(hash-table-key-value-alist, hash-table-key-value-plist):
Remove some useless #'nreverse calls in these files; our hash
tables have no order, it's not helpful to pretend they do.
* behavior.el (read-behavior):
Do the same in this file, in some code evidently copied from
hash-table.el.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* info.el (Info-insert-dir):
* format.el (format-deannotate-region):
* files.el (cd, save-buffers-kill-emacs):
Use #'some, #'every and related functions for applying boolean
operations to lists, instead of rolling our own ones that cons and
don't short-circuit.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* bytecomp.el (byte-compile-initial-macro-environment):
* cl-macs.el (the):
Rephrase the docstring, make its implementation when compiling
files a little nicer.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* descr-text.el (unidata-initialize-unicodedata-database)
(unidata-initialize-unihan-database, describe-char-unicode-data)
(describe-char-unicode-data):
Wrap calls to the database functions with (with-fboundp ...),
avoiding byte compile warnings on builds without support for the
database functions.
(describe-char): (reduce #'max ...), not (apply #'max ...), no
need to cons needlessly.
(describe-char): Remove a redundant lambda wrapping
#'extent-properties.
(describe-char-unicode-data): Call #'nsubst when replacing "" with
nil in the result of #'split-string, instead of consing inside
mapcar.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* x-faces.el (x-available-font-sizes):
* specifier.el (let-specifier):
* package-ui.el (pui-add-required-packages):
* msw-faces.el (mswindows-available-font-sizes):
* modeline.el (modeline-minor-mode-menu):
* minibuf.el (minibuf-directory-files):
Replace the O2N (delq nil (mapcar (lambda (W) (and X Y)) Z)) with
the ON (mapcan (lambda (W) (and X (list Y))) Z) in these files.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (= < > <= >=):
When these functions are handed more than two arguments, and those
arguments have no side effects, transform to a series of two
argument calls, avoiding funcall in the byte-compiled code.
* mule/mule-cmds.el (finish-set-language-environment):
Take advantage of this change in a function called 256 times at
startup.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* bytecomp.el (byte-compile-function-form, byte-compile-quote)
(byte-compile-quote-form):
Warn at compile time, and error at runtime, if a (quote ...) or a
(function ...) form attempts to quote more than one object.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* byte-optimize.el (byte-optimize-apply): Transform (apply 'nconc
(mapcar ...)) to (mapcan ...); warn about use of the first idiom.
* update-elc.el (do-autoload-commands):
* packages.el (packages-find-package-library-path):
* frame.el (frame-list):
* extents.el (extent-descendants):
* etags.el (buffer-tag-table-files):
* dumped-lisp.el (preloaded-file-list):
* device.el (device-list):
* bytecomp-runtime.el (proclaim-inline, proclaim-notinline)
Use #'mapcan, not (apply #'nconc (mapcar ...) in all these files.
* bytecomp-runtime.el (eval-when-compile, eval-and-compile):
In passing, mention that these macros also evaluate the body when
interpreted.
tests/ChangeLog addition:
2011-02-07 Aidan Kehoe <kehoea@parhasard.net>
* automated/lisp-tests.el:
Test lexical scope for `block', `return-from'; add a
Known-Bug-Expect-Failure for a contorted example that fails when
byte-compiled.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Mon, 07 Feb 2011 12:01:24 +0000 |
parents | 6f2158fa75ed |
children | d363790fd936 |
rev | line source |
---|---|
428 | 1 /* alloca.c -- allocate automatically reclaimed memory |
2 (Mostly) portable public-domain implementation -- D A Gwyn | |
3 | |
4 This implementation of the PWB library alloca function, | |
5 which is used to allocate space off the run-time stack so | |
6 that it is automatically reclaimed upon procedure exit, | |
7 was inspired by discussions with J. Q. Johnson of Cornell. | |
8 J.Otto Tennant <jot@cray.com> contributed the Cray support. | |
9 | |
10 There are some preprocessor constants that can | |
11 be defined when compiling for your specific system, for | |
12 improved efficiency; however, the defaults should be okay. | |
13 | |
14 The general concept of this implementation is to keep | |
15 track of all alloca-allocated blocks, and reclaim any | |
16 that are found to be deeper in the stack than the current | |
17 invocation. This heuristic does not reclaim storage as | |
18 soon as it becomes invalid, but it will do so eventually. | |
19 | |
20 As a special case, alloca(0) reclaims storage without | |
21 allocating any. It is a good idea to use alloca(0) in | |
22 your main control loop, etc. to force garbage collection. */ | |
23 | |
24 /* Synched up with: FSF 19.30. */ | |
25 | |
442 | 26 /* Authorship: |
428 | 27 |
28 FSF: A long time ago. | |
851 | 29 Some cleanups for XEmacs. |
428 | 30 */ |
31 | |
32 #ifdef HAVE_CONFIG_H | |
33 #include <config.h> | |
34 #endif | |
35 | |
36 #ifdef emacs | |
851 | 37 #include "lisp.h" |
38 #endif | |
428 | 39 |
40 /* If your stack is a linked list of frames, you have to | |
41 provide an "address metric" ADDRESS_FUNCTION macro. */ | |
42 | |
43 #if defined (CRAY) && defined (CRAY_STACKSEG_END) | |
44 long i00afunc (); | |
45 #define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg)) | |
46 #else | |
47 #define ADDRESS_FUNCTION(arg) &(arg) | |
48 #endif | |
49 | |
50 typedef void *pointer; | |
51 | |
442 | 52 #ifndef NULL |
428 | 53 #define NULL 0 |
54 #endif | |
55 | |
56 /* Define STACK_DIRECTION if you know the direction of stack | |
57 growth for your system; otherwise it will be automatically | |
58 deduced at run-time. | |
59 | |
60 STACK_DIRECTION > 0 => grows toward higher addresses | |
61 STACK_DIRECTION < 0 => grows toward lower addresses | |
62 STACK_DIRECTION = 0 => direction of growth unknown */ | |
63 | |
64 #ifndef STACK_DIRECTION | |
65 #define STACK_DIRECTION 0 /* Direction unknown. */ | |
66 #endif | |
67 | |
68 #if STACK_DIRECTION != 0 | |
69 | |
70 #define STACK_DIR STACK_DIRECTION /* Known at compile-time. */ | |
71 | |
72 #else /* STACK_DIRECTION == 0; need run-time code. */ | |
73 | |
74 static int stack_dir; /* 1 or -1 once known. */ | |
75 #define STACK_DIR stack_dir | |
76 | |
77 static void | |
1111 | 78 find_stack_direction (void) |
428 | 79 { |
80 static char *addr = NULL; /* Address of first `dummy', once known. */ | |
81 auto char dummy; /* To get stack address. */ | |
82 | |
83 if (addr == NULL) | |
84 { /* Initial entry. */ | |
85 addr = ADDRESS_FUNCTION (dummy); | |
86 | |
87 find_stack_direction (); /* Recurse once. */ | |
88 } | |
89 else | |
90 { | |
91 /* Second entry. */ | |
92 if (ADDRESS_FUNCTION (dummy) > addr) | |
93 stack_dir = 1; /* Stack grew upward. */ | |
94 else | |
95 stack_dir = -1; /* Stack grew downward. */ | |
96 } | |
97 } | |
98 | |
99 #endif /* STACK_DIRECTION == 0 */ | |
100 | |
101 /* An "alloca header" is used to: | |
102 (a) chain together all alloca'ed blocks; | |
103 (b) keep track of stack depth. | |
104 | |
105 It is very important that sizeof(header) agree with malloc | |
106 alignment chunk size. The following default should work okay. */ | |
107 | |
851 | 108 #ifndef ALIGNMENT_SIZE |
109 #define ALIGNMENT_SIZE sizeof(double) | |
428 | 110 #endif |
111 | |
112 typedef union hdr | |
113 { | |
851 | 114 char align[ALIGNMENT_SIZE]; /* To force sizeof(header). */ |
428 | 115 struct |
116 { | |
117 union hdr *next; /* For chaining headers. */ | |
118 char *deep; /* For stack depth measure. */ | |
119 } h; | |
120 } header; | |
121 | |
122 static header *last_alloca_header = NULL; /* -> last alloca header. */ | |
123 | |
124 /* Return a pointer to at least SIZE bytes of storage, | |
125 which will be automatically reclaimed upon exit from | |
126 the procedure that called alloca. Originally, this space | |
127 was supposed to be taken from the current stack frame of the | |
128 caller, but that method cannot be made to work for some | |
129 implementations of C, for example under Gould's UTX/32. */ | |
130 | |
131 pointer | |
851 | 132 xemacs_c_alloca (unsigned int size) |
428 | 133 { |
134 auto char probe; /* Probes stack depth: */ | |
442 | 135 register char *depth = ADDRESS_FUNCTION (probe); |
428 | 136 |
137 #if STACK_DIRECTION == 0 | |
138 if (STACK_DIR == 0) /* Unknown growth direction. */ | |
139 find_stack_direction (); | |
140 #endif | |
141 | |
142 /* Reclaim garbage, defined as all alloca'd storage that | |
143 was allocated from deeper in the stack than currently. */ | |
144 | |
145 { | |
2965 | 146 header *hp; /* Traverses linked list. */ |
428 | 147 |
148 for (hp = last_alloca_header; hp != NULL;) | |
149 if ((STACK_DIR > 0 && hp->h.deep > depth) | |
150 || (STACK_DIR < 0 && hp->h.deep < depth)) | |
151 { | |
442 | 152 register header *np = hp->h.next; |
428 | 153 |
851 | 154 #ifdef emacs |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
2965
diff
changeset
|
155 xfree (hp); /* Collect garbage. */ |
851 | 156 #else |
157 free (hp); /* Collect garbage. */ | |
158 #endif | |
428 | 159 |
160 hp = np; /* -> next header. */ | |
161 } | |
162 else | |
163 break; /* Rest are not deeper. */ | |
164 | |
165 last_alloca_header = hp; /* -> last valid storage. */ | |
166 } | |
167 | |
851 | 168 #ifdef emacs |
169 need_to_check_c_alloca = size > 0 || last_alloca_header; | |
170 recompute_funcall_allocation_flag (); | |
171 #endif | |
172 | |
428 | 173 if (size == 0) |
174 return NULL; /* No allocation required. */ | |
175 | |
176 /* Allocate combined header + user data storage. */ | |
177 | |
178 { | |
851 | 179 #ifdef emacs |
2965 | 180 register pointer new_ = xmalloc (sizeof (header) + size); |
851 | 181 #else |
2965 | 182 register pointer new_ = malloc (sizeof (header) + size); |
851 | 183 #endif |
428 | 184 /* Address of header. */ |
185 | |
2965 | 186 ((header *) new_)->h.next = last_alloca_header; |
187 ((header *) new_)->h.deep = depth; | |
428 | 188 |
2965 | 189 last_alloca_header = (header *) new_; |
428 | 190 |
191 /* User storage begins just after header. */ | |
192 | |
2965 | 193 return (pointer) ((char *) new_ + sizeof (header)); |
428 | 194 } |
195 } | |
196 | |
197 #if defined (CRAY) && defined (CRAY_STACKSEG_END) | |
198 | |
199 #ifdef DEBUG_I00AFUNC | |
200 #include <stdio.h> | |
201 #endif | |
202 | |
203 #ifndef CRAY_STACK | |
204 #define CRAY_STACK | |
205 #ifndef CRAY2 | |
206 /* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */ | |
207 struct stack_control_header | |
208 { | |
209 long shgrow:32; /* Number of times stack has grown. */ | |
210 long shaseg:32; /* Size of increments to stack. */ | |
211 long shhwm:32; /* High water mark of stack. */ | |
212 long shsize:32; /* Current size of stack (all segments). */ | |
213 }; | |
214 | |
215 /* The stack segment linkage control information occurs at | |
216 the high-address end of a stack segment. (The stack | |
217 grows from low addresses to high addresses.) The initial | |
218 part of the stack segment linkage control information is | |
219 0200 (octal) words. This provides for register storage | |
220 for the routine which overflows the stack. */ | |
221 | |
222 struct stack_segment_linkage | |
223 { | |
224 long ss[0200]; /* 0200 overflow words. */ | |
225 long sssize:32; /* Number of words in this segment. */ | |
226 long ssbase:32; /* Offset to stack base. */ | |
227 long:32; | |
228 long sspseg:32; /* Offset to linkage control of previous | |
229 segment of stack. */ | |
230 long:32; | |
231 long sstcpt:32; /* Pointer to task common address block. */ | |
232 long sscsnm; /* Private control structure number for | |
233 microtasking. */ | |
234 long ssusr1; /* Reserved for user. */ | |
235 long ssusr2; /* Reserved for user. */ | |
236 long sstpid; /* Process ID for pid based multi-tasking. */ | |
237 long ssgvup; /* Pointer to multitasking thread giveup. */ | |
238 long sscray[7]; /* Reserved for Cray Research. */ | |
239 long ssa0; | |
240 long ssa1; | |
241 long ssa2; | |
242 long ssa3; | |
243 long ssa4; | |
244 long ssa5; | |
245 long ssa6; | |
246 long ssa7; | |
247 long sss0; | |
248 long sss1; | |
249 long sss2; | |
250 long sss3; | |
251 long sss4; | |
252 long sss5; | |
253 long sss6; | |
254 long sss7; | |
255 }; | |
256 | |
257 #else /* CRAY2 */ | |
258 /* The following structure defines the vector of words | |
259 returned by the STKSTAT library routine. */ | |
260 struct stk_stat | |
261 { | |
262 long now; /* Current total stack size. */ | |
263 long maxc; /* Amount of contiguous space which would | |
264 be required to satisfy the maximum | |
265 stack demand to date. */ | |
266 long high_water; /* Stack high-water mark. */ | |
267 long overflows; /* Number of stack overflow ($STKOFEN) calls. */ | |
268 long hits; /* Number of internal buffer hits. */ | |
269 long extends; /* Number of block extensions. */ | |
270 long stko_mallocs; /* Block allocations by $STKOFEN. */ | |
271 long underflows; /* Number of stack underflow calls ($STKRETN). */ | |
272 long stko_free; /* Number of deallocations by $STKRETN. */ | |
273 long stkm_free; /* Number of deallocations by $STKMRET. */ | |
274 long segments; /* Current number of stack segments. */ | |
275 long maxs; /* Maximum number of stack segments so far. */ | |
276 long pad_size; /* Stack pad size. */ | |
277 long current_address; /* Current stack segment address. */ | |
278 long current_size; /* Current stack segment size. This | |
279 number is actually corrupted by STKSTAT to | |
280 include the fifteen word trailer area. */ | |
281 long initial_address; /* Address of initial segment. */ | |
282 long initial_size; /* Size of initial segment. */ | |
283 }; | |
284 | |
285 /* The following structure describes the data structure which trails | |
286 any stack segment. I think that the description in 'asdef' is | |
287 out of date. I only describe the parts that I am sure about. */ | |
288 | |
289 struct stk_trailer | |
290 { | |
291 long this_address; /* Address of this block. */ | |
292 long this_size; /* Size of this block (does not include | |
293 this trailer). */ | |
294 long unknown2; | |
295 long unknown3; | |
296 long link; /* Address of trailer block of previous | |
297 segment. */ | |
298 long unknown5; | |
299 long unknown6; | |
300 long unknown7; | |
301 long unknown8; | |
302 long unknown9; | |
303 long unknown10; | |
304 long unknown11; | |
305 long unknown12; | |
306 long unknown13; | |
307 long unknown14; | |
308 }; | |
309 | |
310 #endif /* CRAY2 */ | |
311 #endif /* not CRAY_STACK */ | |
312 | |
313 #ifdef CRAY2 | |
314 /* Determine a "stack measure" for an arbitrary ADDRESS. | |
315 I doubt that "lint" will like this much. */ | |
316 | |
317 static long | |
318 i00afunc (long *address) | |
319 { | |
320 struct stk_stat status; | |
321 struct stk_trailer *trailer; | |
322 long *block, size; | |
323 long result = 0; | |
324 | |
325 /* We want to iterate through all of the segments. The first | |
326 step is to get the stack status structure. We could do this | |
327 more quickly and more directly, perhaps, by referencing the | |
328 $LM00 common block, but I know that this works. */ | |
329 | |
330 STKSTAT (&status); | |
331 | |
332 /* Set up the iteration. */ | |
333 | |
334 trailer = (struct stk_trailer *) (status.current_address | |
335 + status.current_size | |
336 - 15); | |
337 | |
338 /* There must be at least one stack segment. Therefore it is | |
339 a fatal error if "trailer" is null. */ | |
340 | |
5050
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
341 assert (trailer != 0); |
428 | 342 |
343 /* Discard segments that do not contain our argument address. */ | |
344 | |
345 while (trailer != 0) | |
346 { | |
347 block = (long *) trailer->this_address; | |
348 size = trailer->this_size; | |
349 if (block == 0 || size == 0) | |
2500 | 350 ABORT (); |
428 | 351 trailer = (struct stk_trailer *) trailer->link; |
352 if ((block <= address) && (address < (block + size))) | |
353 break; | |
354 } | |
355 | |
356 /* Set the result to the offset in this segment and add the sizes | |
357 of all predecessor segments. */ | |
358 | |
359 result = address - block; | |
360 | |
361 if (trailer == 0) | |
362 { | |
363 return result; | |
364 } | |
365 | |
366 do | |
367 { | |
5050
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
368 assert (trailer->this_size > 0); |
428 | 369 result += trailer->this_size; |
370 trailer = (struct stk_trailer *) trailer->link; | |
371 } | |
372 while (trailer != 0); | |
373 | |
374 /* We are done. Note that if you present a bogus address (one | |
375 not in any segment), you will get a different number back, formed | |
376 from subtracting the address of the first block. This is probably | |
377 not what you want. */ | |
378 | |
379 return (result); | |
380 } | |
381 | |
382 #else /* not CRAY2 */ | |
383 /* Stack address function for a CRAY-1, CRAY X-MP, or CRAY Y-MP. | |
384 Determine the number of the cell within the stack, | |
385 given the address of the cell. The purpose of this | |
386 routine is to linearize, in some sense, stack addresses | |
387 for alloca. */ | |
388 | |
389 static long | |
390 i00afunc (long address) | |
391 { | |
392 long stkl = 0; | |
393 | |
394 long size, pseg, this_segment, stack; | |
395 long result = 0; | |
396 | |
397 struct stack_segment_linkage *ssptr; | |
398 | |
399 /* Register B67 contains the address of the end of the | |
400 current stack segment. If you (as a subprogram) store | |
401 your registers on the stack and find that you are past | |
402 the contents of B67, you have overflowed the segment. | |
403 | |
404 B67 also points to the stack segment linkage control | |
405 area, which is what we are really interested in. */ | |
406 | |
407 stkl = CRAY_STACKSEG_END (); | |
408 ssptr = (struct stack_segment_linkage *) stkl; | |
409 | |
410 /* If one subtracts 'size' from the end of the segment, | |
411 one has the address of the first word of the segment. | |
412 | |
413 If this is not the first segment, 'pseg' will be | |
414 nonzero. */ | |
415 | |
416 pseg = ssptr->sspseg; | |
417 size = ssptr->sssize; | |
418 | |
419 this_segment = stkl - size; | |
420 | |
421 /* It is possible that calling this routine itself caused | |
422 a stack overflow. Discard stack segments which do not | |
423 contain the target address. */ | |
424 | |
425 while (!(this_segment <= address && address <= stkl)) | |
426 { | |
427 #ifdef DEBUG_I00AFUNC | |
428 fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl); | |
429 #endif | |
430 if (pseg == 0) | |
431 break; | |
432 stkl = stkl - pseg; | |
433 ssptr = (struct stack_segment_linkage *) stkl; | |
434 size = ssptr->sssize; | |
435 pseg = ssptr->sspseg; | |
436 this_segment = stkl - size; | |
437 } | |
438 | |
439 result = address - this_segment; | |
440 | |
441 /* If you subtract pseg from the current end of the stack, | |
442 you get the address of the previous stack segment's end. | |
443 This seems a little convoluted to me, but I'll bet you save | |
444 a cycle somewhere. */ | |
445 | |
446 while (pseg != 0) | |
447 { | |
448 #ifdef DEBUG_I00AFUNC | |
449 fprintf (stderr, "%011o %011o\n", pseg, size); | |
450 #endif | |
451 stkl = stkl - pseg; | |
452 ssptr = (struct stack_segment_linkage *) stkl; | |
453 size = ssptr->sssize; | |
454 pseg = ssptr->sspseg; | |
455 result += size; | |
456 } | |
457 return (result); | |
458 } | |
459 | |
460 #endif /* not CRAY2 */ | |
461 #endif /* CRAY */ |