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