diff options
| author | Kim F. Storm | 2006-07-28 11:12:23 +0000 |
|---|---|---|
| committer | Kim F. Storm | 2006-07-28 11:12:23 +0000 |
| commit | 7ffb6955ce67ed159ae2386b053df929d6220725 (patch) | |
| tree | 75c36c6fc00ea2d01477d99bdfd73e9a6805a8e8 /src/alloc.c | |
| parent | 4dbdb9eb939fffaa7dcf1b39053913ff1f799c7f (diff) | |
| download | emacs-7ffb6955ce67ed159ae2386b053df929d6220725.tar.gz emacs-7ffb6955ce67ed159ae2386b053df929d6220725.zip | |
(valid_pointer_p): New function (from valid_lisp_object_p).
(valid_lisp_object_p): Use it to check for valid SUBRP obj.
Diffstat (limited to 'src/alloc.c')
| -rw-r--r-- | src/alloc.c | 51 |
1 files changed, 33 insertions, 18 deletions
diff --git a/src/alloc.c b/src/alloc.c index b058b29c697..a861504ab89 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -4606,6 +4606,27 @@ mark_stack () | |||
| 4606 | #endif /* GC_MARK_STACK != 0 */ | 4606 | #endif /* GC_MARK_STACK != 0 */ |
| 4607 | 4607 | ||
| 4608 | 4608 | ||
| 4609 | /* Determine whether it is safe to access memory at address P. */ | ||
| 4610 | int valid_pointer_p (p) | ||
| 4611 | void *p; | ||
| 4612 | { | ||
| 4613 | int fd; | ||
| 4614 | |||
| 4615 | /* Obviously, we cannot just access it (we would SEGV trying), so we | ||
| 4616 | trick the o/s to tell us whether p is a valid pointer. | ||
| 4617 | Unfortunately, we cannot use NULL_DEVICE here, as emacs_write may | ||
| 4618 | not validate p in that case. */ | ||
| 4619 | |||
| 4620 | if ((fd = emacs_open ("__Valid__Lisp__Object__", O_CREAT | O_WRONLY | O_TRUNC, 0666)) >= 0) | ||
| 4621 | { | ||
| 4622 | int valid = (emacs_write (fd, (char *)p, 16) == 16); | ||
| 4623 | emacs_close (fd); | ||
| 4624 | unlink ("__Valid__Lisp__Object__"); | ||
| 4625 | return valid; | ||
| 4626 | } | ||
| 4627 | |||
| 4628 | return -1; | ||
| 4629 | } | ||
| 4609 | 4630 | ||
| 4610 | /* Return 1 if OBJ is a valid lisp object. | 4631 | /* Return 1 if OBJ is a valid lisp object. |
| 4611 | Return 0 if OBJ is NOT a valid lisp object. | 4632 | Return 0 if OBJ is NOT a valid lisp object. |
| @@ -4618,9 +4639,7 @@ valid_lisp_object_p (obj) | |||
| 4618 | Lisp_Object obj; | 4639 | Lisp_Object obj; |
| 4619 | { | 4640 | { |
| 4620 | void *p; | 4641 | void *p; |
| 4621 | #if !GC_MARK_STACK | 4642 | #if GC_MARK_STACK |
| 4622 | int fd; | ||
| 4623 | #else | ||
| 4624 | struct mem_node *m; | 4643 | struct mem_node *m; |
| 4625 | #endif | 4644 | #endif |
| 4626 | 4645 | ||
| @@ -4632,26 +4651,22 @@ valid_lisp_object_p (obj) | |||
| 4632 | return 1; | 4651 | return 1; |
| 4633 | 4652 | ||
| 4634 | #if !GC_MARK_STACK | 4653 | #if !GC_MARK_STACK |
| 4635 | /* We need to determine whether it is safe to access memory at | 4654 | return valid_pointer_p (p); |
| 4636 | address P. Obviously, we cannot just access it (we would SEGV | ||
| 4637 | trying), so we trick the o/s to tell us whether p is a valid | ||
| 4638 | pointer. Unfortunately, we cannot use NULL_DEVICE here, as | ||
| 4639 | emacs_write may not validate p in that case. */ | ||
| 4640 | if ((fd = emacs_open ("__Valid__Lisp__Object__", O_CREAT | O_WRONLY | O_TRUNC, 0666)) >= 0) | ||
| 4641 | { | ||
| 4642 | int valid = (emacs_write (fd, (char *)p, 16) == 16); | ||
| 4643 | emacs_close (fd); | ||
| 4644 | unlink ("__Valid__Lisp__Object__"); | ||
| 4645 | return valid; | ||
| 4646 | } | ||
| 4647 | |||
| 4648 | return -1; | ||
| 4649 | #else | 4655 | #else |
| 4650 | 4656 | ||
| 4651 | m = mem_find (p); | 4657 | m = mem_find (p); |
| 4652 | 4658 | ||
| 4653 | if (m == MEM_NIL) | 4659 | if (m == MEM_NIL) |
| 4654 | return 0; | 4660 | { |
| 4661 | int valid = valid_pointer_p (p); | ||
| 4662 | if (valid <= 0) | ||
| 4663 | return valid; | ||
| 4664 | |||
| 4665 | if (SUBRP (obj)) | ||
| 4666 | return 1; | ||
| 4667 | |||
| 4668 | return 0; | ||
| 4669 | } | ||
| 4655 | 4670 | ||
| 4656 | switch (m->type) | 4671 | switch (m->type) |
| 4657 | { | 4672 | { |