comparison src/alloc.c @ 665:fdefd0186b75

[xemacs-hg @ 2001-09-20 06:28:42 by ben] The great integral types renaming. The purpose of this is to rationalize the names used for various integral types, so that they match their intended uses and follow consist conventions, and eliminate types that were not semantically different from each other. The conventions are: -- All integral types that measure quantities of anything are signed. Some people disagree vociferously with this, but their arguments are mostly theoretical, and are vastly outweighed by the practical headaches of mixing signed and unsigned values, and more importantly by the far increased likelihood of inadvertent bugs: Because of the broken "viral" nature of unsigned quantities in C (operations involving mixed signed/unsigned are done unsigned, when exactly the opposite is nearly always wanted), even a single error in declaring a quantity unsigned that should be signed, or even the even more subtle error of comparing signed and unsigned values and forgetting the necessary cast, can be catastrophic, as comparisons will yield wrong results. -Wsign-compare is turned on specifically to catch this, but this tends to result in a great number of warnings when mixing signed and unsigned, and the casts are annoying. More has been written on this elsewhere. -- All such quantity types just mentioned boil down to EMACS_INT, which is 32 bits on 32-bit machines and 64 bits on 64-bit machines. This is guaranteed to be the same size as Lisp objects of type `int', and (as far as I can tell) of size_t (unsigned!) and ssize_t. The only type below that is not an EMACS_INT is Hashcode, which is an unsigned value of the same size as EMACS_INT. -- Type names should be relatively short (no more than 10 characters or so), with the first letter capitalized and no underscores if they can at all be avoided. -- "count" == a zero-based measurement of some quantity. Includes sizes, offsets, and indexes. -- "bpos" == a one-based measurement of a position in a buffer. "Charbpos" and "Bytebpos" count text in the buffer, rather than bytes in memory; thus Bytebpos does not directly correspond to the memory representation. Use "Membpos" for this. -- "Char" refers to internal-format characters, not to the C type "char", which is really a byte. -- For the actual name changes, see the script below. I ran the following script to do the conversion. (NOTE: This script is idempotent. You can safely run it multiple times and it will not screw up previous results -- in fact, it will do nothing if nothing has changed. Thus, it can be run repeatedly as necessary to handle patches coming in from old workspaces, or old branches.) There are two tags, just before and just after the change: `pre-integral-type-rename' and `post-integral-type-rename'. When merging code from the main trunk into a branch, the best thing to do is first merge up to `pre-integral-type-rename', then apply the script and associated changes, then merge from `post-integral-type-change' to the present. (Alternatively, just do the merging in one operation; but you may then have a lot of conflicts needing to be resolved by hand.) Script `fixtypes.sh' follows: ----------------------------------- cut ------------------------------------ files="*.[ch] s/*.h m/*.h config.h.in ../configure.in Makefile.in.in ../lib-src/*.[ch] ../lwlib/*.[ch]" gr Memory_Count Bytecount $files gr Lstream_Data_Count Bytecount $files gr Element_Count Elemcount $files gr Hash_Code Hashcode $files gr extcount bytecount $files gr bufpos charbpos $files gr bytind bytebpos $files gr memind membpos $files gr bufbyte intbyte $files gr Extcount Bytecount $files gr Bufpos Charbpos $files gr Bytind Bytebpos $files gr Memind Membpos $files gr Bufbyte Intbyte $files gr EXTCOUNT BYTECOUNT $files gr BUFPOS CHARBPOS $files gr BYTIND BYTEBPOS $files gr MEMIND MEMBPOS $files gr BUFBYTE INTBYTE $files gr MEMORY_COUNT BYTECOUNT $files gr LSTREAM_DATA_COUNT BYTECOUNT $files gr ELEMENT_COUNT ELEMCOUNT $files gr HASH_CODE HASHCODE $files ----------------------------------- cut ------------------------------------ `fixtypes.sh' is a Bourne-shell script; it uses 'gr': ----------------------------------- cut ------------------------------------ #!/bin/sh # Usage is like this: # gr FROM TO FILES ... # globally replace FROM with TO in FILES. FROM and TO are regular expressions. # backup files are stored in the `backup' directory. from="$1" to="$2" shift 2 echo ${1+"$@"} | xargs global-replace "s/$from/$to/g" ----------------------------------- cut ------------------------------------ `gr' in turn uses a Perl script to do its real work, `global-replace', which follows: ----------------------------------- cut ------------------------------------ : #-*- Perl -*- ### global-modify --- modify the contents of a file by a Perl expression ## Copyright (C) 1999 Martin Buchholz. ## Copyright (C) 2001 Ben Wing. ## Authors: Martin Buchholz <martin@xemacs.org>, Ben Wing <ben@xemacs.org> ## Maintainer: Ben Wing <ben@xemacs.org> ## Current Version: 1.0, May 5, 2001 # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with XEmacs; see the file COPYING. If not, write to the Free # Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA # 02111-1307, USA. eval 'exec perl -w -S $0 ${1+"$@"}' if 0; use strict; use FileHandle; use Carp; use Getopt::Long; use File::Basename; (my $myName = $0) =~ s@.*/@@; my $usage=" Usage: $myName [--help] [--backup-dir=DIR] [--line-mode] [--hunk-mode] PERLEXPR FILE ... Globally modify a file, either line by line or in one big hunk. Typical usage is like this: [with GNU print, GNU xargs: guaranteed to handle spaces, quotes, etc. in file names] find . -name '*.[ch]' -print0 | xargs -0 $0 's/\bCONST\b/const/g'\n [with non-GNU print, xargs] find . -name '*.[ch]' -print | xargs $0 's/\bCONST\b/const/g'\n The file is read in, either line by line (with --line-mode specified) or in one big hunk (with --hunk-mode specified; it's the default), and the Perl expression is then evalled with \$_ set to the line or hunk of text, including the terminating newline if there is one. It should destructively modify the value there, storing the changed result in \$_. Files in which any modifications are made are backed up to the directory specified using --backup-dir, or to `backup' by default. To disable this, use --backup-dir= with no argument. Hunk mode is the default because it is MUCH MUCH faster than line-by-line. Use line-by-line only when it matters, e.g. you want to do a replacement only once per line (the default without the `g' argument). Conversely, when using hunk mode, *ALWAYS* use `g'; otherwise, you will only make one replacement in the entire file! "; my %options = (); $Getopt::Long::ignorecase = 0; &GetOptions ( \%options, 'help', 'backup-dir=s', 'line-mode', 'hunk-mode', ); die $usage if $options{"help"} or @ARGV <= 1; my $code = shift; die $usage if grep (-d || ! -w, @ARGV); sub SafeOpen { open ((my $fh = new FileHandle), $_[0]); confess "Can't open $_[0]: $!" if ! defined $fh; return $fh; } sub SafeClose { close $_[0] or confess "Can't close $_[0]: $!"; } sub FileContents { my $fh = SafeOpen ("< $_[0]"); my $olddollarslash = $/; local $/ = undef; my $contents = <$fh>; $/ = $olddollarslash; return $contents; } sub WriteStringToFile { my $fh = SafeOpen ("> $_[0]"); binmode $fh; print $fh $_[1] or confess "$_[0]: $!\n"; SafeClose $fh; } foreach my $file (@ARGV) { my $changed_p = 0; my $new_contents = ""; if ($options{"line-mode"}) { my $fh = SafeOpen $file; while (<$fh>) { my $save_line = $_; eval $code; $changed_p = 1 if $save_line ne $_; $new_contents .= $_; } } else { my $orig_contents = $_ = FileContents $file; eval $code; if ($_ ne $orig_contents) { $changed_p = 1; $new_contents = $_; } } if ($changed_p) { my $backdir = $options{"backup-dir"}; $backdir = "backup" if !defined ($backdir); if ($backdir) { my ($name, $path, $suffix) = fileparse ($file, ""); my $backfulldir = $path . $backdir; my $backfile = "$backfulldir/$name"; mkdir $backfulldir, 0755 unless -d $backfulldir; print "modifying $file (original saved in $backfile)\n"; rename $file, $backfile; } WriteStringToFile ($file, $new_contents); } } ----------------------------------- cut ------------------------------------ In addition to those programs, I needed to fix up a few other things, particularly relating to the duplicate definitions of types, now that some types merged with others. Specifically: 1. in lisp.h, removed duplicate declarations of Bytecount. The changed code should now look like this: (In each code snippet below, the first and last lines are the same as the original, as are all lines outside of those lines. That allows you to locate the section to be replaced, and replace the stuff in that section, verifying that there isn't anything new added that would need to be kept.) --------------------------------- snip ------------------------------------- /* Counts of bytes or chars */ typedef EMACS_INT Bytecount; typedef EMACS_INT Charcount; /* Counts of elements */ typedef EMACS_INT Elemcount; /* Hash codes */ typedef unsigned long Hashcode; /* ------------------------ dynamic arrays ------------------- */ --------------------------------- snip ------------------------------------- 2. in lstream.h, removed duplicate declaration of Bytecount. Rewrote the comment about this type. The changed code should now look like this: --------------------------------- snip ------------------------------------- #endif /* The have been some arguments over the what the type should be that specifies a count of bytes in a data block to be written out or read in, using Lstream_read(), Lstream_write(), and related functions. Originally it was long, which worked fine; Martin "corrected" these to size_t and ssize_t on the grounds that this is theoretically cleaner and is in keeping with the C standards. Unfortunately, this practice is horribly error-prone due to design flaws in the way that mixed signed/unsigned arithmetic happens. In fact, by doing this change, Martin introduced a subtle but fatal error that caused the operation of sending large mail messages to the SMTP server under Windows to fail. By putting all values back to be signed, avoiding any signed/unsigned mixing, the bug immediately went away. The type then in use was Lstream_Data_Count, so that it be reverted cleanly if a vote came to that. Now it is Bytecount. Some earlier comments about why the type must be signed: This MUST BE SIGNED, since it also is used in functions that return the number of bytes actually read to or written from in an operation, and these functions can return -1 to signal error. Note that the standard Unix read() and write() functions define the count going in as a size_t, which is UNSIGNED, and the count going out as an ssize_t, which is SIGNED. This is a horrible design flaw. Not only is it highly likely to lead to logic errors when a -1 gets interpreted as a large positive number, but operations are bound to fail in all sorts of horrible ways when a number in the upper-half of the size_t range is passed in -- this number is unrepresentable as an ssize_t, so code that checks to see how many bytes are actually written (which is mandatory if you are dealing with certain types of devices) will get completely screwed up. --ben */ typedef enum lstream_buffering --------------------------------- snip ------------------------------------- 3. in dumper.c, there are four places, all inside of switch() statements, where XD_BYTECOUNT appears twice as a case tag. In each case, the two case blocks contain identical code, and you should *REMOVE THE SECOND* and leave the first.
author ben
date Thu, 20 Sep 2001 06:31:11 +0000
parents b39c14581166
children a307f9a2021d
comparison
equal deleted inserted replaced
664:6e99cc8c6ca5 665:fdefd0186b75
241 241
242 /* like malloc and realloc but check for no memory left, and block input. */ 242 /* like malloc and realloc but check for no memory left, and block input. */
243 243
244 #undef xmalloc 244 #undef xmalloc
245 void * 245 void *
246 xmalloc (Memory_Count size) 246 xmalloc (Bytecount size)
247 { 247 {
248 void *val = malloc (size); 248 void *val = malloc (size);
249 249
250 if (!val && (size != 0)) memory_full (); 250 if (!val && (size != 0)) memory_full ();
251 return val; 251 return val;
252 } 252 }
253 253
254 #undef xcalloc 254 #undef xcalloc
255 static void * 255 static void *
256 xcalloc (Element_Count nelem, Memory_Count elsize) 256 xcalloc (Elemcount nelem, Bytecount elsize)
257 { 257 {
258 void *val = calloc (nelem, elsize); 258 void *val = calloc (nelem, elsize);
259 259
260 if (!val && (nelem != 0)) memory_full (); 260 if (!val && (nelem != 0)) memory_full ();
261 return val; 261 return val;
262 } 262 }
263 263
264 void * 264 void *
265 xmalloc_and_zero (Memory_Count size) 265 xmalloc_and_zero (Bytecount size)
266 { 266 {
267 return xcalloc (size, sizeof (char)); 267 return xcalloc (size, sizeof (char));
268 } 268 }
269 269
270 #undef xrealloc 270 #undef xrealloc
271 void * 271 void *
272 xrealloc (void *block, Memory_Count size) 272 xrealloc (void *block, Bytecount size)
273 { 273 {
274 block = realloc (block, size); 274 block = realloc (block, size);
275 275
276 if (!block && (size != 0)) memory_full (); 276 if (!block && (size != 0)) memory_full ();
277 return block; 277 return block;
305 #else 305 #else
306 What kind of strange-ass system are we running on? 306 What kind of strange-ass system are we running on?
307 #endif 307 #endif
308 308
309 static void 309 static void
310 deadbeef_memory (void *ptr, Memory_Count size) 310 deadbeef_memory (void *ptr, Bytecount size)
311 { 311 {
312 four_byte_t *ptr4 = (four_byte_t *) ptr; 312 four_byte_t *ptr4 = (four_byte_t *) ptr;
313 Memory_Count beefs = size >> 2; 313 Bytecount beefs = size >> 2;
314 314
315 /* In practice, size will always be a multiple of four. */ 315 /* In practice, size will always be a multiple of four. */
316 while (beefs--) 316 while (beefs--)
317 (*ptr4++) = 0xDEADBEEF; 317 (*ptr4++) = 0xDEADBEEF;
318 } 318 }
343 } 343 }
344 #endif /* NEED_STRDUP */ 344 #endif /* NEED_STRDUP */
345 345
346 346
347 static void * 347 static void *
348 allocate_lisp_storage (Memory_Count size) 348 allocate_lisp_storage (Bytecount size)
349 { 349 {
350 return xmalloc (size); 350 return xmalloc (size);
351 } 351 }
352 352
353 353
355 After doing the mark phase, GC will walk this linked list 355 After doing the mark phase, GC will walk this linked list
356 and free any lcrecord which hasn't been marked. */ 356 and free any lcrecord which hasn't been marked. */
357 static struct lcrecord_header *all_lcrecords; 357 static struct lcrecord_header *all_lcrecords;
358 358
359 void * 359 void *
360 alloc_lcrecord (Memory_Count size, const struct lrecord_implementation *implementation) 360 alloc_lcrecord (Bytecount size, const struct lrecord_implementation *implementation)
361 { 361 {
362 struct lcrecord_header *lcheader; 362 struct lcrecord_header *lcheader;
363 363
364 type_checking_assert 364 type_checking_assert
365 ((implementation->static_size == 0 ? 365 ((implementation->static_size == 0 ?
1050 for (i = 0; i < len - 1; i++) 1050 for (i = 0; i < len - 1; i++)
1051 mark_object (ptr->contents[i]); 1051 mark_object (ptr->contents[i]);
1052 return (len > 0) ? ptr->contents[len - 1] : Qnil; 1052 return (len > 0) ? ptr->contents[len - 1] : Qnil;
1053 } 1053 }
1054 1054
1055 static Memory_Count 1055 static Bytecount
1056 size_vector (const void *lheader) 1056 size_vector (const void *lheader)
1057 { 1057 {
1058 return FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_Vector, Lisp_Object, contents, 1058 return FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_Vector, Lisp_Object, contents,
1059 ((Lisp_Vector *) lheader)->size); 1059 ((Lisp_Vector *) lheader)->size);
1060 } 1060 }
1074 return 0; 1074 return 0;
1075 } 1075 }
1076 return 1; 1076 return 1;
1077 } 1077 }
1078 1078
1079 static Hash_Code 1079 static Hashcode
1080 vector_hash (Lisp_Object obj, int depth) 1080 vector_hash (Lisp_Object obj, int depth)
1081 { 1081 {
1082 return HASH2 (XVECTOR_LENGTH (obj), 1082 return HASH2 (XVECTOR_LENGTH (obj),
1083 internal_array_hash (XVECTOR_DATA (obj), 1083 internal_array_hash (XVECTOR_DATA (obj),
1084 XVECTOR_LENGTH (obj), 1084 XVECTOR_LENGTH (obj),
1098 vector_description, 1098 vector_description,
1099 size_vector, Lisp_Vector); 1099 size_vector, Lisp_Vector);
1100 1100
1101 /* #### should allocate `small' vectors from a frob-block */ 1101 /* #### should allocate `small' vectors from a frob-block */
1102 static Lisp_Vector * 1102 static Lisp_Vector *
1103 make_vector_internal (Element_Count sizei) 1103 make_vector_internal (Elemcount sizei)
1104 { 1104 {
1105 /* no vector_next */ 1105 /* no vector_next */
1106 Memory_Count sizem = FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_Vector, Lisp_Object, 1106 Bytecount sizem = FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_Vector, Lisp_Object,
1107 contents, sizei); 1107 contents, sizei);
1108 Lisp_Vector *p = (Lisp_Vector *) alloc_lcrecord (sizem, &lrecord_vector); 1108 Lisp_Vector *p = (Lisp_Vector *) alloc_lcrecord (sizem, &lrecord_vector);
1109 1109
1110 p->size = sizei; 1110 p->size = sizei;
1111 return p; 1111 return p;
1112 } 1112 }
1113 1113
1114 Lisp_Object 1114 Lisp_Object
1115 make_vector (Element_Count length, Lisp_Object object) 1115 make_vector (Elemcount length, Lisp_Object object)
1116 { 1116 {
1117 Lisp_Vector *vecp = make_vector_internal (length); 1117 Lisp_Vector *vecp = make_vector_internal (length);
1118 Lisp_Object *p = vector_data (vecp); 1118 Lisp_Object *p = vector_data (vecp);
1119 1119
1120 while (length--) 1120 while (length--)
1262 1262
1263 static Lisp_Object all_bit_vectors; 1263 static Lisp_Object all_bit_vectors;
1264 1264
1265 /* #### should allocate `small' bit vectors from a frob-block */ 1265 /* #### should allocate `small' bit vectors from a frob-block */
1266 static Lisp_Bit_Vector * 1266 static Lisp_Bit_Vector *
1267 make_bit_vector_internal (Element_Count sizei) 1267 make_bit_vector_internal (Elemcount sizei)
1268 { 1268 {
1269 Element_Count num_longs = BIT_VECTOR_LONG_STORAGE (sizei); 1269 Elemcount num_longs = BIT_VECTOR_LONG_STORAGE (sizei);
1270 Memory_Count sizem = FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_Bit_Vector, 1270 Bytecount sizem = FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_Bit_Vector,
1271 unsigned long, 1271 unsigned long,
1272 bits, num_longs); 1272 bits, num_longs);
1273 Lisp_Bit_Vector *p = (Lisp_Bit_Vector *) allocate_lisp_storage (sizem); 1273 Lisp_Bit_Vector *p = (Lisp_Bit_Vector *) allocate_lisp_storage (sizem);
1274 set_lheader_implementation (&p->lheader, &lrecord_bit_vector); 1274 set_lheader_implementation (&p->lheader, &lrecord_bit_vector);
1275 1275
1283 XSETBIT_VECTOR (all_bit_vectors, p); 1283 XSETBIT_VECTOR (all_bit_vectors, p);
1284 return p; 1284 return p;
1285 } 1285 }
1286 1286
1287 Lisp_Object 1287 Lisp_Object
1288 make_bit_vector (Element_Count length, Lisp_Object bit) 1288 make_bit_vector (Elemcount length, Lisp_Object bit)
1289 { 1289 {
1290 Lisp_Bit_Vector *p = make_bit_vector_internal (length); 1290 Lisp_Bit_Vector *p = make_bit_vector_internal (length);
1291 Element_Count num_longs = BIT_VECTOR_LONG_STORAGE (length); 1291 Elemcount num_longs = BIT_VECTOR_LONG_STORAGE (length);
1292 1292
1293 CHECK_BIT (bit); 1293 CHECK_BIT (bit);
1294 1294
1295 if (ZEROP (bit)) 1295 if (ZEROP (bit))
1296 memset (p->bits, 0, num_longs * sizeof (long)); 1296 memset (p->bits, 0, num_longs * sizeof (long));
1297 else 1297 else
1298 { 1298 {
1299 Element_Count bits_in_last = length & (LONGBITS_POWER_OF_2 - 1); 1299 Elemcount bits_in_last = length & (LONGBITS_POWER_OF_2 - 1);
1300 memset (p->bits, ~0, num_longs * sizeof (long)); 1300 memset (p->bits, ~0, num_longs * sizeof (long));
1301 /* But we have to make sure that the unused bits in the 1301 /* But we have to make sure that the unused bits in the
1302 last long are 0, so that equal/hash is easy. */ 1302 last long are 0, so that equal/hash is easy. */
1303 if (bits_in_last) 1303 if (bits_in_last)
1304 p->bits[num_longs - 1] &= (1 << bits_in_last) - 1; 1304 p->bits[num_longs - 1] &= (1 << bits_in_last) - 1;
1310 return bit_vector; 1310 return bit_vector;
1311 } 1311 }
1312 } 1312 }
1313 1313
1314 Lisp_Object 1314 Lisp_Object
1315 make_bit_vector_from_byte_vector (unsigned char *bytevec, Element_Count length) 1315 make_bit_vector_from_byte_vector (unsigned char *bytevec, Elemcount length)
1316 { 1316 {
1317 Element_Count i; 1317 Elemcount i;
1318 Lisp_Bit_Vector *p = make_bit_vector_internal (length); 1318 Lisp_Bit_Vector *p = make_bit_vector_internal (length);
1319 1319
1320 for (i = 0; i < length; i++) 1320 for (i = 0; i < length; i++)
1321 set_bit_vector_bit (p, i, bytevec[i]); 1321 set_bit_vector_bit (p, i, bytevec[i]);
1322 1322
1599 Lisp_Marker *p; 1599 Lisp_Marker *p;
1600 1600
1601 ALLOCATE_FIXED_TYPE (marker, Lisp_Marker, p); 1601 ALLOCATE_FIXED_TYPE (marker, Lisp_Marker, p);
1602 set_lheader_implementation (&p->lheader, &lrecord_marker); 1602 set_lheader_implementation (&p->lheader, &lrecord_marker);
1603 p->buffer = 0; 1603 p->buffer = 0;
1604 p->memind = 0; 1604 p->membpos = 0;
1605 marker_next (p) = 0; 1605 marker_next (p) = 0;
1606 marker_prev (p) = 0; 1606 marker_prev (p) = 0;
1607 p->insertion_type = 0; 1607 p->insertion_type = 0;
1608 XSETMARKER (val, p); 1608 XSETMARKER (val, p);
1609 return val; 1609 return val;
1616 Lisp_Marker *p; 1616 Lisp_Marker *p;
1617 1617
1618 NOSEEUM_ALLOCATE_FIXED_TYPE (marker, Lisp_Marker, p); 1618 NOSEEUM_ALLOCATE_FIXED_TYPE (marker, Lisp_Marker, p);
1619 set_lheader_implementation (&p->lheader, &lrecord_marker); 1619 set_lheader_implementation (&p->lheader, &lrecord_marker);
1620 p->buffer = 0; 1620 p->buffer = 0;
1621 p->memind = 0; 1621 p->membpos = 0;
1622 marker_next (p) = 0; 1622 marker_next (p) = 0;
1623 marker_prev (p) = 0; 1623 marker_prev (p) = 0;
1624 p->insertion_type = 0; 1624 p->insertion_type = 0;
1625 XSETMARKER (val, p); 1625 XSETMARKER (val, p);
1626 return val; 1626 return val;
1840 /* Allocate the string header */ 1840 /* Allocate the string header */
1841 ALLOCATE_FIXED_TYPE (string, Lisp_String, s); 1841 ALLOCATE_FIXED_TYPE (string, Lisp_String, s);
1842 set_lheader_implementation (&s->lheader, &lrecord_string); 1842 set_lheader_implementation (&s->lheader, &lrecord_string);
1843 1843
1844 set_string_data (s, BIG_STRING_FULLSIZE_P (fullsize) 1844 set_string_data (s, BIG_STRING_FULLSIZE_P (fullsize)
1845 ? xnew_array (Bufbyte, length + 1) 1845 ? xnew_array (Intbyte, length + 1)
1846 : allocate_string_chars_struct (s, fullsize)->chars); 1846 : allocate_string_chars_struct (s, fullsize)->chars);
1847 1847
1848 set_string_length (s, length); 1848 set_string_length (s, length);
1849 s->plist = Qnil; 1849 s->plist = Qnil;
1850 1850
1870 Bytecount oldfullsize, newfullsize; 1870 Bytecount oldfullsize, newfullsize;
1871 #ifdef VERIFY_STRING_CHARS_INTEGRITY 1871 #ifdef VERIFY_STRING_CHARS_INTEGRITY
1872 verify_string_chars_integrity (); 1872 verify_string_chars_integrity ();
1873 #endif 1873 #endif
1874 1874
1875 #ifdef ERROR_CHECK_BUFPOS 1875 #ifdef ERROR_CHECK_CHARBPOS
1876 if (pos >= 0) 1876 if (pos >= 0)
1877 { 1877 {
1878 assert (pos <= string_length (s)); 1878 assert (pos <= string_length (s));
1879 if (delta < 0) 1879 if (delta < 0)
1880 assert (pos + (-delta) <= string_length (s)); 1880 assert (pos + (-delta) <= string_length (s));
1882 else 1882 else
1883 { 1883 {
1884 if (delta < 0) 1884 if (delta < 0)
1885 assert ((-delta) <= string_length (s)); 1885 assert ((-delta) <= string_length (s));
1886 } 1886 }
1887 #endif /* ERROR_CHECK_BUFPOS */ 1887 #endif /* ERROR_CHECK_CHARBPOS */
1888 1888
1889 if (delta == 0) 1889 if (delta == 0)
1890 /* simplest case: no size change. */ 1890 /* simplest case: no size change. */
1891 return; 1891 return;
1892 1892
1910 illegal, and we might crash. */ 1910 illegal, and we might crash. */
1911 Bytecount len = string_length (s) + 1 - pos; 1911 Bytecount len = string_length (s) + 1 - pos;
1912 1912
1913 if (delta < 0 && pos >= 0) 1913 if (delta < 0 && pos >= 0)
1914 memmove (string_data (s) + pos + delta, string_data (s) + pos, len); 1914 memmove (string_data (s) + pos + delta, string_data (s) + pos, len);
1915 set_string_data (s, (Bufbyte *) xrealloc (string_data (s), 1915 set_string_data (s, (Intbyte *) xrealloc (string_data (s),
1916 string_length (s) + delta + 1)); 1916 string_length (s) + delta + 1));
1917 if (delta > 0 && pos >= 0) 1917 if (delta > 0 && pos >= 0)
1918 memmove (string_data (s) + pos + delta, string_data (s) + pos, len); 1918 memmove (string_data (s) + pos + delta, string_data (s) + pos, len);
1919 } 1919 }
1920 else /* String has been demoted from BIG_STRING. */ 1920 else /* String has been demoted from BIG_STRING. */
1921 { 1921 {
1922 Bufbyte *new_data = 1922 Intbyte *new_data =
1923 allocate_string_chars_struct (s, newfullsize)->chars; 1923 allocate_string_chars_struct (s, newfullsize)->chars;
1924 Bufbyte *old_data = string_data (s); 1924 Intbyte *old_data = string_data (s);
1925 1925
1926 if (pos >= 0) 1926 if (pos >= 0)
1927 { 1927 {
1928 memcpy (new_data, old_data, pos); 1928 memcpy (new_data, old_data, pos);
1929 memcpy (new_data + pos + delta, old_data + pos, 1929 memcpy (new_data + pos + delta, old_data + pos,
1942 somewhere depends on there not being any unused 1942 somewhere depends on there not being any unused
1943 allocation space, modulo any alignment 1943 allocation space, modulo any alignment
1944 constraints). */ 1944 constraints). */
1945 if (pos >= 0) 1945 if (pos >= 0)
1946 { 1946 {
1947 Bufbyte *addroff = pos + string_data (s); 1947 Intbyte *addroff = pos + string_data (s);
1948 1948
1949 memmove (addroff + delta, addroff, 1949 memmove (addroff + delta, addroff,
1950 /* +1 due to zero-termination. */ 1950 /* +1 due to zero-termination. */
1951 string_length (s) + 1 - pos); 1951 string_length (s) + 1 - pos);
1952 } 1952 }
1953 } 1953 }
1954 else 1954 else
1955 { 1955 {
1956 Bufbyte *old_data = string_data (s); 1956 Intbyte *old_data = string_data (s);
1957 Bufbyte *new_data = 1957 Intbyte *new_data =
1958 BIG_STRING_FULLSIZE_P (newfullsize) 1958 BIG_STRING_FULLSIZE_P (newfullsize)
1959 ? xnew_array (Bufbyte, string_length (s) + delta + 1) 1959 ? xnew_array (Intbyte, string_length (s) + delta + 1)
1960 : allocate_string_chars_struct (s, newfullsize)->chars; 1960 : allocate_string_chars_struct (s, newfullsize)->chars;
1961 1961
1962 if (pos >= 0) 1962 if (pos >= 0)
1963 { 1963 {
1964 memcpy (new_data, old_data, pos); 1964 memcpy (new_data, old_data, pos);
2009 #ifdef MULE 2009 #ifdef MULE
2010 2010
2011 void 2011 void
2012 set_string_char (Lisp_String *s, Charcount i, Emchar c) 2012 set_string_char (Lisp_String *s, Charcount i, Emchar c)
2013 { 2013 {
2014 Bufbyte newstr[MAX_EMCHAR_LEN]; 2014 Intbyte newstr[MAX_EMCHAR_LEN];
2015 Bytecount bytoff = charcount_to_bytecount (string_data (s), i); 2015 Bytecount bytoff = charcount_to_bytecount (string_data (s), i);
2016 Bytecount oldlen = charcount_to_bytecount (string_data (s) + bytoff, 1); 2016 Bytecount oldlen = charcount_to_bytecount (string_data (s) + bytoff, 1);
2017 Bytecount newlen = set_charptr_emchar (newstr, c); 2017 Bytecount newlen = set_charptr_emchar (newstr, c);
2018 2018
2019 if (oldlen != newlen) 2019 if (oldlen != newlen)
2031 (length, character)) 2031 (length, character))
2032 { 2032 {
2033 CHECK_NATNUM (length); 2033 CHECK_NATNUM (length);
2034 CHECK_CHAR_COERCE_INT (character); 2034 CHECK_CHAR_COERCE_INT (character);
2035 { 2035 {
2036 Bufbyte init_str[MAX_EMCHAR_LEN]; 2036 Intbyte init_str[MAX_EMCHAR_LEN];
2037 int len = set_charptr_emchar (init_str, XCHAR (character)); 2037 int len = set_charptr_emchar (init_str, XCHAR (character));
2038 Lisp_Object val = make_uninit_string (len * XINT (length)); 2038 Lisp_Object val = make_uninit_string (len * XINT (length));
2039 2039
2040 if (len == 1) 2040 if (len == 1)
2041 /* Optimize the single-byte case */ 2041 /* Optimize the single-byte case */
2042 memset (XSTRING_DATA (val), XCHAR (character), XSTRING_LENGTH (val)); 2042 memset (XSTRING_DATA (val), XCHAR (character), XSTRING_LENGTH (val));
2043 else 2043 else
2044 { 2044 {
2045 EMACS_INT i; 2045 EMACS_INT i;
2046 Bufbyte *ptr = XSTRING_DATA (val); 2046 Intbyte *ptr = XSTRING_DATA (val);
2047 2047
2048 for (i = XINT (length); i; i--) 2048 for (i = XINT (length); i; i--)
2049 { 2049 {
2050 Bufbyte *init_ptr = init_str; 2050 Intbyte *init_ptr = init_str;
2051 switch (len) 2051 switch (len)
2052 { 2052 {
2053 case 4: *ptr++ = *init_ptr++; 2053 case 4: *ptr++ = *init_ptr++;
2054 case 3: *ptr++ = *init_ptr++; 2054 case 3: *ptr++ = *init_ptr++;
2055 case 2: *ptr++ = *init_ptr++; 2055 case 2: *ptr++ = *init_ptr++;
2064 DEFUN ("string", Fstring, 0, MANY, 0, /* 2064 DEFUN ("string", Fstring, 0, MANY, 0, /*
2065 Concatenate all the argument characters and make the result a string. 2065 Concatenate all the argument characters and make the result a string.
2066 */ 2066 */
2067 (int nargs, Lisp_Object *args)) 2067 (int nargs, Lisp_Object *args))
2068 { 2068 {
2069 Bufbyte *storage = alloca_array (Bufbyte, nargs * MAX_EMCHAR_LEN); 2069 Intbyte *storage = alloca_array (Intbyte, nargs * MAX_EMCHAR_LEN);
2070 Bufbyte *p = storage; 2070 Intbyte *p = storage;
2071 2071
2072 for (; nargs; nargs--, args++) 2072 for (; nargs; nargs--, args++)
2073 { 2073 {
2074 Lisp_Object lisp_char = *args; 2074 Lisp_Object lisp_char = *args;
2075 CHECK_CHAR_COERCE_INT (lisp_char); 2075 CHECK_CHAR_COERCE_INT (lisp_char);
2080 2080
2081 2081
2082 /* Take some raw memory, which MUST already be in internal format, 2082 /* Take some raw memory, which MUST already be in internal format,
2083 and package it up into a Lisp string. */ 2083 and package it up into a Lisp string. */
2084 Lisp_Object 2084 Lisp_Object
2085 make_string (const Bufbyte *contents, Bytecount length) 2085 make_string (const Intbyte *contents, Bytecount length)
2086 { 2086 {
2087 Lisp_Object val; 2087 Lisp_Object val;
2088 2088
2089 /* Make sure we find out about bad make_string's when they happen */ 2089 /* Make sure we find out about bad make_string's when they happen */
2090 #if defined (ERROR_CHECK_BUFPOS) && defined (MULE) 2090 #if defined (ERROR_CHECK_CHARBPOS) && defined (MULE)
2091 bytecount_to_charcount (contents, length); /* Just for the assertions */ 2091 bytecount_to_charcount (contents, length); /* Just for the assertions */
2092 #endif 2092 #endif
2093 2093
2094 val = make_uninit_string (length); 2094 val = make_uninit_string (length);
2095 memcpy (XSTRING_DATA (val), contents, length); 2095 memcpy (XSTRING_DATA (val), contents, length);
2108 coding_system); 2108 coding_system);
2109 return string; 2109 return string;
2110 } 2110 }
2111 2111
2112 Lisp_Object 2112 Lisp_Object
2113 build_string (const CBufbyte *str) 2113 build_string (const CIntbyte *str)
2114 { 2114 {
2115 /* Some strlen's crash and burn if passed null. */ 2115 /* Some strlen's crash and burn if passed null. */
2116 return make_string ((const Bufbyte *) str, (str ? strlen(str) : 0)); 2116 return make_string ((const Intbyte *) str, (str ? strlen(str) : 0));
2117 } 2117 }
2118 2118
2119 Lisp_Object 2119 Lisp_Object
2120 build_ext_string (const Extbyte *str, Lisp_Object coding_system) 2120 build_ext_string (const Extbyte *str, Lisp_Object coding_system)
2121 { 2121 {
2123 return make_ext_string ((const Extbyte *) str, (str ? strlen(str) : 0), 2123 return make_ext_string ((const Extbyte *) str, (str ? strlen(str) : 0),
2124 coding_system); 2124 coding_system);
2125 } 2125 }
2126 2126
2127 Lisp_Object 2127 Lisp_Object
2128 build_translated_string (const CBufbyte *str) 2128 build_translated_string (const CIntbyte *str)
2129 { 2129 {
2130 return build_string (GETTEXT (str)); 2130 return build_string (GETTEXT (str));
2131 } 2131 }
2132 2132
2133 Lisp_Object 2133 Lisp_Object
2134 make_string_nocopy (const Bufbyte *contents, Bytecount length) 2134 make_string_nocopy (const Intbyte *contents, Bytecount length)
2135 { 2135 {
2136 Lisp_String *s; 2136 Lisp_String *s;
2137 Lisp_Object val; 2137 Lisp_Object val;
2138 2138
2139 /* Make sure we find out about bad make_string_nocopy's when they happen */ 2139 /* Make sure we find out about bad make_string_nocopy's when they happen */
2140 #if defined (ERROR_CHECK_BUFPOS) && defined (MULE) 2140 #if defined (ERROR_CHECK_CHARBPOS) && defined (MULE)
2141 bytecount_to_charcount (contents, length); /* Just for the assertions */ 2141 bytecount_to_charcount (contents, length); /* Just for the assertions */
2142 #endif 2142 #endif
2143 2143
2144 /* Allocate the string header */ 2144 /* Allocate the string header */
2145 ALLOCATE_FIXED_TYPE (string, Lisp_String, s); 2145 ALLOCATE_FIXED_TYPE (string, Lisp_String, s);
2146 set_lheader_implementation (&s->lheader, &lrecord_string); 2146 set_lheader_implementation (&s->lheader, &lrecord_string);
2147 SET_C_READONLY_RECORD_HEADER (&s->lheader); 2147 SET_C_READONLY_RECORD_HEADER (&s->lheader);
2148 s->plist = Qnil; 2148 s->plist = Qnil;
2149 set_string_data (s, (Bufbyte *)contents); 2149 set_string_data (s, (Intbyte *)contents);
2150 set_string_length (s, length); 2150 set_string_length (s, length);
2151 2151
2152 XSETSTRING (val, s); 2152 XSETSTRING (val, s);
2153 return val; 2153 return val;
2154 } 2154 }
2225 2225
2226 DEFINE_LRECORD_IMPLEMENTATION ("lcrecord-list", lcrecord_list, 2226 DEFINE_LRECORD_IMPLEMENTATION ("lcrecord-list", lcrecord_list,
2227 mark_lcrecord_list, internal_object_printer, 2227 mark_lcrecord_list, internal_object_printer,
2228 0, 0, 0, 0, struct lcrecord_list); 2228 0, 0, 0, 0, struct lcrecord_list);
2229 Lisp_Object 2229 Lisp_Object
2230 make_lcrecord_list (Element_Count size, 2230 make_lcrecord_list (Elemcount size,
2231 const struct lrecord_implementation *implementation) 2231 const struct lrecord_implementation *implementation)
2232 { 2232 {
2233 struct lcrecord_list *p = alloc_lcrecord_type (struct lcrecord_list, 2233 struct lcrecord_list *p = alloc_lcrecord_type (struct lcrecord_list,
2234 &lrecord_lcrecord_list); 2234 &lrecord_lcrecord_list);
2235 Lisp_Object val; 2235 Lisp_Object val;
2487 else 2487 else
2488 { 2488 {
2489 const struct lrecord_implementation *implementation = 2489 const struct lrecord_implementation *implementation =
2490 LHEADER_IMPLEMENTATION (h); 2490 LHEADER_IMPLEMENTATION (h);
2491 2491
2492 Memory_Count sz = (implementation->size_in_bytes_method ? 2492 Bytecount sz = (implementation->size_in_bytes_method ?
2493 implementation->size_in_bytes_method (h) : 2493 implementation->size_in_bytes_method (h) :
2494 implementation->static_size); 2494 implementation->static_size);
2495 if (free_p) 2495 if (free_p)
2496 { 2496 {
2497 lcrecord_stats[type_index].instances_freed++; 2497 lcrecord_stats[type_index].instances_freed++;
3376 Lisp_Object args[2], whole_msg; 3376 Lisp_Object args[2], whole_msg;
3377 args[0] = build_string (msg ? msg : 3377 args[0] = build_string (msg ? msg :
3378 GETTEXT ((const char *) gc_default_message)); 3378 GETTEXT ((const char *) gc_default_message));
3379 args[1] = build_string ("..."); 3379 args[1] = build_string ("...");
3380 whole_msg = Fconcat (2, args); 3380 whole_msg = Fconcat (2, args);
3381 echo_area_message (f, (Bufbyte *) 0, whole_msg, 0, -1, 3381 echo_area_message (f, (Intbyte *) 0, whole_msg, 0, -1,
3382 Qgarbage_collecting); 3382 Qgarbage_collecting);
3383 } 3383 }
3384 } 3384 }
3385 3385
3386 /***** Now we actually start the garbage collection. */ 3386 /***** Now we actually start the garbage collection. */
3394 /* Save a copy of the contents of the stack, for debugging. */ 3394 /* Save a copy of the contents of the stack, for debugging. */
3395 if (!purify_flag) 3395 if (!purify_flag)
3396 { 3396 {
3397 /* Static buffer in which we save a copy of the C stack at each GC. */ 3397 /* Static buffer in which we save a copy of the C stack at each GC. */
3398 static char *stack_copy; 3398 static char *stack_copy;
3399 static Memory_Count stack_copy_size; 3399 static Bytecount stack_copy_size;
3400 3400
3401 ptrdiff_t stack_diff = &stack_top_variable - stack_bottom; 3401 ptrdiff_t stack_diff = &stack_top_variable - stack_bottom;
3402 Memory_Count stack_size = (stack_diff > 0 ? stack_diff : -stack_diff); 3402 Bytecount stack_size = (stack_diff > 0 ? stack_diff : -stack_diff);
3403 if (stack_size < MAX_SAVE_STACK) 3403 if (stack_size < MAX_SAVE_STACK)
3404 { 3404 {
3405 if (stack_copy_size < stack_size) 3405 if (stack_copy_size < stack_size)
3406 { 3406 {
3407 stack_copy = (char *) xrealloc (stack_copy, stack_size); 3407 stack_copy = (char *) xrealloc (stack_copy, stack_size);
3422 3422
3423 /* Mark all the special slots that serve as the roots of accessibility. */ 3423 /* Mark all the special slots that serve as the roots of accessibility. */
3424 3424
3425 { /* staticpro() */ 3425 { /* staticpro() */
3426 Lisp_Object **p = Dynarr_begin (staticpros); 3426 Lisp_Object **p = Dynarr_begin (staticpros);
3427 Element_Count count; 3427 Elemcount count;
3428 for (count = Dynarr_length (staticpros); count; count--) 3428 for (count = Dynarr_length (staticpros); count; count--)
3429 mark_object (**p++); 3429 mark_object (**p++);
3430 } 3430 }
3431 3431
3432 { /* staticpro_nodump() */ 3432 { /* staticpro_nodump() */
3433 Lisp_Object **p = Dynarr_begin (staticpros_nodump); 3433 Lisp_Object **p = Dynarr_begin (staticpros_nodump);
3434 Element_Count count; 3434 Elemcount count;
3435 for (count = Dynarr_length (staticpros_nodump); count; count--) 3435 for (count = Dynarr_length (staticpros_nodump); count; count--)
3436 mark_object (**p++); 3436 mark_object (**p++);
3437 } 3437 }
3438 3438
3439 { /* GCPRO() */ 3439 { /* GCPRO() */
3536 args[0] = build_string (msg ? msg : 3536 args[0] = build_string (msg ? msg :
3537 GETTEXT ((const char *) 3537 GETTEXT ((const char *)
3538 gc_default_message)); 3538 gc_default_message));
3539 args[1] = build_string ("... done"); 3539 args[1] = build_string ("... done");
3540 whole_msg = Fconcat (2, args); 3540 whole_msg = Fconcat (2, args);
3541 echo_area_message (selected_frame (), (Bufbyte *) 0, 3541 echo_area_message (selected_frame (), (Intbyte *) 0,
3542 whole_msg, 0, -1, 3542 whole_msg, 0, -1,
3543 Qgarbage_collecting); 3543 Qgarbage_collecting);
3544 } 3544 }
3545 } 3545 }
3546 } 3546 }
3762 for want of better data is that sizeof (void *), or maybe 3762 for want of better data is that sizeof (void *), or maybe
3763 2 * sizeof (void *), is required as overhead and that 3763 2 * sizeof (void *), is required as overhead and that
3764 blocks are allocated in the minimum required size except 3764 blocks are allocated in the minimum required size except
3765 that some minimum block size is imposed (e.g. 16 bytes). */ 3765 that some minimum block size is imposed (e.g. 16 bytes). */
3766 3766
3767 Memory_Count 3767 Bytecount
3768 malloced_storage_size (void *ptr, Memory_Count claimed_size, 3768 malloced_storage_size (void *ptr, Bytecount claimed_size,
3769 struct overhead_stats *stats) 3769 struct overhead_stats *stats)
3770 { 3770 {
3771 Memory_Count orig_claimed_size = claimed_size; 3771 Bytecount orig_claimed_size = claimed_size;
3772 3772
3773 #ifdef GNU_MALLOC 3773 #ifdef GNU_MALLOC
3774 if (claimed_size < (Memory_Count) (2 * sizeof (void *))) 3774 if (claimed_size < (Bytecount) (2 * sizeof (void *)))
3775 claimed_size = 2 * sizeof (void *); 3775 claimed_size = 2 * sizeof (void *);
3776 # ifdef SUNOS_LOCALTIME_BUG 3776 # ifdef SUNOS_LOCALTIME_BUG
3777 if (claimed_size < 16) 3777 if (claimed_size < 16)
3778 claimed_size = 16; 3778 claimed_size = 16;
3779 # endif 3779 # endif
3794 claimed_size *= 2; 3794 claimed_size *= 2;
3795 log--; 3795 log--;
3796 } 3796 }
3797 /* We have to come up with some average about the amount of 3797 /* We have to come up with some average about the amount of
3798 blocks used. */ 3798 blocks used. */
3799 if ((Memory_Count) (rand () & 4095) < claimed_size) 3799 if ((Bytecount) (rand () & 4095) < claimed_size)
3800 claimed_size += 3 * sizeof (void *); 3800 claimed_size += 3 * sizeof (void *);
3801 } 3801 }
3802 else 3802 else
3803 { 3803 {
3804 claimed_size += 4095; 3804 claimed_size += 4095;
3845 stats->malloc_overhead += claimed_size - orig_claimed_size; 3845 stats->malloc_overhead += claimed_size - orig_claimed_size;
3846 } 3846 }
3847 return claimed_size; 3847 return claimed_size;
3848 } 3848 }
3849 3849
3850 Memory_Count 3850 Bytecount
3851 fixed_type_block_overhead (Memory_Count size) 3851 fixed_type_block_overhead (Bytecount size)
3852 { 3852 {
3853 Memory_Count per_block = TYPE_ALLOC_SIZE (cons, unsigned char); 3853 Bytecount per_block = TYPE_ALLOC_SIZE (cons, unsigned char);
3854 Memory_Count overhead = 0; 3854 Bytecount overhead = 0;
3855 Memory_Count storage_size = malloced_storage_size (0, per_block, 0); 3855 Bytecount storage_size = malloced_storage_size (0, per_block, 0);
3856 while (size >= per_block) 3856 while (size >= per_block)
3857 { 3857 {
3858 size -= per_block; 3858 size -= per_block;
3859 overhead += sizeof (void *) + per_block - storage_size; 3859 overhead += sizeof (void *) + per_block - storage_size;
3860 } 3860 }