1.1.13: will be tagged as "sbcl-1.1.13"
[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 "sbcl.h"
15 #include "runtime.h"
16 #include "os.h"
17 #include "search.h"
18 #include "thread.h"
19 #include "genesis/primitive-objects.h"
20
21 boolean search_for_type(int type, lispobj **start, int *count)
22 {
23     lispobj obj;
24
25     while ((*count == -1 || (*count > 0)) &&
26            is_valid_lisp_addr((os_vm_address_t)*start)) {
27         obj = **start;
28         if (*count != -1)
29             *count -= 2;
30
31         if (widetag_of(obj) == type)
32             return 1;
33
34         (*start) += 2;
35     }
36     return 0;
37 }
38
39 boolean search_for_symbol(char *name, lispobj **start, int *count)
40 {
41     struct symbol *symbol;
42     struct vector *symbol_name;
43
44     while (search_for_type(SYMBOL_HEADER_WIDETAG, start, count)) {
45         symbol = (struct symbol *)native_pointer((lispobj)*start);
46         if (lowtag_of(symbol->name) == OTHER_POINTER_LOWTAG) {
47             symbol_name = (struct vector *)native_pointer(symbol->name);
48             if (is_valid_lisp_addr((os_vm_address_t)symbol_name) &&
49                 /* FIXME: Broken with more than one type of string
50                    (i.e. even broken given (VECTOR NIL) */
51                 widetag_of(symbol_name->header) == SIMPLE_BASE_STRING_WIDETAG &&
52                 strcmp((char *)symbol_name->data, name) == 0)
53                 return 1;
54         }
55         (*start) += 2;
56     }
57     return 0;
58 }