Mercurial > hg > xemacs-beta
comparison src/alloc.c @ 2367:ecf1ebac70d8
[xemacs-hg @ 2004-11-04 23:05:23 by ben]
commit mega-patch
configure.in: Turn off -Winline and -Wchar-subscripts.
Use the right set of cflags when compiling modules.
Rewrite ldap configuration to separate the inclusion of lber
(needed in recent Cygwin) from the basic checks for the
needed libraries.
add a function for MAKE_JUNK_C; initially code was added to
generate xemacs.def using this, but it will need to be rewritten.
add an rm -f for junk.c to avoid weird Cygwin bug with cp -f onto
an existing file.
Sort list of auto-detected functions and eliminate unused checks for
stpcpy, setlocale and getwd.
Add autodetection of Cygwin scanf problems
BETA: Rewrite section on configure to indicate what flags are important
and what not.
digest-doc.c, make-dump-id.c, profile.c, sorted-doc.c: Add proper decls for main().
make-msgfile.c: Document that this is old junk.
Move proposal to text.c.
make-msgfile.lex: Move proposal to text.c.
make-mswin-unicode.pl: Convert error-generating code so that the entire message will
be seen as a single unrecognized token.
mule/mule-ccl.el: Update docs.
lispref/mule.texi: Update CCL docs.
ldap/eldap.c: Mule-ize.
Use EXTERNAL_LIST_LOOP_2 instead of deleted EXTERNAL_LIST_LOOP.
* XEmacs 21.5.18 "chestnut" is released.
---------------------------------------------------------------
MULE-RELATED WORK:
---------------------------------------------------------------
---------------------------
byte-char conversion
---------------------------
buffer.c, buffer.h, insdel.c, text.c: Port FSF algorithm for byte-char conversion, replacing broken
previous version. Track the char position of the gap. Add
functions to do char-byte conversion downwards as well as upwards.
Move comments about algorithm workings to internals manual.
---------------------------
work on types
---------------------------
alloc.c, console-x-impl.h, dump-data.c, dump-data.h, dumper.c, dialog-msw.c, dired-msw.c, doc.c, editfns.c, esd.c, event-gtk.h, event-msw.c, events.c, file-coding.c, file-coding.h, fns.c, glyphs-eimage.c, glyphs-gtk.c, glyphs-msw.c, glyphs-shared.c, glyphs-x.c, glyphs.c, glyphs.h, gui.c, hpplay.c, imgproc.c, intl-win32.c, lrecord.h, lstream.c, keymap.c, lisp.h, libsst.c, linuxplay.c, miscplay.c, miscplay.h, mule-coding.c, nas.c, nt.c, ntheap.c, ntplay.c, objects-msw.c, objects-tty.c, objects-x.c, print.c, process-nt.c, process.c, redisplay.h, select-common.h, select-gtk.c, select-x.c, sgiplay.c, sound.c, sound.h, sunplay.c, sysfile.h, sysdep.c, syswindows.h, text.c, unexnt.c, win32.c, xgccache.c: Further work on types. This creates a full set of types for all
the basic semantics of `char' that I have so far identified, so that
its semantics can always be identified for the purposes of proper
Mule-safe code, and the raw use of `char' always avoided.
(1) More type renaming, for consistency of naming.
Char_ASCII -> Ascbyte
UChar_ASCII -> UAscbyte
Char_Binary -> CBinbyte
UChar_Binary -> Binbyte
SChar_Binary -> SBinbyte
(2) Introduce Rawbyte, CRawbyte, Boolbyte, Chbyte, UChbyte, and
Bitbyte and use them.
(3) New types Itext, Wexttext and Textcount for separating out
the concepts of bytes and textual units (different under UTF-16
and UTF-32, which are potential internal encodings).
(4) qxestr*_c -> qxestr*_ascii.
lisp.h: New; goes with other qxe() functions. #### Maybe goes in a
different section.
lisp.h: Group generic int-type defs together with EMACS_INT defs.
lisp.h: * lisp.h (WEXTTEXT_IS_WIDE)
New defns.
lisp.h: New type to replace places where int occurs as a boolean.
It's signed because occasionally people may want to use -1 as
an error value, and because unsigned ints are viral -- see comments
in the internals manual against using them.
dynarr.c: int -> Bytecount.
---------------------------
Mule-izing
---------------------------
device-x.c: Partially Mule-ize.
dumper.c, dumper.h: Mule-ize. Use Rawbyte. Use stderr_out not printf. Use wext_*().
sysdep.c, syswindows.h, text.c: New Wexttext API for manipulation of external text that may be
Unicode (e.g. startup code under Windows).
emacs.c: Mule-ize. Properly deal with argv in external encoding.
Use wext_*() and Wexttext. Use Rawbyte.
#if 0 some old junk on SCO that is unlikely to be correct.
Rewrite allocation code in run-temacs.
emacs.c, symsinit.h, win32.c: Rename win32 init function and call it even earlier, to
initialize mswindows_9x_p even earlier, for use in startup code
(XEUNICODE_P).
process.c: Use _wenviron not environ under Windows, to get Unicode environment
variables.
event-Xt.c: Mule-ize drag-n-drop related stuff.
dragdrop.c, dragdrop.h, frame-x.c: Mule-ize.
text.h: Add some more stand-in defines for particular kinds of conversion;
use in Mule-ization work in frame-x.c etc.
---------------------------
Freshening
---------------------------
intl-auto-encap-win32.c, intl-auto-encap-win32.h: Regenerate.
---------------------------
Unicode-work
---------------------------
intl-win32.c, syswindows.h: Factor out common options to MultiByteToWideChar and
WideCharToMultiByte. Add convert_unicode_to_multibyte_malloc()
and convert_unicode_to_multibyte_dynarr() and use. Add stuff for
alloca() conversion of multibyte/unicode.
alloc.c: Use dfc_external_data_len() in case of unicode coding system.
alloc.c, mule-charset.c: Don't zero out and reinit charset Unicode tables. This fucks up
dump-time loading. Anyway, either we load them at dump time or
run time, never both.
unicode.c: Dump the blank tables as well.
---------------------------------------------------------------
DOCUMENTATION, MOSTLY MULE-RELATED:
---------------------------------------------------------------
EmacsFrame.c, emodules.c, event-Xt.c, fileio.c, input-method-xlib.c, mule-wnnfns.c, redisplay-gtk.c, redisplay-tty.c, redisplay-x.c, regex.c, sysdep.c: Add comment about Mule work needed.
text.h: Add more documentation describing why DFC routines were not written
to return their value. Add some other DFC documentation.
console-msw.c, console-msw.h: Add pointer to docs in win32.c.
emacs.c: Add comments on sources of doc info.
text.c, charset.h, unicode.c, intl-win32.c, intl-encap-win32.c, text.h, file-coding.c, mule-coding.c: Collect background comments and related to text matters and
internationalization, and proposals for work to be done, in text.c
or Internals manual, stuff related to specific textual API's in
text.h, and stuff related to internal implementation of Unicode
conversion in unicode.c. Put lots of pointers to the comments to
make them easier to find.
s/mingw32.h, s/win32-common.h, s/win32-native.h, s/windowsnt.h, win32.c: Add bunches of new documentation on the different kinds of
builds and environments under Windows and how they work.
Collect this info in win32.c. Add pointers to these docs in
the relevant s/* files.
emacs.c: Document places with long comments.
Remove comment about exiting, move to internals manual, put
in pointer.
event-stream.c: Move docs about event queues and focus to internals manual, put
in pointer.
events.h: Move docs about event stream callbacks to internals manual, put
in pointer.
profile.c, redisplay.c, signal.c: Move documentation to the Internals manual.
process-nt.c: Add pointer to comment in win32-native.el.
lisp.h: Add comments about some comment conventions.
lisp.h: Add comment about the second argument.
device-msw.c, redisplay-msw.c: @@#### comments are out-of-date.
---------------------------------------------------------------
PDUMP WORK (MOTIVATED BY UNICODE CHANGES)
---------------------------------------------------------------
alloc.c, buffer.c, bytecode.c, console-impl.h, console.c, device.c, dumper.c, lrecord.h, elhash.c, emodules.h, events.c, extents.c, frame.c, glyphs.c, glyphs.h, mule-charset.c, mule-coding.c, objects.c, profile.c, rangetab.c, redisplay.c, specifier.c, specifier.h, window.c, lstream.c, file-coding.h, file-coding.c: PDUMP:
Properly implement dump_add_root_block(), which never worked before,
and is necessary for dumping Unicode tables.
Pdump name changes for accuracy:
XD_STRUCT_PTR -> XD_BLOCK_PTR.
XD_STRUCT_ARRAY -> XD_BLOCK_ARRAY.
XD_C_STRING -> XD_ASCII_STRING.
*_structure_* -> *_block_*.
lrecord.h: some comments added about
dump_add_root_block() vs dump_add_root_block_ptr().
extents.c: remove incorrect comment about pdump problems with gap array.
---------------------------------------------------------------
ALLOCATION
---------------------------------------------------------------
abbrev.c, alloc.c, bytecode.c, casefiddle.c, device-msw.c, device-x.c, dired-msw.c, doc.c, doprnt.c, dragdrop.c, editfns.c, emodules.c, file-coding.c, fileio.c, filelock.c, fns.c, glyphs-eimage.c, glyphs-gtk.c, glyphs-msw.c, glyphs-x.c, gui-msw.c, gui-x.c, imgproc.c, intl-win32.c, lread.c, menubar-gtk.c, menubar.c, nt.c, objects-msw.c, objects-x.c, print.c, process-nt.c, process-unix.c, process.c, realpath.c, redisplay.c, search.c, select-common.c, symbols.c, sysdep.c, syswindows.h, text.c, text.h, ui-byhand.c: New macros {alloca,xnew}_{itext,{i,ext,raw,bin,asc}bytes} for
more convenient allocation of these commonly requested items.
Modify functions to use alloca_ibytes, alloca_array, alloca_extbytes,
xnew_ibytes, etc. also XREALLOC_ARRAY, xnew.
alloc.c: Rewrite the allocation functions to factor out repeated code.
Add assertions for freeing dumped data.
lisp.h: Moved down and consolidated with other allocation stuff.
lisp.h, dynarr.c: New functions for allocation that's very efficient when mostly in
LIFO order.
lisp.h, text.c, text.h: Factor out some stuff for general use by alloca()-conversion funs.
text.h, lisp.h: Fill out convenience routines for allocating various kinds of
bytes and put them in lisp.h. Use them in place of xmalloc(),
ALLOCA().
text.h: Fill out the convenience functions so the _MALLOC() kinds match
the alloca() kinds.
---------------------------------------------------------------
ERROR-CHECKING
---------------------------------------------------------------
text.h: Create ASSERT_ASCTEXT_ASCII() and ASSERT_ASCTEXT_ASCII_LEN()
from similar Eistring checkers and change the Eistring checkers to
use them instead.
---------------------------------------------------------------
MACROS IN LISP.H
---------------------------------------------------------------
lisp.h: Redo GCPRO declarations. Create a "base" set of functions that can
be used to generate any kind of gcpro sets -- regular, ngcpro,
nngcpro, private ones used in GC_EXTERNAL_LIST_LOOP_2.
buffer.c, callint.c, chartab.c, console-msw.c, device-x.c, dialog-msw.c, dired.c, extents.c, ui-gtk.c, rangetab.c, nt.c, mule-coding.c, minibuf.c, menubar-msw.c, menubar.c, menubar-gtk.c, lread.c, lisp.h, gutter.c, glyphs.c, glyphs-widget.c, fns.c, fileio.c, file-coding.c, specifier.c: Eliminate EXTERNAL_LIST_LOOP, which does not check for circularities.
Use EXTERNAL_LIST_LOOP_2 instead or EXTERNAL_LIST_LOOP_3
or EXTERNAL_PROPERTY_LIST_LOOP_3 or GC_EXTERNAL_LIST_LOOP_2
(new macro). Removed/redid comments on EXTERNAL_LIST_LOOP.
---------------------------------------------------------------
SPACING FIXES
---------------------------------------------------------------
callint.c, hftctl.c, number-gmp.c, process-unix.c: Spacing fixes.
---------------------------------------------------------------
FIX FOR GEOMETRY PROBLEM IN FIRST FRAME
---------------------------------------------------------------
unicode.c: Add workaround for newlib bug in sscanf() [should be fixed by
release 1.5.12 of Cygwin].
toolbar.c: bug fix for problem of initial frame being 77 chars wide on Windows.
will be overridden by my other ws.
---------------------------------------------------------------
FIX FOR LEAKING PROCESS HANDLES:
---------------------------------------------------------------
process-nt.c: Fixes for leaking handles. Inspired by work done by Adrian Aichner
<adrian@xemacs.org>.
---------------------------------------------------------------
FIX FOR CYGWIN BUG (Unicode-related):
---------------------------------------------------------------
unicode.c: Add workaround for newlib bug in sscanf() [should be fixed by
release 1.5.12 of Cygwin].
---------------------------------------------------------------
WARNING FIXES:
---------------------------------------------------------------
console-stream.c: `reinit' is unused.
compiler.h, event-msw.c, frame-msw.c, intl-encap-win32.c, text.h: Add stuff to deal with ANSI-aliasing warnings I got.
regex.c: Gather includes together to avoid warning.
---------------------------------------------------------------
CHANGES TO INITIALIZATION ROUTINES:
---------------------------------------------------------------
buffer.c, emacs.c, console.c, debug.c, device-x.c, device.c, dragdrop.c, emodules.c, eval.c, event-Xt.c, event-gtk.c, event-msw.c, event-stream.c, event-tty.c, events.c, extents.c, faces.c, file-coding.c, fileio.c, font-lock.c, frame-msw.c, glyphs-widget.c, glyphs.c, gui-x.c, insdel.c, lread.c, lstream.c, menubar-gtk.c, menubar-x.c, minibuf.c, mule-wnnfns.c, objects-msw.c, objects.c, print.c, scrollbar-x.c, search.c, select-x.c, text.c, undo.c, unicode.c, window.c, symsinit.h: Call reinit_*() functions directly from emacs.c, for clarity.
Factor out some redundant init code. Move disallowed stuff
that had crept into vars_of_glyphs() into complex_vars_of_glyphs().
Call init_eval_semi_early() from eval.c not in the middle of
vars_of_() in emacs.c since there should be no order dependency
in the latter calls.
---------------------------------------------------------------
ARMAGEDDON:
---------------------------------------------------------------
alloc.c, emacs.c, lisp.h, print.c: Rename inhibit_non_essential_printing_operations to
inhibit_non_essential_conversion_operations.
text.c: Assert on !inhibit_non_essential_conversion_operations.
console-msw.c, print.c: Don't do conversion in SetConsoleTitle or FindWindow to avoid
problems during armageddon. Put #errors for NON_ASCII_INTERNAL_FORMAT
in places where problems would arise.
---------------------------------------------------------------
CHANGES TO THE BUILD PROCEDURE:
---------------------------------------------------------------
config.h.in, s/cxux.h, s/usg5-4-2.h, m/powerpc.h: Add comment about correct ordering of this file.
Rearrange everything to follow this -- put all #undefs together
and before the s&m files. Add undefs for HAVE_ALLOCA, C_ALLOCA,
BROKEN_ALLOCA_IN_FUNCTION_CALLS, STACK_DIRECTION. Remove unused
HAVE_STPCPY, HAVE_GETWD, HAVE_SETLOCALE.
m/gec63.h: Deleted; totally broken, not used at all, not in FSF.
m/7300.h, m/acorn.h, m/alliant-2800.h, m/alliant.h, m/altos.h, m/amdahl.h, m/apollo.h, m/att3b.h, m/aviion.h, m/celerity.h, m/clipper.h, m/cnvrgnt.h, m/convex.h, m/cydra5.h, m/delta.h, m/delta88k.h, m/dpx2.h, m/elxsi.h, m/ews4800r.h, m/gould.h, m/hp300bsd.h, m/hp800.h, m/hp9000s300.h, m/i860.h, m/ibmps2-aix.h, m/ibmrs6000.h, m/ibmrt-aix.h, m/ibmrt.h, m/intel386.h, m/iris4d.h, m/iris5d.h, m/iris6d.h, m/irist.h, m/isi-ov.h, m/luna88k.h, m/m68k.h, m/masscomp.h, m/mg1.h, m/mips-nec.h, m/mips-siemens.h, m/mips.h, m/news.h, m/nh3000.h, m/nh4000.h, m/ns32000.h, m/orion105.h, m/pfa50.h, m/plexus.h, m/pmax.h, m/powerpc.h, m/pyrmips.h, m/sequent-ptx.h, m/sequent.h, m/sgi-challenge.h, m/symmetry.h, m/tad68k.h, m/tahoe.h, m/targon31.h, m/tekxd88.h, m/template.h, m/tower32.h, m/tower32v3.h, m/ustation.h, m/vax.h, m/wicat.h, m/xps100.h: Delete C_ALLOCA, HAVE_ALLOCA, STACK_DIRECTION,
BROKEN_ALLOCA_IN_FUNCTION_CALLS. All of this is auto-detected.
When in doubt, I followed recent FSF sources, which also have
these things deleted.
author | ben |
---|---|
date | Thu, 04 Nov 2004 23:08:28 +0000 |
parents | 04bc9d2f42c7 |
children | 3d8143fc88e1 |
comparison
equal
deleted
inserted
replaced
2366:2a392e0c390a | 2367:ecf1ebac70d8 |
---|---|
1 /* Storage allocation and gc for XEmacs Lisp interpreter. | 1 /* Storage allocation and gc for XEmacs Lisp interpreter. |
2 Copyright (C) 1985-1998 Free Software Foundation, Inc. | 2 Copyright (C) 1985-1998 Free Software Foundation, Inc. |
3 Copyright (C) 1995 Sun Microsystems, Inc. | 3 Copyright (C) 1995 Sun Microsystems, Inc. |
4 Copyright (C) 1995, 1996, 2001, 2002, 2003 Ben Wing. | 4 Copyright (C) 1995, 1996, 2001, 2002, 2003, 2004 Ben Wing. |
5 | 5 |
6 This file is part of XEmacs. | 6 This file is part of XEmacs. |
7 | 7 |
8 XEmacs is free software; you can redistribute it and/or modify it | 8 XEmacs is free software; you can redistribute it and/or modify it |
9 under the terms of the GNU General Public License as published by the | 9 under the terms of the GNU General Public License as published by the |
194 Lisp_Object Vpost_gc_hook, Qpost_gc_hook; | 194 Lisp_Object Vpost_gc_hook, Qpost_gc_hook; |
195 | 195 |
196 /* "Garbage collecting" */ | 196 /* "Garbage collecting" */ |
197 Lisp_Object Vgc_message; | 197 Lisp_Object Vgc_message; |
198 Lisp_Object Vgc_pointer_glyph; | 198 Lisp_Object Vgc_pointer_glyph; |
199 static const Char_ASCII gc_default_message[] = "Garbage collecting"; | 199 static const Ascbyte gc_default_message[] = "Garbage collecting"; |
200 Lisp_Object Qgarbage_collecting; | 200 Lisp_Object Qgarbage_collecting; |
201 | 201 |
202 static Lisp_Object QSin_garbage_collection; | 202 static Lisp_Object QSin_garbage_collection; |
203 | 203 |
204 /* Non-zero means we're in the process of doing the dump */ | 204 /* Non-zero means we're in the process of doing the dump */ |
309 #endif | 309 #endif |
310 if ((char *) val < (char *) minimum_address_seen) | 310 if ((char *) val < (char *) minimum_address_seen) |
311 minimum_address_seen = (char *) val; | 311 minimum_address_seen = (char *) val; |
312 } | 312 } |
313 | 313 |
314 /* like malloc and realloc but check for no memory left. */ | |
315 | |
316 #ifdef ERROR_CHECK_MALLOC | 314 #ifdef ERROR_CHECK_MALLOC |
317 static int in_malloc; | 315 static int in_malloc; |
318 extern int regex_malloc_disallowed; | 316 extern int regex_malloc_disallowed; |
319 #endif | 317 |
318 #define MALLOC_BEGIN() \ | |
319 do \ | |
320 { \ | |
321 assert (!in_malloc); \ | |
322 assert (!regex_malloc_disallowed); \ | |
323 in_malloc = 1; \ | |
324 } \ | |
325 while (0) | |
326 | |
327 #define FREE_OR_REALLOC_BEGIN(block) \ | |
328 do \ | |
329 { \ | |
330 /* Unbelievably, calling free() on 0xDEADBEEF doesn't cause an \ | |
331 error until much later on for many system mallocs, such as \ | |
332 the one that comes with Solaris 2.3. FMH!! */ \ | |
333 assert (block != (void *) 0xDEADBEEF); \ | |
334 /* You cannot free something within dumped space, because there is \ | |
335 no longer any sort of malloc structure associated with the block. \ | |
336 If you are tripping this, you may need to conditionalize on \ | |
337 DUMPEDP. */ \ | |
338 assert (!DUMPEDP (block)); \ | |
339 MALLOC_BEGIN (); \ | |
340 } \ | |
341 while (0) | |
342 | |
343 #define MALLOC_END() \ | |
344 do \ | |
345 { \ | |
346 in_malloc = 0; \ | |
347 } \ | |
348 while (0) | |
349 | |
350 #else /* ERROR_CHECK_MALLOC */ | |
351 | |
352 #define MALLOC_BEGIN(block) | |
353 #define FREE_OR_REALLOC_BEGIN(block) | |
354 #define MALLOC_END() | |
355 | |
356 #endif /* ERROR_CHECK_MALLOC */ | |
357 | |
358 static void | |
359 malloc_after (void *val, Bytecount size) | |
360 { | |
361 if (!val && size != 0) | |
362 memory_full (); | |
363 set_alloc_mins_and_maxes (val, size); | |
364 } | |
365 | |
366 /* like malloc, calloc, realloc, free but: | |
367 | |
368 -- check for no memory left | |
369 -- set internal mins and maxes | |
370 -- with error-checking on, check for reentrancy, invalid freeing, etc. | |
371 */ | |
320 | 372 |
321 #undef xmalloc | 373 #undef xmalloc |
322 void * | 374 void * |
323 xmalloc (Bytecount size) | 375 xmalloc (Bytecount size) |
324 { | 376 { |
325 void *val; | 377 void *val; |
326 #ifdef ERROR_CHECK_MALLOC | 378 MALLOC_BEGIN (); |
327 assert (!in_malloc); | |
328 assert (!regex_malloc_disallowed); | |
329 in_malloc = 1; | |
330 #endif | |
331 val = malloc (size); | 379 val = malloc (size); |
332 #ifdef ERROR_CHECK_MALLOC | 380 MALLOC_END (); |
333 in_malloc = 0; | 381 malloc_after (val, size); |
334 #endif | |
335 if (!val && (size != 0)) memory_full (); | |
336 set_alloc_mins_and_maxes (val, size); | |
337 return val; | 382 return val; |
338 } | 383 } |
339 | 384 |
340 #undef xcalloc | 385 #undef xcalloc |
341 static void * | 386 static void * |
342 xcalloc (Elemcount nelem, Bytecount elsize) | 387 xcalloc (Elemcount nelem, Bytecount elsize) |
343 { | 388 { |
344 void *val; | 389 void *val; |
345 #ifdef ERROR_CHECK_MALLOC | 390 MALLOC_BEGIN (); |
346 assert (!in_malloc); | |
347 assert (!regex_malloc_disallowed); | |
348 in_malloc = 1; | |
349 #endif | |
350 val= calloc (nelem, elsize); | 391 val= calloc (nelem, elsize); |
351 #ifdef ERROR_CHECK_MALLOC | 392 MALLOC_END (); |
352 in_malloc = 0; | 393 malloc_after (val, nelem * elsize); |
353 #endif | |
354 | |
355 if (!val && (nelem != 0)) memory_full (); | |
356 set_alloc_mins_and_maxes (val, nelem * elsize); | |
357 return val; | 394 return val; |
358 } | 395 } |
359 | 396 |
360 void * | 397 void * |
361 xmalloc_and_zero (Bytecount size) | 398 xmalloc_and_zero (Bytecount size) |
365 | 402 |
366 #undef xrealloc | 403 #undef xrealloc |
367 void * | 404 void * |
368 xrealloc (void *block, Bytecount size) | 405 xrealloc (void *block, Bytecount size) |
369 { | 406 { |
370 #ifdef ERROR_CHECK_MALLOC | 407 FREE_OR_REALLOC_BEGIN (block); |
371 assert (!in_malloc); | |
372 assert (!regex_malloc_disallowed); | |
373 in_malloc = 1; | |
374 #endif | |
375 block = realloc (block, size); | 408 block = realloc (block, size); |
376 #ifdef ERROR_CHECK_MALLOC | 409 MALLOC_END (); |
377 in_malloc = 0; | 410 malloc_after (block, size); |
378 #endif | |
379 | |
380 if (!block && (size != 0)) memory_full (); | |
381 set_alloc_mins_and_maxes (block, size); | |
382 return block; | 411 return block; |
383 } | 412 } |
384 | 413 |
385 void | 414 void |
386 xfree_1 (void *block) | 415 xfree_1 (void *block) |
387 { | 416 { |
388 #ifdef ERROR_CHECK_MALLOC | 417 #ifdef ERROR_CHECK_MALLOC |
389 /* Unbelievably, calling free() on 0xDEADBEEF doesn't cause an | |
390 error until much later on for many system mallocs, such as | |
391 the one that comes with Solaris 2.3. FMH!! */ | |
392 assert (block != (void *) 0xDEADBEEF); | |
393 assert (block); | 418 assert (block); |
394 assert (!in_malloc); | |
395 assert (!regex_malloc_disallowed); | |
396 in_malloc = 1; | |
397 #endif /* ERROR_CHECK_MALLOC */ | 419 #endif /* ERROR_CHECK_MALLOC */ |
420 FREE_OR_REALLOC_BEGIN (block); | |
398 free (block); | 421 free (block); |
399 #ifdef ERROR_CHECK_MALLOC | 422 MALLOC_END (); |
400 in_malloc = 0; | |
401 #endif | |
402 } | 423 } |
403 | 424 |
404 #ifdef ERROR_CHECK_GC | 425 #ifdef ERROR_CHECK_GC |
405 | 426 |
406 static void | 427 static void |
951 /* TYPE and STRUCTTYPE are the same as in ALLOCATE_FIXED_TYPE(). */ | 972 /* TYPE and STRUCTTYPE are the same as in ALLOCATE_FIXED_TYPE(). */ |
952 | 973 |
953 #define FREE_FIXED_TYPE(type, structtype, ptr) do { \ | 974 #define FREE_FIXED_TYPE(type, structtype, ptr) do { \ |
954 structtype *FFT_ptr = (ptr); \ | 975 structtype *FFT_ptr = (ptr); \ |
955 gc_checking_assert (!LRECORD_FREE_P (FFT_ptr)); \ | 976 gc_checking_assert (!LRECORD_FREE_P (FFT_ptr)); \ |
977 gc_checking_assert (!DUMPEDP (FFT_ptr)); \ | |
956 ADDITIONAL_FREE_##type (FFT_ptr); \ | 978 ADDITIONAL_FREE_##type (FFT_ptr); \ |
957 deadbeef_memory (FFT_ptr, sizeof (structtype)); \ | 979 deadbeef_memory (FFT_ptr, sizeof (structtype)); \ |
958 PUT_FIXED_TYPE_ON_FREE_LIST (type, structtype, FFT_ptr); \ | 980 PUT_FIXED_TYPE_ON_FREE_LIST (type, structtype, FFT_ptr); \ |
959 MARK_LRECORD_AS_FREE (FFT_ptr); \ | 981 MARK_LRECORD_AS_FREE (FFT_ptr); \ |
960 } while (0) | 982 } while (0) |
2496 DEFUN ("string", Fstring, 0, MANY, 0, /* | 2518 DEFUN ("string", Fstring, 0, MANY, 0, /* |
2497 Concatenate all the argument characters and make the result a string. | 2519 Concatenate all the argument characters and make the result a string. |
2498 */ | 2520 */ |
2499 (int nargs, Lisp_Object *args)) | 2521 (int nargs, Lisp_Object *args)) |
2500 { | 2522 { |
2501 Ibyte *storage = alloca_array (Ibyte, nargs * MAX_ICHAR_LEN); | 2523 Ibyte *storage = alloca_ibytes (nargs * MAX_ICHAR_LEN); |
2502 Ibyte *p = storage; | 2524 Ibyte *p = storage; |
2503 | 2525 |
2504 for (; nargs; nargs--, args++) | 2526 for (; nargs; nargs--, args++) |
2505 { | 2527 { |
2506 Lisp_Object lisp_char = *args; | 2528 Lisp_Object lisp_char = *args; |
2581 | 2603 |
2582 Lisp_Object | 2604 Lisp_Object |
2583 build_ext_string (const Extbyte *str, Lisp_Object coding_system) | 2605 build_ext_string (const Extbyte *str, Lisp_Object coding_system) |
2584 { | 2606 { |
2585 /* Some strlen's crash and burn if passed null. */ | 2607 /* Some strlen's crash and burn if passed null. */ |
2586 return make_ext_string ((const Extbyte *) str, (str ? strlen(str) : 0), | 2608 return make_ext_string ((const Extbyte *) str, |
2609 (str ? dfc_external_data_len (str, coding_system) : | |
2610 0), | |
2587 coding_system); | 2611 coding_system); |
2588 } | 2612 } |
2589 | 2613 |
2590 Lisp_Object | 2614 Lisp_Object |
2591 build_msg_intstring (const Ibyte *str) | 2615 build_msg_intstring (const Ibyte *str) |
2790 /* Make sure the size is correct. This will catch, for example, | 2814 /* Make sure the size is correct. This will catch, for example, |
2791 putting a window configuration on the wrong free list. */ | 2815 putting a window configuration on the wrong free list. */ |
2792 gc_checking_assert (detagged_lisp_object_size (lheader) == list->size); | 2816 gc_checking_assert (detagged_lisp_object_size (lheader) == list->size); |
2793 /* Make sure the object isn't already freed. */ | 2817 /* Make sure the object isn't already freed. */ |
2794 gc_checking_assert (!free_header->lcheader.free); | 2818 gc_checking_assert (!free_header->lcheader.free); |
2819 /* Freeing stuff in dumped memory is bad. If you trip this, you | |
2820 may need to check for this before freeing. */ | |
2821 gc_checking_assert (!OBJECT_DUMPED_P (lcrecord)); | |
2795 | 2822 |
2796 if (implementation->finalizer) | 2823 if (implementation->finalizer) |
2797 implementation->finalizer (lheader, 0); | 2824 implementation->finalizer (lheader, 0); |
2798 /* Yes, there are two ways to indicate freeness -- the type is | 2825 /* Yes, there are two ways to indicate freeness -- the type is |
2799 lrecord_type_free or the ->free flag is set. We used to do only the | 2826 lrecord_type_free or the ->free flag is set. We used to do only the |
2889 }; | 2916 }; |
2890 | 2917 |
2891 #ifdef DEBUG_XEMACS | 2918 #ifdef DEBUG_XEMACS |
2892 | 2919 |
2893 static const struct memory_description staticpro_one_name_description_1[] = { | 2920 static const struct memory_description staticpro_one_name_description_1[] = { |
2894 { XD_C_STRING, 0 }, | 2921 { XD_ASCII_STRING, 0 }, |
2895 { XD_END } | 2922 { XD_END } |
2896 }; | 2923 }; |
2897 | 2924 |
2898 static const struct sized_memory_description staticpro_one_name_description = { | 2925 static const struct sized_memory_description staticpro_one_name_description = { |
2899 sizeof (char *), | 2926 sizeof (char *), |
3112 case XD_LISP_OBJECT: | 3139 case XD_LISP_OBJECT: |
3113 case XD_LO_LINK: | 3140 case XD_LO_LINK: |
3114 return sizeof (Lisp_Object); | 3141 return sizeof (Lisp_Object); |
3115 case XD_OPAQUE_PTR: | 3142 case XD_OPAQUE_PTR: |
3116 return sizeof (void *); | 3143 return sizeof (void *); |
3117 case XD_STRUCT_PTR: | 3144 case XD_BLOCK_PTR: |
3118 { | 3145 { |
3119 EMACS_INT val = lispdesc_indirect_count (desc1->data1, desc, obj); | 3146 EMACS_INT val = lispdesc_indirect_count (desc1->data1, desc, obj); |
3120 return val * sizeof (void *); | 3147 return val * sizeof (void *); |
3121 } | 3148 } |
3122 case XD_STRUCT_ARRAY: | 3149 case XD_BLOCK_ARRAY: |
3123 { | 3150 { |
3124 EMACS_INT val = lispdesc_indirect_count (desc1->data1, desc, obj); | 3151 EMACS_INT val = lispdesc_indirect_count (desc1->data1, desc, obj); |
3125 | 3152 |
3126 return (val * | 3153 return (val * |
3127 lispdesc_structure_size | 3154 lispdesc_block_size |
3128 (rdata, lispdesc_indirect_description (obj, desc1->data2))); | 3155 (rdata, lispdesc_indirect_description (obj, desc1->data2))); |
3129 } | 3156 } |
3130 case XD_OPAQUE_DATA_PTR: | 3157 case XD_OPAQUE_DATA_PTR: |
3131 return sizeof (void *); | 3158 return sizeof (void *); |
3132 case XD_UNION_DYNAMIC_SIZE: | 3159 case XD_UNION_DYNAMIC_SIZE: |
3171 max_size = size; | 3198 max_size = size; |
3172 } | 3199 } |
3173 return max_size; | 3200 return max_size; |
3174 } | 3201 } |
3175 } | 3202 } |
3176 case XD_C_STRING: | 3203 case XD_ASCII_STRING: |
3177 return sizeof (void *); | 3204 return sizeof (void *); |
3178 case XD_DOC_STRING: | 3205 case XD_DOC_STRING: |
3179 return sizeof (void *); | 3206 return sizeof (void *); |
3180 case XD_INT_RESET: | 3207 case XD_INT_RESET: |
3181 return sizeof (int); | 3208 return sizeof (int); |
3215 trigger a protection fault when reading from invalid memory. We | 3242 trigger a protection fault when reading from invalid memory. We |
3216 need to handle this -- perhaps in a stupid but dependable way, | 3243 need to handle this -- perhaps in a stupid but dependable way, |
3217 i.e. by trapping SIGSEGV and SIGBUS.) */ | 3244 i.e. by trapping SIGSEGV and SIGBUS.) */ |
3218 | 3245 |
3219 Bytecount | 3246 Bytecount |
3220 lispdesc_structure_size (const void *obj, | 3247 lispdesc_block_size_1 (const void *obj, Bytecount size, |
3221 const struct sized_memory_description *sdesc) | 3248 const struct memory_description *desc) |
3222 { | 3249 { |
3223 EMACS_INT max_offset = -1; | 3250 EMACS_INT max_offset = -1; |
3224 int max_offset_pos = -1; | 3251 int max_offset_pos = -1; |
3225 int pos; | 3252 int pos; |
3226 const struct memory_description *desc; | 3253 |
3227 | 3254 if (size) |
3228 if (sdesc->size) | 3255 return size; |
3229 return sdesc->size; | |
3230 | |
3231 desc = sdesc->description; | |
3232 | 3256 |
3233 for (pos = 0; desc[pos].type != XD_END; pos++) | 3257 for (pos = 0; desc[pos].type != XD_END; pos++) |
3234 { | 3258 { |
3235 EMACS_INT offset = lispdesc_indirect_count (desc[pos].offset, desc, obj); | 3259 EMACS_INT offset = lispdesc_indirect_count (desc[pos].offset, desc, obj); |
3236 if (offset == max_offset) | 3260 if (offset == max_offset) |
3403 const struct sized_memory_description *sdesc, | 3427 const struct sized_memory_description *sdesc, |
3404 int count) | 3428 int count) |
3405 { | 3429 { |
3406 int i; | 3430 int i; |
3407 Bytecount elsize; | 3431 Bytecount elsize; |
3408 elsize = lispdesc_structure_size (data, sdesc); | 3432 elsize = lispdesc_block_size (data, sdesc); |
3409 | 3433 |
3410 for (i = 0; i < count; i++) | 3434 for (i = 0; i < count; i++) |
3411 { | 3435 { |
3412 kkcc_gc_stack_push (((char *) data) + elsize * i, sdesc->description); | 3436 kkcc_gc_stack_push (((char *) data) + elsize * i, sdesc->description); |
3413 } | 3437 } |
3452 case XD_LONG: | 3476 case XD_LONG: |
3453 case XD_INT_RESET: | 3477 case XD_INT_RESET: |
3454 case XD_LO_LINK: | 3478 case XD_LO_LINK: |
3455 case XD_OPAQUE_PTR: | 3479 case XD_OPAQUE_PTR: |
3456 case XD_OPAQUE_DATA_PTR: | 3480 case XD_OPAQUE_DATA_PTR: |
3457 case XD_C_STRING: | 3481 case XD_ASCII_STRING: |
3458 case XD_DOC_STRING: | 3482 case XD_DOC_STRING: |
3459 break; | 3483 break; |
3460 case XD_LISP_OBJECT: | 3484 case XD_LISP_OBJECT: |
3461 { | 3485 { |
3462 const Lisp_Object *stored_obj = (const Lisp_Object *) rdata; | 3486 const Lisp_Object *stored_obj = (const Lisp_Object *) rdata; |
3489 mark_object_maybe_checking_free | 3513 mark_object_maybe_checking_free |
3490 (*stored_obj, (desc1->flags) & XD_FLAG_FREE_LISP_OBJECT); | 3514 (*stored_obj, (desc1->flags) & XD_FLAG_FREE_LISP_OBJECT); |
3491 } | 3515 } |
3492 break; | 3516 break; |
3493 } | 3517 } |
3494 case XD_STRUCT_PTR: | 3518 case XD_BLOCK_PTR: |
3495 { | 3519 { |
3496 EMACS_INT count = lispdesc_indirect_count (desc1->data1, desc, | 3520 EMACS_INT count = lispdesc_indirect_count (desc1->data1, desc, |
3497 data); | 3521 data); |
3498 const struct sized_memory_description *sdesc = | 3522 const struct sized_memory_description *sdesc = |
3499 lispdesc_indirect_description (data, desc1->data2); | 3523 lispdesc_indirect_description (data, desc1->data2); |
3500 const char *dobj = * (const char **) rdata; | 3524 const char *dobj = * (const char **) rdata; |
3501 if (dobj) | 3525 if (dobj) |
3502 mark_struct_contents (dobj, sdesc, count); | 3526 mark_struct_contents (dobj, sdesc, count); |
3503 break; | 3527 break; |
3504 } | 3528 } |
3505 case XD_STRUCT_ARRAY: | 3529 case XD_BLOCK_ARRAY: |
3506 { | 3530 { |
3507 EMACS_INT count = lispdesc_indirect_count (desc1->data1, desc, | 3531 EMACS_INT count = lispdesc_indirect_count (desc1->data1, desc, |
3508 data); | 3532 data); |
3509 const struct sized_memory_description *sdesc = | 3533 const struct sized_memory_description *sdesc = |
3510 lispdesc_indirect_description (data, desc1->data2); | 3534 lispdesc_indirect_description (data, desc1->data2); |
4667 } | 4691 } |
4668 | 4692 |
4669 /***** Now we actually start the garbage collection. */ | 4693 /***** Now we actually start the garbage collection. */ |
4670 | 4694 |
4671 gc_in_progress = 1; | 4695 gc_in_progress = 1; |
4672 inhibit_non_essential_printing_operations = 1; | 4696 inhibit_non_essential_conversion_operations = 1; |
4673 | 4697 |
4674 gc_generation_number[0]++; | 4698 gc_generation_number[0]++; |
4675 | 4699 |
4676 #if MAX_SAVE_STACK > 0 | 4700 #if MAX_SAVE_STACK > 0 |
4677 | 4701 |
4831 if (gc_cons_threshold < 10000) | 4855 if (gc_cons_threshold < 10000) |
4832 gc_cons_threshold = 10000; | 4856 gc_cons_threshold = 10000; |
4833 #endif | 4857 #endif |
4834 recompute_need_to_garbage_collect (); | 4858 recompute_need_to_garbage_collect (); |
4835 | 4859 |
4836 inhibit_non_essential_printing_operations = 0; | 4860 inhibit_non_essential_conversion_operations = 0; |
4837 gc_in_progress = 0; | 4861 gc_in_progress = 0; |
4838 | 4862 |
4839 run_post_gc_actions (); | 4863 run_post_gc_actions (); |
4840 | 4864 |
4841 /******* End of garbage collection ********/ | 4865 /******* End of garbage collection ********/ |
4885 } | 4909 } |
4886 | 4910 |
4887 /* Debugging aids. */ | 4911 /* Debugging aids. */ |
4888 | 4912 |
4889 static Lisp_Object | 4913 static Lisp_Object |
4890 gc_plist_hack (const Char_ASCII *name, int value, Lisp_Object tail) | 4914 gc_plist_hack (const Ascbyte *name, int value, Lisp_Object tail) |
4891 { | 4915 { |
4892 /* C doesn't have local functions (or closures, or GC, or readable syntax, | 4916 /* C doesn't have local functions (or closures, or GC, or readable syntax, |
4893 or portable numeric datatypes, or bit-vectors, or characters, or | 4917 or portable numeric datatypes, or bit-vectors, or characters, or |
4894 arrays, or exceptions, or ...) */ | 4918 arrays, or exceptions, or ...) */ |
4895 return cons3 (intern (name), make_int (value), tail); | 4919 return cons3 (intern (name), make_int (value), tail); |
5392 INIT_LRECORD_IMPLEMENTATION (lcrecord_list); | 5416 INIT_LRECORD_IMPLEMENTATION (lcrecord_list); |
5393 INIT_LRECORD_IMPLEMENTATION (free); | 5417 INIT_LRECORD_IMPLEMENTATION (free); |
5394 | 5418 |
5395 staticpros = Dynarr_new2 (Lisp_Object_ptr_dynarr, Lisp_Object *); | 5419 staticpros = Dynarr_new2 (Lisp_Object_ptr_dynarr, Lisp_Object *); |
5396 Dynarr_resize (staticpros, 1410); /* merely a small optimization */ | 5420 Dynarr_resize (staticpros, 1410); /* merely a small optimization */ |
5397 dump_add_root_struct_ptr (&staticpros, &staticpros_description); | 5421 dump_add_root_block_ptr (&staticpros, &staticpros_description); |
5398 #ifdef DEBUG_XEMACS | 5422 #ifdef DEBUG_XEMACS |
5399 staticpro_names = Dynarr_new2 (char_ptr_dynarr, char *); | 5423 staticpro_names = Dynarr_new2 (char_ptr_dynarr, char *); |
5400 Dynarr_resize (staticpro_names, 1410); /* merely a small optimization */ | 5424 Dynarr_resize (staticpro_names, 1410); /* merely a small optimization */ |
5401 dump_add_root_struct_ptr (&staticpro_names, &staticpro_names_description); | 5425 dump_add_root_block_ptr (&staticpro_names, &staticpro_names_description); |
5402 #endif | 5426 #endif |
5403 | 5427 |
5404 init_lcrecord_lists (); | 5428 init_lcrecord_lists (); |
5405 } | 5429 } |
5406 | 5430 |