diff options
author | Eli Zaretskii <eliz@gnu.org> | 2021-09-22 10:07:25 +0300 |
---|---|---|
committer | Eli Zaretskii <eliz@gnu.org> | 2021-09-22 10:07:25 +0300 |
commit | 7973227f67cd8ea4a1ed590ebc279b34ece86c12 (patch) | |
tree | 53a0482ef7ef8fd33f34ae9a4cf3e62ddc28227b /src/buffer.h | |
parent | 3d575534d43802552f59eb1b990939cb3412d4e9 (diff) | |
download | emacs-7973227f67cd8ea4a1ed590ebc279b34ece86c12.tar.gz |
Update comments warning about GC-resistant C programming
* src/eval.c: Remove an outdated comment about protection from GC.
* src/buffer.h:
* src/lisp.h: Add warnings about using 'char *' pointers to text
of Lisp strings and buffer text in code that could GC. Reported by
Po Lu <luangruo@yahoo.com>
Diffstat (limited to 'src/buffer.h')
-rw-r--r-- | src/buffer.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/buffer.h b/src/buffer.h index 24e9c3fcbc8..8623bed08e6 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -60,6 +60,14 @@ enum { BEG = 1, BEG_BYTE = BEG }; /* Macros for the addresses of places in the buffer. */ +/* WARNING: Use the 'char *' pointers to buffer text with care in code + that could GC: GC can relocate buffer text, invalidating such + pointers. It is best to use character or byte position instead, + delaying the access through BYTE_POS_ADDR etc. pointers to the + latest possible moment. If you must use the 'char *' pointers + (e.g., for speed), be sure to adjust them after any call that could + potentially GC. */ + /* Address of beginning of buffer. */ #define BEG_ADDR (current_buffer->text->beg) @@ -1002,6 +1010,9 @@ SET_BUF_PT_BOTH (struct buffer *buf, ptrdiff_t charpos, ptrdiff_t byte) or convert between a byte position and an address. These functions do not check that the position is in range. */ +/* See the important WARNING above about using the 'char *' pointers + returned by these functions. */ + /* Return the address of byte position N in current buffer. */ INLINE unsigned char * |