comparison src/buffer.c @ 88547:ef1b2fbc435f

(emacs_strerror): Declare. (MMAP_ALLOCATED_P, mmap_enlarge, syms_of_buffer): Import changes from trunk.
author Dave Love <fx@gnu.org>
date Fri, 17 May 2002 16:33:41 +0000
parents e3a506b5f300
children 8628701201ae
comparison
equal deleted inserted replaced
88546:7471723e43b0 88547:ef1b2fbc435f
1 /* Buffer manipulation primitives for GNU Emacs. 1 /* Buffer manipulation primitives for GNU Emacs.
2 Copyright (C) 1985,86,87,88,89,93,94,95,97,98, 1999, 2000, 2001 2 Copyright (C) 1985,86,87,88,89,93,94,95,97,98, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc. 3 Free Software Foundation, Inc.
4 4
5 This file is part of GNU Emacs. 5 This file is part of GNU Emacs.
6 6
7 GNU Emacs is free software; you can redistribute it and/or modify 7 GNU Emacs is free software; you can redistribute it and/or modify
182 static void alloc_buffer_text P_ ((struct buffer *, size_t)); 182 static void alloc_buffer_text P_ ((struct buffer *, size_t));
183 static void free_buffer_text P_ ((struct buffer *b)); 183 static void free_buffer_text P_ ((struct buffer *b));
184 static Lisp_Object copy_overlays P_ ((struct buffer *, Lisp_Object)); 184 static Lisp_Object copy_overlays P_ ((struct buffer *, Lisp_Object));
185 static void modify_overlay P_ ((struct buffer *, int, int)); 185 static void modify_overlay P_ ((struct buffer *, int, int));
186 186
187 extern char * emacs_strerror P_ ((int));
187 188
188 /* For debugging; temporary. See set_buffer_internal. */ 189 /* For debugging; temporary. See set_buffer_internal. */
189 /* Lisp_Object Qlisp_mode, Vcheck_symbol; */ 190 /* Lisp_Object Qlisp_mode, Vcheck_symbol; */
190 191
191 void 192 void
4348 #define MMAP_USER_AREA(P) \ 4349 #define MMAP_USER_AREA(P) \
4349 ((POINTER_TYPE *) ((char *) (P) + MMAP_REGION_STRUCT_SIZE)) 4350 ((POINTER_TYPE *) ((char *) (P) + MMAP_REGION_STRUCT_SIZE))
4350 4351
4351 #define MEM_ALIGN sizeof (double) 4352 #define MEM_ALIGN sizeof (double)
4352 4353
4354 /* Predicate returning true if part of the address range [START ..
4355 END[ is currently mapped. Used to prevent overwriting an existing
4356 memory mapping.
4357
4358 Default is to conservativly assume the address range is occupied by
4359 something else. This can be overridden by system configuration
4360 files if system-specific means to determine this exists. */
4361
4362 #ifndef MMAP_ALLOCATED_P
4363 #define MMAP_ALLOCATED_P(start, end) 1
4364 #endif
4365
4353 /* Function prototypes. */ 4366 /* Function prototypes. */
4354 4367
4355 static int mmap_free_1 P_ ((struct mmap_region *)); 4368 static int mmap_free_1 P_ ((struct mmap_region *));
4356 static int mmap_enlarge P_ ((struct mmap_region *, int)); 4369 static int mmap_enlarge P_ ((struct mmap_region *, int));
4357 static struct mmap_region *mmap_find P_ ((POINTER_TYPE *, POINTER_TYPE *)); 4370 static struct mmap_region *mmap_find P_ ((POINTER_TYPE *, POINTER_TYPE *));
4440 success = 1; 4453 success = 1;
4441 } 4454 }
4442 } 4455 }
4443 else if (npages > 0) 4456 else if (npages > 0)
4444 { 4457 {
4445 struct mmap_region *r2;
4446
4447 nbytes = npages * mmap_page_size; 4458 nbytes = npages * mmap_page_size;
4448 4459
4449 /* Try to map additional pages at the end of the region. We 4460 /* Try to map additional pages at the end of the region. We
4450 cannot do this if the address range is already occupied by 4461 cannot do this if the address range is already occupied by
4451 something else because mmap deletes any previous mapping. 4462 something else because mmap deletes any previous mapping.
4452 I'm not sure this is worth doing, let's see. */ 4463 I'm not sure this is worth doing, let's see. */
4453 r2 = mmap_find (region_end, region_end + nbytes); 4464 if (!MMAP_ALLOCATED_P (region_end, region_end + nbytes))
4454 if (r2 == NULL)
4455 { 4465 {
4456 POINTER_TYPE *p; 4466 POINTER_TYPE *p;
4457 4467
4458 p = mmap (region_end, nbytes, PROT_READ | PROT_WRITE, 4468 p = mmap (region_end, nbytes, PROT_READ | PROT_WRITE,
4459 MAP_ANON | MAP_PRIVATE | MAP_FIXED, mmap_fd, 0); 4469 MAP_ANON | MAP_PRIVATE | MAP_FIXED, mmap_fd, 0);
4969 4979
4970 Fset_buffer (Fget_buffer_create (build_string ("*scratch*"))); 4980 Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
4971 if (NILP (buffer_defaults.enable_multibyte_characters)) 4981 if (NILP (buffer_defaults.enable_multibyte_characters))
4972 Fset_buffer_multibyte (Qnil); 4982 Fset_buffer_multibyte (Qnil);
4973 4983
4974 /* If PWD is accurate, use it instead of calling getwd. This is faster 4984 /* If PWD is accurate, use it instead of calling getwd. PWD is
4975 when PWD is right, and may avoid a fatal error. */ 4985 sometimes a nicer name, and using it may avoid a fatal error if a
4986 parent directory is searchable but not readable. */
4976 if ((pwd = getenv ("PWD")) != 0 4987 if ((pwd = getenv ("PWD")) != 0
4977 && (IS_DIRECTORY_SEP (*pwd) || (*pwd && IS_DEVICE_SEP (pwd[1]))) 4988 && (IS_DIRECTORY_SEP (*pwd) || (*pwd && IS_DEVICE_SEP (pwd[1])))
4978 && stat (pwd, &pwdstat) == 0 4989 && stat (pwd, &pwdstat) == 0
4979 && stat (".", &dotstat) == 0 4990 && stat (".", &dotstat) == 0
4980 && dotstat.st_ino == pwdstat.st_ino 4991 && dotstat.st_ino == pwdstat.st_ino
5231 DEFVAR_PER_BUFFER ("major-mode", &current_buffer->major_mode, 5242 DEFVAR_PER_BUFFER ("major-mode", &current_buffer->major_mode,
5232 make_number (Lisp_Symbol), 5243 make_number (Lisp_Symbol),
5233 doc: /* Symbol for current buffer's major mode. */); 5244 doc: /* Symbol for current buffer's major mode. */);
5234 5245
5235 DEFVAR_PER_BUFFER ("mode-name", &current_buffer->mode_name, 5246 DEFVAR_PER_BUFFER ("mode-name", &current_buffer->mode_name,
5236 make_number (Lisp_String), 5247 Qnil,
5237 doc: /* Pretty name of current buffer's major mode (a string). */); 5248 doc: /* Pretty name of current buffer's major mode (a string). */);
5238 5249
5239 DEFVAR_PER_BUFFER ("abbrev-mode", &current_buffer->abbrev_mode, Qnil, 5250 DEFVAR_PER_BUFFER ("abbrev-mode", &current_buffer->abbrev_mode, Qnil,
5240 doc: /* Non-nil turns on automatic expansion of abbrevs as they are inserted. */); 5251 doc: /* Non-nil turns on automatic expansion of abbrevs as they are inserted. */);
5241 5252
5283 It does not apply to sending output to subprocesses, however. 5294 It does not apply to sending output to subprocesses, however.
5284 5295
5285 If this is nil, the buffer is saved without any code conversion 5296 If this is nil, the buffer is saved without any code conversion
5286 unless some coding system is specified in `file-coding-system-alist' 5297 unless some coding system is specified in `file-coding-system-alist'
5287 for the buffer file. 5298 for the buffer file.
5299
5300 If the text to be saved cannot be encoded as specified by this variable,
5301 an alternative encoding is selected by `select-safe-coding-system', which see.
5288 5302
5289 The variable `coding-system-for-write', if non-nil, overrides this variable. 5303 The variable `coding-system-for-write', if non-nil, overrides this variable.
5290 5304
5291 This variable is never applied to a way of decoding a file while reading it. */); 5305 This variable is never applied to a way of decoding a file while reading it. */);
5292 5306
5466 the variable's value remains nil. That prevents the error 5480 the variable's value remains nil. That prevents the error
5467 from happening repeatedly and making Emacs nonfunctional. */); 5481 from happening repeatedly and making Emacs nonfunctional. */);
5468 Vbefore_change_functions = Qnil; 5482 Vbefore_change_functions = Qnil;
5469 5483
5470 DEFVAR_LISP ("after-change-functions", &Vafter_change_functions, 5484 DEFVAR_LISP ("after-change-functions", &Vafter_change_functions,
5471 doc: /* List of function to call after each text change. 5485 doc: /* List of functions to call after each text change.
5472 Three arguments are passed to each function: the positions of 5486 Three arguments are passed to each function: the positions of
5473 the beginning and end of the range of changed text, 5487 the beginning and end of the range of changed text,
5474 and the length in bytes of the pre-change text replaced by that range. 5488 and the length in bytes of the pre-change text replaced by that range.
5475 \(For an insertion, the pre-change length is zero; 5489 \(For an insertion, the pre-change length is zero;
5476 for a deletion, that length is the number of bytes deleted, 5490 for a deletion, that length is the number of bytes deleted,