diff options
Diffstat (limited to 'src/lisp.h')
| -rw-r--r-- | src/lisp.h | 63 |
1 files changed, 53 insertions, 10 deletions
diff --git a/src/lisp.h b/src/lisp.h index 40e4821bc10..5c81bc5dd8a 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -1388,7 +1388,50 @@ enum | |||
| 1388 | SAVE_OBJECT | 1388 | SAVE_OBJECT |
| 1389 | }; | 1389 | }; |
| 1390 | 1390 | ||
| 1391 | /* Special object used to hold a different values for later use. */ | 1391 | /* Special object used to hold a different values for later use. |
| 1392 | |||
| 1393 | This is mostly used to package C integers and pointers to call | ||
| 1394 | record_unwind_protect. Typical task is to pass just one C pointer | ||
| 1395 | to unwind function. You should pack pointer with make_save_pointer | ||
| 1396 | and then get it back with XSAVE_POINTER, e.g.: | ||
| 1397 | |||
| 1398 | ... | ||
| 1399 | struct my_data *md = get_my_data (); | ||
| 1400 | record_unwind_protect (my_unwind, make_save_pointer (md)); | ||
| 1401 | ... | ||
| 1402 | |||
| 1403 | Lisp_Object my_unwind (Lisp_Object arg) | ||
| 1404 | { | ||
| 1405 | struct my_data *md = XSAVE_POINTER (arg, 0); | ||
| 1406 | ... | ||
| 1407 | } | ||
| 1408 | |||
| 1409 | If yon need to pass more than just one C pointer, you should | ||
| 1410 | use make_save_value. This function allows you to pack up to | ||
| 1411 | 4 integers, pointers or Lisp_Objects and conveniently get them | ||
| 1412 | back with XSAVE_POINTER, XSAVE_INTEGER and XSAVE_OBJECT macros: | ||
| 1413 | |||
| 1414 | ... | ||
| 1415 | struct my_data *md = get_my_data (); | ||
| 1416 | ptrdiff_t my_offset = get_my_offset (); | ||
| 1417 | Lisp_Object my_object = get_my_object (); | ||
| 1418 | record_unwind_protect | ||
| 1419 | (my_unwind, make_save_value ("pio", md, my_offset, my_object)); | ||
| 1420 | ... | ||
| 1421 | |||
| 1422 | Lisp_Object my_unwind (Lisp_Object arg) | ||
| 1423 | { | ||
| 1424 | struct my_data *md = XSAVE_POINTER (arg, 0); | ||
| 1425 | ptrdiff_t my_offset = XSAVE_INTEGER (arg, 1); | ||
| 1426 | Lisp_Object my_object = XSAVE_OBJECT (arg, 2); | ||
| 1427 | ... | ||
| 1428 | } | ||
| 1429 | |||
| 1430 | If ENABLE_CHECKING is in effect, XSAVE_xxx macros do type checking of the | ||
| 1431 | saved objects and raise eassert if type of the saved object doesn't match | ||
| 1432 | the type which is extracted. In the example above, XSAVE_INTEGER (arg, 2) | ||
| 1433 | or XSAVE_OBJECT (arg, 1) are wrong because integer was saved in slot 1 and | ||
| 1434 | Lisp_Object was saved in slot 2 of ARG. */ | ||
| 1392 | 1435 | ||
| 1393 | struct Lisp_Save_Value | 1436 | struct Lisp_Save_Value |
| 1394 | { | 1437 | { |
| @@ -3018,8 +3061,8 @@ extern bool abort_on_gc; | |||
| 3018 | extern Lisp_Object make_float (double); | 3061 | extern Lisp_Object make_float (double); |
| 3019 | extern void display_malloc_warning (void); | 3062 | extern void display_malloc_warning (void); |
| 3020 | extern ptrdiff_t inhibit_garbage_collection (void); | 3063 | extern ptrdiff_t inhibit_garbage_collection (void); |
| 3021 | extern Lisp_Object format_save_value (const char *, ...); | 3064 | extern Lisp_Object make_save_value (const char *, ...); |
| 3022 | extern Lisp_Object make_save_value (void *, ptrdiff_t); | 3065 | extern Lisp_Object make_save_pointer (void *); |
| 3023 | extern Lisp_Object build_overlay (Lisp_Object, Lisp_Object, Lisp_Object); | 3066 | extern Lisp_Object build_overlay (Lisp_Object, Lisp_Object, Lisp_Object); |
| 3024 | extern void free_marker (Lisp_Object); | 3067 | extern void free_marker (Lisp_Object); |
| 3025 | extern void free_cons (struct Lisp_Cons *); | 3068 | extern void free_cons (struct Lisp_Cons *); |
| @@ -3701,16 +3744,16 @@ extern void *record_xmalloc (size_t); | |||
| 3701 | NITEMS items, each of the same type as *BUF. MULTIPLIER must | 3744 | NITEMS items, each of the same type as *BUF. MULTIPLIER must |
| 3702 | positive. The code is tuned for MULTIPLIER being a constant. */ | 3745 | positive. The code is tuned for MULTIPLIER being a constant. */ |
| 3703 | 3746 | ||
| 3704 | #define SAFE_NALLOCA(buf, multiplier, nitems) \ | 3747 | #define SAFE_NALLOCA(buf, multiplier, nitems) \ |
| 3705 | do { \ | 3748 | do { \ |
| 3706 | if ((nitems) <= MAX_ALLOCA / sizeof *(buf) / (multiplier)) \ | 3749 | if ((nitems) <= MAX_ALLOCA / sizeof *(buf) / (multiplier)) \ |
| 3707 | (buf) = alloca (sizeof *(buf) * (multiplier) * (nitems)); \ | 3750 | (buf) = alloca (sizeof *(buf) * (multiplier) * (nitems)); \ |
| 3708 | else \ | 3751 | else \ |
| 3709 | { \ | 3752 | { \ |
| 3710 | (buf) = xnmalloc (nitems, sizeof *(buf) * (multiplier)); \ | 3753 | (buf) = xnmalloc (nitems, sizeof *(buf) * (multiplier)); \ |
| 3711 | sa_must_free = 1; \ | 3754 | sa_must_free = 1; \ |
| 3712 | record_unwind_protect (safe_alloca_unwind, \ | 3755 | record_unwind_protect (safe_alloca_unwind, \ |
| 3713 | make_save_value (buf, 0)); \ | 3756 | make_save_pointer (buf)); \ |
| 3714 | } \ | 3757 | } \ |
| 3715 | } while (0) | 3758 | } while (0) |
| 3716 | 3759 | ||
| @@ -3735,7 +3778,7 @@ extern void *record_xmalloc (size_t); | |||
| 3735 | { \ | 3778 | { \ |
| 3736 | Lisp_Object arg_; \ | 3779 | Lisp_Object arg_; \ |
| 3737 | buf = xmalloc ((nelt) * word_size); \ | 3780 | buf = xmalloc ((nelt) * word_size); \ |
| 3738 | arg_ = make_save_value (buf, nelt); \ | 3781 | arg_ = make_save_value ("pi", buf, nelt); \ |
| 3739 | XSAVE_VALUE (arg_)->area = 1; \ | 3782 | XSAVE_VALUE (arg_)->area = 1; \ |
| 3740 | sa_must_free = 1; \ | 3783 | sa_must_free = 1; \ |
| 3741 | record_unwind_protect (safe_alloca_unwind, arg_); \ | 3784 | record_unwind_protect (safe_alloca_unwind, arg_); \ |