Mercurial > emacs
comparison src/lisp.h @ 57724:80393689541a
(USE_SAFE_ALLOCA): Add and init sa_must_free integer.
(SAFE_ALLOCA, SAFE_ALLOCA_LISP): Increment it when malloc is used.
(SAFE_FREE): Test it to determine if we need to unwind to free.
Remove size arg. All users changed.
(SAFE_FREE_LISP) Remove. All users changed to use SAFE_FREE.
author | Kim F. Storm <storm@cua.dk> |
---|---|
date | Tue, 26 Oct 2004 22:37:02 +0000 |
parents | e624ae20de7c |
children | c955f6add62a 4056279af756 3a5b83e18d41 |
comparison
equal
deleted
inserted
replaced
57723:6a65cb24e1be | 57724:80393689541a |
---|---|
3261 #define MAX_ALLOCA 16*1024 | 3261 #define MAX_ALLOCA 16*1024 |
3262 | 3262 |
3263 extern Lisp_Object safe_alloca_unwind (Lisp_Object); | 3263 extern Lisp_Object safe_alloca_unwind (Lisp_Object); |
3264 | 3264 |
3265 #define USE_SAFE_ALLOCA \ | 3265 #define USE_SAFE_ALLOCA \ |
3266 int sa_count = SPECPDL_INDEX () | 3266 int sa_count = SPECPDL_INDEX (), sa_must_free = 0 |
3267 | 3267 |
3268 /* SAFE_ALLOCA allocates a simple buffer. */ | 3268 /* SAFE_ALLOCA allocates a simple buffer. */ |
3269 | 3269 |
3270 #define SAFE_ALLOCA(buf, type, size) \ | 3270 #define SAFE_ALLOCA(buf, type, size) \ |
3271 do { \ | 3271 do { \ |
3272 if ((size) < MAX_ALLOCA) \ | 3272 if ((size) < MAX_ALLOCA) \ |
3273 buf = (type) alloca (size); \ | 3273 buf = (type) alloca (size); \ |
3274 else \ | 3274 else \ |
3275 { \ | 3275 { \ |
3276 buf = (type) xmalloc (size); \ | 3276 buf = (type) xmalloc (size); \ |
3277 sa_must_free++; \ | |
3277 record_unwind_protect (safe_alloca_unwind, \ | 3278 record_unwind_protect (safe_alloca_unwind, \ |
3278 make_save_value (buf, 0)); \ | 3279 make_save_value (buf, 0)); \ |
3279 } \ | 3280 } \ |
3280 } while (0) | 3281 } while (0) |
3281 | 3282 |
3282 /* SAFE_FREE frees xmalloced memory and enables GC as needed. */ | 3283 /* SAFE_FREE frees xmalloced memory and enables GC as needed. */ |
3283 | 3284 |
3284 #define SAFE_FREE(size) \ | 3285 #define SAFE_FREE() \ |
3285 do { \ | 3286 do { \ |
3286 if ((size) >= MAX_ALLOCA) \ | 3287 if (sa_must_free) { \ |
3288 sa_must_free = 0; \ | |
3287 unbind_to (sa_count, Qnil); \ | 3289 unbind_to (sa_count, Qnil); \ |
3290 } \ | |
3288 } while (0) | 3291 } while (0) |
3289 | 3292 |
3290 | 3293 |
3291 /* SAFE_ALLOCA_LISP allocates an array of Lisp_Objects. */ | 3294 /* SAFE_ALLOCA_LISP allocates an array of Lisp_Objects. */ |
3292 | 3295 |
3299 { \ | 3302 { \ |
3300 Lisp_Object arg_; \ | 3303 Lisp_Object arg_; \ |
3301 buf = (Lisp_Object *) xmalloc (size_); \ | 3304 buf = (Lisp_Object *) xmalloc (size_); \ |
3302 arg_ = make_save_value (buf, nelt); \ | 3305 arg_ = make_save_value (buf, nelt); \ |
3303 XSAVE_VALUE (arg_)->dogc = 1; \ | 3306 XSAVE_VALUE (arg_)->dogc = 1; \ |
3307 sa_must_free++; \ | |
3304 record_unwind_protect (safe_alloca_unwind, arg_); \ | 3308 record_unwind_protect (safe_alloca_unwind, arg_); \ |
3305 } \ | 3309 } \ |
3306 } while (0) | 3310 } while (0) |
3307 | 3311 |
3308 #define SAFE_FREE_LISP(nelt) \ | |
3309 do { \ | |
3310 if (((nelt) * sizeof (Lisp_Object)) >= MAX_ALLOCA) \ | |
3311 unbind_to (sa_count, Qnil); \ | |
3312 } while (0) | |
3313 | |
3314 | |
3315 | 3312 |
3316 #endif /* EMACS_LISP_H */ | 3313 #endif /* EMACS_LISP_H */ |
3317 | 3314 |
3318 /* arch-tag: 9b2ed020-70eb-47ac-94ee-e1c2a5107d5e | 3315 /* arch-tag: 9b2ed020-70eb-47ac-94ee-e1c2a5107d5e |
3319 (do not change this comment) */ | 3316 (do not change this comment) */ |