0.7.2.6:
[sbcl.git] / src / runtime / search.c
1 /*
2  * This software is part of the SBCL system. See the README file for
3  * more information.
4  *
5  * This software is derived from the CMU CL system, which was
6  * written at Carnegie Mellon University and released into the
7  * public domain. The software is in the public domain and is
8  * provided with absolutely no warranty. See the COPYING and CREDITS
9  * files for more information.
10  */
11
12 #include <string.h>
13
14 #include "runtime.h"
15 #include "sbcl.h"
16 #include "os.h"
17 #include "search.h"
18
19 boolean search_for_type(int type, lispobj **start, int *count)
20 {
21     lispobj obj, *addr;
22
23     while ((*count == -1 || (*count > 0)) &&
24            is_valid_lisp_addr((os_vm_address_t)*start)) {
25         obj = **start;
26         addr = *start;
27         if (*count != -1)
28             *count -= 2;
29
30         if (widetag_of(obj) == type)
31             return 1;
32
33         (*start) += 2;
34     }
35     return 0;
36 }
37
38 boolean search_for_symbol(char *name, lispobj **start, int *count)
39 {
40     struct symbol *symbol;
41     struct vector *symbol_name;
42
43     while (search_for_type(SYMBOL_HEADER_WIDETAG, start, count)) {
44         symbol = (struct symbol *)native_pointer((lispobj)*start);
45         if (lowtag_of(symbol->name) == OTHER_POINTER_LOWTAG) {
46             symbol_name = (struct vector *)native_pointer(symbol->name);
47             if (is_valid_lisp_addr((os_vm_address_t)symbol_name) &&
48                 widetag_of(symbol_name->header) == SIMPLE_STRING_WIDETAG &&
49                 strcmp((char *)symbol_name->data, name) == 0)
50                 return 1;
51         }
52         (*start) += 2;
53     }
54     return 0;
55 }