0.6.12.48:
[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 "runtime.h"
13 #include "sbcl.h"
14 #include "os.h"
15 #include "search.h"
16
17 boolean search_for_type(int type, lispobj **start, int *count)
18 {
19     lispobj obj, *addr;
20
21     while ((*count == -1 || (*count > 0)) &&
22            is_valid_lisp_addr((os_vm_address_t)*start)) {
23         obj = **start;
24         addr = *start;
25         if (*count != -1)
26             *count -= 2;
27
28         if (TypeOf(obj) == type)
29             return 1;
30
31         (*start) += 2;
32     }
33     return 0;
34 }
35
36 boolean search_for_symbol(char *name, lispobj **start, int *count)
37 {
38     struct symbol *symbol;
39     struct vector *symbol_name;
40
41     while (search_for_type(type_SymbolHeader, start, count)) {
42         symbol = (struct symbol *)native_pointer((lispobj)*start);
43         if (LowtagOf(symbol->name) == type_OtherPointer) {
44             symbol_name = (struct vector *)native_pointer(symbol->name);
45             if (is_valid_lisp_addr((os_vm_address_t)symbol_name) &&
46                 TypeOf(symbol_name->header) == type_SimpleString &&
47                 strcmp((char *)symbol_name->data, name) == 0)
48                 return 1;
49         }
50         (*start) += 2;
51     }
52     return 0;
53 }