diff options
| author | Eli Zaretskii | 2021-09-22 10:07:25 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2021-09-22 10:07:25 +0300 |
| commit | 7973227f67cd8ea4a1ed590ebc279b34ece86c12 (patch) | |
| tree | 53a0482ef7ef8fd33f34ae9a4cf3e62ddc28227b /src | |
| parent | 3d575534d43802552f59eb1b990939cb3412d4e9 (diff) | |
| download | emacs-7973227f67cd8ea4a1ed590ebc279b34ece86c12.tar.gz emacs-7973227f67cd8ea4a1ed590ebc279b34ece86c12.zip | |
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')
| -rw-r--r-- | src/buffer.h | 11 | ||||
| -rw-r--r-- | src/eval.c | 3 | ||||
| -rw-r--r-- | src/lisp.h | 8 |
3 files changed, 19 insertions, 3 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 }; | |||
| 60 | 60 | ||
| 61 | /* Macros for the addresses of places in the buffer. */ | 61 | /* Macros for the addresses of places in the buffer. */ |
| 62 | 62 | ||
| 63 | /* WARNING: Use the 'char *' pointers to buffer text with care in code | ||
| 64 | that could GC: GC can relocate buffer text, invalidating such | ||
| 65 | pointers. It is best to use character or byte position instead, | ||
| 66 | delaying the access through BYTE_POS_ADDR etc. pointers to the | ||
| 67 | latest possible moment. If you must use the 'char *' pointers | ||
| 68 | (e.g., for speed), be sure to adjust them after any call that could | ||
| 69 | potentially GC. */ | ||
| 70 | |||
| 63 | /* Address of beginning of buffer. */ | 71 | /* Address of beginning of buffer. */ |
| 64 | #define BEG_ADDR (current_buffer->text->beg) | 72 | #define BEG_ADDR (current_buffer->text->beg) |
| 65 | 73 | ||
| @@ -1002,6 +1010,9 @@ SET_BUF_PT_BOTH (struct buffer *buf, ptrdiff_t charpos, ptrdiff_t byte) | |||
| 1002 | or convert between a byte position and an address. | 1010 | or convert between a byte position and an address. |
| 1003 | These functions do not check that the position is in range. */ | 1011 | These functions do not check that the position is in range. */ |
| 1004 | 1012 | ||
| 1013 | /* See the important WARNING above about using the 'char *' pointers | ||
| 1014 | returned by these functions. */ | ||
| 1015 | |||
| 1005 | /* Return the address of byte position N in current buffer. */ | 1016 | /* Return the address of byte position N in current buffer. */ |
| 1006 | 1017 | ||
| 1007 | INLINE unsigned char * | 1018 | INLINE unsigned char * |
diff --git a/src/eval.c b/src/eval.c index 76fe671b6dd..2bb7cfe6002 100644 --- a/src/eval.c +++ b/src/eval.c | |||
| @@ -364,9 +364,6 @@ do_debug_on_call (Lisp_Object code, ptrdiff_t count) | |||
| 364 | call_debugger (list1 (code)); | 364 | call_debugger (list1 (code)); |
| 365 | } | 365 | } |
| 366 | 366 | ||
| 367 | /* NOTE!!! Every function that can call EVAL must protect its args | ||
| 368 | and temporaries from garbage collection while it needs them. | ||
| 369 | The definition of `For' shows what you have to do. */ | ||
| 370 | 367 | ||
| 371 | DEFUN ("or", For, Sor, 0, UNEVALLED, 0, | 368 | DEFUN ("or", For, Sor, 0, UNEVALLED, 0, |
| 372 | doc: /* Eval args until one of them yields non-nil, then return that value. | 369 | doc: /* Eval args until one of them yields non-nil, then return that value. |
diff --git a/src/lisp.h b/src/lisp.h index 720e621d19c..09e0b8e9bda 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -1555,6 +1555,14 @@ STRING_MULTIBYTE (Lisp_Object str) | |||
| 1555 | 1555 | ||
| 1556 | /* Convenience functions for dealing with Lisp strings. */ | 1556 | /* Convenience functions for dealing with Lisp strings. */ |
| 1557 | 1557 | ||
| 1558 | /* WARNING: Use the 'char *' pointers to string data with care in code | ||
| 1559 | that could GC: GC can relocate string data, invalidating such | ||
| 1560 | pointers. It is best to use string character or byte index | ||
| 1561 | instead, delaying the access through SDATA/SSDATA pointers to the | ||
| 1562 | latest possible moment. If you must use the 'char *' pointers | ||
| 1563 | (e.g., for speed), be sure to adjust them after any call that could | ||
| 1564 | potentially GC. */ | ||
| 1565 | |||
| 1558 | INLINE unsigned char * | 1566 | INLINE unsigned char * |
| 1559 | SDATA (Lisp_Object string) | 1567 | SDATA (Lisp_Object string) |
| 1560 | { | 1568 | { |